UNPKG

@adyen/react-native

Version:

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

75 lines (74 loc) 2.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getWrapper = getWrapper; var _reactNative = require("react-native"); var _ComponentMap = require("../ComponentMap"); var _constants = require("../core/constants"); var _ComponentWrapper = require("./ComponentWrapper"); var _ActionHandlingComponentWrapper = require("./ActionHandlingComponentWrapper"); var _DropInModule = require("../modules/DropInModule"); var _AdyenInstant = require("../modules/AdyenInstant"); var _AdyenApplePay = require("../modules/AdyenApplePay"); var _AdyenGooglePay = require("../modules/AdyenGooglePay"); var _DropInComponentWrapper = require("./DropInComponentWrapper"); /** * Get native component capable of handling provided payment method type. */ function getWrapper(typeName, paymentMethods) { switch (typeName) { case 'dropin': case 'dropIn': case 'drop-in': case 'adyendropin': return { nativeComponent: new _DropInComponentWrapper.DropInComponentWrapper({ nativeModule: _DropInModule.AdyenDropIn }) }; case 'applepay': return { nativeComponent: new _ComponentWrapper.ComponentWrapper({ nativeModule: _AdyenApplePay.AdyenApplePay }) }; case 'paywithgoogle': case 'googlepay': return { nativeComponent: new _ActionHandlingComponentWrapper.ActionHandlingComponentWrapper({ nativeModule: _AdyenGooglePay.AdyenGooglePay }) }; default: break; } const paymentMethod = (0, _ComponentMap.find)(paymentMethods, typeName); if (!paymentMethod) { throw new Error(_constants.UNKNOWN_PAYMENT_METHOD_ERROR + typeName); } if (_ComponentMap.UNSUPPORTED_PAYMENT_METHODS.includes(typeName)) { throw new Error(_constants.UNSUPPORTED_PAYMENT_METHOD_ERROR + typeName); } let nativeComponent; if (_ComponentMap.ADDRESS_COMPONENTS.includes(typeName)) { nativeComponent = new _DropInComponentWrapper.DropInComponentWrapper({ nativeModule: _DropInModule.AdyenDropIn }); } else { // New iDEAL not treated as INSTANT on Android var extendedComponentList = _ComponentMap.NATIVE_COMPONENTS; if (_reactNative.Platform.OS === `android`) { extendedComponentList.push(`ideal`); } const nativeModule = extendedComponentList.includes(typeName) ? _DropInModule.AdyenDropIn : _AdyenInstant.AdyenInstant; nativeComponent = new _ActionHandlingComponentWrapper.ActionHandlingComponentWrapper({ nativeModule: nativeModule }); } return { nativeComponent: nativeComponent, paymentMethod: paymentMethod }; } //# sourceMappingURL=getWrapper.js.map