UNPKG

@adyen/react-native

Version:

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

59 lines (54 loc) 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SessionWrapper = void 0; var _reactNative = require("react-native"); var _core = require("../../core"); /** Native module interface specific to Session */ class SessionWrapper { subscriptions = new Map(); constructor(nativeModule) { this.nativeModule = nativeModule; this.eventEmitter = new _reactNative.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(_core.Event.onSessionComplete)?.remove(); const subscription = this.eventEmitter.addListener(_core.Event.onSessionComplete, callback); this.subscriptions.set(_core.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(_core.Event.onSessionError)?.remove(); const subscription = this.eventEmitter.addListener(_core.Event.onSessionError, callback); this.subscriptions.set(_core.Event.onSessionError, subscription); return subscription; } /** * Remove all session event listeners. */ removeAllListeners() { this.subscriptions.forEach(sub => sub.remove()); this.subscriptions.clear(); } } exports.SessionWrapper = SessionWrapper; //# sourceMappingURL=SessionWrapper.js.map