ordering-ui-react-native 0.14.61 → 0.14.64

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,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.14.61",
3
+ "version": "0.14.64",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -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
- <View style={{ zIndex: 9999, height: '100%', width: '100%', position: 'absolute', backgroundColor: 'white' }}>
653
- <Icon
654
- name="x"
655
- size={35}
656
- style={{ backgroundColor: 'white', paddingTop: 30, paddingLeft: 10 }}
657
- onPress={handleCloseWebview}
658
- />
659
- <OText
660
- style={{
661
- textAlign: 'center',
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
- <View style={{ zIndex: 9999, height: '100%', width: '100%', position: 'absolute', backgroundColor: 'white' }}>
719
- <Icon
720
- name="x"
721
- size={35}
722
- style={{ backgroundColor: 'white', paddingTop: 30, paddingLeft: 10 }}
723
- onPress={handleCloseWebview}
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
- <OText
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
- if(paymethod?.gateway === 'paypal' || paymethod?.gateway === 'square') {
97
+ if (webViewPaymentGateway.includes(paymethod?.gateway)) {
96
98
  handlePaymentMethodClickCustom(paymethod)
97
99
  }
98
100
  setCardData(paymethodData)
@@ -0,0 +1,150 @@
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 } : {}
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
+ )}
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,
@@ -45,6 +45,15 @@ export const OrderContentComponent = (props: OrderContent) => {
45
45
 
46
46
  const pastOrderStatuses = [1, 2, 5, 6, 10, 11, 12, 16, 17]
47
47
 
48
+ const walletName: any = {
49
+ cash: {
50
+ name: t('PAY_WITH_CASH_WALLET', 'Pay with Cash Wallet'),
51
+ },
52
+ credit_point: {
53
+ name: t('PAY_WITH_CREDITS_POINTS_WALLET', 'Pay with Credit Points Wallet'),
54
+ }
55
+ }
56
+
48
57
  const styles = StyleSheet.create({
49
58
  linkWithIcons: {
50
59
  flexDirection: 'row',
@@ -441,7 +450,7 @@ export const OrderContentComponent = (props: OrderContent) => {
441
450
  )
442
451
  }
443
452
 
444
- <Total>
453
+ <Total style={{ paddingBottom: 10 }}>
445
454
  <Table>
446
455
  <OText mBottom={4} style={styles.textBold}>
447
456
  {t('TOTAL', 'Total')}
@@ -455,6 +464,52 @@ export const OrderContentComponent = (props: OrderContent) => {
455
464
  </OText>
456
465
  </Table>
457
466
  </Total>
467
+
468
+ {order?.payment_events?.length > 0 && (
469
+ <View>
470
+ <OText size={14} color={theme.colors.textNormal}>{t('PAYMENTS', 'Payments')}</OText>
471
+ <View
472
+ style={{
473
+ width: '100%',
474
+ marginTop: 5
475
+ }}
476
+ >
477
+ {order?.payment_events?.map((event: any) => (
478
+ <View
479
+ key={event.id}
480
+ style={{
481
+ display: 'flex',
482
+ flexDirection: 'row',
483
+ justifyContent: 'space-between',
484
+ alignItems: 'center',
485
+ marginBottom: 10
486
+ }}
487
+ >
488
+ <View
489
+ style={{
490
+ display: 'flex',
491
+ flexDirection: 'column',
492
+ }}
493
+ >
494
+ <OText>
495
+ {event?.wallet_event
496
+ ? walletName[event?.wallet_event?.wallet?.type]?.name
497
+ : event?.paymethod?.name}
498
+ </OText>
499
+ {event?.data?.charge_id && (
500
+ <OText>
501
+ {`${t('CODE', 'Code')}: ${event?.data?.charge_id}`}
502
+ </OText>
503
+ )}
504
+ </View>
505
+ <OText>
506
+ -{parsePrice(event.amount)}
507
+ </OText>
508
+ </View>
509
+ ))}
510
+ </View>
511
+ </View>
512
+ )}
458
513
  </OrderBill >
459
514
  <OModal
460
515
  open={openReviewModal}
@@ -14,7 +14,7 @@ import {
14
14
  } from '../shared'
15
15
 
16
16
  import { useTheme } from 'styled-components/native';
17
- import { StyleSheet } from 'react-native';
17
+ import { StyleSheet, View } from 'react-native';
18
18
 
19
19
  import {
20
20
  useLanguage,
@@ -84,6 +84,25 @@ export const OrderHeaderComponent = (props: OrderHeader) => {
84
84
  17: theme.colors.statusOrderRed,
85
85
  };
86
86
 
87
+ const walletName: any = {
88
+ cash: {
89
+ name: t('CASH_WALLET', 'Cash Wallet'),
90
+ },
91
+ credit_point: {
92
+ name: t('CREDITS_POINTS_WALLET', 'Credit Points Wallet'),
93
+ }
94
+ }
95
+
96
+ const orderTypes = (type: number) => type === 1
97
+ ? t('DELIVERY', 'Delivery')
98
+ : order.delivery_type === 2
99
+ ? t('PICKUP', 'Pickup')
100
+ : order.delivery_type === 3
101
+ ? t('EAT_IN', 'Eat in')
102
+ : order.delivery_type === 4
103
+ ? t('CURBSIDE', 'Curbside')
104
+ : t('DRIVER_THRU', 'Driver thru')
105
+
87
106
  return (
88
107
  <>
89
108
  <Header>
@@ -176,18 +195,30 @@ export const OrderHeaderComponent = (props: OrderHeader) => {
176
195
  </>
177
196
  </OText>
178
197
  {!order?.isLogistic && order?.delivery_type && (!order?.order_group_id || !logisticOrderStatus?.includes(order?.status)) && (
179
- <OText size={13}>
180
- {`${order?.paymethod?.name} - ${order.delivery_type === 1
181
- ? t('DELIVERY', 'Delivery')
182
- : order.delivery_type === 2
183
- ? t('PICKUP', 'Pickup')
184
- : order.delivery_type === 3
185
- ? t('EAT_IN', 'Eat in')
186
- : order.delivery_type === 4
187
- ? t('CURBSIDE', 'Curbside')
188
- : t('DRIVER_THRU', 'Driver thru')
189
- }`}
190
- </OText>
198
+ <>
199
+ <OText size={13}>
200
+ <OText size={13} weight='bold'>{`${t('ORDER_TYPE', 'Order Type')}: `}</OText>
201
+ {orderTypes(order.delivery_type)}
202
+ </OText>
203
+ {order?.payment_events?.length > 0 && (
204
+ <View>
205
+ <OText size={13}>
206
+ <OText size={13} weight='bold'>
207
+ {`${t('PAYMENT_METHODS', 'Payment methods')}: `}
208
+ </OText>
209
+ {order?.payment_events?.map((event: any, idx: number) => {
210
+ return event?.wallet_event
211
+ ? idx < order?.payment_events?.length - 1
212
+ ? `${walletName[event?.wallet_event?.wallet?.type]?.name} - `
213
+ : walletName[event?.wallet_event?.wallet?.type]?.name
214
+ : idx < order?.payment_events?.length - 1
215
+ ? `${event?.paymethod?.name} - `
216
+ : event?.paymethod?.name
217
+ })}
218
+ </OText>
219
+ </View>
220
+ )}
221
+ </>
191
222
  )}
192
223
  </OrderHeader>
193
224
  </>
@@ -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
- // const timerId = useRef<any>(false)
118
+ const timerId = useRef<any>(false)
119
119
  // const panResponder = useRef(
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
- // })
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
- // const resetInactivityTimeout = () => {
169
- // clearTimeout(timerId.current)
170
- // timerId.current = setInterval(() => {
171
- // getBusinesses(true)
172
- // }, 600000)
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
- // useEffect(() => {
176
- // resetInactivityTimeout()
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
- const isWalletEnabled = configs?.wallet_enabled?.value === '1' && (configs?.wallet_cash_enabled?.value === '1' || configs?.wallet_credit_point_enabled?.value === '1')
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
- onNavigationRedirect={onNavigationRedirect}
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 d, yyyy h:mm A')} + delivery time)`}</OText>
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 = [3, 32, 66]; //exclude paypal & connect & redirect
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={() => handleUpsellingPage()}
189
+ onClick={() => {
190
+ handleUpsellingPage()
191
+ setIsCheckout(true)
192
+ }}
189
193
  />
190
194
  </View>
191
195
  </>