@gmisoftware/react-native-pay 0.0.6 → 0.0.8
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PaymentRequest, PaymentResult, PaymentItem, GooglePayEnvironment } from '../types';
|
|
2
2
|
export interface UsePaymentCheckoutConfig {
|
|
3
3
|
merchantIdentifier: string;
|
|
4
|
+
merchantName?: string;
|
|
4
5
|
countryCode?: string;
|
|
5
6
|
currencyCode?: string;
|
|
6
7
|
supportedNetworks?: string[];
|
|
@@ -67,16 +67,12 @@ const utils_1 = require("../utils");
|
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
69
|
function usePaymentCheckout(config) {
|
|
70
|
-
// Payment status state
|
|
71
70
|
const [status, setStatus] = (0, react_1.useState)(null);
|
|
72
71
|
const [isCheckingStatus, setIsCheckingStatus] = (0, react_1.useState)(true);
|
|
73
|
-
// Cart state
|
|
74
72
|
const [items, setItems] = (0, react_1.useState)([]);
|
|
75
|
-
// Payment state
|
|
76
73
|
const [isProcessing, setIsProcessing] = (0, react_1.useState)(false);
|
|
77
74
|
const [result, setResult] = (0, react_1.useState)(null);
|
|
78
75
|
const [error, setError] = (0, react_1.useState)(null);
|
|
79
|
-
// Check payment status on mount
|
|
80
76
|
(0, react_1.useEffect)(() => {
|
|
81
77
|
try {
|
|
82
78
|
const paymentStatus = HybridPaymentHandler.payServiceStatus();
|
|
@@ -90,14 +86,13 @@ function usePaymentCheckout(config) {
|
|
|
90
86
|
setIsCheckingStatus(false);
|
|
91
87
|
}
|
|
92
88
|
}, []);
|
|
93
|
-
// Calculate total
|
|
94
89
|
const total = (0, react_1.useMemo)(() => (0, utils_1.calculateTotal)(items), [items]);
|
|
95
|
-
// Build payment request
|
|
96
90
|
const paymentRequest = (0, react_1.useMemo)(() => {
|
|
97
|
-
const { merchantIdentifier, countryCode = 'US', currencyCode = 'USD', supportedNetworks = ['visa', 'mastercard', 'amex', 'discover'], merchantCapabilities = ['3DS'], googlePayEnvironment, googlePayGateway, googlePayGatewayMerchantId, } = config;
|
|
91
|
+
const { merchantIdentifier, merchantName, countryCode = 'US', currencyCode = 'USD', supportedNetworks = ['visa', 'mastercard', 'amex', 'discover'], merchantCapabilities = ['3DS'], googlePayEnvironment, googlePayGateway, googlePayGatewayMerchantId, } = config;
|
|
98
92
|
return {
|
|
99
93
|
merchantIdentifier,
|
|
100
94
|
countryCode,
|
|
95
|
+
merchantName,
|
|
101
96
|
currencyCode,
|
|
102
97
|
supportedNetworks,
|
|
103
98
|
merchantCapabilities,
|
|
@@ -125,7 +120,6 @@ function usePaymentCheckout(config) {
|
|
|
125
120
|
const clearItems = (0, react_1.useCallback)(() => {
|
|
126
121
|
setItems([]);
|
|
127
122
|
}, []);
|
|
128
|
-
// Start payment
|
|
129
123
|
const startPayment = (0, react_1.useCallback)(async () => {
|
|
130
124
|
if (items.length === 0) {
|
|
131
125
|
const emptyCartError = new Error('Cart is empty');
|
|
@@ -152,7 +146,6 @@ function usePaymentCheckout(config) {
|
|
|
152
146
|
setIsProcessing(false);
|
|
153
147
|
}
|
|
154
148
|
}, [items, paymentRequest]);
|
|
155
|
-
// Reset all state
|
|
156
149
|
const reset = (0, react_1.useCallback)(() => {
|
|
157
150
|
setIsProcessing(false);
|
|
158
151
|
setResult(null);
|
package/lib/types/Payment.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@ import { createPaymentItem, calculateTotal } from '../utils'
|
|
|
15
15
|
|
|
16
16
|
export interface UsePaymentCheckoutConfig {
|
|
17
17
|
merchantIdentifier: string
|
|
18
|
+
merchantName?: string
|
|
18
19
|
countryCode?: string
|
|
19
20
|
currencyCode?: string
|
|
20
21
|
supportedNetworks?: string[]
|
|
@@ -116,19 +117,15 @@ export interface UsePaymentCheckoutReturn {
|
|
|
116
117
|
export function usePaymentCheckout(
|
|
117
118
|
config: UsePaymentCheckoutConfig
|
|
118
119
|
): UsePaymentCheckoutReturn {
|
|
119
|
-
// Payment status state
|
|
120
120
|
const [status, setStatus] = useState<PayServiceStatus | null>(null)
|
|
121
121
|
const [isCheckingStatus, setIsCheckingStatus] = useState(true)
|
|
122
122
|
|
|
123
|
-
// Cart state
|
|
124
123
|
const [items, setItems] = useState<PaymentItem[]>([])
|
|
125
124
|
|
|
126
|
-
// Payment state
|
|
127
125
|
const [isProcessing, setIsProcessing] = useState(false)
|
|
128
126
|
const [result, setResult] = useState<PaymentResult | null>(null)
|
|
129
127
|
const [error, setError] = useState<Error | null>(null)
|
|
130
128
|
|
|
131
|
-
// Check payment status on mount
|
|
132
129
|
useEffect(() => {
|
|
133
130
|
try {
|
|
134
131
|
const paymentStatus = HybridPaymentHandler.payServiceStatus()
|
|
@@ -141,13 +138,12 @@ export function usePaymentCheckout(
|
|
|
141
138
|
}
|
|
142
139
|
}, [])
|
|
143
140
|
|
|
144
|
-
// Calculate total
|
|
145
141
|
const total = useMemo(() => calculateTotal(items), [items])
|
|
146
142
|
|
|
147
|
-
// Build payment request
|
|
148
143
|
const paymentRequest = useMemo<PaymentRequest>(() => {
|
|
149
144
|
const {
|
|
150
145
|
merchantIdentifier,
|
|
146
|
+
merchantName,
|
|
151
147
|
countryCode = 'US',
|
|
152
148
|
currencyCode = 'USD',
|
|
153
149
|
supportedNetworks = ['visa', 'mastercard', 'amex', 'discover'],
|
|
@@ -160,6 +156,7 @@ export function usePaymentCheckout(
|
|
|
160
156
|
return {
|
|
161
157
|
merchantIdentifier,
|
|
162
158
|
countryCode,
|
|
159
|
+
merchantName,
|
|
163
160
|
currencyCode,
|
|
164
161
|
supportedNetworks,
|
|
165
162
|
merchantCapabilities,
|
|
@@ -213,7 +210,6 @@ export function usePaymentCheckout(
|
|
|
213
210
|
setItems([])
|
|
214
211
|
}, [])
|
|
215
212
|
|
|
216
|
-
// Start payment
|
|
217
213
|
const startPayment = useCallback(async (): Promise<PaymentResult | null> => {
|
|
218
214
|
if (items.length === 0) {
|
|
219
215
|
const emptyCartError = new Error('Cart is empty')
|
|
@@ -246,7 +242,6 @@ export function usePaymentCheckout(
|
|
|
246
242
|
}
|
|
247
243
|
}, [items, paymentRequest])
|
|
248
244
|
|
|
249
|
-
// Reset all state
|
|
250
245
|
const reset = useCallback(() => {
|
|
251
246
|
setIsProcessing(false)
|
|
252
247
|
setResult(null)
|