ordering-ui-react-native 0.14.98 → 0.14.99
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/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React, { useState, useEffect } from 'react'
|
|
2
2
|
import { useLanguage } from 'ordering-components/native'
|
|
3
|
-
import {
|
|
3
|
+
import { useGooglePay, ApplePayButton, useApplePay } from '@stripe/stripe-react-native'
|
|
4
4
|
import { OButton } from '../shared';
|
|
5
5
|
import { Platform, View } from 'react-native';
|
|
6
6
|
import { StripeMethodFormParams } from '../../types';
|
|
7
|
-
|
|
7
|
+
import Spinner from 'react-native-loading-spinner-overlay';
|
|
8
|
+
import { android_app_id } from '../../config.json'
|
|
8
9
|
export const StripeMethodForm = (props: StripeMethodFormParams) => {
|
|
9
10
|
const {
|
|
10
11
|
cart,
|
|
@@ -17,10 +18,11 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
|
|
|
17
18
|
const { initGooglePay, createGooglePayPaymentMethod, loading } = useGooglePay();
|
|
18
19
|
const { presentApplePay, isApplePaySupported } = useApplePay();
|
|
19
20
|
const [initialized, setInitialized] = useState(false);
|
|
21
|
+
const [loadingGooglePayment, setLoadingGooglePayment] = useState(false)
|
|
20
22
|
const [, t] = useLanguage()
|
|
21
|
-
|
|
23
|
+
|
|
22
24
|
useEffect(() => {
|
|
23
|
-
if (paymethod !== 'google_pay') return
|
|
25
|
+
if (paymethod !== 'google_pay' || !initGooglePay) return
|
|
24
26
|
if (Platform.OS === 'ios') {
|
|
25
27
|
setErrors(t('GOOGLE_PAY_NOT_SUPPORTED', 'Google pay not supported'))
|
|
26
28
|
return
|
|
@@ -29,7 +31,7 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
|
|
|
29
31
|
try {
|
|
30
32
|
const { error } = await initGooglePay({
|
|
31
33
|
testEnv: devMode,
|
|
32
|
-
merchantName:
|
|
34
|
+
merchantName: android_app_id,
|
|
33
35
|
countryCode: 'US',
|
|
34
36
|
billingAddressConfig: {
|
|
35
37
|
format: 'FULL',
|
|
@@ -61,14 +63,14 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
|
|
|
61
63
|
}, [])
|
|
62
64
|
|
|
63
65
|
const createPaymentMethod = async () => {
|
|
64
|
-
|
|
66
|
+
setLoadingGooglePayment(true)
|
|
65
67
|
const { error, paymentMethod } = await createGooglePayPaymentMethod({
|
|
66
68
|
amount: cart?.balance ?? cart?.total,
|
|
67
69
|
currencyCode: 'USD',
|
|
68
70
|
});
|
|
69
|
-
|
|
70
71
|
if (error) {
|
|
71
72
|
setErrors(error.code + ' - ' + error.message);
|
|
73
|
+
setLoadingGooglePayment(false)
|
|
72
74
|
return;
|
|
73
75
|
} else if (paymentMethod) {
|
|
74
76
|
handleSource({
|
|
@@ -82,8 +84,8 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
|
|
|
82
84
|
}
|
|
83
85
|
})
|
|
84
86
|
onCancel()
|
|
87
|
+
setLoadingGooglePayment(false)
|
|
85
88
|
}
|
|
86
|
-
setInitialized(false);
|
|
87
89
|
};
|
|
88
90
|
|
|
89
91
|
const pay = async () => {
|
|
@@ -130,17 +132,17 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
|
|
|
130
132
|
<>
|
|
131
133
|
{paymethod === 'google_pay' ? (
|
|
132
134
|
<View>
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
135
|
+
<OButton
|
|
136
|
+
textStyle={{
|
|
137
|
+
color: '#fff'
|
|
138
|
+
}}
|
|
139
|
+
imgRightSrc={null}
|
|
140
|
+
onClick={createPaymentMethod}
|
|
141
|
+
isDisabled={loading || !initialized}
|
|
142
|
+
text={t('PAY_WITH_GOOGLE_PAY', 'Pay with Google Pay')}
|
|
143
|
+
isLoading={loading || !initialized}
|
|
144
|
+
style={{ marginTop: 20 }}
|
|
145
|
+
/>
|
|
144
146
|
</View>
|
|
145
147
|
) : (
|
|
146
148
|
<View>
|
|
@@ -158,6 +160,9 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
|
|
|
158
160
|
)}
|
|
159
161
|
</View>
|
|
160
162
|
)}
|
|
163
|
+
<Spinner
|
|
164
|
+
visible={loadingGooglePayment}
|
|
165
|
+
/>
|
|
161
166
|
</>
|
|
162
167
|
)
|
|
163
168
|
}
|