@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
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
<img width="1660" height="512" alt="react-native-pay" src="https://github.com/user-attachments/assets/b06a4afb-5a0b-4605-a0e1-75793ab4df15" />
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
4
|
|
|
@@ -13,21 +13,25 @@ Built with [Nitro Modules](https://nitro.margelo.com/) for high-performance nati
|
|
|
13
13
|
|
|
14
14
|
[Features](#features) • [Installation](#installation) • [Quick Start](#quick-start) • [Documentation](#documentation) • [API Reference](#api-reference)
|
|
15
15
|
|
|
16
|
+
**Full documentation** is available at [gmi-software.github.io/react-native-pay](https://gmi-software.github.io/react-native-pay/). The Docusaurus source lives in **[`docs/`](docs/)**; run `bun run docs:start` to view it locally, or `bun run docs:build` to build static files.
|
|
17
|
+
|
|
18
|
+
This package presents native payment sheets and returns tokens. Your backend and gateway integration still perform the actual charge.
|
|
19
|
+
|
|
16
20
|
</div>
|
|
17
21
|
|
|
18
22
|
---
|
|
19
23
|
|
|
20
24
|
## Features
|
|
21
25
|
|
|
22
|
-
- ✅ **Unified API** -
|
|
23
|
-
- ✅ **One Hook
|
|
26
|
+
- ✅ **Unified API** - Shared payment request/result model across Apple Pay and Google Pay
|
|
27
|
+
- ✅ **One Hook for Checkout State** - `usePaymentCheckout()` handles availability checks, cart state, and payment-sheet start
|
|
24
28
|
- ✅ **Native UI Components** - Platform-specific payment buttons with full customization
|
|
25
29
|
- ✅ **Type-Safe** - Comprehensive TypeScript definitions with full IntelliSense support
|
|
26
30
|
- ✅ **Configurable** - Dynamic environment and gateway configuration for both platforms
|
|
27
31
|
- ✅ **Built-in Cart** - Shopping cart functionality with batch operations
|
|
28
32
|
- ✅ **Modern Architecture** - Built with Nitro Modules for optimal performance
|
|
29
33
|
- ✅ **Expo Compatible** - Config plugins for seamless Expo integration
|
|
30
|
-
- ✅ **Production
|
|
34
|
+
- ✅ **Production Focused** - Built for real-world apps with backend gateway processing
|
|
31
35
|
|
|
32
36
|
---
|
|
33
37
|
|
|
@@ -200,7 +204,6 @@ function CheckoutScreen() {
|
|
|
200
204
|
isProcessing,
|
|
201
205
|
error,
|
|
202
206
|
} = usePaymentCheckout({
|
|
203
|
-
merchantIdentifier: 'merchant.com.yourcompany.app',
|
|
204
207
|
currencyCode: 'USD',
|
|
205
208
|
countryCode: 'US',
|
|
206
209
|
})
|
|
@@ -298,6 +301,8 @@ export default CheckoutScreen
|
|
|
298
301
|
|
|
299
302
|
## Documentation
|
|
300
303
|
|
|
304
|
+
The **[`docs/`](docs/)** directory contains the full technical documentation (Docusaurus, English): introduction, quick start, installation & setup, API reference, guides, troubleshooting, and compatibility. Run `bun run docs:start` to serve it locally.
|
|
305
|
+
|
|
301
306
|
### Payment Flow Overview
|
|
302
307
|
|
|
303
308
|
```
|
|
@@ -315,14 +320,14 @@ For Google Pay, you need to configure your payment gateway:
|
|
|
315
320
|
|
|
316
321
|
```typescript
|
|
317
322
|
const checkout = usePaymentCheckout({
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
countryCode: 'US',
|
|
323
|
+
currencyCode: "USD",
|
|
324
|
+
countryCode: "US",
|
|
321
325
|
// Google Pay specific
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
+
googlePayMerchantId: "your_google_pay_merchant_id",
|
|
327
|
+
googlePayEnvironment: "TEST", // or 'PRODUCTION'
|
|
328
|
+
googlePayGateway: "stripe",
|
|
329
|
+
googlePayGatewayMerchantId: "your_stripe_merchant_id",
|
|
330
|
+
});
|
|
326
331
|
```
|
|
327
332
|
|
|
328
333
|
#### Supported Payment Gateways
|
|
@@ -348,16 +353,17 @@ The all-in-one hook for handling payments. Manages availability checking, cart s
|
|
|
348
353
|
|
|
349
354
|
```typescript
|
|
350
355
|
interface UsePaymentCheckoutConfig {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
356
|
+
merchantName?: string;
|
|
357
|
+
countryCode?: string; // Default: 'US'
|
|
358
|
+
currencyCode?: string; // Default: 'USD'
|
|
359
|
+
supportedNetworks?: string[]; // Default: ['visa', 'mastercard', 'amex', 'discover']
|
|
360
|
+
merchantCapabilities?: string[]; // Default: ['3DS']
|
|
361
|
+
applePayMerchantIdentifier?: string; // Optional iOS override
|
|
357
362
|
// Google Pay specific (Android)
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
363
|
+
googlePayMerchantId?: string;
|
|
364
|
+
googlePayEnvironment?: "TEST" | "PRODUCTION";
|
|
365
|
+
googlePayGateway?: string;
|
|
366
|
+
googlePayGatewayMerchantId?: string;
|
|
361
367
|
}
|
|
362
368
|
```
|
|
363
369
|
|
|
@@ -366,28 +372,28 @@ interface UsePaymentCheckoutConfig {
|
|
|
366
372
|
```typescript
|
|
367
373
|
interface UsePaymentCheckoutReturn {
|
|
368
374
|
// Payment availability
|
|
369
|
-
canMakePayments: boolean // Can user make payments?
|
|
370
|
-
canSetupCards: boolean // Can user add cards?
|
|
371
|
-
isCheckingStatus: boolean // Loading state for availability check
|
|
375
|
+
canMakePayments: boolean; // Can user make payments?
|
|
376
|
+
canSetupCards: boolean; // Can user add cards?
|
|
377
|
+
isCheckingStatus: boolean; // Loading state for availability check
|
|
372
378
|
|
|
373
379
|
// Cart management
|
|
374
|
-
items: PaymentItem[] // Current cart items
|
|
375
|
-
total: number // Total amount
|
|
376
|
-
addItem: (label: string, amount: number, type?:
|
|
377
|
-
addItems: (items: Array<{ label; amount; type? }>) => void
|
|
378
|
-
removeItem: (index: number) => void
|
|
379
|
-
updateItem: (index: number, updates: Partial<PaymentItem>) => void
|
|
380
|
-
clearItems: () => void
|
|
380
|
+
items: PaymentItem[]; // Current cart items
|
|
381
|
+
total: number; // Total amount
|
|
382
|
+
addItem: (label: string, amount: number, type?: "final" | "pending") => void;
|
|
383
|
+
addItems: (items: Array<{ label; amount; type? }>) => void;
|
|
384
|
+
removeItem: (index: number) => void;
|
|
385
|
+
updateItem: (index: number, updates: Partial<PaymentItem>) => void;
|
|
386
|
+
clearItems: () => void;
|
|
381
387
|
|
|
382
388
|
// Payment processing
|
|
383
|
-
startPayment: () => Promise<PaymentResult | null
|
|
384
|
-
isProcessing: boolean // Payment in progress?
|
|
385
|
-
result: PaymentResult | null // Last payment result
|
|
386
|
-
error: Error | null // Last error
|
|
389
|
+
startPayment: () => Promise<PaymentResult | null>;
|
|
390
|
+
isProcessing: boolean; // Payment in progress?
|
|
391
|
+
result: PaymentResult | null; // Last payment result
|
|
392
|
+
error: Error | null; // Last error
|
|
387
393
|
|
|
388
394
|
// Utilities
|
|
389
|
-
reset: () => void // Reset payment state
|
|
390
|
-
paymentRequest: PaymentRequest // Full request object
|
|
395
|
+
reset: () => void; // Reset payment state
|
|
396
|
+
paymentRequest: PaymentRequest; // Full request object
|
|
391
397
|
}
|
|
392
398
|
```
|
|
393
399
|
|
|
@@ -395,26 +401,26 @@ interface UsePaymentCheckoutReturn {
|
|
|
395
401
|
|
|
396
402
|
```typescript
|
|
397
403
|
const checkout = usePaymentCheckout({
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
googlePayEnvironment:
|
|
402
|
-
googlePayGateway:
|
|
403
|
-
googlePayGatewayMerchantId:
|
|
404
|
-
})
|
|
404
|
+
currencyCode: "USD",
|
|
405
|
+
countryCode: "US",
|
|
406
|
+
googlePayMerchantId: "your_google_pay_merchant_id",
|
|
407
|
+
googlePayEnvironment: "TEST",
|
|
408
|
+
googlePayGateway: "stripe",
|
|
409
|
+
googlePayGatewayMerchantId: "your_stripe_merchant_id",
|
|
410
|
+
});
|
|
405
411
|
|
|
406
412
|
// Add single item
|
|
407
|
-
checkout.addItem(
|
|
413
|
+
checkout.addItem("Product", 29.99);
|
|
408
414
|
|
|
409
415
|
// Add multiple items at once
|
|
410
416
|
checkout.addItems([
|
|
411
|
-
{ label:
|
|
412
|
-
{ label:
|
|
413
|
-
{ label:
|
|
414
|
-
])
|
|
417
|
+
{ label: "Product", amount: 29.99 },
|
|
418
|
+
{ label: "Shipping", amount: 5.0 },
|
|
419
|
+
{ label: "Tax", amount: 2.8, type: "final" },
|
|
420
|
+
]);
|
|
415
421
|
|
|
416
422
|
// Process payment
|
|
417
|
-
const result = await checkout.startPayment()
|
|
423
|
+
const result = await checkout.startPayment();
|
|
418
424
|
```
|
|
419
425
|
|
|
420
426
|
---
|
|
@@ -430,17 +436,17 @@ Low-level payment handler for direct control.
|
|
|
430
436
|
Check payment service availability.
|
|
431
437
|
|
|
432
438
|
```typescript
|
|
433
|
-
const status = HybridPaymentHandler.payServiceStatus()
|
|
434
|
-
console.log(
|
|
435
|
-
console.log(
|
|
439
|
+
const status = HybridPaymentHandler.payServiceStatus();
|
|
440
|
+
console.log("Can make payments:", status.canMakePayments);
|
|
441
|
+
console.log("Can setup cards:", status.canSetupCards);
|
|
436
442
|
```
|
|
437
443
|
|
|
438
444
|
**Returns:**
|
|
439
445
|
|
|
440
446
|
```typescript
|
|
441
447
|
interface PayServiceStatus {
|
|
442
|
-
canMakePayments: boolean
|
|
443
|
-
canSetupCards: boolean
|
|
448
|
+
canMakePayments: boolean;
|
|
449
|
+
canSetupCards: boolean;
|
|
444
450
|
}
|
|
445
451
|
```
|
|
446
452
|
|
|
@@ -450,29 +456,29 @@ Start a payment request.
|
|
|
450
456
|
|
|
451
457
|
```typescript
|
|
452
458
|
const result = await HybridPaymentHandler.startPayment({
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
})
|
|
459
|
+
countryCode: "US",
|
|
460
|
+
currencyCode: "USD",
|
|
461
|
+
merchantCapabilities: ["3DS"],
|
|
462
|
+
supportedNetworks: ["visa", "mastercard", "amex"],
|
|
463
|
+
paymentItems: [{ label: "Total", amount: 29.99, type: "final" }],
|
|
464
|
+
googlePayMerchantId: "your_google_pay_merchant_id",
|
|
465
|
+
});
|
|
460
466
|
```
|
|
461
467
|
|
|
462
468
|
**Returns:**
|
|
463
469
|
|
|
464
470
|
```typescript
|
|
465
471
|
interface PaymentResult {
|
|
466
|
-
success: boolean
|
|
467
|
-
transactionId?: string
|
|
468
|
-
token?: PaymentToken
|
|
469
|
-
error?: string
|
|
472
|
+
success: boolean;
|
|
473
|
+
transactionId?: string;
|
|
474
|
+
token?: PaymentToken;
|
|
475
|
+
error?: string;
|
|
470
476
|
}
|
|
471
477
|
|
|
472
478
|
interface PaymentToken {
|
|
473
|
-
paymentMethod: PaymentMethod
|
|
474
|
-
transactionIdentifier: string
|
|
475
|
-
paymentData: string // Base64 encoded
|
|
479
|
+
paymentMethod: PaymentMethod;
|
|
480
|
+
transactionIdentifier: string;
|
|
481
|
+
paymentData: string; // Base64 encoded
|
|
476
482
|
}
|
|
477
483
|
```
|
|
478
484
|
|
|
@@ -481,7 +487,7 @@ interface PaymentToken {
|
|
|
481
487
|
Check if specific card networks are supported.
|
|
482
488
|
|
|
483
489
|
```typescript
|
|
484
|
-
const canPay = HybridPaymentHandler.canMakePayments([
|
|
490
|
+
const canPay = HybridPaymentHandler.canMakePayments(["visa", "mastercard"]);
|
|
485
491
|
```
|
|
486
492
|
|
|
487
493
|
---
|
|
@@ -496,28 +502,25 @@ Native Apple Pay button with full customization.
|
|
|
496
502
|
|
|
497
503
|
```typescript
|
|
498
504
|
interface ApplePayButtonProps {
|
|
499
|
-
buttonType
|
|
500
|
-
|
|
|
501
|
-
|
|
|
502
|
-
|
|
|
503
|
-
|
|
|
504
|
-
|
|
|
505
|
-
|
|
|
506
|
-
|
|
|
507
|
-
|
|
|
508
|
-
|
|
|
509
|
-
|
|
|
510
|
-
|
|
|
511
|
-
|
|
|
512
|
-
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
onPress: () => void
|
|
520
|
-
style?: ViewStyle
|
|
505
|
+
buttonType:
|
|
506
|
+
| "buy"
|
|
507
|
+
| "setUp"
|
|
508
|
+
| "book"
|
|
509
|
+
| "donate"
|
|
510
|
+
| "continue"
|
|
511
|
+
| "reload"
|
|
512
|
+
| "addMoney"
|
|
513
|
+
| "topUp"
|
|
514
|
+
| "order"
|
|
515
|
+
| "rent"
|
|
516
|
+
| "support"
|
|
517
|
+
| "contribute"
|
|
518
|
+
| "tip";
|
|
519
|
+
|
|
520
|
+
buttonStyle: "white" | "whiteOutline" | "black";
|
|
521
|
+
|
|
522
|
+
onPress?: () => void;
|
|
523
|
+
style?: ViewStyle;
|
|
521
524
|
}
|
|
522
525
|
```
|
|
523
526
|
|
|
@@ -540,22 +543,22 @@ Native Google Pay button with customization.
|
|
|
540
543
|
|
|
541
544
|
```typescript
|
|
542
545
|
interface GooglePayButtonProps {
|
|
543
|
-
buttonType
|
|
544
|
-
|
|
|
545
|
-
|
|
|
546
|
-
|
|
|
547
|
-
|
|
|
548
|
-
|
|
|
549
|
-
|
|
|
550
|
-
|
|
|
551
|
-
|
|
|
552
|
-
|
|
553
|
-
theme
|
|
554
|
-
|
|
555
|
-
radius?: number // Corner radius in dp
|
|
556
|
-
|
|
557
|
-
onPress
|
|
558
|
-
style?: ViewStyle
|
|
546
|
+
buttonType:
|
|
547
|
+
| "buy"
|
|
548
|
+
| "book"
|
|
549
|
+
| "checkout"
|
|
550
|
+
| "donate"
|
|
551
|
+
| "order"
|
|
552
|
+
| "pay"
|
|
553
|
+
| "subscribe"
|
|
554
|
+
| "plain";
|
|
555
|
+
|
|
556
|
+
theme: "dark" | "light";
|
|
557
|
+
|
|
558
|
+
radius?: number; // Corner radius in dp
|
|
559
|
+
|
|
560
|
+
onPress?: () => void;
|
|
561
|
+
style?: ViewStyle;
|
|
559
562
|
}
|
|
560
563
|
```
|
|
561
564
|
|
|
@@ -580,18 +583,18 @@ interface GooglePayButtonProps {
|
|
|
580
583
|
Create a complete payment request from simplified config.
|
|
581
584
|
|
|
582
585
|
```typescript
|
|
583
|
-
import { createPaymentRequest } from
|
|
586
|
+
import { createPaymentRequest } from "@gmisoftware/react-native-pay";
|
|
584
587
|
|
|
585
588
|
const request = createPaymentRequest({
|
|
586
|
-
merchantIdentifier: 'merchant.com.example',
|
|
587
589
|
amount: 29.99,
|
|
588
|
-
label:
|
|
589
|
-
countryCode:
|
|
590
|
-
currencyCode:
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
590
|
+
label: "Coffee Subscription",
|
|
591
|
+
countryCode: "US",
|
|
592
|
+
currencyCode: "USD",
|
|
593
|
+
googlePayMerchantId: "your_google_pay_merchant_id",
|
|
594
|
+
googlePayEnvironment: "TEST",
|
|
595
|
+
googlePayGateway: "stripe",
|
|
596
|
+
googlePayGatewayMerchantId: "your_merchant_id",
|
|
597
|
+
});
|
|
595
598
|
```
|
|
596
599
|
|
|
597
600
|
#### `createPaymentItem(label, amount, type)`
|
|
@@ -599,9 +602,9 @@ const request = createPaymentRequest({
|
|
|
599
602
|
Create a payment item.
|
|
600
603
|
|
|
601
604
|
```typescript
|
|
602
|
-
import { createPaymentItem } from
|
|
605
|
+
import { createPaymentItem } from "@gmisoftware/react-native-pay";
|
|
603
606
|
|
|
604
|
-
const item = createPaymentItem(
|
|
607
|
+
const item = createPaymentItem("Subscription", 29.99, "final");
|
|
605
608
|
// { label: 'Subscription', amount: 29.99, type: 'final' }
|
|
606
609
|
```
|
|
607
610
|
|
|
@@ -610,14 +613,14 @@ const item = createPaymentItem('Subscription', 29.99, 'final')
|
|
|
610
613
|
Calculate total from payment items.
|
|
611
614
|
|
|
612
615
|
```typescript
|
|
613
|
-
import { calculateTotal } from
|
|
616
|
+
import { calculateTotal } from "@gmisoftware/react-native-pay";
|
|
614
617
|
|
|
615
618
|
const items = [
|
|
616
|
-
{ label:
|
|
617
|
-
{ label:
|
|
618
|
-
]
|
|
619
|
+
{ label: "Product", amount: 29.99, type: "final" },
|
|
620
|
+
{ label: "Tax", amount: 2.4, type: "final" },
|
|
621
|
+
];
|
|
619
622
|
|
|
620
|
-
const total = calculateTotal(items) // 32.39
|
|
623
|
+
const total = calculateTotal(items); // 32.39
|
|
621
624
|
```
|
|
622
625
|
|
|
623
626
|
#### `formatNetworkName(network)`
|
|
@@ -625,11 +628,11 @@ const total = calculateTotal(items) // 32.39
|
|
|
625
628
|
Format card network name for display.
|
|
626
629
|
|
|
627
630
|
```typescript
|
|
628
|
-
import { formatNetworkName } from
|
|
631
|
+
import { formatNetworkName } from "@gmisoftware/react-native-pay";
|
|
629
632
|
|
|
630
|
-
formatNetworkName(
|
|
631
|
-
formatNetworkName(
|
|
632
|
-
formatNetworkName(
|
|
633
|
+
formatNetworkName("visa"); // "Visa"
|
|
634
|
+
formatNetworkName("mastercard"); // "Mastercard"
|
|
635
|
+
formatNetworkName("amex"); // "American Express"
|
|
633
636
|
```
|
|
634
637
|
|
|
635
638
|
---
|
|
@@ -641,106 +644,107 @@ formatNetworkName('amex') // "American Express"
|
|
|
641
644
|
```typescript
|
|
642
645
|
// Payment Item
|
|
643
646
|
interface PaymentItem {
|
|
644
|
-
label: string
|
|
645
|
-
amount: number
|
|
646
|
-
type:
|
|
647
|
+
label: string;
|
|
648
|
+
amount: number;
|
|
649
|
+
type: "final" | "pending";
|
|
647
650
|
}
|
|
648
651
|
|
|
649
652
|
// Payment Request
|
|
650
653
|
interface PaymentRequest {
|
|
651
|
-
|
|
652
|
-
merchantName?: string
|
|
653
|
-
countryCode: string
|
|
654
|
-
currencyCode: string
|
|
655
|
-
paymentItems: PaymentItem[]
|
|
656
|
-
merchantCapabilities: string[]
|
|
657
|
-
supportedNetworks: string[]
|
|
658
|
-
shippingType?: string
|
|
659
|
-
shippingMethods?: PaymentItem[]
|
|
660
|
-
billingContactRequired?: boolean
|
|
661
|
-
shippingContactRequired?: boolean
|
|
654
|
+
applePayMerchantIdentifier?: string;
|
|
655
|
+
merchantName?: string;
|
|
656
|
+
countryCode: string;
|
|
657
|
+
currencyCode: string;
|
|
658
|
+
paymentItems: PaymentItem[];
|
|
659
|
+
merchantCapabilities: string[];
|
|
660
|
+
supportedNetworks: string[];
|
|
661
|
+
shippingType?: string;
|
|
662
|
+
shippingMethods?: PaymentItem[];
|
|
663
|
+
billingContactRequired?: boolean;
|
|
664
|
+
shippingContactRequired?: boolean;
|
|
662
665
|
// Google Pay specific
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
+
googlePayMerchantId?: string;
|
|
667
|
+
googlePayEnvironment?: "TEST" | "PRODUCTION";
|
|
668
|
+
googlePayGateway?: string;
|
|
669
|
+
googlePayGatewayMerchantId?: string;
|
|
666
670
|
}
|
|
667
671
|
|
|
668
672
|
// Payment Result
|
|
669
673
|
interface PaymentResult {
|
|
670
|
-
success: boolean
|
|
671
|
-
transactionId?: string
|
|
672
|
-
token?: PaymentToken
|
|
673
|
-
error?: string
|
|
674
|
+
success: boolean;
|
|
675
|
+
transactionId?: string;
|
|
676
|
+
token?: PaymentToken;
|
|
677
|
+
error?: string;
|
|
674
678
|
}
|
|
675
679
|
|
|
676
680
|
// Payment Token
|
|
677
681
|
interface PaymentToken {
|
|
678
|
-
paymentMethod: PaymentMethod
|
|
679
|
-
transactionIdentifier: string
|
|
680
|
-
paymentData: string // Base64 encoded
|
|
682
|
+
paymentMethod: PaymentMethod;
|
|
683
|
+
transactionIdentifier: string;
|
|
684
|
+
paymentData: string; // Base64 encoded
|
|
681
685
|
}
|
|
682
686
|
|
|
683
687
|
// Payment Method
|
|
684
688
|
interface PaymentMethod {
|
|
685
|
-
displayName?: string
|
|
686
|
-
network?: PaymentNetwork
|
|
687
|
-
type: PaymentMethodType
|
|
688
|
-
secureElementPass?: PKSecureElementPass
|
|
689
|
-
billingAddress?: CNContact
|
|
689
|
+
displayName?: string;
|
|
690
|
+
network?: PaymentNetwork;
|
|
691
|
+
type: PaymentMethodType;
|
|
692
|
+
secureElementPass?: PKSecureElementPass;
|
|
693
|
+
billingAddress?: CNContact;
|
|
690
694
|
}
|
|
691
695
|
|
|
692
696
|
// Payment Networks
|
|
693
697
|
type PaymentNetwork =
|
|
694
|
-
|
|
|
695
|
-
|
|
|
696
|
-
|
|
|
697
|
-
|
|
|
698
|
-
|
|
|
699
|
-
|
|
|
700
|
-
|
|
|
701
|
-
|
|
|
702
|
-
|
|
|
703
|
-
|
|
|
704
|
-
|
|
|
698
|
+
| "visa"
|
|
699
|
+
| "mastercard"
|
|
700
|
+
| "amex"
|
|
701
|
+
| "discover"
|
|
702
|
+
| "jcb"
|
|
703
|
+
| "maestro"
|
|
704
|
+
| "electron"
|
|
705
|
+
| "elo"
|
|
706
|
+
| "idcredit"
|
|
707
|
+
| "interac"
|
|
708
|
+
| "privateLabel";
|
|
705
709
|
|
|
706
710
|
// Payment Method Type
|
|
707
|
-
type PaymentMethodType =
|
|
711
|
+
type PaymentMethodType = "unknown" | "debit" | "credit" | "prepaid" | "store";
|
|
708
712
|
```
|
|
709
713
|
|
|
710
714
|
### Contact Types
|
|
711
715
|
|
|
712
716
|
```typescript
|
|
713
717
|
interface CNContact {
|
|
714
|
-
identifier: string
|
|
715
|
-
contactType:
|
|
716
|
-
namePrefix: string
|
|
717
|
-
givenName: string
|
|
718
|
-
middleName: string
|
|
719
|
-
familyName: string
|
|
720
|
-
previousFamilyName: string
|
|
721
|
-
nameSuffix: string
|
|
722
|
-
nickname: string
|
|
723
|
-
organizationName: string
|
|
724
|
-
departmentName: string
|
|
725
|
-
jobTitle: string
|
|
726
|
-
phoneticGivenName: string
|
|
727
|
-
phoneticMiddleName: string
|
|
728
|
-
phoneticFamilyName: string
|
|
729
|
-
phoneticOrganizationName?: string
|
|
730
|
-
note: string
|
|
731
|
-
imageDataAvailable?: boolean
|
|
732
|
-
phoneNumbers: CNLabeledPhoneNumber[]
|
|
733
|
-
emailAddresses: CNLabeledEmailAddress[]
|
|
734
|
-
postalAddresses: CNLabeledPostalAddress[]
|
|
718
|
+
identifier: string;
|
|
719
|
+
contactType: "person" | "organization";
|
|
720
|
+
namePrefix: string;
|
|
721
|
+
givenName: string;
|
|
722
|
+
middleName: string;
|
|
723
|
+
familyName: string;
|
|
724
|
+
previousFamilyName: string;
|
|
725
|
+
nameSuffix: string;
|
|
726
|
+
nickname: string;
|
|
727
|
+
organizationName: string;
|
|
728
|
+
departmentName: string;
|
|
729
|
+
jobTitle: string;
|
|
730
|
+
phoneticGivenName: string;
|
|
731
|
+
phoneticMiddleName: string;
|
|
732
|
+
phoneticFamilyName: string;
|
|
733
|
+
phoneticOrganizationName?: string;
|
|
734
|
+
note: string;
|
|
735
|
+
imageDataAvailable?: boolean;
|
|
736
|
+
phoneNumbers: CNLabeledPhoneNumber[];
|
|
737
|
+
emailAddresses: CNLabeledEmailAddress[];
|
|
738
|
+
postalAddresses: CNLabeledPostalAddress[];
|
|
735
739
|
}
|
|
736
740
|
|
|
737
741
|
interface CNPostalAddress {
|
|
738
|
-
street?: string
|
|
739
|
-
city?: string
|
|
740
|
-
state?: string
|
|
741
|
-
postalCode?: string
|
|
742
|
-
country?: string
|
|
743
|
-
isoCountryCode?: string
|
|
742
|
+
street?: string;
|
|
743
|
+
city?: string;
|
|
744
|
+
state?: string;
|
|
745
|
+
postalCode?: string;
|
|
746
|
+
country?: string;
|
|
747
|
+
isoCountryCode?: string;
|
|
744
748
|
}
|
|
745
749
|
```
|
|
746
750
|
|
|
@@ -770,11 +774,11 @@ if (!status.canMakePayments) {
|
|
|
770
774
|
|
|
771
775
|
// 2. Create payment request
|
|
772
776
|
const paymentRequest = createPaymentRequest({
|
|
773
|
-
merchantIdentifier: 'merchant.com.example',
|
|
774
777
|
amount: 99.99,
|
|
775
778
|
label: 'Premium Subscription',
|
|
776
779
|
countryCode: 'US',
|
|
777
780
|
currencyCode: 'USD',
|
|
781
|
+
googlePayMerchantId: 'your_google_pay_merchant_id',
|
|
778
782
|
googlePayEnvironment: 'PRODUCTION',
|
|
779
783
|
googlePayGateway: 'stripe',
|
|
780
784
|
googlePayGatewayMerchantId: 'your_merchant_id',
|
|
@@ -799,7 +803,7 @@ const handlePayment = async () => {
|
|
|
799
803
|
// 4. Render button
|
|
800
804
|
return Platform.OS === 'ios' ? (
|
|
801
805
|
<ApplePayButton
|
|
802
|
-
buttonType="
|
|
806
|
+
buttonType="buy"
|
|
803
807
|
buttonStyle="black"
|
|
804
808
|
onPress={handlePayment}
|
|
805
809
|
/>
|
|
@@ -816,33 +820,32 @@ return Platform.OS === 'ios' ? (
|
|
|
816
820
|
|
|
817
821
|
```typescript
|
|
818
822
|
const checkout = usePaymentCheckout({
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
})
|
|
823
|
+
currencyCode: "USD",
|
|
824
|
+
});
|
|
822
825
|
|
|
823
826
|
// Add items dynamically
|
|
824
827
|
const handleAddToCart = (product) => {
|
|
825
|
-
checkout.addItem(product.name, product.price)
|
|
826
|
-
}
|
|
828
|
+
checkout.addItem(product.name, product.price);
|
|
829
|
+
};
|
|
827
830
|
|
|
828
831
|
// Update quantity
|
|
829
832
|
const handleUpdateQuantity = (index, quantity) => {
|
|
830
|
-
const item = checkout.items[index]
|
|
833
|
+
const item = checkout.items[index];
|
|
831
834
|
checkout.updateItem(index, {
|
|
832
835
|
amount: item.amount * quantity,
|
|
833
|
-
})
|
|
834
|
-
}
|
|
836
|
+
});
|
|
837
|
+
};
|
|
835
838
|
|
|
836
839
|
// Apply discount
|
|
837
840
|
const handleApplyDiscount = (discountPercent) => {
|
|
838
|
-
const discountAmount = checkout.total * (discountPercent / 100)
|
|
839
|
-
checkout.addItem(
|
|
840
|
-
}
|
|
841
|
+
const discountAmount = checkout.total * (discountPercent / 100);
|
|
842
|
+
checkout.addItem("Discount", -discountAmount, "final");
|
|
843
|
+
};
|
|
841
844
|
|
|
842
845
|
// Clear cart
|
|
843
846
|
const handleClearCart = () => {
|
|
844
|
-
checkout.clearItems()
|
|
845
|
-
}
|
|
847
|
+
checkout.clearItems();
|
|
848
|
+
};
|
|
846
849
|
```
|
|
847
850
|
|
|
848
851
|
### Custom Payment Buttons
|
|
@@ -882,28 +885,28 @@ After receiving the payment token, process it on your server:
|
|
|
882
885
|
|
|
883
886
|
```javascript
|
|
884
887
|
// Backend API endpoint
|
|
885
|
-
app.post(
|
|
886
|
-
const { token } = req.body
|
|
888
|
+
app.post("/process-payment", async (req, res) => {
|
|
889
|
+
const { token } = req.body;
|
|
887
890
|
|
|
888
891
|
try {
|
|
889
892
|
// For Apple Pay
|
|
890
893
|
if (token.paymentData) {
|
|
891
894
|
const charge = await stripe.charges.create({
|
|
892
895
|
amount: 2999, // $29.99
|
|
893
|
-
currency:
|
|
896
|
+
currency: "usd",
|
|
894
897
|
source: token.paymentData, // Apple Pay token
|
|
895
|
-
description:
|
|
896
|
-
})
|
|
898
|
+
description: "Payment from React Native Pay",
|
|
899
|
+
});
|
|
897
900
|
}
|
|
898
901
|
|
|
899
902
|
// For Google Pay
|
|
900
903
|
// The token format depends on your gateway
|
|
901
904
|
|
|
902
|
-
res.json({ success: true, chargeId: charge.id })
|
|
905
|
+
res.json({ success: true, chargeId: charge.id });
|
|
903
906
|
} catch (error) {
|
|
904
|
-
res.status(500).json({ error: error.message })
|
|
907
|
+
res.status(500).json({ error: error.message });
|
|
905
908
|
}
|
|
906
|
-
})
|
|
909
|
+
});
|
|
907
910
|
```
|
|
908
911
|
|
|
909
912
|
---
|
|
@@ -967,7 +970,7 @@ app.post('/process-payment', async (req, res) => {
|
|
|
967
970
|
2. **Type Safety** - Full TypeScript coverage with runtime validation
|
|
968
971
|
3. **Performance** - Built with Nitro Modules for native speed
|
|
969
972
|
4. **Developer Experience** - Simple hooks API with sensible defaults
|
|
970
|
-
5. **Production
|
|
973
|
+
5. **Production Focused** - Designed around backend-controlled payment flows
|
|
971
974
|
|
|
972
975
|
---
|
|
973
976
|
|