@gmisoftware/react-native-pay 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +223 -220
- package/android/src/main/java/com/margelo/nitro/pay/GooglePayRequestBuilder.kt +37 -10
- package/android/src/main/java/com/margelo/nitro/pay/HybridPaymentHandler.kt +27 -8
- package/ios/HybridPaymentHandler.swift +90 -6
- package/lib/hooks/__tests__/usePaymentCheckout.integration.test.d.ts +1 -0
- package/lib/hooks/__tests__/usePaymentCheckout.integration.test.js +191 -0
- package/lib/hooks/usePaymentCheckout.d.ts +47 -3
- package/lib/hooks/usePaymentCheckout.js +6 -4
- package/lib/plugin/__tests__/index.test.d.ts +1 -0
- package/lib/plugin/__tests__/index.test.js +33 -0
- package/lib/plugin/__tests__/withApplePay.test.d.ts +1 -0
- package/lib/plugin/__tests__/withApplePay.test.js +58 -0
- package/lib/plugin/__tests__/withGooglePay.test.d.ts +1 -0
- package/lib/plugin/__tests__/withGooglePay.test.js +45 -0
- package/lib/plugin/withApplePay.d.ts +1 -0
- package/lib/plugin/withApplePay.js +19 -4
- package/lib/types/Payment.d.ts +2 -1
- package/lib/utils/__tests__/paymentHelpers.test.d.ts +1 -0
- package/lib/utils/__tests__/paymentHelpers.test.js +75 -0
- package/lib/utils/paymentHelpers.d.ts +1 -4
- package/lib/utils/paymentHelpers.js +2 -5
- package/nitrogen/generated/android/NitroPay+autolinking.cmake +1 -1
- package/nitrogen/generated/android/NitroPay+autolinking.gradle +1 -1
- package/nitrogen/generated/android/NitroPayOnLoad.cpp +1 -1
- package/nitrogen/generated/android/NitroPayOnLoad.hpp +1 -1
- package/nitrogen/generated/android/c++/JCNContact.hpp +1 -1
- package/nitrogen/generated/android/c++/JCNContactType.hpp +1 -1
- package/nitrogen/generated/android/c++/JCNLabeledEmailAddress.hpp +1 -1
- package/nitrogen/generated/android/c++/JCNLabeledPhoneNumber.hpp +1 -1
- package/nitrogen/generated/android/c++/JCNLabeledPostalAddress.hpp +1 -1
- package/nitrogen/generated/android/c++/JCNPhoneNumber.hpp +1 -1
- package/nitrogen/generated/android/c++/JCNPostalAddress.hpp +1 -1
- package/nitrogen/generated/android/c++/JFunc_void.hpp +1 -1
- package/nitrogen/generated/android/c++/JGooglePayButtonTheme.hpp +1 -1
- package/nitrogen/generated/android/c++/JGooglePayButtonType.hpp +1 -1
- package/nitrogen/generated/android/c++/JGooglePayEnvironment.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridGooglePayButtonSpec.cpp +1 -1
- package/nitrogen/generated/android/c++/JHybridGooglePayButtonSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridPaymentHandlerSpec.cpp +1 -1
- package/nitrogen/generated/android/c++/JHybridPaymentHandlerSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JPKSecureElementPass.hpp +1 -1
- package/nitrogen/generated/android/c++/JPassActivationState.hpp +1 -1
- package/nitrogen/generated/android/c++/JPayServiceStatus.hpp +1 -1
- package/nitrogen/generated/android/c++/JPaymentItem.hpp +1 -1
- package/nitrogen/generated/android/c++/JPaymentItemType.hpp +1 -1
- package/nitrogen/generated/android/c++/JPaymentMethod.hpp +1 -1
- package/nitrogen/generated/android/c++/JPaymentMethodType.hpp +1 -1
- package/nitrogen/generated/android/c++/JPaymentNetwork.hpp +1 -1
- package/nitrogen/generated/android/c++/JPaymentRequest.hpp +10 -6
- package/nitrogen/generated/android/c++/JPaymentResult.hpp +1 -1
- package/nitrogen/generated/android/c++/JPaymentToken.hpp +1 -1
- package/nitrogen/generated/android/c++/views/JHybridGooglePayButtonStateUpdater.cpp +1 -1
- package/nitrogen/generated/android/c++/views/JHybridGooglePayButtonStateUpdater.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNContact.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNContactType.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNLabeledEmailAddress.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNLabeledPhoneNumber.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNLabeledPostalAddress.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNPhoneNumber.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNPostalAddress.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/Func_void.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/GooglePayButtonTheme.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/GooglePayButtonType.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/GooglePayEnvironment.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/HybridGooglePayButtonSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/HybridPaymentHandlerSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/NitroPayOnLoad.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PKSecureElementPass.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PassActivationState.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PayServiceStatus.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentItem.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentItemType.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentMethod.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentMethodType.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentNetwork.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentRequest.kt +7 -4
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentResult.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentToken.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/views/HybridGooglePayButtonManager.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/views/HybridGooglePayButtonStateUpdater.kt +1 -1
- package/nitrogen/generated/ios/NitroPay+autolinking.rb +1 -1
- package/nitrogen/generated/ios/NitroPay-Swift-Cxx-Bridge.cpp +1 -1
- package/nitrogen/generated/ios/NitroPay-Swift-Cxx-Bridge.hpp +1 -1
- package/nitrogen/generated/ios/NitroPay-Swift-Cxx-Umbrella.hpp +1 -1
- package/nitrogen/generated/ios/NitroPayAutolinking.mm +1 -1
- package/nitrogen/generated/ios/NitroPayAutolinking.swift +1 -1
- package/nitrogen/generated/ios/c++/HybridApplePayButtonSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridApplePayButtonSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/c++/HybridPaymentHandlerSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridPaymentHandlerSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/c++/views/HybridApplePayButtonComponent.mm +1 -1
- package/nitrogen/generated/ios/swift/ApplePayButtonStyle.swift +1 -1
- package/nitrogen/generated/ios/swift/ApplePayButtonType.swift +1 -1
- package/nitrogen/generated/ios/swift/CNContact.swift +1 -1
- package/nitrogen/generated/ios/swift/CNContactType.swift +1 -1
- package/nitrogen/generated/ios/swift/CNLabeledEmailAddress.swift +1 -1
- package/nitrogen/generated/ios/swift/CNLabeledPhoneNumber.swift +1 -1
- package/nitrogen/generated/ios/swift/CNLabeledPostalAddress.swift +1 -1
- package/nitrogen/generated/ios/swift/CNPhoneNumber.swift +1 -1
- package/nitrogen/generated/ios/swift/CNPostalAddress.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_PaymentResult.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +1 -1
- package/nitrogen/generated/ios/swift/GooglePayEnvironment.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridApplePayButtonSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridApplePayButtonSpec_cxx.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridPaymentHandlerSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridPaymentHandlerSpec_cxx.swift +1 -1
- package/nitrogen/generated/ios/swift/PKSecureElementPass.swift +1 -1
- package/nitrogen/generated/ios/swift/PassActivationState.swift +1 -1
- package/nitrogen/generated/ios/swift/PayServiceStatus.swift +1 -1
- package/nitrogen/generated/ios/swift/PaymentItem.swift +1 -1
- package/nitrogen/generated/ios/swift/PaymentItemType.swift +1 -1
- package/nitrogen/generated/ios/swift/PaymentMethod.swift +1 -1
- package/nitrogen/generated/ios/swift/PaymentMethodType.swift +1 -1
- package/nitrogen/generated/ios/swift/PaymentNetwork.swift +1 -1
- package/nitrogen/generated/ios/swift/PaymentRequest.swift +55 -6
- package/nitrogen/generated/ios/swift/PaymentResult.swift +1 -1
- package/nitrogen/generated/ios/swift/PaymentToken.swift +1 -1
- package/nitrogen/generated/shared/c++/ApplePayButtonStyle.hpp +1 -1
- package/nitrogen/generated/shared/c++/ApplePayButtonType.hpp +1 -1
- package/nitrogen/generated/shared/c++/CNContact.hpp +1 -1
- package/nitrogen/generated/shared/c++/CNContactType.hpp +1 -1
- package/nitrogen/generated/shared/c++/CNLabeledEmailAddress.hpp +1 -1
- package/nitrogen/generated/shared/c++/CNLabeledPhoneNumber.hpp +1 -1
- package/nitrogen/generated/shared/c++/CNLabeledPostalAddress.hpp +1 -1
- package/nitrogen/generated/shared/c++/CNPhoneNumber.hpp +1 -1
- package/nitrogen/generated/shared/c++/CNPostalAddress.hpp +1 -1
- package/nitrogen/generated/shared/c++/GooglePayButtonTheme.hpp +1 -1
- package/nitrogen/generated/shared/c++/GooglePayButtonType.hpp +1 -1
- package/nitrogen/generated/shared/c++/GooglePayEnvironment.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridApplePayButtonSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridApplePayButtonSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridGooglePayButtonSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridGooglePayButtonSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridPaymentHandlerSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridPaymentHandlerSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/PKSecureElementPass.hpp +1 -1
- package/nitrogen/generated/shared/c++/PassActivationState.hpp +1 -1
- package/nitrogen/generated/shared/c++/PayServiceStatus.hpp +1 -1
- package/nitrogen/generated/shared/c++/PaymentItem.hpp +1 -1
- package/nitrogen/generated/shared/c++/PaymentItemType.hpp +1 -1
- package/nitrogen/generated/shared/c++/PaymentMethod.hpp +1 -1
- package/nitrogen/generated/shared/c++/PaymentMethodType.hpp +1 -1
- package/nitrogen/generated/shared/c++/PaymentNetwork.hpp +1 -1
- package/nitrogen/generated/shared/c++/PaymentRequest.hpp +10 -6
- package/nitrogen/generated/shared/c++/PaymentResult.hpp +1 -1
- package/nitrogen/generated/shared/c++/PaymentToken.hpp +1 -1
- package/nitrogen/generated/shared/c++/views/HybridApplePayButtonComponent.cpp +1 -1
- package/nitrogen/generated/shared/c++/views/HybridApplePayButtonComponent.hpp +1 -1
- package/nitrogen/generated/shared/c++/views/HybridGooglePayButtonComponent.cpp +1 -1
- package/nitrogen/generated/shared/c++/views/HybridGooglePayButtonComponent.hpp +1 -1
- package/package.json +11 -4
- package/src/hooks/__tests__/usePaymentCheckout.integration.test.ts +244 -0
- package/src/hooks/usePaymentCheckout.ts +60 -5
- package/src/plugin/__tests__/index.test.ts +37 -0
- package/src/plugin/__tests__/withApplePay.test.ts +83 -0
- package/src/plugin/__tests__/withGooglePay.test.ts +66 -0
- package/src/plugin/withApplePay.ts +34 -6
- package/src/types/Payment.ts +4 -1
- package/src/utils/__tests__/paymentHelpers.test.ts +93 -0
- package/src/utils/paymentHelpers.ts +1 -6
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const withApplePay_1 = require("../withApplePay");
|
|
4
|
+
const mockWithEntitlementsPlist = jest.fn((config, action) => action('modResults' in config ? config : { modResults: config }));
|
|
5
|
+
const mockWithInfoPlist = jest.fn((config, action) => action('modResults' in config ? config : { modResults: config }));
|
|
6
|
+
jest.mock('expo/config-plugins', () => ({
|
|
7
|
+
withEntitlementsPlist: (config, action) => mockWithEntitlementsPlist(config, action),
|
|
8
|
+
withInfoPlist: (config, action) => mockWithInfoPlist(config, action),
|
|
9
|
+
}));
|
|
10
|
+
describe('withApplePay', () => {
|
|
11
|
+
it('adds a single merchant entitlement', () => {
|
|
12
|
+
const result = (0, withApplePay_1.setApplePayEntitlement)('merchant.com.one', {});
|
|
13
|
+
expect(result).toEqual({
|
|
14
|
+
'com.apple.developer.in-app-payments': ['merchant.com.one'],
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
it('adds multiple merchants and de-duplicates existing values', () => {
|
|
18
|
+
const result = (0, withApplePay_1.setApplePayEntitlement)(['merchant.com.a', 'merchant.com.b', 'merchant.com.a', ''], {
|
|
19
|
+
'com.apple.developer.in-app-payments': ['merchant.com.a'],
|
|
20
|
+
});
|
|
21
|
+
expect(result).toEqual({
|
|
22
|
+
'com.apple.developer.in-app-payments': [
|
|
23
|
+
'merchant.com.a',
|
|
24
|
+
'merchant.com.b',
|
|
25
|
+
],
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
it('writes merchant identifiers into Info.plist', () => {
|
|
29
|
+
const result = (0, withApplePay_1.setApplePayMerchantIdentifiersInInfoPlist)(['merchant.com.a', 'merchant.com.b', 'merchant.com.a', ''], {});
|
|
30
|
+
expect(result).toEqual({
|
|
31
|
+
ReactNativePayApplePayMerchantIdentifiers: [
|
|
32
|
+
'merchant.com.a',
|
|
33
|
+
'merchant.com.b',
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
it('does not modify config when merchantIdentifier is missing', () => {
|
|
38
|
+
const config = { name: 'app' };
|
|
39
|
+
const result = (0, withApplePay_1.withApplePay)(config, {});
|
|
40
|
+
expect(result).toBe(config);
|
|
41
|
+
expect(mockWithEntitlementsPlist).not.toHaveBeenCalled();
|
|
42
|
+
expect(mockWithInfoPlist).not.toHaveBeenCalled();
|
|
43
|
+
});
|
|
44
|
+
it('applies entitlements when merchantIdentifier is provided', () => {
|
|
45
|
+
const config = {};
|
|
46
|
+
const result = (0, withApplePay_1.withApplePay)(config, {
|
|
47
|
+
merchantIdentifier: 'merchant.com.test',
|
|
48
|
+
});
|
|
49
|
+
expect(mockWithEntitlementsPlist).toHaveBeenCalledTimes(1);
|
|
50
|
+
expect(mockWithInfoPlist).toHaveBeenCalledTimes(1);
|
|
51
|
+
expect(result).toEqual({
|
|
52
|
+
modResults: {
|
|
53
|
+
'com.apple.developer.in-app-payments': ['merchant.com.test'],
|
|
54
|
+
ReactNativePayApplePayMerchantIdentifiers: ['merchant.com.test'],
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mockAddMetaDataItemToMainApplication = jest.fn();
|
|
4
|
+
const mockGetMainApplicationOrThrow = jest.fn();
|
|
5
|
+
const mockRemoveMetaDataItemFromMainApplication = jest.fn();
|
|
6
|
+
const mockWithAndroidManifest = jest.fn((config, action) => action({ modResults: config }));
|
|
7
|
+
jest.mock('expo/config-plugins', () => ({
|
|
8
|
+
AndroidConfig: {
|
|
9
|
+
Manifest: {
|
|
10
|
+
addMetaDataItemToMainApplication: (...args) => mockAddMetaDataItemToMainApplication(...args),
|
|
11
|
+
getMainApplicationOrThrow: (...args) => mockGetMainApplicationOrThrow(...args),
|
|
12
|
+
removeMetaDataItemFromMainApplication: (...args) => mockRemoveMetaDataItemFromMainApplication(...args),
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
withAndroidManifest: (config, action) => mockWithAndroidManifest(config, action),
|
|
16
|
+
}));
|
|
17
|
+
const withGooglePay_1 = require("../withGooglePay");
|
|
18
|
+
describe('withGooglePay', () => {
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
mockGetMainApplicationOrThrow.mockReturnValue({ name: 'main-app' });
|
|
21
|
+
});
|
|
22
|
+
it('enables Google Pay metadata when enabled=true', () => {
|
|
23
|
+
const manifest = { application: [] };
|
|
24
|
+
const result = (0, withGooglePay_1.setGooglePayMetaData)(true, manifest);
|
|
25
|
+
expect(result).toBe(manifest);
|
|
26
|
+
expect(mockGetMainApplicationOrThrow).toHaveBeenCalledWith(manifest);
|
|
27
|
+
expect(mockAddMetaDataItemToMainApplication).toHaveBeenCalledWith({ name: 'main-app' }, 'com.google.android.gms.wallet.api.enabled', 'true');
|
|
28
|
+
expect(mockRemoveMetaDataItemFromMainApplication).not.toHaveBeenCalled();
|
|
29
|
+
});
|
|
30
|
+
it('removes Google Pay metadata when enabled=false', () => {
|
|
31
|
+
const manifest = { application: [] };
|
|
32
|
+
const result = (0, withGooglePay_1.setGooglePayMetaData)(false, manifest);
|
|
33
|
+
expect(result).toBe(manifest);
|
|
34
|
+
expect(mockGetMainApplicationOrThrow).toHaveBeenCalledWith(manifest);
|
|
35
|
+
expect(mockRemoveMetaDataItemFromMainApplication).toHaveBeenCalledWith({ name: 'main-app' }, 'com.google.android.gms.wallet.api.enabled');
|
|
36
|
+
expect(mockAddMetaDataItemToMainApplication).not.toHaveBeenCalled();
|
|
37
|
+
});
|
|
38
|
+
it('wires withAndroidManifest and applies metadata by plugin prop', () => {
|
|
39
|
+
const config = { name: 'app' };
|
|
40
|
+
const result = (0, withGooglePay_1.withGooglePay)(config, { enableGooglePay: true });
|
|
41
|
+
expect(mockWithAndroidManifest).toHaveBeenCalledTimes(1);
|
|
42
|
+
expect(result).toEqual({ modResults: { name: 'app' } });
|
|
43
|
+
expect(mockAddMetaDataItemToMainApplication).toHaveBeenCalled();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ConfigPlugin } from 'expo/config-plugins';
|
|
2
2
|
import type { ReactNativePayPluginProps } from './type';
|
|
3
3
|
export declare function setApplePayEntitlement(merchantIdentifiers: string | string[], entitlements: Record<string, any>): Record<string, any>;
|
|
4
|
+
export declare function setApplePayMerchantIdentifiersInInfoPlist(merchantIdentifiers: string | string[], infoPlist: Record<string, any>): Record<string, any>;
|
|
4
5
|
export declare const withApplePay: ConfigPlugin<ReactNativePayPluginProps>;
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withApplePay = void 0;
|
|
4
4
|
exports.setApplePayEntitlement = setApplePayEntitlement;
|
|
5
|
+
exports.setApplePayMerchantIdentifiersInInfoPlist = setApplePayMerchantIdentifiersInInfoPlist;
|
|
5
6
|
const config_plugins_1 = require("expo/config-plugins");
|
|
7
|
+
const APPLE_PAY_ENTITLEMENT_KEY = 'com.apple.developer.in-app-payments';
|
|
8
|
+
const APPLE_PAY_INFO_PLIST_KEY = 'ReactNativePayApplePayMerchantIdentifiers';
|
|
6
9
|
function setApplePayEntitlement(merchantIdentifiers, entitlements) {
|
|
7
|
-
const
|
|
8
|
-
const merchants = entitlements[key] ?? [];
|
|
10
|
+
const merchants = entitlements[APPLE_PAY_ENTITLEMENT_KEY] ?? [];
|
|
9
11
|
if (!Array.isArray(merchantIdentifiers)) {
|
|
10
12
|
merchantIdentifiers = [merchantIdentifiers];
|
|
11
13
|
}
|
|
@@ -15,18 +17,31 @@ function setApplePayEntitlement(merchantIdentifiers, entitlements) {
|
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
if (merchants.length) {
|
|
18
|
-
entitlements[
|
|
20
|
+
entitlements[APPLE_PAY_ENTITLEMENT_KEY] = merchants;
|
|
19
21
|
}
|
|
20
22
|
return entitlements;
|
|
21
23
|
}
|
|
24
|
+
function setApplePayMerchantIdentifiersInInfoPlist(merchantIdentifiers, infoPlist) {
|
|
25
|
+
const merchants = Array.isArray(merchantIdentifiers)
|
|
26
|
+
? merchantIdentifiers.filter(Boolean)
|
|
27
|
+
: [merchantIdentifiers].filter(Boolean);
|
|
28
|
+
if (merchants.length) {
|
|
29
|
+
infoPlist[APPLE_PAY_INFO_PLIST_KEY] = [...new Set(merchants)];
|
|
30
|
+
}
|
|
31
|
+
return infoPlist;
|
|
32
|
+
}
|
|
22
33
|
const withApplePay = (expoConfig, { merchantIdentifier }) => {
|
|
23
34
|
// If merchantIdentifier is not passed Apple Pay won't be initialize
|
|
24
35
|
if (!merchantIdentifier) {
|
|
25
36
|
return expoConfig;
|
|
26
37
|
}
|
|
27
|
-
|
|
38
|
+
const withEntitlements = (0, config_plugins_1.withEntitlementsPlist)(expoConfig, (config) => {
|
|
28
39
|
config.modResults = setApplePayEntitlement(merchantIdentifier, config.modResults);
|
|
29
40
|
return config;
|
|
30
41
|
});
|
|
42
|
+
return (0, config_plugins_1.withInfoPlist)(withEntitlements, (config) => {
|
|
43
|
+
config.modResults = setApplePayMerchantIdentifiersInInfoPlist(merchantIdentifier, config.modResults);
|
|
44
|
+
return config;
|
|
45
|
+
});
|
|
31
46
|
};
|
|
32
47
|
exports.withApplePay = withApplePay;
|
package/lib/types/Payment.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export interface PaymentToken {
|
|
|
40
40
|
paymentData: string;
|
|
41
41
|
}
|
|
42
42
|
export interface PaymentRequest {
|
|
43
|
-
|
|
43
|
+
applePayMerchantIdentifier?: string;
|
|
44
44
|
merchantName?: string;
|
|
45
45
|
countryCode: string;
|
|
46
46
|
currencyCode: string;
|
|
@@ -51,6 +51,7 @@ export interface PaymentRequest {
|
|
|
51
51
|
shippingMethods?: PaymentItem[];
|
|
52
52
|
billingContactRequired?: boolean;
|
|
53
53
|
shippingContactRequired?: boolean;
|
|
54
|
+
googlePayMerchantId?: string;
|
|
54
55
|
googlePayEnvironment?: GooglePayEnvironment;
|
|
55
56
|
googlePayGateway?: string;
|
|
56
57
|
googlePayGatewayMerchantId?: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const paymentHelpers_1 = require("../paymentHelpers");
|
|
4
|
+
describe('paymentHelpers', () => {
|
|
5
|
+
it('creates payment items with default and explicit type', () => {
|
|
6
|
+
expect((0, paymentHelpers_1.createPaymentItem)('Coffee', 4.99)).toEqual({
|
|
7
|
+
label: 'Coffee',
|
|
8
|
+
amount: 4.99,
|
|
9
|
+
type: 'final',
|
|
10
|
+
});
|
|
11
|
+
expect((0, paymentHelpers_1.createPaymentItem)('Shipping', 2.5, 'pending')).toEqual({
|
|
12
|
+
label: 'Shipping',
|
|
13
|
+
amount: 2.5,
|
|
14
|
+
type: 'pending',
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
it('calculates totals from line items', () => {
|
|
18
|
+
expect((0, paymentHelpers_1.calculateTotal)([
|
|
19
|
+
(0, paymentHelpers_1.createPaymentItem)('Product', 10),
|
|
20
|
+
(0, paymentHelpers_1.createPaymentItem)('Tax', 2.15),
|
|
21
|
+
(0, paymentHelpers_1.createPaymentItem)('Shipping', 3.35),
|
|
22
|
+
])).toBeCloseTo(15.5);
|
|
23
|
+
});
|
|
24
|
+
it('creates payment requests with sane defaults', () => {
|
|
25
|
+
const request = (0, paymentHelpers_1.createPaymentRequest)({
|
|
26
|
+
amount: 19.99,
|
|
27
|
+
label: 'Pro Plan',
|
|
28
|
+
});
|
|
29
|
+
expect(request).toEqual({
|
|
30
|
+
countryCode: 'US',
|
|
31
|
+
currencyCode: 'USD',
|
|
32
|
+
paymentItems: [{ label: 'Pro Plan', amount: 19.99, type: 'final' }],
|
|
33
|
+
supportedNetworks: [
|
|
34
|
+
paymentHelpers_1.CommonNetworks.VISA,
|
|
35
|
+
paymentHelpers_1.CommonNetworks.MASTERCARD,
|
|
36
|
+
paymentHelpers_1.CommonNetworks.AMEX,
|
|
37
|
+
paymentHelpers_1.CommonNetworks.DISCOVER,
|
|
38
|
+
],
|
|
39
|
+
merchantCapabilities: ['3DS'],
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
it('allows overriding defaults in payment requests', () => {
|
|
43
|
+
const request = (0, paymentHelpers_1.createPaymentRequest)({
|
|
44
|
+
amount: 39.99,
|
|
45
|
+
label: 'Deluxe',
|
|
46
|
+
countryCode: 'PL',
|
|
47
|
+
currencyCode: 'PLN',
|
|
48
|
+
supportedNetworks: ['visa'],
|
|
49
|
+
merchantCapabilities: ['EMV'],
|
|
50
|
+
merchantName: 'My Store',
|
|
51
|
+
applePayMerchantIdentifier: 'merchant.com.apple.override',
|
|
52
|
+
googlePayMerchantId: 'google-pay-merchant-id',
|
|
53
|
+
});
|
|
54
|
+
expect(request.countryCode).toBe('PL');
|
|
55
|
+
expect(request.currencyCode).toBe('PLN');
|
|
56
|
+
expect(request.supportedNetworks).toEqual(['visa']);
|
|
57
|
+
expect(request.merchantCapabilities).toEqual(['EMV']);
|
|
58
|
+
expect(request.merchantName).toBe('My Store');
|
|
59
|
+
expect(request.applePayMerchantIdentifier).toBe('merchant.com.apple.override');
|
|
60
|
+
expect(request.googlePayMerchantId).toBe('google-pay-merchant-id');
|
|
61
|
+
});
|
|
62
|
+
it('formats and parses amount values', () => {
|
|
63
|
+
expect((0, paymentHelpers_1.formatAmount)(29.9)).toBe('29.90');
|
|
64
|
+
expect((0, paymentHelpers_1.parseAmount)('29.90')).toBeCloseTo(29.9);
|
|
65
|
+
});
|
|
66
|
+
it('checks network support using case-insensitive matching', () => {
|
|
67
|
+
expect((0, paymentHelpers_1.isNetworkSupported)('AMEX', ['visa', 'amex'])).toBe(true);
|
|
68
|
+
expect((0, paymentHelpers_1.isNetworkSupported)('discover', ['visa', 'mastercard'])).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
it('formats known payment networks for display', () => {
|
|
71
|
+
expect((0, paymentHelpers_1.formatNetworkName)('visa')).toBe('Visa');
|
|
72
|
+
expect((0, paymentHelpers_1.formatNetworkName)('amex')).toBe('American Express');
|
|
73
|
+
expect((0, paymentHelpers_1.formatNetworkName)('privateLabel')).toBe('Private Label');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
* import { createPaymentRequest, calculateTotal } from 'react-native-pay'
|
|
12
12
|
*
|
|
13
13
|
* const request = createPaymentRequest({
|
|
14
|
-
* merchantIdentifier: 'merchant.com.example',
|
|
15
14
|
* amount: 29.99,
|
|
16
15
|
* label: 'Coffee Subscription'
|
|
17
16
|
* })
|
|
@@ -67,13 +66,12 @@ export declare function calculateTotal(items: PaymentItem[]): number;
|
|
|
67
66
|
* - supportedNetworks: ['visa', 'mastercard', 'amex', 'discover']
|
|
68
67
|
* - merchantCapabilities: ['3DS']
|
|
69
68
|
*
|
|
70
|
-
* @param options - Payment request options (
|
|
69
|
+
* @param options - Payment request options (amount and label required)
|
|
71
70
|
* @returns Complete PaymentRequest object
|
|
72
71
|
*
|
|
73
72
|
* @example
|
|
74
73
|
* ```typescript
|
|
75
74
|
* const request = createPaymentRequest({
|
|
76
|
-
* merchantIdentifier: 'merchant.com.example',
|
|
77
75
|
* amount: 29.99,
|
|
78
76
|
* label: 'Coffee Subscription',
|
|
79
77
|
* countryCode: 'CA', // override default
|
|
@@ -82,7 +80,6 @@ export declare function calculateTotal(items: PaymentItem[]): number;
|
|
|
82
80
|
* ```
|
|
83
81
|
*/
|
|
84
82
|
export declare function createPaymentRequest(options: Partial<PaymentRequest> & {
|
|
85
|
-
merchantIdentifier: string;
|
|
86
83
|
amount: number;
|
|
87
84
|
label: string;
|
|
88
85
|
}): PaymentRequest;
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
* import { createPaymentRequest, calculateTotal } from 'react-native-pay'
|
|
13
13
|
*
|
|
14
14
|
* const request = createPaymentRequest({
|
|
15
|
-
* merchantIdentifier: 'merchant.com.example',
|
|
16
15
|
* amount: 29.99,
|
|
17
16
|
* label: 'Coffee Subscription'
|
|
18
17
|
* })
|
|
@@ -80,13 +79,12 @@ function calculateTotal(items) {
|
|
|
80
79
|
* - supportedNetworks: ['visa', 'mastercard', 'amex', 'discover']
|
|
81
80
|
* - merchantCapabilities: ['3DS']
|
|
82
81
|
*
|
|
83
|
-
* @param options - Payment request options (
|
|
82
|
+
* @param options - Payment request options (amount and label required)
|
|
84
83
|
* @returns Complete PaymentRequest object
|
|
85
84
|
*
|
|
86
85
|
* @example
|
|
87
86
|
* ```typescript
|
|
88
87
|
* const request = createPaymentRequest({
|
|
89
|
-
* merchantIdentifier: 'merchant.com.example',
|
|
90
88
|
* amount: 29.99,
|
|
91
89
|
* label: 'Coffee Subscription',
|
|
92
90
|
* countryCode: 'CA', // override default
|
|
@@ -95,14 +93,13 @@ function calculateTotal(items) {
|
|
|
95
93
|
* ```
|
|
96
94
|
*/
|
|
97
95
|
function createPaymentRequest(options) {
|
|
98
|
-
const {
|
|
96
|
+
const { amount, label, countryCode = 'US', currencyCode = 'USD', supportedNetworks = [
|
|
99
97
|
exports.CommonNetworks.VISA,
|
|
100
98
|
exports.CommonNetworks.MASTERCARD,
|
|
101
99
|
exports.CommonNetworks.AMEX,
|
|
102
100
|
exports.CommonNetworks.DISCOVER,
|
|
103
101
|
], merchantCapabilities = ['3DS'], ...rest } = options;
|
|
104
102
|
return {
|
|
105
|
-
merchantIdentifier,
|
|
106
103
|
countryCode,
|
|
107
104
|
currencyCode,
|
|
108
105
|
paymentItems: [createPaymentItem(label, amount, 'final')],
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# NitroPay+autolinking.cmake
|
|
3
3
|
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
# https://github.com/mrousavy/nitro
|
|
5
|
-
# Copyright ©
|
|
5
|
+
# Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
#
|
|
7
7
|
|
|
8
8
|
# This is a CMake file that adds all files generated by Nitrogen
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// NitroPay+autolinking.gradle
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
/// This is a Gradle file that adds all files generated by Nitrogen
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// NitroPayOnLoad.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#ifndef BUILDING_NITROPAY_WITH_GENERATED_CMAKE_PROJECT
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// JHybridGooglePayButtonSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "JHybridGooglePayButtonSpec.hpp"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// JHybridPaymentHandlerSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "JHybridPaymentHandlerSpec.hpp"
|