UNPKG

@adyen/react-native

Version:

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

48 lines (47 loc) 2.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkPaymentMethodsResponse = exports.checkConfiguration = void 0; var _reactNative = require("react-native"); 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 Error('paymentMethodsResponse was provided but of an incorrect type (should be an object but a string was provided).' + 'Try JSON.parse("{...}") your paymentMethodsResponse.'); } if (paymentMethodsResponse instanceof Array) { throw new Error('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 && !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 && _reactNative.Platform.OS === 'ios' && !configuration.returnUrl) { throw new Error(`Parameter returnUrl is required`); } if (configuration && configuration.returnUrl && 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 && configuration.clientKey && !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 && configuration.amount && !configuration.countryCode) { console.warn('To show the amount on the Pay button both amount and countryCode must be set.'); } if (configuration && 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 && 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