@adyen/react-native
Version:
Wraps Adyen Checkout Drop-In and Components for iOS and Android for convenient use with React Native
60 lines (59 loc) • 2.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getWrapper = getWrapper;
var _ComponentMap = require("../ComponentMap");
var _constants = require("../core/constants");
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()
};
case 'applepay':
return {
nativeComponent: new _ActionHandlingComponentWrapper.ActionHandlingComponentWrapper(_AdyenApplePay.AdyenApplePay)
};
case 'paywithgoogle':
case 'googlepay':
return {
nativeComponent: new _ActionHandlingComponentWrapper.ActionHandlingComponentWrapper(_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;
// Currently this resolves address lookup and bin lookup callbacks for Dropin-based Card payment.
if (_ComponentMap.ADDRESS_COMPONENTS.includes(typeName)) {
nativeComponent = new _DropInComponentWrapper.DropInComponentWrapper();
} else {
var extendedComponentList = _ComponentMap.NATIVE_COMPONENTS;
const nativeModule = extendedComponentList.includes(typeName) ? _DropInModule.AdyenDropIn : _AdyenInstant.AdyenInstant;
nativeComponent = new _ActionHandlingComponentWrapper.ActionHandlingComponentWrapper(nativeModule);
}
return {
nativeComponent: nativeComponent,
paymentMethod: paymentMethod
};
}
//# sourceMappingURL=getWrapper.js.map