@gmisoftware/react-native-pay 0.0.4
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/NitroPay.podspec +31 -0
- package/README.md +455 -0
- package/android/CMakeLists.txt +29 -0
- package/android/build.gradle +144 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +8 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/pay/Constants.kt +49 -0
- package/android/src/main/java/com/margelo/nitro/pay/GooglePayButtonFactory.kt +95 -0
- package/android/src/main/java/com/margelo/nitro/pay/GooglePayRequestBuilder.kt +170 -0
- package/android/src/main/java/com/margelo/nitro/pay/HybridGooglePayButton.kt +146 -0
- package/android/src/main/java/com/margelo/nitro/pay/HybridPaymentHandler.kt +184 -0
- package/android/src/main/java/com/margelo/nitro/pay/NitroPayPackage.kt +26 -0
- package/android/src/main/java/com/margelo/nitro/pay/PaymentMapper.kt +89 -0
- package/app.plugin.js +1 -0
- package/ios/ApplePayButtonFactory.swift +53 -0
- package/ios/Bridge.h +8 -0
- package/ios/HybridApplePayButton.swift +60 -0
- package/ios/HybridPaymentHandler.swift +248 -0
- package/ios/PassKitTypeMapper.swift +192 -0
- package/lib/hooks/index.d.ts +7 -0
- package/lib/hooks/index.js +10 -0
- package/lib/hooks/usePaymentCheckout.d.ts +95 -0
- package/lib/hooks/usePaymentCheckout.js +183 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +29 -0
- package/lib/plugin/index.d.ts +4 -0
- package/lib/plugin/index.js +10 -0
- package/lib/plugin/type.d.ts +4 -0
- package/lib/plugin/type.js +2 -0
- package/lib/plugin/withApplePay.d.ts +4 -0
- package/lib/plugin/withApplePay.js +32 -0
- package/lib/plugin/withGooglePay.d.ts +4 -0
- package/lib/plugin/withGooglePay.js +24 -0
- package/lib/specs/ApplePayButton.nitro.d.ts +13 -0
- package/lib/specs/ApplePayButton.nitro.js +2 -0
- package/lib/specs/GooglePayButton.nitro.d.ts +14 -0
- package/lib/specs/GooglePayButton.nitro.js +2 -0
- package/lib/specs/PaymentHandler.nitro.d.ts +10 -0
- package/lib/specs/PaymentHandler.nitro.js +2 -0
- package/lib/types/Contact.d.ts +51 -0
- package/lib/types/Contact.js +6 -0
- package/lib/types/Payment.d.ts +67 -0
- package/lib/types/Payment.js +6 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +18 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.js +20 -0
- package/lib/utils/paymentHelpers.d.ts +144 -0
- package/lib/utils/paymentHelpers.js +190 -0
- package/nitro.json +30 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroPay+autolinking.cmake +87 -0
- package/nitrogen/generated/android/NitroPay+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroPayOnLoad.cpp +58 -0
- package/nitrogen/generated/android/NitroPayOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JCNContact.hpp +202 -0
- package/nitrogen/generated/android/c++/JCNContactType.hpp +59 -0
- package/nitrogen/generated/android/c++/JCNLabeledEmailAddress.hpp +62 -0
- package/nitrogen/generated/android/c++/JCNLabeledPhoneNumber.hpp +64 -0
- package/nitrogen/generated/android/c++/JCNLabeledPostalAddress.hpp +64 -0
- package/nitrogen/generated/android/c++/JCNPhoneNumber.hpp +57 -0
- package/nitrogen/generated/android/c++/JCNPostalAddress.hpp +78 -0
- package/nitrogen/generated/android/c++/JFunc_void.hpp +74 -0
- package/nitrogen/generated/android/c++/JGooglePayButtonTheme.hpp +59 -0
- package/nitrogen/generated/android/c++/JGooglePayButtonType.hpp +77 -0
- package/nitrogen/generated/android/c++/JGooglePayEnvironment.hpp +59 -0
- package/nitrogen/generated/android/c++/JHybridGooglePayButtonSpec.cpp +96 -0
- package/nitrogen/generated/android/c++/JHybridGooglePayButtonSpec.hpp +71 -0
- package/nitrogen/generated/android/c++/JHybridPaymentHandlerSpec.cpp +154 -0
- package/nitrogen/generated/android/c++/JHybridPaymentHandlerSpec.hpp +66 -0
- package/nitrogen/generated/android/c++/JPKSecureElementPass.hpp +96 -0
- package/nitrogen/generated/android/c++/JPassActivationState.hpp +68 -0
- package/nitrogen/generated/android/c++/JPayServiceStatus.hpp +61 -0
- package/nitrogen/generated/android/c++/JPaymentItem.hpp +67 -0
- package/nitrogen/generated/android/c++/JPaymentItemType.hpp +59 -0
- package/nitrogen/generated/android/c++/JPaymentMethod.hpp +97 -0
- package/nitrogen/generated/android/c++/JPaymentMethodType.hpp +68 -0
- package/nitrogen/generated/android/c++/JPaymentNetwork.hpp +86 -0
- package/nitrogen/generated/android/c++/JPaymentRequest.hpp +181 -0
- package/nitrogen/generated/android/c++/JPaymentResult.hpp +97 -0
- package/nitrogen/generated/android/c++/JPaymentToken.hpp +91 -0
- package/nitrogen/generated/android/c++/views/JHybridGooglePayButtonStateUpdater.cpp +68 -0
- package/nitrogen/generated/android/c++/views/JHybridGooglePayButtonStateUpdater.hpp +49 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNContact.kt +96 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNContactType.kt +21 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNLabeledEmailAddress.kt +39 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNLabeledPhoneNumber.kt +39 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNLabeledPostalAddress.kt +39 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNPhoneNumber.kt +36 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNPostalAddress.kt +51 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/Func_void.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/GooglePayButtonTheme.kt +21 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/GooglePayButtonType.kt +27 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/GooglePayEnvironment.kt +21 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/HybridGooglePayButtonSpec.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/HybridPaymentHandlerSpec.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/NitroPayOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PKSecureElementPass.kt +63 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PassActivationState.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PayServiceStatus.kt +39 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentItem.kt +42 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentItemType.kt +21 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentMethod.kt +48 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentMethodType.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentNetwork.kt +30 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentRequest.kt +72 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentResult.kt +45 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentToken.kt +42 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/views/HybridGooglePayButtonManager.kt +50 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/views/HybridGooglePayButtonStateUpdater.kt +23 -0
- package/nitrogen/generated/ios/NitroPay+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroPay-Swift-Cxx-Bridge.cpp +73 -0
- package/nitrogen/generated/ios/NitroPay-Swift-Cxx-Bridge.hpp +415 -0
- package/nitrogen/generated/ios/NitroPay-Swift-Cxx-Umbrella.hpp +116 -0
- package/nitrogen/generated/ios/NitroPayAutolinking.mm +41 -0
- package/nitrogen/generated/ios/NitroPayAutolinking.swift +40 -0
- package/nitrogen/generated/ios/c++/HybridApplePayButtonSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridApplePayButtonSpecSwift.hpp +92 -0
- package/nitrogen/generated/ios/c++/HybridPaymentHandlerSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridPaymentHandlerSpecSwift.hpp +148 -0
- package/nitrogen/generated/ios/c++/views/HybridApplePayButtonComponent.mm +106 -0
- package/nitrogen/generated/ios/swift/ApplePayButtonStyle.swift +44 -0
- package/nitrogen/generated/ios/swift/ApplePayButtonType.swift +84 -0
- package/nitrogen/generated/ios/swift/CNContact.swift +329 -0
- package/nitrogen/generated/ios/swift/CNContactType.swift +40 -0
- package/nitrogen/generated/ios/swift/CNLabeledEmailAddress.swift +65 -0
- package/nitrogen/generated/ios/swift/CNLabeledPhoneNumber.swift +65 -0
- package/nitrogen/generated/ios/swift/CNLabeledPostalAddress.swift +65 -0
- package/nitrogen/generated/ios/swift/CNPhoneNumber.swift +35 -0
- package/nitrogen/generated/ios/swift/CNPostalAddress.swift +204 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_PaymentResult.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/GooglePayEnvironment.swift +40 -0
- package/nitrogen/generated/ios/swift/HybridApplePayButtonSpec.swift +51 -0
- package/nitrogen/generated/ios/swift/HybridApplePayButtonSpec_cxx.swift +175 -0
- package/nitrogen/generated/ios/swift/HybridPaymentHandlerSpec.swift +52 -0
- package/nitrogen/generated/ios/swift/HybridPaymentHandlerSpec_cxx.swift +155 -0
- package/nitrogen/generated/ios/swift/PKSecureElementPass.swift +191 -0
- package/nitrogen/generated/ios/swift/PassActivationState.swift +52 -0
- package/nitrogen/generated/ios/swift/PayServiceStatus.swift +46 -0
- package/nitrogen/generated/ios/swift/PaymentItem.swift +57 -0
- package/nitrogen/generated/ios/swift/PaymentItemType.swift +40 -0
- package/nitrogen/generated/ios/swift/PaymentMethod.swift +134 -0
- package/nitrogen/generated/ios/swift/PaymentMethodType.swift +52 -0
- package/nitrogen/generated/ios/swift/PaymentNetwork.swift +76 -0
- package/nitrogen/generated/ios/swift/PaymentRequest.swift +341 -0
- package/nitrogen/generated/ios/swift/PaymentResult.swift +118 -0
- package/nitrogen/generated/ios/swift/PaymentToken.swift +57 -0
- package/nitrogen/generated/shared/c++/ApplePayButtonStyle.hpp +80 -0
- package/nitrogen/generated/shared/c++/ApplePayButtonType.hpp +120 -0
- package/nitrogen/generated/shared/c++/CNContact.hpp +168 -0
- package/nitrogen/generated/shared/c++/CNContactType.hpp +76 -0
- package/nitrogen/generated/shared/c++/CNLabeledEmailAddress.hpp +80 -0
- package/nitrogen/generated/shared/c++/CNLabeledPhoneNumber.hpp +82 -0
- package/nitrogen/generated/shared/c++/CNLabeledPostalAddress.hpp +82 -0
- package/nitrogen/generated/shared/c++/CNPhoneNumber.hpp +75 -0
- package/nitrogen/generated/shared/c++/CNPostalAddress.hpp +96 -0
- package/nitrogen/generated/shared/c++/GooglePayButtonTheme.hpp +76 -0
- package/nitrogen/generated/shared/c++/GooglePayButtonType.hpp +100 -0
- package/nitrogen/generated/shared/c++/GooglePayEnvironment.hpp +76 -0
- package/nitrogen/generated/shared/c++/HybridApplePayButtonSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridApplePayButtonSpec.hpp +73 -0
- package/nitrogen/generated/shared/c++/HybridGooglePayButtonSpec.cpp +28 -0
- package/nitrogen/generated/shared/c++/HybridGooglePayButtonSpec.hpp +75 -0
- package/nitrogen/generated/shared/c++/HybridPaymentHandlerSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridPaymentHandlerSpec.hpp +74 -0
- package/nitrogen/generated/shared/c++/PKSecureElementPass.hpp +114 -0
- package/nitrogen/generated/shared/c++/PassActivationState.hpp +88 -0
- package/nitrogen/generated/shared/c++/PayServiceStatus.hpp +79 -0
- package/nitrogen/generated/shared/c++/PaymentItem.hpp +85 -0
- package/nitrogen/generated/shared/c++/PaymentItemType.hpp +76 -0
- package/nitrogen/generated/shared/c++/PaymentMethod.hpp +103 -0
- package/nitrogen/generated/shared/c++/PaymentMethodType.hpp +88 -0
- package/nitrogen/generated/shared/c++/PaymentNetwork.hpp +112 -0
- package/nitrogen/generated/shared/c++/PaymentRequest.hpp +130 -0
- package/nitrogen/generated/shared/c++/PaymentResult.hpp +90 -0
- package/nitrogen/generated/shared/c++/PaymentToken.hpp +85 -0
- package/nitrogen/generated/shared/c++/views/HybridApplePayButtonComponent.cpp +111 -0
- package/nitrogen/generated/shared/c++/views/HybridApplePayButtonComponent.hpp +111 -0
- package/nitrogen/generated/shared/c++/views/HybridGooglePayButtonComponent.cpp +123 -0
- package/nitrogen/generated/shared/c++/views/HybridGooglePayButtonComponent.hpp +112 -0
- package/nitrogen/generated/shared/json/ApplePayButtonConfig.json +12 -0
- package/nitrogen/generated/shared/json/GooglePayButtonConfig.json +13 -0
- package/package.json +116 -0
- package/react-native.config.js +16 -0
- package/src/hooks/index.ts +12 -0
- package/src/hooks/usePaymentCheckout.ts +281 -0
- package/src/index.ts +32 -0
- package/src/plugin/index.ts +17 -0
- package/src/plugin/type.ts +4 -0
- package/src/plugin/withApplePay.ts +44 -0
- package/src/plugin/withGooglePay.ts +41 -0
- package/src/specs/ApplePayButton.nitro.ts +37 -0
- package/src/specs/GooglePayButton.nitro.ts +34 -0
- package/src/specs/PaymentHandler.nitro.ts +13 -0
- package/src/types/Contact.ts +58 -0
- package/src/types/Payment.ts +104 -0
- package/src/types/index.ts +2 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/paymentHelpers.ts +215 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for payment operations
|
|
3
|
+
*
|
|
4
|
+
* This module provides helper functions for creating and formatting
|
|
5
|
+
* payment requests and related data structures.
|
|
6
|
+
*
|
|
7
|
+
* @module paymentHelpers
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createPaymentRequest, calculateTotal } from 'react-native-pay'
|
|
12
|
+
*
|
|
13
|
+
* const request = createPaymentRequest({
|
|
14
|
+
* merchantIdentifier: 'merchant.com.example',
|
|
15
|
+
* amount: 29.99,
|
|
16
|
+
* label: 'Coffee Subscription'
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import type { PaymentItem, PaymentRequest, PaymentNetwork } from '../types';
|
|
21
|
+
/**
|
|
22
|
+
* Payment networks supported by both Apple Pay and Google Pay
|
|
23
|
+
*/
|
|
24
|
+
export declare const CommonNetworks: {
|
|
25
|
+
readonly VISA: "visa";
|
|
26
|
+
readonly MASTERCARD: "mastercard";
|
|
27
|
+
readonly AMEX: "amex";
|
|
28
|
+
readonly DISCOVER: "discover";
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Creates a payment item with the specified label, amount, and type.
|
|
32
|
+
*
|
|
33
|
+
* @param label - Display label for the payment item
|
|
34
|
+
* @param amount - Amount in the payment currency
|
|
35
|
+
* @param type - Item type: 'final' for confirmed amounts, 'pending' for estimates
|
|
36
|
+
* @returns A PaymentItem object
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const item = createPaymentItem('Subscription', 29.99, 'final')
|
|
41
|
+
* const shipping = createPaymentItem('Shipping', 5.00, 'pending')
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function createPaymentItem(label: string, amount: number, type?: 'final' | 'pending'): PaymentItem;
|
|
45
|
+
/**
|
|
46
|
+
* Calculates the total amount from an array of payment items.
|
|
47
|
+
*
|
|
48
|
+
* @param items - Array of payment items to sum
|
|
49
|
+
* @returns Total amount
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const items = [
|
|
54
|
+
* createPaymentItem('Product', 29.99),
|
|
55
|
+
* createPaymentItem('Tax', 2.40)
|
|
56
|
+
* ]
|
|
57
|
+
* const total = calculateTotal(items) // 32.39
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function calculateTotal(items: PaymentItem[]): number;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a payment request with sensible defaults.
|
|
63
|
+
*
|
|
64
|
+
* Default values:
|
|
65
|
+
* - countryCode: 'US'
|
|
66
|
+
* - currencyCode: 'USD'
|
|
67
|
+
* - supportedNetworks: ['visa', 'mastercard', 'amex', 'discover']
|
|
68
|
+
* - merchantCapabilities: ['3DS']
|
|
69
|
+
*
|
|
70
|
+
* @param options - Payment request options (merchantIdentifier, amount, label required)
|
|
71
|
+
* @returns Complete PaymentRequest object
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const request = createPaymentRequest({
|
|
76
|
+
* merchantIdentifier: 'merchant.com.example',
|
|
77
|
+
* amount: 29.99,
|
|
78
|
+
* label: 'Coffee Subscription',
|
|
79
|
+
* countryCode: 'CA', // override default
|
|
80
|
+
* currencyCode: 'CAD' // override default
|
|
81
|
+
* })
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function createPaymentRequest(options: Partial<PaymentRequest> & {
|
|
85
|
+
merchantIdentifier: string;
|
|
86
|
+
amount: number;
|
|
87
|
+
label: string;
|
|
88
|
+
}): PaymentRequest;
|
|
89
|
+
/**
|
|
90
|
+
* Formats an amount to 2 decimal places.
|
|
91
|
+
*
|
|
92
|
+
* @param amount - Numeric amount to format
|
|
93
|
+
* @returns Formatted amount string
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* formatAmount(29.9) // "29.90"
|
|
98
|
+
* formatAmount(100) // "100.00"
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function formatAmount(amount: number): string;
|
|
102
|
+
/**
|
|
103
|
+
* Parses an amount string to a number.
|
|
104
|
+
*
|
|
105
|
+
* @param amountString - String representation of amount
|
|
106
|
+
* @returns Parsed numeric amount
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* parseAmount("29.99") // 29.99
|
|
111
|
+
* parseAmount("100") // 100
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare function parseAmount(amountString: string): number;
|
|
115
|
+
/**
|
|
116
|
+
* Checks if a payment network is supported.
|
|
117
|
+
* Case-insensitive comparison.
|
|
118
|
+
*
|
|
119
|
+
* @param network - Network to check
|
|
120
|
+
* @param supportedNetworks - Array of supported networks
|
|
121
|
+
* @returns True if network is supported
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* isNetworkSupported('visa', ['visa', 'mastercard']) // true
|
|
126
|
+
* isNetworkSupported('AMEX', ['visa', 'amex']) // true
|
|
127
|
+
* isNetworkSupported('discover', ['visa', 'mastercard']) // false
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export declare function isNetworkSupported(network: string, supportedNetworks: string[]): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Formats a payment network identifier for human-readable display.
|
|
133
|
+
*
|
|
134
|
+
* @param network - Payment network identifier
|
|
135
|
+
* @returns Formatted network name
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* formatNetworkName('visa') // "Visa"
|
|
140
|
+
* formatNetworkName('amex') // "American Express"
|
|
141
|
+
* formatNetworkName('mastercard') // "Mastercard"
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export declare function formatNetworkName(network: PaymentNetwork): string;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for payment operations
|
|
4
|
+
*
|
|
5
|
+
* This module provides helper functions for creating and formatting
|
|
6
|
+
* payment requests and related data structures.
|
|
7
|
+
*
|
|
8
|
+
* @module paymentHelpers
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { createPaymentRequest, calculateTotal } from 'react-native-pay'
|
|
13
|
+
*
|
|
14
|
+
* const request = createPaymentRequest({
|
|
15
|
+
* merchantIdentifier: 'merchant.com.example',
|
|
16
|
+
* amount: 29.99,
|
|
17
|
+
* label: 'Coffee Subscription'
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.CommonNetworks = void 0;
|
|
23
|
+
exports.createPaymentItem = createPaymentItem;
|
|
24
|
+
exports.calculateTotal = calculateTotal;
|
|
25
|
+
exports.createPaymentRequest = createPaymentRequest;
|
|
26
|
+
exports.formatAmount = formatAmount;
|
|
27
|
+
exports.parseAmount = parseAmount;
|
|
28
|
+
exports.isNetworkSupported = isNetworkSupported;
|
|
29
|
+
exports.formatNetworkName = formatNetworkName;
|
|
30
|
+
/**
|
|
31
|
+
* Payment networks supported by both Apple Pay and Google Pay
|
|
32
|
+
*/
|
|
33
|
+
exports.CommonNetworks = {
|
|
34
|
+
VISA: 'visa',
|
|
35
|
+
MASTERCARD: 'mastercard',
|
|
36
|
+
AMEX: 'amex',
|
|
37
|
+
DISCOVER: 'discover',
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Creates a payment item with the specified label, amount, and type.
|
|
41
|
+
*
|
|
42
|
+
* @param label - Display label for the payment item
|
|
43
|
+
* @param amount - Amount in the payment currency
|
|
44
|
+
* @param type - Item type: 'final' for confirmed amounts, 'pending' for estimates
|
|
45
|
+
* @returns A PaymentItem object
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const item = createPaymentItem('Subscription', 29.99, 'final')
|
|
50
|
+
* const shipping = createPaymentItem('Shipping', 5.00, 'pending')
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
function createPaymentItem(label, amount, type = 'final') {
|
|
54
|
+
return { label, amount, type };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Calculates the total amount from an array of payment items.
|
|
58
|
+
*
|
|
59
|
+
* @param items - Array of payment items to sum
|
|
60
|
+
* @returns Total amount
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const items = [
|
|
65
|
+
* createPaymentItem('Product', 29.99),
|
|
66
|
+
* createPaymentItem('Tax', 2.40)
|
|
67
|
+
* ]
|
|
68
|
+
* const total = calculateTotal(items) // 32.39
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
function calculateTotal(items) {
|
|
72
|
+
return items.reduce((sum, item) => sum + item.amount, 0);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates a payment request with sensible defaults.
|
|
76
|
+
*
|
|
77
|
+
* Default values:
|
|
78
|
+
* - countryCode: 'US'
|
|
79
|
+
* - currencyCode: 'USD'
|
|
80
|
+
* - supportedNetworks: ['visa', 'mastercard', 'amex', 'discover']
|
|
81
|
+
* - merchantCapabilities: ['3DS']
|
|
82
|
+
*
|
|
83
|
+
* @param options - Payment request options (merchantIdentifier, amount, label required)
|
|
84
|
+
* @returns Complete PaymentRequest object
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const request = createPaymentRequest({
|
|
89
|
+
* merchantIdentifier: 'merchant.com.example',
|
|
90
|
+
* amount: 29.99,
|
|
91
|
+
* label: 'Coffee Subscription',
|
|
92
|
+
* countryCode: 'CA', // override default
|
|
93
|
+
* currencyCode: 'CAD' // override default
|
|
94
|
+
* })
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
function createPaymentRequest(options) {
|
|
98
|
+
const { merchantIdentifier, amount, label, countryCode = 'US', currencyCode = 'USD', supportedNetworks = [
|
|
99
|
+
exports.CommonNetworks.VISA,
|
|
100
|
+
exports.CommonNetworks.MASTERCARD,
|
|
101
|
+
exports.CommonNetworks.AMEX,
|
|
102
|
+
exports.CommonNetworks.DISCOVER,
|
|
103
|
+
], merchantCapabilities = ['3DS'], ...rest } = options;
|
|
104
|
+
return {
|
|
105
|
+
merchantIdentifier,
|
|
106
|
+
countryCode,
|
|
107
|
+
currencyCode,
|
|
108
|
+
paymentItems: [createPaymentItem(label, amount, 'final')],
|
|
109
|
+
supportedNetworks,
|
|
110
|
+
merchantCapabilities,
|
|
111
|
+
...rest,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Formats an amount to 2 decimal places.
|
|
116
|
+
*
|
|
117
|
+
* @param amount - Numeric amount to format
|
|
118
|
+
* @returns Formatted amount string
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* formatAmount(29.9) // "29.90"
|
|
123
|
+
* formatAmount(100) // "100.00"
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
function formatAmount(amount) {
|
|
127
|
+
return amount.toFixed(2);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Parses an amount string to a number.
|
|
131
|
+
*
|
|
132
|
+
* @param amountString - String representation of amount
|
|
133
|
+
* @returns Parsed numeric amount
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* parseAmount("29.99") // 29.99
|
|
138
|
+
* parseAmount("100") // 100
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
function parseAmount(amountString) {
|
|
142
|
+
return parseFloat(amountString);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Checks if a payment network is supported.
|
|
146
|
+
* Case-insensitive comparison.
|
|
147
|
+
*
|
|
148
|
+
* @param network - Network to check
|
|
149
|
+
* @param supportedNetworks - Array of supported networks
|
|
150
|
+
* @returns True if network is supported
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* isNetworkSupported('visa', ['visa', 'mastercard']) // true
|
|
155
|
+
* isNetworkSupported('AMEX', ['visa', 'amex']) // true
|
|
156
|
+
* isNetworkSupported('discover', ['visa', 'mastercard']) // false
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
function isNetworkSupported(network, supportedNetworks) {
|
|
160
|
+
return supportedNetworks.some((supported) => supported.toLowerCase() === network.toLowerCase());
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Formats a payment network identifier for human-readable display.
|
|
164
|
+
*
|
|
165
|
+
* @param network - Payment network identifier
|
|
166
|
+
* @returns Formatted network name
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* formatNetworkName('visa') // "Visa"
|
|
171
|
+
* formatNetworkName('amex') // "American Express"
|
|
172
|
+
* formatNetworkName('mastercard') // "Mastercard"
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
function formatNetworkName(network) {
|
|
176
|
+
const networkNames = {
|
|
177
|
+
visa: 'Visa',
|
|
178
|
+
mastercard: 'Mastercard',
|
|
179
|
+
amex: 'American Express',
|
|
180
|
+
discover: 'Discover',
|
|
181
|
+
jcb: 'JCB',
|
|
182
|
+
maestro: 'Maestro',
|
|
183
|
+
electron: 'Visa Electron',
|
|
184
|
+
elo: 'Elo',
|
|
185
|
+
idcredit: 'iD Credit',
|
|
186
|
+
interac: 'Interac',
|
|
187
|
+
privateLabel: 'Private Label',
|
|
188
|
+
};
|
|
189
|
+
return networkNames[network] || network;
|
|
190
|
+
}
|
package/nitro.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://nitro.margelo.com/nitro.schema.json",
|
|
3
|
+
"cxxNamespace": [
|
|
4
|
+
"pay"
|
|
5
|
+
],
|
|
6
|
+
"ios": {
|
|
7
|
+
"iosModuleName": "NitroPay"
|
|
8
|
+
},
|
|
9
|
+
"android": {
|
|
10
|
+
"androidNamespace": [
|
|
11
|
+
"pay"
|
|
12
|
+
],
|
|
13
|
+
"androidCxxLibName": "NitroPay"
|
|
14
|
+
},
|
|
15
|
+
"autolinking": {
|
|
16
|
+
"ApplePayButton": {
|
|
17
|
+
"swift": "HybridApplePayButton"
|
|
18
|
+
},
|
|
19
|
+
"GooglePayButton": {
|
|
20
|
+
"kotlin": "HybridGooglePayButton"
|
|
21
|
+
},
|
|
22
|
+
"PaymentHandler": {
|
|
23
|
+
"swift": "HybridPaymentHandler",
|
|
24
|
+
"kotlin": "HybridPaymentHandler"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"ignorePaths": [
|
|
28
|
+
"**/node_modules"
|
|
29
|
+
]
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
** linguist-generated=true
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#
|
|
2
|
+
# NitroPay+autolinking.cmake
|
|
3
|
+
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
# https://github.com/mrousavy/nitro
|
|
5
|
+
# Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
# This is a CMake file that adds all files generated by Nitrogen
|
|
9
|
+
# to the current CMake project.
|
|
10
|
+
#
|
|
11
|
+
# To use it, add this to your CMakeLists.txt:
|
|
12
|
+
# ```cmake
|
|
13
|
+
# include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/NitroPay+autolinking.cmake)
|
|
14
|
+
# ```
|
|
15
|
+
|
|
16
|
+
# Define a flag to check if we are building properly
|
|
17
|
+
add_definitions(-DBUILDING_NITROPAY_WITH_GENERATED_CMAKE_PROJECT)
|
|
18
|
+
|
|
19
|
+
# Enable Raw Props parsing in react-native (for Nitro Views)
|
|
20
|
+
add_definitions(-DRN_SERIALIZABLE_STATE)
|
|
21
|
+
|
|
22
|
+
# Add all headers that were generated by Nitrogen
|
|
23
|
+
include_directories(
|
|
24
|
+
"../nitrogen/generated/shared/c++"
|
|
25
|
+
"../nitrogen/generated/android/c++"
|
|
26
|
+
"../nitrogen/generated/android/"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Add all .cpp sources that were generated by Nitrogen
|
|
30
|
+
target_sources(
|
|
31
|
+
# CMake project name (Android C++ library name)
|
|
32
|
+
NitroPay PRIVATE
|
|
33
|
+
# Autolinking Setup
|
|
34
|
+
../nitrogen/generated/android/NitroPayOnLoad.cpp
|
|
35
|
+
# Shared Nitrogen C++ sources
|
|
36
|
+
../nitrogen/generated/shared/c++/HybridApplePayButtonSpec.cpp
|
|
37
|
+
../nitrogen/generated/shared/c++/views/HybridApplePayButtonComponent.cpp
|
|
38
|
+
../nitrogen/generated/shared/c++/HybridGooglePayButtonSpec.cpp
|
|
39
|
+
../nitrogen/generated/shared/c++/views/HybridGooglePayButtonComponent.cpp
|
|
40
|
+
../nitrogen/generated/shared/c++/HybridPaymentHandlerSpec.cpp
|
|
41
|
+
# Android-specific Nitrogen C++ sources
|
|
42
|
+
../nitrogen/generated/android/c++/JHybridGooglePayButtonSpec.cpp
|
|
43
|
+
../nitrogen/generated/android/c++/views/JHybridGooglePayButtonStateUpdater.cpp
|
|
44
|
+
../nitrogen/generated/android/c++/JHybridPaymentHandlerSpec.cpp
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
|
|
48
|
+
# Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
|
|
49
|
+
target_compile_definitions(
|
|
50
|
+
NitroPay PRIVATE
|
|
51
|
+
-DFOLLY_NO_CONFIG=1
|
|
52
|
+
-DFOLLY_HAVE_CLOCK_GETTIME=1
|
|
53
|
+
-DFOLLY_USE_LIBCPP=1
|
|
54
|
+
-DFOLLY_CFG_NO_COROUTINES=1
|
|
55
|
+
-DFOLLY_MOBILE=1
|
|
56
|
+
-DFOLLY_HAVE_RECVMMSG=1
|
|
57
|
+
-DFOLLY_HAVE_PTHREAD=1
|
|
58
|
+
# Once we target android-23 above, we can comment
|
|
59
|
+
# the following line. NDK uses GNU style stderror_r() after API 23.
|
|
60
|
+
-DFOLLY_HAVE_XSI_STRERROR_R=1
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
# Add all libraries required by the generated specs
|
|
64
|
+
find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
|
|
65
|
+
find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
|
|
66
|
+
find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library
|
|
67
|
+
|
|
68
|
+
# Link all libraries together
|
|
69
|
+
target_link_libraries(
|
|
70
|
+
NitroPay
|
|
71
|
+
fbjni::fbjni # <-- Facebook C++ JNI helpers
|
|
72
|
+
ReactAndroid::jsi # <-- RN: JSI
|
|
73
|
+
react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# Link react-native (different prefab between RN 0.75 and RN 0.76)
|
|
77
|
+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
78
|
+
target_link_libraries(
|
|
79
|
+
NitroPay
|
|
80
|
+
ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
|
|
81
|
+
)
|
|
82
|
+
else()
|
|
83
|
+
target_link_libraries(
|
|
84
|
+
NitroPay
|
|
85
|
+
ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
|
|
86
|
+
)
|
|
87
|
+
endif()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroPay+autolinking.gradle
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
/// This is a Gradle file that adds all files generated by Nitrogen
|
|
9
|
+
/// to the current Gradle project.
|
|
10
|
+
///
|
|
11
|
+
/// To use it, add this to your build.gradle:
|
|
12
|
+
/// ```gradle
|
|
13
|
+
/// apply from: '../nitrogen/generated/android/NitroPay+autolinking.gradle'
|
|
14
|
+
/// ```
|
|
15
|
+
|
|
16
|
+
logger.warn("[NitroModules] 🔥 NitroPay is boosted by nitro!")
|
|
17
|
+
|
|
18
|
+
android {
|
|
19
|
+
sourceSets {
|
|
20
|
+
main {
|
|
21
|
+
java.srcDirs += [
|
|
22
|
+
// Nitrogen files
|
|
23
|
+
"${project.projectDir}/../nitrogen/generated/android/kotlin"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroPayOnLoad.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#ifndef BUILDING_NITROPAY_WITH_GENERATED_CMAKE_PROJECT
|
|
9
|
+
#error NitroPayOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#include "NitroPayOnLoad.hpp"
|
|
13
|
+
|
|
14
|
+
#include <jni.h>
|
|
15
|
+
#include <fbjni/fbjni.h>
|
|
16
|
+
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
|
+
|
|
18
|
+
#include "JHybridGooglePayButtonSpec.hpp"
|
|
19
|
+
#include "JFunc_void.hpp"
|
|
20
|
+
#include "views/JHybridGooglePayButtonStateUpdater.hpp"
|
|
21
|
+
#include "JHybridPaymentHandlerSpec.hpp"
|
|
22
|
+
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
23
|
+
|
|
24
|
+
namespace margelo::nitro::pay {
|
|
25
|
+
|
|
26
|
+
int initialize(JavaVM* vm) {
|
|
27
|
+
using namespace margelo::nitro;
|
|
28
|
+
using namespace margelo::nitro::pay;
|
|
29
|
+
using namespace facebook;
|
|
30
|
+
|
|
31
|
+
return facebook::jni::initialize(vm, [] {
|
|
32
|
+
// Register native JNI methods
|
|
33
|
+
margelo::nitro::pay::JHybridGooglePayButtonSpec::registerNatives();
|
|
34
|
+
margelo::nitro::pay::JFunc_void_cxx::registerNatives();
|
|
35
|
+
margelo::nitro::pay::views::JHybridGooglePayButtonStateUpdater::registerNatives();
|
|
36
|
+
margelo::nitro::pay::JHybridPaymentHandlerSpec::registerNatives();
|
|
37
|
+
|
|
38
|
+
// Register Nitro Hybrid Objects
|
|
39
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
40
|
+
"GooglePayButton",
|
|
41
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
42
|
+
static DefaultConstructableObject<JHybridGooglePayButtonSpec::javaobject> object("com/margelo/nitro/pay/HybridGooglePayButton");
|
|
43
|
+
auto instance = object.create();
|
|
44
|
+
return instance->cthis()->shared();
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
48
|
+
"PaymentHandler",
|
|
49
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
50
|
+
static DefaultConstructableObject<JHybridPaymentHandlerSpec::javaobject> object("com/margelo/nitro/pay/HybridPaymentHandler");
|
|
51
|
+
auto instance = object.create();
|
|
52
|
+
return instance->cthis()->shared();
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
} // namespace margelo::nitro::pay
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroPayOnLoad.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include <jni.h>
|
|
9
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
10
|
+
|
|
11
|
+
namespace margelo::nitro::pay {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Initializes the native (C++) part of NitroPay, and autolinks all Hybrid Objects.
|
|
15
|
+
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`).
|
|
16
|
+
* Example:
|
|
17
|
+
* ```cpp (cpp-adapter.cpp)
|
|
18
|
+
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
19
|
+
* return margelo::nitro::pay::initialize(vm);
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
int initialize(JavaVM* vm);
|
|
24
|
+
|
|
25
|
+
} // namespace margelo::nitro::pay
|