ordering-ui-react-native 0.14.38 → 0.14.40-release

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.
Files changed (56) hide show
  1. package/package.json +2 -2
  2. package/src/components/BusinessItemAccordion/index.tsx +2 -2
  3. package/src/components/BusinessProductsListing/index.tsx +10 -26
  4. package/src/components/Cart/index.tsx +136 -62
  5. package/src/components/Cart/styles.tsx +7 -0
  6. package/src/components/Checkout/index.tsx +32 -168
  7. package/src/components/OrderDetails/index.tsx +102 -34
  8. package/src/components/OrderDetails/styles.tsx +7 -0
  9. package/src/components/OrderSummary/index.tsx +142 -58
  10. package/src/components/OrderSummary/styles.tsx +10 -2
  11. package/src/components/PaymentOptions/index.tsx +3 -1
  12. package/src/components/PaymentOptionsWebView/index.tsx +150 -0
  13. package/src/components/ProductForm/index.tsx +7 -9
  14. package/src/components/SingleProductCard/index.tsx +1 -1
  15. package/src/components/StripeElementsForm/index.tsx +28 -13
  16. package/src/components/TaxInformation/index.tsx +58 -26
  17. package/src/components/UpsellingProducts/index.tsx +13 -31
  18. package/src/components/VerifyPhone/styles.tsx +1 -2
  19. package/src/components/shared/OIcon.tsx +4 -1
  20. package/src/index.tsx +2 -0
  21. package/src/navigators/HomeNavigator.tsx +6 -0
  22. package/src/pages/ProductDetails.tsx +55 -0
  23. package/src/types/index.tsx +2 -0
  24. package/themes/doordash/src/components/LoginForm/index.tsx +1 -2
  25. package/themes/kiosk/src/components/Cart/index.tsx +14 -21
  26. package/themes/kiosk/src/components/CartItem/index.tsx +9 -7
  27. package/themes/kiosk/src/components/CustomerName/index.tsx +2 -1
  28. package/themes/kiosk/src/components/Intro/index.tsx +4 -4
  29. package/themes/kiosk/src/components/OptionCard/index.tsx +11 -6
  30. package/themes/kiosk/src/components/PaymentOptions/index.tsx +46 -44
  31. package/themes/original/src/components/BusinessItemAccordion/index.tsx +12 -9
  32. package/themes/original/src/components/BusinessItemAccordion/styles.tsx +3 -2
  33. package/themes/original/src/components/BusinessProductsListing/index.tsx +8 -4
  34. package/themes/original/src/components/BusinessesListing/index.tsx +100 -75
  35. package/themes/original/src/components/Cart/index.tsx +122 -24
  36. package/themes/original/src/components/Cart/styles.tsx +8 -1
  37. package/themes/original/src/components/Checkout/index.tsx +38 -3
  38. package/themes/original/src/components/Help/index.tsx +1 -1
  39. package/themes/original/src/components/Home/index.tsx +5 -3
  40. package/themes/original/src/components/MessageListing/index.tsx +4 -2
  41. package/themes/original/src/components/OrderDetails/index.tsx +114 -42
  42. package/themes/original/src/components/OrderDetails/styles.tsx +8 -1
  43. package/themes/original/src/components/OrderProgress/index.tsx +2 -1
  44. package/themes/original/src/components/OrderSummary/index.tsx +132 -23
  45. package/themes/original/src/components/OrderSummary/styles.tsx +7 -0
  46. package/themes/original/src/components/PaymentOptionWallet/index.tsx +6 -2
  47. package/themes/original/src/components/PaymentOptions/index.tsx +8 -2
  48. package/themes/original/src/components/ProductForm/index.tsx +63 -65
  49. package/themes/original/src/components/ProductForm/styles.tsx +6 -0
  50. package/themes/original/src/components/ProductOptionSubOption/index.tsx +3 -2
  51. package/themes/original/src/components/SingleProductCard/index.tsx +21 -11
  52. package/themes/original/src/components/SingleProductCard/styles.tsx +4 -0
  53. package/themes/original/src/components/StripeElementsForm/index.tsx +28 -13
  54. package/themes/original/src/components/TaxInformation/index.tsx +59 -27
  55. package/themes/original/src/components/UpsellingProducts/index.tsx +26 -18
  56. package/themes/original/src/types/index.tsx +2 -0
