@adyen/react-native
Version:
Wraps Adyen Checkout Drop-In and Components for iOS and Android for convenient use with React Native
50 lines (49 loc) • 1.52 kB
JavaScript
;
import { ADDRESS_COMPONENTS, NATIVE_COMPONENTS, UNSUPPORTED_PAYMENT_METHODS } from '../../core';
import { AdyenApplePay, AdyenDropIn, AdyenGooglePay, AdyenInstant } from '..';
import { UNKNOWN_PAYMENT_METHOD_ERROR, UNSUPPORTED_PAYMENT_METHOD_ERROR } from './constants';
import { find } from './utils';
/**
* 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: AdyenDropIn
};
case 'applepay':
return {
nativeComponent: AdyenApplePay
};
case 'paywithgoogle':
case 'googlepay':
return {
nativeComponent: 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 = AdyenDropIn;
} else {
nativeComponent = NATIVE_COMPONENTS.includes(typeName) ? AdyenDropIn : AdyenInstant;
}
return {
nativeComponent,
paymentMethod
};
}
//# sourceMappingURL=getWrapper.js.map