UNPKG

stripe-react-native-apple-pay

Version:

React Native wrapper around Stripe Apple Pay

97 lines (93 loc) 3.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; exports.setApplePayEntitlement = setApplePayEntitlement; exports.setGooglePayMetaData = setGooglePayMetaData; exports.withNoopSwiftFile = void 0; var _configPlugins = require("@expo/config-plugins"); const { addMetaDataItemToMainApplication, getMainApplicationOrThrow, removeMetaDataItemFromMainApplication } = _configPlugins.AndroidConfig.Manifest; const pkg = require('stripe-react-native-apple-pay/package.json'); const withStripe = (config, props) => { config = withStripeIos(config, props); config = withNoopSwiftFile(config); config = withStripeAndroid(config, props); return config; }; const withStripeIos = (expoConfig, { merchantIdentifier }) => { return (0, _configPlugins.withEntitlementsPlist)(expoConfig, config => { config.modResults = setApplePayEntitlement(merchantIdentifier, config.modResults); return config; }); }; /** * Adds the following to the entitlements: * * <key>com.apple.developer.in-app-payments</key> * <array> * <string>[MERCHANT_IDENTIFIER]</string> * </array> */ function setApplePayEntitlement(merchantIdentifiers, entitlements) { const key = 'com.apple.developer.in-app-payments'; const merchants = entitlements[key] ?? []; if (!Array.isArray(merchantIdentifiers)) { merchantIdentifiers = [merchantIdentifiers]; } for (const id of merchantIdentifiers) { if (id && !merchants.includes(id)) { merchants.push(id); } } if (merchants.length) { entitlements[key] = merchants; } return entitlements; } /** * Add a blank Swift file to the Xcode project for Swift compatibility. */ const withNoopSwiftFile = config => { return _configPlugins.IOSConfig.XcodeProjectFile.withBuildSourceFile(config, { filePath: 'noop-file.swift', contents: ['//', '// @generated', '// A blank Swift file must be created for native modules with Swift files to work correctly.', '//', ''].join('\n') }); }; exports.withNoopSwiftFile = withNoopSwiftFile; const withStripeAndroid = (expoConfig, { enableGooglePay = false }) => { return (0, _configPlugins.withAndroidManifest)(expoConfig, config => { config.modResults = setGooglePayMetaData(enableGooglePay, config.modResults); return config; }); }; /** * Adds the following to AndroidManifest.xml: * * <application> * ... * <meta-data * android:name="com.google.android.gms.wallet.api.enabled" * android:value="true|false" /> * </application> */ function setGooglePayMetaData(enabled, modResults) { const GOOGLE_PAY_META_NAME = 'com.google.android.gms.wallet.api.enabled'; const mainApplication = getMainApplicationOrThrow(modResults); if (enabled) { addMetaDataItemToMainApplication(mainApplication, GOOGLE_PAY_META_NAME, 'true'); } else { removeMetaDataItemFromMainApplication(mainApplication, GOOGLE_PAY_META_NAME); } return modResults; } var _default = exports.default = (0, _configPlugins.createRunOncePlugin)(withStripe, pkg.name, pkg.version); //# sourceMappingURL=withStripe.js.map