@@ -14,13 +14,13 @@ import {
14
14
  OSProductList,
15
15
  OSBill,
16
16
  OSTable,
17
- OSRow
17
+ OSRow,
18
+ Divider
18
19
  } from './styles';
19
20
 
20
21
  import { ProductItemAccordion } from '../ProductItemAccordion';
21
22
  import { CouponControl } from '../CouponControl';
22
- import { OInput, OModal, OText } from '../shared';
23
- import { ProductForm } from '../ProductForm';
23
+ import { OAlert, OInput, OModal, OText } from '../shared';
24
24
  import { verifyDecimals } from '../../utils';
25
25
  import { useTheme } from 'styled-components/native';
26
26
  import { TaxInformation } from '../TaxInformation';
@@ -36,7 +36,9 @@ const OrderSummaryUI = (props: any) => {
36
36
  isCartPending,
37
37
  isFromCheckout,
38
38
  commentState,
39
- handleChangeComment
39
+ handleChangeComment,
40
+ onNavigationRedirect,
41
+ handleRemoveOfferClick
40
42
  } = props;
41
43
 
42
44
  const theme = useTheme();
@@ -45,9 +47,8 @@ const OrderSummaryUI = (props: any) => {
45
47
  const [orderState] = useOrder();
46
48
  const [{ parsePrice, parseNumber }] = useUtils();
47
49
  const [validationFields] = useValidationFields();
48
- const [openProduct, setModalIsOpen] = useState(false)
49
- const [curProduct, setCurProduct] = useState<any>(null)
50
50
  const [openTaxModal, setOpenTaxModal] = useState<any>({ open: false, data: null })
51
+ const [confirm, setConfirm] = useState<any>({ open: false, content: null, handleOnAccept: null, id: null, title: null })
51
52
 
52
53
  const isCouponEnabled = validationFields?.fields?.checkout?.coupon?.enabled;
53
54
 
@@ -56,14 +57,16 @@ const OrderSummaryUI = (props: any) => {
56
57
  }
57
58
 
58
59
  const handleEditProduct = (product: any) => {
59
- setCurProduct(product)
60
- setModalIsOpen(true)
61
- }
62
-
63
- const handlerProductAction = (product: any) => {
64
- if (Object.keys(product).length) {
65
- setModalIsOpen(false)
66
- }
60
+ onNavigationRedirect &&
61
+ onNavigationRedirect('ProductDetails', {
62
+ isCartProduct: true,
63
+ productCart: product,
64
+ businessSlug: cart?.business?.slug,
65
+ businessId: cart?.business_id,
66
+ categoryId: product?.category_id,
67
+ productId: product?.id,
68
+ isFromCheckout: isFromCheckout,
69
+ })
67
70
  }
68
71
 
69
72
  const getIncludedTaxes = () => {
@@ -76,6 +79,22 @@ const OrderSummaryUI = (props: any) => {
76
79
  }
77
80
  }
78
81
 
82
+ const getIncludedTaxesDiscounts = () => {
83
+ return cart?.taxes?.filter((tax: any) => tax?.type === 1)?.reduce((carry: number, tax: any) => carry + (tax?.summary?.tax_after_discount ?? tax?.summary?.tax), 0)
84
+ }
85
+
86
+ const onRemoveOffer = (id: number) => {
87
+ setConfirm({
88
+ open: true,
89
+ content: [t('QUESTION_DELETE_OFFER', 'Are you sure that you want to delete the offer?')],
90
+ title: t('OFFER', 'Offer'),
91
+ handleOnAccept: () => {
92
+ setConfirm({ ...confirm, open: false })
93
+ handleRemoveOfferClick(id)
94
+ }
95
+ })
96
+ }
97
+
79
98
  return (
80
99
  <OSContainer>
81
100
  {cart?.products?.length > 0 && (
@@ -99,35 +118,65 @@ const OrderSummaryUI = (props: any) => {
99
118
  {cart?.valid && (
100
119
  <OSBill>
101
120
  <OSTable>
102
- <OText size={18}>{t('SUBTOTAL', 'Subtotal')}</OText>
103
- <OText size={18}>{parsePrice(cart?.subtotal + getIncludedTaxes())}</OText>
121
+ <OText size={16}>{t('SUBTOTAL', 'Subtotal')}</OText>
122
+ <OText size={16}>{parsePrice(cart?.subtotal + getIncludedTaxes())}</OText>
104
123
  </OSTable>
105
- {cart?.discount > 0 && cart?.total >= 0 && (
124
+ {cart?.discount > 0 && cart?.total >= 0 && cart?.offers?.length === 0 && (
106
125
  <OSTable>
107
126
  {cart?.discount_type === 1 ? (
108
- <OText size={18}>
109
- {t('DISCOUNT', 'Discount')}
110
- <OText size={18}>{`(${verifyDecimals(cart?.discount_rate, parsePrice)}%)`}</OText>
127
+ <OText size={16}>
128
+ {t('DISCOUNT', 'Discount')}{' '}
129
+ <OText size={16}>{`(${verifyDecimals(cart?.discount_rate, parsePrice)}%)`}</OText>
111
130
  </OText>
112
131
  ) : (
113
- <OText size={18}>{t('DISCOUNT', 'Discount')}</OText>
132
+ <OText size={16}>{t('DISCOUNT', 'Discount')}</OText>
133
+ )}
134
+ <OText size={16}>- {parsePrice(cart?.discount || 0)}</OText>
135
+ </OSTable>
136
+ )}
137
+ {
138
+ cart?.offers?.length > 0 && cart?.offers?.filter((offer: any) => offer?.target === 1)?.map((offer: any) => (
139
+ <OSTable key={offer.id}>
140
+ <OSRow>
141
+ <OText size={16}>{offer.name}</OText>
142
+ {offer.rate_type === 1 && (
143
+ <OText size={16}>{`(${verifyDecimals(offer?.rate, parsePrice)}%)`}</OText>
144
+ )}
145
+ <TouchableOpacity style={{ marginLeft: 5, top: 3 }} onPress={() => setOpenTaxModal({ open: true, data: offer, type: 'offer_target_1' })}>
146
+ <AntIcon name='exclamationcircleo' size={20} color={theme.colors.primary} />
147
+ </TouchableOpacity>
148
+ <TouchableOpacity style={{ marginLeft: 5, top: 3 }} onPress={() => onRemoveOffer(offer?.id)}>
149
+ <AntIcon name='closecircle' size={20} color={theme.colors.primary} />
150
+ </TouchableOpacity>
151
+ </OSRow>
152
+ <OText size={16} numberOfLines={2}>- {parsePrice(offer?.summary?.discount)}</OText>
153
+ </OSTable>
154
+ ))
155
+ }
156
+ <Divider />
157
+ {cart?.subtotal_with_discount > 0 && cart?.discount > 0 && cart?.total >= 0 && (
158
+ <OSTable>
159
+ <OText size={16} numberOfLines={1}>{t('SUBTOTAL_WITH_DISCOUNT', 'Subtotal with discount')}</OText>
160
+ {cart?.business?.tax_type === 1 ? (
161
+ <OText size={16}>{parsePrice(cart?.subtotal_with_discount + getIncludedTaxesDiscounts() ?? 0)}</OText>
162
+ ) : (
163
+ <OText size={16}>{parsePrice(cart?.subtotal_with_discount ?? 0)}</OText>
114
164
  )}
115
- <OText size={18}>- {parsePrice(cart?.discount || 0)}</OText>
116
165
  </OSTable>
117
166
  )}
118
167
  {
119
168
  cart?.taxes?.length > 0 && cart?.taxes?.filter((tax: any) => tax?.type === 2 && tax?.rate !== 0).map((tax: any) => (
120
169
  <OSTable key={tax?.id}>
121
170
  <OSRow>
122
- <OText size={18} numberOfLines={1}>
171
+ <OText size={16} numberOfLines={1}>
123
172
  {tax?.name || t('INHERIT_FROM_BUSINESS', 'Inherit from business')}{' '}
124
173
  {`(${verifyDecimals(tax?.rate, parseNumber)}%)`}{' '}
125
174
  </OText>
126
- <TouchableOpacity onPress={() => setOpenTaxModal({ open: true, data: tax })} >
175
+ <TouchableOpacity onPress={() => setOpenTaxModal({ open: true, data: tax, type: 'tax' })} >
127
176
  <AntIcon name='exclamationcircleo' size={20} color={theme.colors.primary} />
128
177
  </TouchableOpacity>
129
178
  </OSRow>
130
- <OText size={18}>{parsePrice(tax?.summary?.tax || 0)}</OText>
179
+ <OText size={16}>{parsePrice(tax?.summary?.tax_after_discount ?? tax?.summary?.tax ?? 0)}</OText>
131
180
  </OSTable>
132
181
  ))
133
182
  }
@@ -135,27 +184,69 @@ const OrderSummaryUI = (props: any) => {
135
184
  cart?.fees?.length > 0 && cart?.fees?.filter((fee: any) => !(fee.fixed === 0 && fee.percentage === 0))?.map((fee: any) => (
136
185
  <OSTable key={fee.id}>
137
186
  <OSRow>
138
- <OText size={18} numberOfLines={1}>
187
+ <OText size={16} numberOfLines={1}>
139
188
  {fee.name || t('INHERIT_FROM_BUSINESS', 'Inherit from business')}{' '}
140
189
  ({parsePrice(fee?.fixed)} + {fee.percentage}%){' '}
141
190
  </OText>
142
- <TouchableOpacity onPress={() => setOpenTaxModal({ open: true, data: fee })} >
191
+ <TouchableOpacity onPress={() => setOpenTaxModal({ open: true, data: fee, type: 'fee' })} >
143
192
  <AntIcon name='exclamationcircleo' size={20} color={theme.colors.primary} />
144
193
  </TouchableOpacity>
145
194
  </OSRow>
146
- <OText size={18}>{parsePrice(fee?.summary?.fixed + fee?.summary?.percentage || 0)}</OText>
195
+ <OText size={16}>{parsePrice(fee?.summary?.fixed + (fee?.summary?.percentage_after_discount ?? fee?.summary?.percentage) ?? 0)}</OText>
196
+ </OSTable>
197
+ ))
198
+ }
199
+ {
200
+ cart?.offers?.length > 0 && cart?.offers?.filter((offer: any) => offer?.target === 3)?.map((offer: any) => (
201
+ <OSTable key={offer.id}>
202
+ <OSRow>
203
+ <OText size={16}>{offer.name}</OText>
204
+ {offer.rate_type === 1 && (
205
+ <OText size={16}>{`(${verifyDecimals(offer?.rate, parsePrice)}%)`}</OText>
206
+ )}
207
+ <TouchableOpacity style={{ marginLeft: 5, top: 3 }} onPress={() => setOpenTaxModal({ open: true, data: offer, type: 'offer_target_3' })}>
208
+ <AntIcon name='exclamationcircleo' size={20} color={theme.colors.primary} />
209
+ </TouchableOpacity>
210
+ <TouchableOpacity style={{ marginLeft: 5, top: 3 }} onPress={() => onRemoveOffer(offer?.id)}>
211
+ <AntIcon name='closecircle' size={20} color={theme.colors.primary} />
212
+ </TouchableOpacity>
213
+ </OSRow>
214
+ <OText size={16}>
215
+ - {parsePrice(offer?.summary?.discount)}
216
+ </OText>
147
217
  </OSTable>
148
218
  ))
149
219
  }
150
220
  {orderState?.options?.type === 1 && cart?.delivery_price > 0 && (
151
221
  <OSTable>
152
- <OText size={18}>{t('DELIVERY_FEE', 'Delivery Fee')}</OText>
153
- <OText size={18}>{parsePrice(cart?.delivery_price)}</OText>
222
+ <OText size={16}>{t('DELIVERY_FEE', 'Delivery Fee')}</OText>
223
+ <OText size={16}>{parsePrice(cart?.delivery_price)}</OText>
154
224
  </OSTable>
155
225
  )}
226
+ {
227
+ cart?.offers?.length > 0 && cart?.offers?.filter((offer: any) => offer?.target === 2)?.map((offer: any) => (
228
+ <OSTable key={offer.id}>
229
+ <OSRow>
230
+ <OText size={16}>{offer.name}</OText>
231
+ {offer.rate_type === 1 && (
232
+ <OText size={16}>{`(${verifyDecimals(offer?.rate, parsePrice)}%)`}</OText>
233
+ )}
234
+ <TouchableOpacity style={{ marginLeft: 3, top: 3 }} onPress={() => setOpenTaxModal({ open: true, data: offer, type: 'offer_target_2' })}>
235
+ <AntIcon name='exclamationcircleo' size={20} color={theme.colors.primary} />
236
+ </TouchableOpacity>
237
+ <TouchableOpacity style={{ marginLeft: 3, top: 3 }} onPress={() => onRemoveOffer(offer?.id)}>
238
+ <AntIcon name='closecircle' size={20} color={theme.colors.primary} />
239
+ </TouchableOpacity>
240
+ </OSRow>
241
+ <OText size={16}>
242
+ - {parsePrice(offer?.summary?.discount)}
243
+ </OText>
244
+ </OSTable>
245
+ ))
246
+ }
156
247
  {cart?.driver_tip > 0 && (
157
248
  <OSTable>
158
- <OText size={18}>
249
+ <OText size={16}>
159
250
  {t('DRIVER_TIP', 'Driver tip')}
160
251
  {cart?.driver_tip_rate > 0 &&
161
252
  parseInt(configs?.driver_tip_type?.value, 10) === 2 &&
@@ -164,7 +255,7 @@ const OrderSummaryUI = (props: any) => {
164
255
  `(${verifyDecimals(cart?.driver_tip_rate, parseNumber)}%)`
165
256
  )}
166
257
  </OText>
167
- <OText size={18}>{parsePrice(cart?.driver_tip)}</OText>
258
+ <OText size={16}>{parsePrice(cart?.driver_tip)}</OText>
168
259
  </OSTable>
169
260
  )}
170
261
  {isCouponEnabled && !isCartPending && (
@@ -177,22 +268,20 @@ const OrderSummaryUI = (props: any) => {
177
268
  </View>
178
269
  </View>
179
270
  )}
180
- {cart?.total >= 1 && (
181
271
  <View style={{ marginTop: 15, borderTopWidth: 1, borderTopColor: '#d9d9d9' }}>
182
272
  <OSTable style={{ marginTop: 15 }}>
183
- <OText size={18} style={{ fontWeight: 'bold' }}>
273
+ <OText size={16} style={{ fontWeight: 'bold' }}>
184
274
  {t('TOTAL', 'Total')}
185
275
  </OText>
186
- <OText size={18} style={{ fontWeight: 'bold' }} color={theme.colors.primary}>
187
- {parsePrice(cart?.total)}
276
+ <OText size={16} style={{ fontWeight: 'bold' }} color={theme.colors.primary}>
277
+ {parsePrice(cart?.total >= 0 ? cart?.total : 0)}
188
278
  </OText>
189
279
  </OSTable>
190
280
  </View>
191
- )}
192
281
  {cart?.status !== 2 && (
193
282
  <OSTable>
194
283
  <View style={{ width: '100%', marginTop: 20 }}>
195
- <OText>{t('COMMENTS', 'Comments')}</OText>
284
+ <OText size={16}>{t('COMMENTS', 'Comments')}</OText>
196
285
  <View style={{ flex: 1, width: '100%' }}>
197
286
  <OInput
198
287
  value={cart?.comment}
@@ -223,32 +312,27 @@ const OrderSummaryUI = (props: any) => {
223
312
  )}
224
313
  </OSBill>
225
314
  )}
226
- <OModal
227
- open={openProduct}
228
- entireModal
229
- customClose
230
- onClose={() => setModalIsOpen(false)}
231
- isAvoidKeyBoardView
232
- >
233
- <ProductForm
234
- isCartProduct
235
- productCart={curProduct}
236
- businessSlug={cart?.business?.slug}
237
- businessId={cart?.business_id}
238
- categoryId={curProduct?.category_id}
239
- productId={curProduct?.id}
240
- onSave={handlerProductAction}
241
- onClose={() => setModalIsOpen(false)}
242
- isFromCheckout={isFromCheckout}
243
- />
244
- </OModal>
245
315
  <OModal
246
316
  open={openTaxModal.open}
247
317
  onClose={() => setOpenTaxModal({ open: false, data: null })}
248
318
  entireModal
319
+ title={`${openTaxModal.data?.name ||
320
+ t('INHERIT_FROM_BUSINESS', 'Inherit from business')} ${openTaxModal.data?.rate_type !== 2 ? `(${typeof openTaxModal.data?.rate === 'number' ? `${openTaxModal.data?.rate}%` : `${parsePrice(openTaxModal.data?.fixed ?? 0)} + ${openTaxModal.data?.percentage}%`})` : ''} `}
249
321
  >
250
- <TaxInformation data={openTaxModal.data} products={cart.products} />
322
+ <TaxInformation
323
+ type={openTaxModal.type}
324
+ data={openTaxModal.data}
325
+ products={cart?.products}
326
+ />
251
327
  </OModal>
328
+ <OAlert
329
+ open={confirm.open}
330
+ title={confirm.title}
331
+ content={confirm.content}
332
+ onAccept={confirm.handleOnAccept}
333
+ onCancel={() => setConfirm({ ...confirm, open: false, title: null })}
334
+ onClose={() => setConfirm({ ...confirm, open: false, title: null })}
335
+ />
252
336
  </>
253
337
  )}
254
338
  </OSContainer>
@@ -33,5 +33,13 @@ export const OSCoupon = styled.View`
33
33
  export const OSRow = styled.View`
34
34
  flex-direction: row;
35
35
  overflow: hidden;
36
- width: 80%;
37
- `
36
+ width: 70%;
37
+ flex-wrap: wrap;
38
+ `
39
+
40
+ export const Divider = styled.View`
41
+ border-color: #EAEAEA;
42
+ border-width: 1px;
43
+ margin-top: 5px;
44
+ margin-bottom: 10px;
45
+ `
@@ -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
+ )}
@@ -52,7 +52,6 @@ export const ProductOptionsUI = (props: any) => {
52
52
  handleChangeSuboptionState,
53
53
  handleChangeCommentState,
54
54
  productObject,
55
- onClose,
56
55
  businessSlug
57
56
  } = props
58
57
 
@@ -84,7 +83,6 @@ export const ProductOptionsUI = (props: any) => {
84
83
  }
85
84
 
86
85
  const handleRedirectLogin = (product : any) => {
87
- onClose()
88
86
  navigation.navigate('Login', {product: {businessId: product?.businessId, id: product?.id, categoryId: product?.categoryId, slug: businessSlug} })
89
87
  }
90
88
 
@@ -110,7 +108,7 @@ export const ProductOptionsUI = (props: any) => {
110
108
  name="x"
111
109
  size={35}
112
110
  style={{ color: theme.colors.white, backgroundColor: 'rgba(0,0,0,0.3)' }}
113
- onPress={onClose}
111
+ onPress={props.handleGoBack}
114
112
  />
115
113
  </View>
116
114
  </TopHeader>
@@ -134,26 +132,26 @@ export const ProductOptionsUI = (props: any) => {
134
132
  <View style={{ flexDirection: 'column', width: '100%' }}>
135
133
  <View style={{ flexDirection: 'row', marginTop: 15 }}>
136
134
  <OText size={20} style={{ flex: I18nManager.isRTL ? 0 : 1, marginBottom: 10 }}>{product?.name || productCart.name}{' '}</OText>
137
- {product?.calories && (
135
+ {!!product?.calories && (
138
136
  <OText size={16} style={styles.caloriesStyle}>{product?.calories} cal</OText>
139
137
  )}
140
138
  </View>
141
139
  <View style={{ flexDirection: 'row', marginBottom: 10 }}>
142
140
  <OText size={16} style={{ flex: I18nManager.isRTL ? 1 : 0 }} color={theme.colors.primary}>{productCart.price ? parsePrice(productCart.price) : ''}</OText>
143
- {product?.offer_price && (
141
+ {!!product?.offer_price !== null && product?.in_offer && (
144
142
  <OText style={styles.regularPriceStyle}>{parsePrice(product?.offer_price)}</OText>
145
143
  )}
146
144
  </View>
147
- {(product?.estimated_person || (product?.sku && product?.sku !== '-1' && product?.sku !== '1')) && (
145
+ {(!!product?.estimated_person || (!!product?.sku && product?.sku !== '-1' && product?.sku !== '1')) && (
148
146
  <OText size={14} style={{ flex: I18nManager.isRTL ? 1 : 0, marginBottom: 10 }} color={'#909BA9'}>
149
147
  {
150
148
  ((product?.sku && product?.sku !== '-1' && product?.sku !== '1') || (productCart?.sku && productCart?.sku !== '-1' && productCart?.sku !== '1'))
151
149
  && <>{t('SKU', 'Sku')}{' '}{product?.sku || productCart?.sku}</>
152
150
  }
153
- {product?.sku && product?.sku !== '-1' && product?.sku !== '1' && product?.estimated_person && (
151
+ {!!product?.sku && product?.sku !== '-1' && product?.sku !== '1' && !!product?.estimated_person && (
154
152
  <>&nbsp;&#183;&nbsp;</>
155
153
  )}
156
- {product?.estimated_person
154
+ {!!product?.estimated_person
157
155
  && <>{product?.estimated_person}{' '}{t('ESTIMATED_PERSONS', 'persons')}</>
158
156
  }
159
157
  </OText>
@@ -337,7 +335,7 @@ export const ProductOptionsUI = (props: any) => {
337
335
  />
338
336
  ) : (
339
337
  <OButton
340
- onClick={navigation.navigate('AddressList')}
338
+ onClick={() => navigation.navigate('AddressList')}
341
339
  />
342
340
  )
343
341
  )}
@@ -86,7 +86,7 @@ export const SingleProductCard = (props: SingleProductCardParams) => {
86
86
  <OText size={12} numberOfLines={2} ellipsizeMode='tail' style={styles.textStyle}>{product?.description}</OText>
87
87
  <PricesContainer>
88
88
  <OText color={theme.colors.primary}>{parsePrice(product?.price)}</OText>
89
- {product?.offer_price && (
89
+ {!!product?.offer_price !== null && product?.in_offer && (
90
90
  <OText style={styles.regularPriceStyle}>{parsePrice(product?.offer_price)}</OText>
91
91
  )}
92
92
  </PricesContainer>
@@ -33,19 +33,33 @@ const StripeElementsFormUI = (props: any) => {
33
33
  const { confirmSetupIntent, loading: confirmSetupLoading } = useConfirmSetupIntent();
34
34
  const [createPmLoading, setCreatePmLoading] = useState(false);
35
35
 
36
- const billingDetails = {
37
- name: `${user.name} ${user.lastname}`,
38
- email: user.email,
39
- address: user.address
40
- };
36
+ let billingDetails: any = {}
37
+
38
+ if (user?.name || user?.lastname) {
39
+ if (user?.name) {
40
+ billingDetails.name = user?.name
41
+ }
42
+ if (user?.lastname) {
43
+ billingDetails.name = `${billingDetails?.name} ${user?.lastname}`
44
+ }
45
+ }
46
+
47
+ if (user?.email) {
48
+ billingDetails.email = user?.email
49
+ }
50
+
51
+ if (user?.address) {
52
+ billingDetails.addressLine1 = user?.address
53
+ }
41
54
 
42
55
  const createPayMethod = async () => {
56
+ const params: any = { type: 'Card' }
57
+ if (Object.keys(billingDetails).length > 0) {
58
+ params.billingDetails = billingDetails
59
+ }
43
60
  try {
44
61
  setCreatePmLoading(true)
45
- const { paymentMethod } = await createPaymentMethod({
46
- type: 'Card',
47
- billingDetails,
48
- });
62
+ const { paymentMethod } = await createPaymentMethod(params);
49
63
 
50
64
  setCreatePmLoading(false)
51
65
  handleSource && handleSource({
@@ -68,11 +82,12 @@ const StripeElementsFormUI = (props: any) => {
68
82
  createPayMethod();
69
83
  return
70
84
  }
85
+ const params: any = { type: 'Card' }
86
+ if (Object.keys(billingDetails).length > 0) {
87
+ params.billingDetails = billingDetails
88
+ }
71
89
  try {
72
- const { setupIntent, error } = await confirmSetupIntent(requirements, {
73
- type: 'Card',
74
- billingDetails,
75
- });
90
+ const { setupIntent, error } = await confirmSetupIntent(requirements, params);
76
91
 
77
92
  if (setupIntent?.status === 'Succeeded') {
78
93
  stripeTokenHandler(setupIntent?.paymentMethodId, user, businessId);