UNPKG

@adyen/react-native

Version:

Wraps Adyen Checkout Drop-In and Components for iOS and Android for convenient use with React Native

55 lines (49 loc) 1.75 kB
"use strict"; import { NativeEventEmitter } from 'react-native'; import { Event } from '../../core'; /** Native module interface specific to Session */ export class SessionWrapper { subscriptions = new Map(); constructor(nativeModule) { this.nativeModule = nativeModule; this.eventEmitter = new NativeEventEmitter(nativeModule); } hide(success, option) { this.nativeModule.hide(success, { message: option?.message ?? '' }); } createSession(session, configuration) { return this.nativeModule.createSession(session, configuration); } /** * Subscribe to session completion events. * @param callback - Called when the session completes successfully. * @returns EmitterSubscription that can be used to remove the listener. */ assignCompletionHandler(callback) { this.subscriptions.get(Event.onSessionComplete)?.remove(); const subscription = this.eventEmitter.addListener(Event.onSessionComplete, callback); this.subscriptions.set(Event.onSessionComplete, subscription); return subscription; } /** * Subscribe to session error events. * @param callback - Called when the session fails with an error. * @returns EmitterSubscription that can be used to remove the listener. */ assignErrorHandler(callback) { this.subscriptions.get(Event.onSessionError)?.remove(); const subscription = this.eventEmitter.addListener(Event.onSessionError, callback); this.subscriptions.set(Event.onSessionError, subscription); return subscription; } /** * Remove all session event listeners. */ removeAllListeners() { this.subscriptions.forEach(sub => sub.remove()); this.subscriptions.clear(); } } //# sourceMappingURL=SessionWrapper.js.map