@adyen/react-native
Version:
Wraps Adyen Checkout Drop-In and Components for iOS and Android for convenient use with React Native
55 lines (54 loc) • 2.06 kB
JavaScript
import { ADDRESS_COMPONENTS, find, NATIVE_COMPONENTS, UNSUPPORTED_PAYMENT_METHODS } from '../ComponentMap';
import { UNKNOWN_PAYMENT_METHOD_ERROR, UNSUPPORTED_PAYMENT_METHOD_ERROR } from '../core/constants';
import { ActionHandlingComponentWrapper } from './ActionHandlingComponentWrapper';
import { AdyenDropIn } from '../modules/DropInModule';
import { AdyenInstant } from '../modules/AdyenInstant';
import { AdyenApplePay } from '../modules/AdyenApplePay';
import { AdyenGooglePay } from '../modules/AdyenGooglePay';
import { DropInComponentWrapper } from './DropInComponentWrapper';
/**
* Get native component capable of handling provided payment method type.
*/
export function getWrapper(typeName, paymentMethods) {
switch (typeName) {
case 'dropin':
case 'dropIn':
case 'drop-in':
case 'adyendropin':
return {
nativeComponent: new DropInComponentWrapper()
};
case 'applepay':
return {
nativeComponent: new ActionHandlingComponentWrapper(AdyenApplePay)
};
case 'paywithgoogle':
case 'googlepay':
return {
nativeComponent: new ActionHandlingComponentWrapper(AdyenGooglePay)
};
default:
break;
}
const paymentMethod = find(paymentMethods, typeName);
if (!paymentMethod) {
throw new Error(UNKNOWN_PAYMENT_METHOD_ERROR + typeName);
}
if (UNSUPPORTED_PAYMENT_METHODS.includes(typeName)) {
throw new Error(UNSUPPORTED_PAYMENT_METHOD_ERROR + typeName);
}
let nativeComponent;
// Currently this resolves address lookup and bin lookup callbacks for Dropin-based Card payment.
if (ADDRESS_COMPONENTS.includes(typeName)) {
nativeComponent = new DropInComponentWrapper();
} else {
var extendedComponentList = NATIVE_COMPONENTS;
const nativeModule = extendedComponentList.includes(typeName) ? AdyenDropIn : AdyenInstant;
nativeComponent = new ActionHandlingComponentWrapper(nativeModule);
}
return {
nativeComponent: nativeComponent,
paymentMethod: paymentMethod
};
}
//# sourceMappingURL=getWrapper.js.map