UNPKG

@adyen/react-native

Version:

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

49 lines (48 loc) 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkPaymentMethodsResponse = exports.checkConfiguration = void 0; const checkPaymentMethodsResponse = paymentMethodsResponse => { if (paymentMethodsResponse === undefined) { throw new Error('paymentMethodsResponse is undefined. Make sure to make POST `paymentMethods` or call `conext.startSession()`' + 'Try JSON.parse("{...}") your paymentMethodsResponse.'); } if (typeof paymentMethodsResponse === 'string') { throw new TypeError('paymentMethodsResponse was provided but of an incorrect type (should be an object but a string was provided).' + 'Try JSON.parse("{...}") your paymentMethodsResponse.'); } if (Array.isArray(paymentMethodsResponse)) { throw new TypeError('paymentMethodsResponse was provided but of an incorrect type (should be an object but an array was provided).' + 'Please check you are passing the whole response.'); } if (!paymentMethodsResponse?.paymentMethods?.length && !paymentMethodsResponse?.storedPaymentMethods?.length) { console.warn('paymentMethodsResponse was provided but no payment methods were found.'); } return paymentMethodsResponse; }; exports.checkPaymentMethodsResponse = checkPaymentMethodsResponse; const countryCodeRegex = /^[A-Z]{2}$/; const currencyCodeRegex = /^[A-Z]{3}$/; const clientKeyRegex = /^[a-z]{4,8}_[a-zA-Z0-9]{8,128}$/; const checkConfiguration = configuration => { if (!configuration?.returnUrl) { throw new Error(`Parameter returnUrl is required`); } if (configuration?.returnUrl?.startsWith('http')) { console.warn('Your `returnUrl` is not a Custom URL scheme. Make sure `redirectFromIssuerMethod` in `payments` is set to "GET"'); } if (!configuration?.clientKey) { throw new Error(`Parameter clientKey is required`); } else if (!clientKeyRegex.test(configuration.clientKey)) { throw new Error(`Invalid client key: ${configuration.clientKey}. ` + `Valid client key starts with environment name (e.x. 'live_XXXXXXXXXX').`); } if (configuration?.amount && !configuration?.countryCode) { console.warn('To show the amount on the Pay button both amount and countryCode must be set.'); } if (configuration?.amount && !currencyCodeRegex.test(configuration.amount.currency)) { throw new Error(`Invalid currency code: ${configuration.amount.currency}. ` + `The currency code must be in ISO 4217 "alphabetic code" format. Example: "EUR" or "USD". `); } if (configuration?.countryCode && !countryCodeRegex.test(configuration.countryCode)) { throw new Error(`Invalid country code: ${configuration.countryCode}. ` + `The shopper's country code must be in ISO 3166-1 alpha-2 format. Example: "NL" or "US".`); } }; exports.checkConfiguration = checkConfiguration; //# sourceMappingURL=utils.js.map