ordering-ui-react-native 0.14.60 → 0.14.63

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.60",
3
+ "version": "0.14.63",
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
  </>
@@ -95,7 +95,7 @@ interface Props {
95
95
  style?: ViewStyle;
96
96
  bgImage: ImageSourcePropType;
97
97
  innerStyle?: ViewStyle;
98
- icon: ImageSourcePropType;
98
+ icon?: ImageSourcePropType;
99
99
  iconStyle?: ImageStyle;
100
100
  callToActionText: string;
101
101
  callToActionTextStyle?: TextStyle;
@@ -15,6 +15,8 @@ import { Container } from '../../layouts/Container'
15
15
  import NavBar from '../NavBar'
16
16
  import { LANDSCAPE, PORTRAIT, useDeviceOrientation } from '../../../../../src/hooks/DeviceOrientation'
17
17
  import GridContainer from '../../layouts/GridContainer'
18
+ import AntDesignIcon from 'react-native-vector-icons/AntDesign'
19
+ import MaterialIcon from 'react-native-vector-icons/MaterialCommunityIcons'
18
20
 
19
21
  const OrderTypeSelectorCardUI = (props: OrderTypeSelectParams) => {
20
22
  const {
@@ -27,7 +29,7 @@ const OrderTypeSelectorCardUI = (props: OrderTypeSelectParams) => {
27
29
  callback
28
30
  } = props
29
31
 
30
- const theme = useTheme();
32
+ const theme = useTheme();
31
33
  const [, t] = useLanguage();
32
34
  const [orientationState] = useDeviceOrientation();
33
35
  const [orderState] = useOrder()
@@ -45,7 +47,7 @@ const OrderTypeSelectorCardUI = (props: OrderTypeSelectParams) => {
45
47
  }
46
48
 
47
49
  useEffect(() => {
48
- if(isCardCliked){
50
+ if (isCardCliked) {
49
51
  callback?.()
50
52
  setIsCardClicked(false)
51
53
  setIsLoadingCard(null)
@@ -57,8 +59,8 @@ const OrderTypeSelectorCardUI = (props: OrderTypeSelectParams) => {
57
59
  <Container>
58
60
  <NavBar
59
61
  title={t('ORDER_TYPE_X_ID', 'Order type')}
60
- {...(goBack && { onActionLeft: goBack } )}
61
- btnStyle={{paddingLeft: 0}}
62
+ {...(goBack && { onActionLeft: goBack })}
63
+ btnStyle={{ paddingLeft: 0 }}
62
64
  />
63
65
 
64
66
  <View style={{ marginVertical: orientationState?.dimensions?.height * 0.03 }}>
@@ -83,13 +85,13 @@ const OrderTypeSelectorCardUI = (props: OrderTypeSelectParams) => {
83
85
  style={cardStyle}
84
86
  isDisabled={isCardCliked}
85
87
  isLoading={isLoadingCard === 'Eat In'}
86
- title={t('EAT_IN','Eat In')}
88
+ title={t('EAT_IN', 'Eat In')}
87
89
  description={t('EAT_IN_DESCRIPTION', 'We are very glad to have you here. Bon appetit!')}
88
90
  bgImage={theme.images.general.eatIn}
89
- icon={theme.images.general.pushPin}
91
+ VectorIcon={() => <MaterialIcon name='pin-outline' size={28} color='white' style={{ marginBottom: 10 }} />}
90
92
  callToActionText={t('START_MY_ORDER', 'Start my order')}
91
93
  onClick={() => {
92
- if(_eatIn?.value !== orderState?.options?.type){
94
+ if (_eatIn?.value !== orderState?.options?.type) {
93
95
  handleChangeOrderType(_eatIn?.value);
94
96
  setIsCardClicked(true)
95
97
  setIsLoadingCard('Eat In')
@@ -106,15 +108,15 @@ const OrderTypeSelectorCardUI = (props: OrderTypeSelectParams) => {
106
108
 
107
109
  <OptionCard
108
110
  style={cardStyle}
109
- title={t('TAKE_OUT','Take out')}
111
+ title={t('TAKE_OUT', 'Take out')}
110
112
  isDisabled={isCardCliked}
111
113
  isLoading={isLoadingCard === 'Take out'}
112
114
  description={t('TAKE_OUT_DESCRIPTION', 'You are very welcome anytime you visit us!')}
113
115
  bgImage={theme.images.general.takeOut}
114
- icon={theme.images.general.shoppingCart}
116
+ VectorIcon={() => <AntDesignIcon name='shoppingcart' size={28} color='white' style={{ marginBottom: 10 }} />}
115
117
  callToActionText={t('START_MY_ORDER', 'Start my order')}
116
118
  onClick={() => {
117
- if(_takeOut?.value !== orderState?.options?.type){
119
+ if (_takeOut?.value !== orderState?.options?.type) {
118
120
  handleChangeOrderType(_takeOut?.value);
119
121
  setIsCardClicked(true)
120
122
  setIsLoadingCard('Take out')
@@ -246,8 +246,9 @@ export const ProductOptionsUI = (props: any) => {
246
246
  {...navBarProps}
247
247
  titleColor={theme.colors.white}
248
248
  btnStyle={{
249
- width: 66,
250
- height: 66,
249
+ width: 55,
250
+ height: 55,
251
+ overflow: 'scroll',
251
252
  backgroundColor: 'black',
252
253
  borderRadius: 100,
253
254
  color: 'white',
@@ -125,7 +125,7 @@ const UpsellingProductsUI = (props: UpsellingProductsParams) => {
125
125
  {product.name}
126
126
  </OText>
127
127
 
128
- {product?.price && (
128
+ {!!product?.price && (
129
129
  <OText>
130
130
  <OText
131
131
  color={theme.colors.primary}
@@ -200,7 +200,7 @@ const UpsellingProductsUI = (props: UpsellingProductsParams) => {
200
200
  {product.name}
201
201
  </OText>
202
202
 
203
- {product?.price && (
203
+ {!!product?.price && (
204
204
  <OText>
205
205
  <OText
206
206
  color={theme.colors.primary}
@@ -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'
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
  )}
@@ -569,7 +590,7 @@ const CheckoutUI = (props: any) => {
569
590
  </OText>
570
591
  )}
571
592
 
572
- {!paymethodSelected && cart?.status !== 2 && cart?.valid && (
593
+ {(!paymethodSelected && cart?.balance > 0) && cart?.status !== 2 && cart?.valid && (
573
594
  <OText
574
595
  color={theme.colors.error}
575
596
  size={12}
@@ -605,8 +626,8 @@ const CheckoutUI = (props: any) => {
605
626
  {!cartState.loading && cart && cart?.status !== 2 && (
606
627
  <FloatingButton
607
628
  handleClick={() => handlePlaceOrder()}
608
- isSecondaryBtn={loading || !cart?.valid || !paymethodSelected || placing || errorCash || cart?.subtotal < cart?.minimum}
609
- disabled={loading || !cart?.valid || !paymethodSelected || placing || errorCash || cart?.subtotal < cart?.minimum}
629
+ isSecondaryBtn={loading || !cart?.valid || (!paymethodSelected && cart?.balance > 0) || placing || errorCash || cart?.subtotal < cart?.minimum}
630
+ disabled={loading || !cart?.valid || (!paymethodSelected && cart?.balance > 0) || placing || errorCash || cart?.subtotal < cart?.minimum}
610
631
  btnText={cart?.subtotal >= cart?.minimum
611
632
  ? (
612
633
  placing
@@ -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
  }
@@ -7,7 +7,8 @@ import {
7
7
  PaymentOptionWallet as PaymentOptionWalletController,
8
8
  useLanguage,
9
9
  useUtils,
10
- useOrder
10
+ useOrder,
11
+ useConfig
11
12
  } from 'ordering-components/native'
12
13
 
13
14
  import {
@@ -27,11 +28,15 @@ const PaymentOptionWalletUI = (props: any) => {
27
28
 
28
29
  const theme = useTheme()
29
30
  const [, t] = useLanguage()
31
+ const [{ configs }] = useConfig()
30
32
  const [{ carts }] = useOrder()
31
33
  const [{ parsePrice }] = useUtils()
32
34
 
33
35
  const cart = carts?.[`businessId:${businessId}`] ?? {}
34
36
 
37
+ const isWalletCashEnabled = configs?.wallet_cash_enabled?.value === '1'
38
+ const isWalletPointsEnabled = configs?.wallet_credit_point_enabled?.value === '1'
39
+
35
40
  const styles = StyleSheet.create({
36
41
  checkBoxStyle: {
37
42
  width: 25,
@@ -48,9 +53,11 @@ const PaymentOptionWalletUI = (props: any) => {
48
53
  const walletName: any = {
49
54
  cash: {
50
55
  name: t('PAY_WITH_CASH_WALLET', 'Pay with Cash Wallet'),
56
+ isActive: isWalletCashEnabled
51
57
  },
52
58
  credit_point: {
53
59
  name: t('PAY_WITH_CREDITS_POINTS_WALLET', 'Pay with Credit Points Wallet'),
60
+ isActive: isWalletPointsEnabled
54
61
  }
55
62
  }
56
63
 
@@ -85,7 +92,7 @@ const PaymentOptionWalletUI = (props: any) => {
85
92
  walletsState.result?.length > 0 &&
86
93
  (
87
94
  <>
88
- {walletsState.result?.map((wallet: any, idx: any) => wallet.valid && wallet.balance >= 0 && (
95
+ {walletsState.result?.map((wallet: any, idx: any) => wallet.valid && wallet.balance >= 0 && walletName[wallet.type]?.isActive && (
89
96
  <Container
90
97
  key={wallet.id}
91
98
  isBottomBorder={idx === walletsState.result?.filter((wallet: any) => wallet.valid)?.length - 1}
@@ -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
  </>
@@ -99,7 +99,7 @@ const ProfileListUI = (props: ProfileParams) => {
99
99
  const { height } = useWindowDimensions();
100
100
  const { top, bottom } = useSafeAreaInsets();
101
101
 
102
- const isWalletEnabled = configs?.wallet_enabled?.value === '1'
102
+ const isWalletEnabled = configs?.wallet_enabled?.value === '1' && (configs?.wallet_cash_enabled?.value === '1' || configs?.wallet_credit_point_enabled?.value === '1')
103
103
 
104
104
  const onRedirect = (route: string, params?: any) => {
105
105
  navigation.navigate(route, params)
@@ -35,19 +35,25 @@ const WalletsUI = (props: any) => {
35
35
  const theme = useTheme()
36
36
  const [{ parsePrice, parseDate }] = useUtils()
37
37
  const [{ configs }] = useConfig()
38
+ const isWalletCashEnabled = configs?.wallet_cash_enabled?.value === '1'
39
+ const isWalletPointsEnabled = configs?.wallet_credit_point_enabled?.value === '1'
38
40
 
39
- const [tabSelected, setTabSelected] = useState('cash')
41
+ const [tabSelected, setTabSelected] = useState(isWalletCashEnabled ? 'cash' : 'credit_point')
42
+
43
+ const isWalletEnabled = configs?.wallet_enabled?.value === '1' && (isWalletCashEnabled || isWalletPointsEnabled)
40
44
 
41
45
  const currentWalletSelected = (walletList.wallets?.length > 0 && walletList.wallets?.find((w: any) => w.type === tabSelected)) ?? null
42
46
 
43
47
  const walletName: any = {
44
48
  cash: {
45
49
  name: t('CASH_WALLET', 'Cash Wallet'),
46
- value: 0
50
+ value: 0,
51
+ isActive: isWalletCashEnabled
47
52
  },
48
53
  credit_point: {
49
54
  name: t('CREDITS_POINTS_WALLET', 'Credit Points Wallet'),
50
- value: 1
55
+ value: 1,
56
+ isActive: isWalletPointsEnabled
51
57
  }
52
58
  }
53
59
 
@@ -61,7 +67,7 @@ const WalletsUI = (props: any) => {
61
67
  }
62
68
 
63
69
  useEffect(() => {
64
- if (configs?.wallet_enabled?.value === '0') {
70
+ if (!isWalletEnabled) {
65
71
  navigation.navigate('BottomTab', {
66
72
  screen: 'Profile'
67
73
  })
@@ -85,7 +91,7 @@ const WalletsUI = (props: any) => {
85
91
  (
86
92
  <>
87
93
  <OTabs>
88
- {walletList.wallets?.map((wallet: any) =>(
94
+ {walletList.wallets?.map((wallet: any) => walletName[wallet.type]?.isActive && (
89
95
  <Pressable
90
96
  key={wallet.id}
91
97
  onPress={() => handleChangeTab(wallet)}