ordering-ui-react-native 0.14.62 → 0.14.65
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 +1 -1
- package/src/components/Checkout/index.tsx +23 -163
- package/src/components/PaymentOptions/index.tsx +3 -1
- package/src/components/PaymentOptionsWebView/index.tsx +151 -0
- package/src/index.tsx +2 -0
- package/themes/original/src/components/BusinessesListing/index.tsx +29 -19
- package/themes/original/src/components/Checkout/index.tsx +37 -4
- package/themes/original/src/components/MomentOption/index.tsx +1 -1
- package/themes/original/src/components/PaymentOptions/index.tsx +8 -2
- package/themes/original/src/components/UpsellingProducts/index.tsx +7 -3
package/package.json
CHANGED
|
@@ -55,6 +55,7 @@ import { ActivityIndicator } from 'react-native-paper';
|
|
|
55
55
|
import WebView from 'react-native-webview';
|
|
56
56
|
import Icon from 'react-native-vector-icons/Feather';
|
|
57
57
|
import { OrderCreating } from '../OrderCreating';
|
|
58
|
+
import { PaymentOptionsWebView } from '../PaymentOptionsWebView';
|
|
58
59
|
|
|
59
60
|
const mapConfigs = {
|
|
60
61
|
mapZoom: 16,
|
|
@@ -129,16 +130,12 @@ const CheckoutUI = (props: any) => {
|
|
|
129
130
|
const [{ options, carts, loading }, { confirmCart }] = useOrder();
|
|
130
131
|
const [validationFields] = useValidationFields();
|
|
131
132
|
const [ordering] = useApi()
|
|
132
|
-
const webviewRef = useRef<any>(null)
|
|
133
|
-
const webviewRefSquare = useRef<any>(null)
|
|
134
133
|
const [errorCash, setErrorCash] = useState(false);
|
|
135
134
|
const [userErrors, setUserErrors] = useState<any>([]);
|
|
136
135
|
const [isUserDetailsEdit, setIsUserDetailsEdit] = useState(false);
|
|
137
136
|
const [phoneUpdate, setPhoneUpdate] = useState(false);
|
|
138
137
|
const [showGateway, setShowGateway] = useState<any>({ closedByUsed: false, open: false });
|
|
139
138
|
const [webviewPaymethod, setWebviewPaymethod] = useState<any>(null)
|
|
140
|
-
const [progClr, setProgClr] = useState('#424242');
|
|
141
|
-
const [prog, setProg] = useState(true);
|
|
142
139
|
const [openOrderCreating, setOpenOrderCreating] = useState(false)
|
|
143
140
|
const [cardData, setCardData] = useState(null)
|
|
144
141
|
const [isDeliveryOptionModalVisible, setIsDeliveryOptionModalVisible] = useState(false)
|
|
@@ -202,29 +199,6 @@ const CheckoutUI = (props: any) => {
|
|
|
202
199
|
setPhoneUpdate(val)
|
|
203
200
|
}
|
|
204
201
|
|
|
205
|
-
const onMessage = (e: any) => {
|
|
206
|
-
if (e?.nativeEvent?.data && e?.nativeEvent?.data !== 'undefined') {
|
|
207
|
-
let payment = JSON.parse(e.nativeEvent.data);
|
|
208
|
-
setOpenOrderCreating(true)
|
|
209
|
-
if (payment === 'api error') {
|
|
210
|
-
setShowGateway({ closedByUser: true, open: false })
|
|
211
|
-
setProg(true);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (payment) {
|
|
215
|
-
if (payment.error) {
|
|
216
|
-
showToast(ToastType.Error, payment.result)
|
|
217
|
-
setOpenOrderCreating(false)
|
|
218
|
-
} else if (payment?.result?.order?.uuid) {
|
|
219
|
-
showToast(ToastType.Success, t('ORDER_PLACED_SUCCESSfULLY', 'The order was placed successfully'))
|
|
220
|
-
onNavigationRedirect && onNavigationRedirect('OrderDetails', { orderId: payment?.result?.order?.uuid, goToBusinessList: true })
|
|
221
|
-
}
|
|
222
|
-
setProg(true);
|
|
223
|
-
setShowGateway({ closedByUser: false, open: false })
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
202
|
const onFailPaypal = async () => {
|
|
229
203
|
if (showGateway.closedByUser === true) {
|
|
230
204
|
await confirmCart(cart.uuid)
|
|
@@ -236,11 +210,6 @@ const CheckoutUI = (props: any) => {
|
|
|
236
210
|
setWebviewPaymethod(paymethod)
|
|
237
211
|
}
|
|
238
212
|
|
|
239
|
-
const handleCloseWebview = () => {
|
|
240
|
-
setProg(true);
|
|
241
|
-
setShowGateway({ open: false, closedByUser: true })
|
|
242
|
-
}
|
|
243
|
-
|
|
244
213
|
const changeDeliveryOption = (option: any) => {
|
|
245
214
|
handleChangeDeliveryOption(option)
|
|
246
215
|
setIsDeliveryOptionModalVisible(false)
|
|
@@ -649,141 +618,32 @@ const CheckoutUI = (props: any) => {
|
|
|
649
618
|
</>
|
|
650
619
|
)}
|
|
651
620
|
{webviewPaymethod?.gateway === 'paypal' && showGateway.open && (
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
fontSize: 16,
|
|
663
|
-
fontWeight: 'bold',
|
|
664
|
-
color: '#00457C',
|
|
665
|
-
marginBottom: 5,
|
|
666
|
-
marginTop: 10
|
|
667
|
-
}}>
|
|
668
|
-
{t('PAYPAL_GATEWAY', 'PayPal GateWay')}
|
|
669
|
-
</OText>
|
|
670
|
-
<View style={{ padding: 20, opacity: prog ? 1 : 0, backgroundColor: 'white' }}>
|
|
671
|
-
<ActivityIndicator size={24} color={progClr} />
|
|
672
|
-
</View>
|
|
673
|
-
<WebView
|
|
674
|
-
source={{ uri: `${ordering.root}/html/paypal_react_native` }}
|
|
675
|
-
onMessage={onMessage}
|
|
676
|
-
ref={webviewRef}
|
|
677
|
-
javaScriptEnabled={true}
|
|
678
|
-
javaScriptEnabledAndroid={true}
|
|
679
|
-
cacheEnabled={false}
|
|
680
|
-
cacheMode='LOAD_NO_CACHE'
|
|
681
|
-
style={{ flex: 1 }}
|
|
682
|
-
onLoadStart={() => {
|
|
683
|
-
setProg(true);
|
|
684
|
-
setProgClr('#424242');
|
|
685
|
-
}}
|
|
686
|
-
onLoadProgress={() => {
|
|
687
|
-
setProg(true);
|
|
688
|
-
setProgClr('#00457C');
|
|
689
|
-
}}
|
|
690
|
-
onLoad={() => {
|
|
691
|
-
setProg(true);
|
|
692
|
-
setProgClr('#00457C');
|
|
693
|
-
}}
|
|
694
|
-
onLoadEnd={(e) => {
|
|
695
|
-
const message = {
|
|
696
|
-
action: 'init',
|
|
697
|
-
data: {
|
|
698
|
-
urlPlace: `${ordering.root}/carts/${cart?.uuid}/place`,
|
|
699
|
-
urlConfirm: `${ordering.root}/carts/${cart?.uuid}/confirm`,
|
|
700
|
-
payData: {
|
|
701
|
-
paymethod_id: webviewPaymethod?.id,
|
|
702
|
-
amount: cart?.total,
|
|
703
|
-
delivery_zone_id: cart?.delivery_zone_id,
|
|
704
|
-
user_id: user?.id
|
|
705
|
-
},
|
|
706
|
-
currency: configs?.stripe_currency?.value || currency,
|
|
707
|
-
userToken: token,
|
|
708
|
-
clientId: webviewPaymethod?.credentials?.client_id
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
setProg(false);
|
|
712
|
-
webviewRef?.current?.postMessage?.(JSON.stringify(message))
|
|
713
|
-
}}
|
|
621
|
+
<PaymentOptionsWebView
|
|
622
|
+
onNavigationRedirect={onNavigationRedirect}
|
|
623
|
+
uri={`${ordering.root}/html/paypal_react_native`}
|
|
624
|
+
user={user}
|
|
625
|
+
token={token}
|
|
626
|
+
cart={cart}
|
|
627
|
+
currency={currency}
|
|
628
|
+
webviewPaymethod={webviewPaymethod}
|
|
629
|
+
setShowGateway={setShowGateway}
|
|
630
|
+
setOpenOrderCreating={setOpenOrderCreating}
|
|
714
631
|
/>
|
|
715
|
-
</View>
|
|
716
632
|
)}
|
|
717
633
|
{webviewPaymethod?.gateway === 'square' && showGateway.open && (
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
634
|
+
<PaymentOptionsWebView
|
|
635
|
+
onNavigationRedirect={onNavigationRedirect}
|
|
636
|
+
uri={`https://test-square-f50f7.web.app`}
|
|
637
|
+
user={user}
|
|
638
|
+
token={token}
|
|
639
|
+
cart={cart}
|
|
640
|
+
currency={currency}
|
|
641
|
+
webviewPaymethod={webviewPaymethod}
|
|
642
|
+
setShowGateway={setShowGateway}
|
|
643
|
+
setOpenOrderCreating={setOpenOrderCreating}
|
|
644
|
+
locationId={'L1NGAY5M6KJRX'}
|
|
724
645
|
/>
|
|
725
|
-
|
|
726
|
-
style={{
|
|
727
|
-
textAlign: 'center',
|
|
728
|
-
fontSize: 16,
|
|
729
|
-
fontWeight: 'bold',
|
|
730
|
-
color: '#00457C',
|
|
731
|
-
marginBottom: 5,
|
|
732
|
-
marginTop: 10
|
|
733
|
-
}}>
|
|
734
|
-
{t('SQUARE_PAYMENT', 'Square payment')}
|
|
735
|
-
</OText>
|
|
736
|
-
<View style={{ padding: 20, opacity: prog ? 1 : 0, backgroundColor: 'white' }}>
|
|
737
|
-
<ActivityIndicator size={24} color={progClr} />
|
|
738
|
-
</View>
|
|
739
|
-
<WebView
|
|
740
|
-
source={{ uri: `https://test-square-f50f7.web.app` }}
|
|
741
|
-
onMessage={onMessage}
|
|
742
|
-
ref={webviewRefSquare}
|
|
743
|
-
javaScriptEnabled={true}
|
|
744
|
-
javaScriptEnabledAndroid={true}
|
|
745
|
-
cacheEnabled={false}
|
|
746
|
-
cacheMode='LOAD_NO_CACHE'
|
|
747
|
-
style={{ flex: 1 }}
|
|
748
|
-
onShouldStartLoadWithRequest={() => true}
|
|
749
|
-
onLoadStart={() => {
|
|
750
|
-
setProg(true);
|
|
751
|
-
setProgClr('#424242');
|
|
752
|
-
}}
|
|
753
|
-
onLoadProgress={() => {
|
|
754
|
-
setProg(true);
|
|
755
|
-
setProgClr('#00457C');
|
|
756
|
-
}}
|
|
757
|
-
onLoad={() => {
|
|
758
|
-
setProg(true);
|
|
759
|
-
setProgClr('#00457C');
|
|
760
|
-
}}
|
|
761
|
-
onLoadEnd={(e) => {
|
|
762
|
-
const message = {
|
|
763
|
-
action: 'init',
|
|
764
|
-
data: {
|
|
765
|
-
urlPlace: `${ordering.root}/carts/${cart?.uuid}/place`,
|
|
766
|
-
urlConfirm: `${ordering.root}/carts/${cart?.uuid}/confirm`,
|
|
767
|
-
payData: {
|
|
768
|
-
paymethod_id: webviewPaymethod?.id,
|
|
769
|
-
amount: cart?.total,
|
|
770
|
-
delivery_zone_id: cart?.delivery_zone_id,
|
|
771
|
-
user_id: user?.id,
|
|
772
|
-
user_name: user?.name
|
|
773
|
-
},
|
|
774
|
-
currency: configs?.stripe_currency?.value || currency,
|
|
775
|
-
userToken: token,
|
|
776
|
-
clientId: 'sandbox-sq0idb-rMLAce87hOfpGvokZCygEw',
|
|
777
|
-
locationId: 'L1NGAY5M6KJRX'
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
setProg(false);
|
|
781
|
-
webviewRefSquare?.current?.postMessage?.(JSON.stringify(message))
|
|
782
|
-
}}
|
|
783
|
-
/>
|
|
784
|
-
</View>
|
|
785
|
-
)
|
|
786
|
-
}
|
|
646
|
+
)}
|
|
787
647
|
{openOrderCreating && (
|
|
788
648
|
<View style={{ zIndex: 9999, height: '100%', width: '100%', position: 'absolute', backgroundColor: 'white' }}>
|
|
789
649
|
<OrderCreating
|
|
@@ -45,6 +45,8 @@ const stripeOptions: any = ['stripe_direct', 'stripe', 'stripe_connect']
|
|
|
45
45
|
// { name: 'iDEAL', value: 'ideal' }
|
|
46
46
|
// ]
|
|
47
47
|
|
|
48
|
+
const webViewPaymentGateway: any = ['paypal', 'square']
|
|
49
|
+
|
|
48
50
|
const PaymentOptionsUI = (props: any) => {
|
|
49
51
|
const {
|
|
50
52
|
cart,
|
|
@@ -92,7 +94,7 @@ const PaymentOptionsUI = (props: any) => {
|
|
|
92
94
|
const handlePaymentMethodClick = (paymethod: any) => {
|
|
93
95
|
const isPopupMethod = ['stripe', 'stripe_direct', 'stripe_connect', 'stripe_redirect', 'paypal', 'square'].includes(paymethod?.gateway)
|
|
94
96
|
handlePaymethodClick(paymethod, isPopupMethod)
|
|
95
|
-
|
|
97
|
+
if (webViewPaymentGateway.includes(paymethod?.gateway)) {
|
|
96
98
|
handlePaymentMethodClickCustom(paymethod)
|
|
97
99
|
}
|
|
98
100
|
setCardData(paymethodData)
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import React, { useRef, useState } from 'react'
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import Icon from 'react-native-vector-icons/Feather';
|
|
4
|
+
import WebView from 'react-native-webview';
|
|
5
|
+
import { ActivityIndicator } from 'react-native-paper';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
ToastType,
|
|
9
|
+
useToast,
|
|
10
|
+
useApi,
|
|
11
|
+
useLanguage,
|
|
12
|
+
useConfig
|
|
13
|
+
} from 'ordering-components/native';
|
|
14
|
+
|
|
15
|
+
import { OText } from '../shared';
|
|
16
|
+
|
|
17
|
+
interface PaymentOptionsWebViewParams {
|
|
18
|
+
onNavigationRedirect?: Function,
|
|
19
|
+
uri?: any,
|
|
20
|
+
user?: any,
|
|
21
|
+
token?: any,
|
|
22
|
+
cart?: any,
|
|
23
|
+
currency?: any,
|
|
24
|
+
webviewPaymethod?: any,
|
|
25
|
+
setShowGateway?: any,
|
|
26
|
+
setOpenOrderCreating?: any,
|
|
27
|
+
locationId?: any
|
|
28
|
+
}
|
|
29
|
+
export const PaymentOptionsWebView = (props: PaymentOptionsWebViewParams) => {
|
|
30
|
+
const {
|
|
31
|
+
onNavigationRedirect,
|
|
32
|
+
uri,
|
|
33
|
+
user,
|
|
34
|
+
token,
|
|
35
|
+
cart,
|
|
36
|
+
currency,
|
|
37
|
+
webviewPaymethod,
|
|
38
|
+
setShowGateway,
|
|
39
|
+
setOpenOrderCreating,
|
|
40
|
+
locationId
|
|
41
|
+
} = props
|
|
42
|
+
|
|
43
|
+
const webviewRef = useRef<any>(null)
|
|
44
|
+
const [, { showToast }] = useToast();
|
|
45
|
+
const [ordering] = useApi()
|
|
46
|
+
const [{ configs }] = useConfig();
|
|
47
|
+
const [, t] = useLanguage();
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
const [progClr, setProgClr] = useState('#424242');
|
|
51
|
+
const [prog, setProg] = useState(true);
|
|
52
|
+
|
|
53
|
+
const handleCloseWebview = () => {
|
|
54
|
+
setProg(true);
|
|
55
|
+
setShowGateway({ open: false, closedByUser: true })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const onMessage = (e: any) => {
|
|
59
|
+
if (e?.nativeEvent?.data && e?.nativeEvent?.data !== 'undefined') {
|
|
60
|
+
let payment = JSON.parse(e.nativeEvent.data);
|
|
61
|
+
|
|
62
|
+
if (payment === 'api error') {
|
|
63
|
+
setShowGateway({ closedByUser: true, open: false })
|
|
64
|
+
setProg(true);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (payment) {
|
|
68
|
+
if (payment.error) {
|
|
69
|
+
showToast(ToastType.Error, payment.result)
|
|
70
|
+
setOpenOrderCreating && setOpenOrderCreating(false)
|
|
71
|
+
} else if (payment?.result?.order?.uuid) {
|
|
72
|
+
showToast(ToastType.Success, t('ORDER_PLACED_SUCCESSfULLY', 'The order was placed successfully'))
|
|
73
|
+
onNavigationRedirect && onNavigationRedirect('OrderDetails', { orderId: payment?.result?.order?.uuid, isFromCheckout: true })
|
|
74
|
+
}
|
|
75
|
+
setProg(true);
|
|
76
|
+
setShowGateway({ closedByUser: false, open: false })
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<View style={{ zIndex: 9999, height: '100%', width: '100%', position: 'absolute', backgroundColor: 'white' }}>
|
|
83
|
+
<Icon
|
|
84
|
+
name="x"
|
|
85
|
+
size={35}
|
|
86
|
+
style={{ backgroundColor: 'white', paddingTop: 30, paddingLeft: 10 }}
|
|
87
|
+
onPress={handleCloseWebview}
|
|
88
|
+
/>
|
|
89
|
+
<OText
|
|
90
|
+
style={{
|
|
91
|
+
textAlign: 'center',
|
|
92
|
+
fontSize: 16,
|
|
93
|
+
fontWeight: 'bold',
|
|
94
|
+
color: '#00457C',
|
|
95
|
+
marginBottom: 5,
|
|
96
|
+
marginTop: 10
|
|
97
|
+
}}>
|
|
98
|
+
{webviewPaymethod?.gateway === 'paypal' ? (t('PAYPAL_GATEWAY', 'PayPal GateWay')) : (t('SQUARE_PAYMENT', 'Square payment'))}
|
|
99
|
+
</OText>
|
|
100
|
+
<View style={{ padding: 20, opacity: prog ? 1 : 0, backgroundColor: 'white' }}>
|
|
101
|
+
<ActivityIndicator size={24} color={progClr} />
|
|
102
|
+
</View>
|
|
103
|
+
<WebView
|
|
104
|
+
source={{ uri: uri }}
|
|
105
|
+
onMessage={onMessage}
|
|
106
|
+
ref={webviewRef}
|
|
107
|
+
javaScriptEnabled={true}
|
|
108
|
+
javaScriptEnabledAndroid={true}
|
|
109
|
+
cacheEnabled={false}
|
|
110
|
+
cacheMode='LOAD_NO_CACHE'
|
|
111
|
+
style={{ flex: 1 }}
|
|
112
|
+
onShouldStartLoadWithRequest={() => true}
|
|
113
|
+
onLoadStart={() => {
|
|
114
|
+
setProg(true);
|
|
115
|
+
setProgClr('#424242');
|
|
116
|
+
}}
|
|
117
|
+
onLoadProgress={() => {
|
|
118
|
+
setProg(true);
|
|
119
|
+
setProgClr('#00457C');
|
|
120
|
+
}}
|
|
121
|
+
onLoad={() => {
|
|
122
|
+
setProg(true);
|
|
123
|
+
setProgClr('#00457C');
|
|
124
|
+
}}
|
|
125
|
+
onLoadEnd={(e) => {
|
|
126
|
+
const messageParams = locationId ? { locationId, clientId: webviewPaymethod?.credentials?.application_id } : {}
|
|
127
|
+
const message = {
|
|
128
|
+
action: 'init',
|
|
129
|
+
data: {
|
|
130
|
+
urlPlace: `${ordering.root}/carts/${cart?.uuid}/place`,
|
|
131
|
+
urlConfirm: `${ordering.root}/carts/${cart?.uuid}/confirm`,
|
|
132
|
+
payData: {
|
|
133
|
+
paymethod_id: webviewPaymethod?.id,
|
|
134
|
+
amount: cart?.balance ?? cart?.total,
|
|
135
|
+
delivery_zone_id: cart?.delivery_zone_id,
|
|
136
|
+
user_id: user?.id,
|
|
137
|
+
user_name: user?.name
|
|
138
|
+
},
|
|
139
|
+
currency: configs?.stripe_currency?.value || currency,
|
|
140
|
+
userToken: token,
|
|
141
|
+
clientId: webviewPaymethod?.credentials?.client_id,
|
|
142
|
+
...messageParams
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
setProg(false);
|
|
146
|
+
webviewRef?.current?.postMessage?.(JSON.stringify(message))
|
|
147
|
+
}}
|
|
148
|
+
/>
|
|
149
|
+
</View>
|
|
150
|
+
)
|
|
151
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -45,6 +45,7 @@ import { OrdersOption } from './components/OrdersOption';
|
|
|
45
45
|
import { PaymentOptionCash } from './components/PaymentOptionCash';
|
|
46
46
|
import { PaymentOptionStripe } from './components/PaymentOptionStripe';
|
|
47
47
|
import { PaymentOptions } from './components/PaymentOptions';
|
|
48
|
+
import { PaymentOptionsWebView } from './components/PaymentOptionsWebView';
|
|
48
49
|
import { PhoneInputNumber } from './components/PhoneInputNumber';
|
|
49
50
|
import { PreviousOrders } from './components/PreviousOrders';
|
|
50
51
|
import { ProductForm } from './components/ProductForm';
|
|
@@ -144,6 +145,7 @@ export {
|
|
|
144
145
|
PaymentOptionCash,
|
|
145
146
|
PaymentOptionStripe,
|
|
146
147
|
PaymentOptions,
|
|
148
|
+
PaymentOptionsWebView,
|
|
147
149
|
PhoneInputNumber,
|
|
148
150
|
PreviousOrders,
|
|
149
151
|
ProductForm,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder';
|
|
3
3
|
import Geolocation from '@react-native-community/geolocation'
|
|
4
4
|
import {
|
|
@@ -44,7 +44,7 @@ import { BusinessFeaturedController } from '../BusinessFeaturedController';
|
|
|
44
44
|
import { HighestRatedBusinesses } from '../HighestRatedBusinesses';
|
|
45
45
|
import { getTypesText, convertToRadian } from '../../utils';
|
|
46
46
|
import { OrderProgress } from '../OrderProgress';
|
|
47
|
-
import { useIsFocused } from '@react-navigation/native';
|
|
47
|
+
import { useFocusEffect, useIsFocused } from '@react-navigation/native';
|
|
48
48
|
|
|
49
49
|
const PIXELS_TO_SCROLL = 1000;
|
|
50
50
|
|
|
@@ -115,15 +115,15 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
|
|
|
115
115
|
const [featuredBusiness, setFeaturedBusinesses] = useState(Array);
|
|
116
116
|
const [isFarAway, setIsFarAway] = useState(false)
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
const timerId = useRef<any>(false)
|
|
119
119
|
// const panResponder = useRef(
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
//
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
//
|
|
120
|
+
// PanResponder.create({
|
|
121
|
+
// onMoveShouldSetPanResponder: (e, gestureState) => {
|
|
122
|
+
// const { dx, dy } = gestureState;
|
|
123
|
+
// resetInactivityTimeout()
|
|
124
|
+
// return (Math.abs(dx) > 20) || (Math.abs(dy) > 20);
|
|
125
|
+
// },
|
|
126
|
+
// })
|
|
127
127
|
// ).current
|
|
128
128
|
|
|
129
129
|
const configTypes =
|
|
@@ -165,16 +165,18 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
|
|
|
165
165
|
}
|
|
166
166
|
}, [businessesList.businesses]);
|
|
167
167
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
168
|
+
const resetInactivityTimeout = () => {
|
|
169
|
+
clearTimeout(timerId.current)
|
|
170
|
+
timerId.current = setInterval(() => {
|
|
171
|
+
if (!businessesList.loading) {
|
|
172
|
+
getBusinesses(true)
|
|
173
|
+
}
|
|
174
|
+
}, 300000)
|
|
175
|
+
}
|
|
174
176
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
resetInactivityTimeout()
|
|
179
|
+
}, [])
|
|
178
180
|
|
|
179
181
|
const handleOnRefresh = () => {
|
|
180
182
|
if (!businessesList.loading) {
|
|
@@ -195,6 +197,14 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
|
|
|
195
197
|
})
|
|
196
198
|
}, [orderState?.options?.address?.location])
|
|
197
199
|
|
|
200
|
+
useFocusEffect(
|
|
201
|
+
useCallback(() => {
|
|
202
|
+
getBusinesses(true)
|
|
203
|
+
resetInactivityTimeout()
|
|
204
|
+
return () => clearTimeout(timerId.current)
|
|
205
|
+
}, [navigation])
|
|
206
|
+
)
|
|
207
|
+
|
|
198
208
|
return (
|
|
199
209
|
<ScrollView style={styles.container} onScroll={(e) => handleScroll(e)} showsVerticalScrollIndicator={false}
|
|
200
210
|
refreshControl={
|
|
@@ -49,6 +49,7 @@ import NavBar from '../NavBar';
|
|
|
49
49
|
import { OrderSummary } from '../OrderSummary';
|
|
50
50
|
import { getTypesText } from '../../utils';
|
|
51
51
|
import { CartStoresListing } from '../CartStoresListing';
|
|
52
|
+
import { PaymentOptionsWebView } from '../../../../../src/components/PaymentOptionsWebView';
|
|
52
53
|
|
|
53
54
|
const mapConfigs = {
|
|
54
55
|
mapZoom: 16,
|
|
@@ -83,6 +84,7 @@ const CheckoutUI = (props: any) => {
|
|
|
83
84
|
deliveryOptionSelected,
|
|
84
85
|
instructionsOptions,
|
|
85
86
|
handleChangeDeliveryOption,
|
|
87
|
+
currency
|
|
86
88
|
} = props
|
|
87
89
|
|
|
88
90
|
const theme = useTheme();
|
|
@@ -114,10 +116,11 @@ const CheckoutUI = (props: any) => {
|
|
|
114
116
|
|
|
115
117
|
const [, { showToast }] = useToast();
|
|
116
118
|
const [, t] = useLanguage();
|
|
117
|
-
const [{ user }] = useSession();
|
|
119
|
+
const [{ user, token }] = useSession();
|
|
120
|
+
const [ordering] = useApi()
|
|
118
121
|
const [{ configs }] = useConfig();
|
|
119
122
|
const [{ parsePrice, parseDate }] = useUtils();
|
|
120
|
-
const [{ options, carts, loading }] = useOrder();
|
|
123
|
+
const [{ options, carts, loading }, { confirmCart }] = useOrder();
|
|
121
124
|
const [validationFields] = useValidationFields();
|
|
122
125
|
|
|
123
126
|
const [errorCash, setErrorCash] = useState(false);
|
|
@@ -126,8 +129,11 @@ const CheckoutUI = (props: any) => {
|
|
|
126
129
|
const [phoneUpdate, setPhoneUpdate] = useState(false);
|
|
127
130
|
const [openChangeStore, setOpenChangeStore] = useState(false)
|
|
128
131
|
const [isDeliveryOptionModalVisible, setIsDeliveryOptionModalVisible] = useState(false)
|
|
132
|
+
const [showGateway, setShowGateway] = useState<any>({ closedByUsed: false, open: false });
|
|
133
|
+
const [webviewPaymethod, setWebviewPaymethod] = useState<any>(null)
|
|
129
134
|
|
|
130
|
-
|
|
135
|
+
|
|
136
|
+
const isWalletEnabled = configs?.wallet_enabled?.value === '1' && (configs?.wallet_cash_enabled?.value === '1' || configs?.wallet_credit_point_enabled?.value === '1')
|
|
131
137
|
|
|
132
138
|
const driverTipsOptions = typeof configs?.driver_tip_options?.value === 'string'
|
|
133
139
|
? JSON.parse(configs?.driver_tip_options?.value) || []
|
|
@@ -156,6 +162,16 @@ const CheckoutUI = (props: any) => {
|
|
|
156
162
|
setIsUserDetailsEdit(true)
|
|
157
163
|
}
|
|
158
164
|
|
|
165
|
+
const handlePaymentMethodClick = (paymethod: any) => {
|
|
166
|
+
setShowGateway({ closedByUser: false, open: true })
|
|
167
|
+
setWebviewPaymethod(paymethod)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const onFailPaypal = async () => {
|
|
171
|
+
if (showGateway.closedByUser === true) {
|
|
172
|
+
await confirmCart(cart.uuid)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
159
175
|
const changeDeliveryOption = (option: any) => {
|
|
160
176
|
handleChangeDeliveryOption(option)
|
|
161
177
|
setIsDeliveryOptionModalVisible(false)
|
|
@@ -216,6 +232,10 @@ const CheckoutUI = (props: any) => {
|
|
|
216
232
|
}
|
|
217
233
|
}, [cart?.products])
|
|
218
234
|
|
|
235
|
+
useEffect(() => {
|
|
236
|
+
onFailPaypal()
|
|
237
|
+
}, [showGateway.closedByUser])
|
|
238
|
+
|
|
219
239
|
return (
|
|
220
240
|
<>
|
|
221
241
|
<Container noPadding>
|
|
@@ -503,6 +523,7 @@ const CheckoutUI = (props: any) => {
|
|
|
503
523
|
setErrorCash={setErrorCash}
|
|
504
524
|
onNavigationRedirect={onNavigationRedirect}
|
|
505
525
|
paySelected={paymethodSelected}
|
|
526
|
+
handlePaymentMethodClickCustom={handlePaymentMethodClick}
|
|
506
527
|
/>
|
|
507
528
|
</ChPaymethods>
|
|
508
529
|
</ChSection>
|
|
@@ -549,7 +570,7 @@ const CheckoutUI = (props: any) => {
|
|
|
549
570
|
<OrderSummary
|
|
550
571
|
cart={cart}
|
|
551
572
|
isCartPending={cart?.status === 2}
|
|
552
|
-
|
|
573
|
+
onNavigationRedirect={onNavigationRedirect}
|
|
553
574
|
/>
|
|
554
575
|
</>
|
|
555
576
|
)}
|
|
@@ -622,6 +643,18 @@ const CheckoutUI = (props: any) => {
|
|
|
622
643
|
iosBottom={20}
|
|
623
644
|
/>
|
|
624
645
|
)}
|
|
646
|
+
{webviewPaymethod?.gateway === 'paypal' && showGateway.open && (
|
|
647
|
+
<PaymentOptionsWebView
|
|
648
|
+
onNavigationRedirect={onNavigationRedirect}
|
|
649
|
+
uri={`${ordering.root}/html/paypal_react_native`}
|
|
650
|
+
user={user}
|
|
651
|
+
token={token}
|
|
652
|
+
cart={cart}
|
|
653
|
+
currency={currency}
|
|
654
|
+
webviewPaymethod={webviewPaymethod}
|
|
655
|
+
setShowGateway={setShowGateway}
|
|
656
|
+
/>
|
|
657
|
+
)}
|
|
625
658
|
</>
|
|
626
659
|
)
|
|
627
660
|
}
|
|
@@ -277,7 +277,7 @@ const MomentOptionUI = (props: MomentOptionParams) => {
|
|
|
277
277
|
style={{ marginEnd: 24 }}
|
|
278
278
|
/>
|
|
279
279
|
)}
|
|
280
|
-
<OText color={optionSelected.isAsap ? theme.colors.textNormal : theme.colors.disabled}>{t('ASAP_ABBREVIATION', 'ASAP') + ` (${moment().format('dddd, MMM
|
|
280
|
+
<OText color={optionSelected.isAsap ? theme.colors.textNormal : theme.colors.disabled}>{t('ASAP_ABBREVIATION', 'ASAP') + ` (${moment().format('dddd, MMM D, yyyy h:mm A')} + delivery time)`}</OText>
|
|
281
281
|
</WrapSelectOption>
|
|
282
282
|
<WrapSelectOption
|
|
283
283
|
onPress={() => setOptionSelected({ isAsap: false, isSchedule: true })}
|
|
@@ -37,6 +37,8 @@ const stripeOptions: any = ['stripe_direct', 'stripe', 'stripe_connect']
|
|
|
37
37
|
// { name: 'iDEAL', value: 'ideal' }
|
|
38
38
|
// ]
|
|
39
39
|
|
|
40
|
+
const webViewPaymentGateway: any = ['paypal', 'square']
|
|
41
|
+
|
|
40
42
|
const PaymentOptionsUI = (props: any) => {
|
|
41
43
|
const {
|
|
42
44
|
cart,
|
|
@@ -49,7 +51,8 @@ const PaymentOptionsUI = (props: any) => {
|
|
|
49
51
|
onNavigationRedirect,
|
|
50
52
|
handlePaymethodClick,
|
|
51
53
|
handlePaymethodDataChange,
|
|
52
|
-
isOpenMethod
|
|
54
|
+
isOpenMethod,
|
|
55
|
+
handlePaymentMethodClickCustom
|
|
53
56
|
} = props
|
|
54
57
|
|
|
55
58
|
const theme = useTheme();
|
|
@@ -90,6 +93,9 @@ const PaymentOptionsUI = (props: any) => {
|
|
|
90
93
|
|
|
91
94
|
const handlePaymentMethodClick = (paymethod: any) => {
|
|
92
95
|
const isPopupMethod = ['stripe', 'stripe_direct', 'stripe_connect', 'stripe_redirect', 'paypal'].includes(paymethod?.gateway)
|
|
96
|
+
if (webViewPaymentGateway.includes(paymethod?.gateway)) {
|
|
97
|
+
handlePaymentMethodClickCustom(paymethod)
|
|
98
|
+
}
|
|
93
99
|
handlePaymethodClick(paymethod, isPopupMethod)
|
|
94
100
|
}
|
|
95
101
|
|
|
@@ -139,7 +145,7 @@ const PaymentOptionsUI = (props: any) => {
|
|
|
139
145
|
)
|
|
140
146
|
}
|
|
141
147
|
|
|
142
|
-
const excludeIds: any = [
|
|
148
|
+
const excludeIds: any = [32, 66]; //exclude paypal & connect & redirect
|
|
143
149
|
|
|
144
150
|
return (
|
|
145
151
|
<PMContainer>
|
|
@@ -70,6 +70,7 @@ const UpsellingProductsUI = (props: UpsellingProductsParams) => {
|
|
|
70
70
|
const [{ parsePrice }] = useUtils()
|
|
71
71
|
const [, t] = useLanguage()
|
|
72
72
|
const { bottom } = useSafeAreaInsets()
|
|
73
|
+
const [isCheckout, setIsCheckout] = useState(false)
|
|
73
74
|
|
|
74
75
|
const cart = carts?.[`businessId:${props.businessId}`] ?? {}
|
|
75
76
|
const cartProducts = cart?.products?.length
|
|
@@ -95,8 +96,8 @@ const UpsellingProductsUI = (props: UpsellingProductsParams) => {
|
|
|
95
96
|
}, [upsellingProducts.loading, upsellingProducts?.products.length])
|
|
96
97
|
|
|
97
98
|
useEffect(() => {
|
|
98
|
-
Object.keys(cart).length === 0 && onNavigationRedirect && onNavigationRedirect('MyOrders')
|
|
99
|
-
}, [cart])
|
|
99
|
+
isCheckout && Object.keys(cart).length === 0 && onNavigationRedirect && onNavigationRedirect('MyOrders')
|
|
100
|
+
}, [cart, isCheckout])
|
|
100
101
|
|
|
101
102
|
const handleFormProduct = (product: any) => {
|
|
102
103
|
onNavigationRedirect && onNavigationRedirect('ProductDetails', {
|
|
@@ -185,7 +186,10 @@ const UpsellingProductsUI = (props: UpsellingProductsParams) => {
|
|
|
185
186
|
text={t('CHECKOUT', 'Checkout')}
|
|
186
187
|
style={{...styles.closeUpsellingButton}}
|
|
187
188
|
textStyle={{ color: theme.colors.white, fontSize: 14 }}
|
|
188
|
-
onClick={() =>
|
|
189
|
+
onClick={() => {
|
|
190
|
+
handleUpsellingPage()
|
|
191
|
+
setIsCheckout(true)
|
|
192
|
+
}}
|
|
189
193
|
/>
|
|
190
194
|
</View>
|
|
191
195
|
</>
|