ordering-ui-react-native 0.14.97 → 0.15.0
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
|
}
|
|
@@ -96,11 +96,24 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
const onProductClick = (product: any) => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
const cartProduct = currentCart?.products?.find((cproduct: any) => cproduct?.id === product?.id)
|
|
100
|
+
if (cartProduct) {
|
|
101
|
+
onRedirect('ProductDetails', {
|
|
102
|
+
businessId: business.id,
|
|
103
|
+
isCartProduct: true,
|
|
104
|
+
productCart: cartProduct,
|
|
105
|
+
businessSlug: business?.slug,
|
|
106
|
+
categoryId: cartProduct?.category_id,
|
|
107
|
+
productId: cartProduct?.id,
|
|
108
|
+
})
|
|
109
|
+
} else {
|
|
110
|
+
onRedirect('ProductDetails', {
|
|
111
|
+
product: product,
|
|
112
|
+
businessSlug: business.slug,
|
|
113
|
+
businessId: business.id,
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
|
|
104
117
|
}
|
|
105
118
|
|
|
106
119
|
const handleCancel = () => {
|
|
@@ -77,25 +77,18 @@ export const SingleProductCard = (props: SingleProductCardParams) => {
|
|
|
77
77
|
const editMode = typeof product?.code !== 'undefined';
|
|
78
78
|
|
|
79
79
|
const removeToBalance = editMode ? product?.quantity : 0;
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
)
|
|
84
|
-
const totalBalance = (productCart?.quantity || 0) - removeToBalance;
|
|
80
|
+
const cartProducts: any = Object.values(orderState.carts).reduce((products: any, _cart: any) => [...products, ..._cart?.products], [])
|
|
81
|
+
const productBalance = cartProducts.reduce((sum: any, _product: any) => sum + (_product.id === product?.id ? _product.quantity : 0), 0)
|
|
82
|
+
|
|
83
|
+
const totalBalance = (productBalance || 0) - removeToBalance
|
|
85
84
|
|
|
86
85
|
const maxCartProductConfig =
|
|
87
86
|
(stateConfig.configs.max_product_amount
|
|
88
87
|
? parseInt(stateConfig.configs.max_product_amount)
|
|
89
88
|
: 100) - totalBalance;
|
|
90
89
|
|
|
91
|
-
const productBalance =
|
|
92
|
-
(cart?.products?.reduce(
|
|
93
|
-
(sum: any, _product: any) =>
|
|
94
|
-
sum + (product && _product.id === product?.id ? _product.quantity : 0),
|
|
95
|
-
0,
|
|
96
|
-
) || 0) - removeToBalance;
|
|
97
90
|
let maxCartProductInventory =
|
|
98
|
-
(product?.inventoried ? product?.quantity : undefined) -
|
|
91
|
+
(product?.inventoried ? product?.quantity : undefined) - totalBalance;
|
|
99
92
|
maxCartProductInventory = !isNaN(maxCartProductInventory)
|
|
100
93
|
? maxCartProductInventory
|
|
101
94
|
: maxCartProductConfig;
|