ordering-ui-react-native 0.18.80 → 0.18.82

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.18.80",
3
+ "version": "0.18.82",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect } from 'react'
2
- import { useLanguage, useConfig } from 'ordering-components/native'
2
+ import { useLanguage, useConfig, useOrder } from 'ordering-components/native'
3
3
  import { useGooglePay, useApplePay } from '@stripe/stripe-react-native'
4
4
  import { Platform } from 'react-native';
5
5
  import { StripeMethodFormParams } from '../../types';
@@ -21,6 +21,7 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
21
21
  } = props
22
22
  const { initGooglePay, createGooglePayPaymentMethod, loading } = useGooglePay();
23
23
  const { presentApplePay, isApplePaySupported } = useApplePay();
24
+ const [{ loading: loadingCart }] = useOrder()
24
25
  const [, t] = useLanguage()
25
26
  const [{ configs }] = useConfig()
26
27
  const applePay = ['global_apple_pay', 'apple_pay']
@@ -35,53 +36,15 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
35
36
  setPlaceByMethodPay(false)
36
37
  return
37
38
  }
38
- const initialize = async () => {
39
- try {
40
- setMethodPaySupported({
41
- ...methodPaySupported,
42
- loading: true
43
- })
44
- const { error } = await initGooglePay({
45
- testEnv: devMode,
46
- merchantName: android_app_id,
47
- countryCode: 'US',
48
- billingAddressConfig: {
49
- format: 'FULL',
50
- isPhoneNumberRequired: true,
51
- isRequired: false,
52
- },
53
- existingPaymentMethodRequired: false,
54
- isEmailRequired: true,
55
- });
56
-
57
- if (error) {
58
- setErrors(error.code + ' - ' + error.message);
59
- setMethodPaySupported({
60
- enabled: false,
61
- loading: false
62
- })
63
- setPlaceByMethodPay(false)
64
- return;
65
- }
66
- setMethodPaySupported({
67
- enabled: true,
68
- loading: false
69
- })
70
- setPlaceByMethodPay(false)
71
- setErrors('')
72
- } catch (err: any) {
73
- setErrors('Catch ' + err?.message)
74
- setMethodPaySupported({
75
- enabled: false,
76
- loading: false
77
- })
78
- setPlaceByMethodPay(false)
79
- }
80
- }
81
- if (googlePay.includes(paymethod) && !methodPaySupported?.enabled) {
82
- initialize();
39
+ if (!loadingCart) {
40
+ setMethodPaySupported({
41
+ enabled: true,
42
+ loading: false
43
+ })
44
+ setPlaceByMethodPay(false)
45
+ setErrors('')
83
46
  }
84
- }, [initGooglePay, paymethod]);
47
+ }, [paymethod, loadingCart]);
85
48
 
86
49
  useEffect(() => {
87
50
  if (applePay.includes(paymethod) && !paymethod) return
@@ -95,11 +58,57 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
95
58
  }
96
59
  }, [paymethod])
97
60
 
61
+ const initialize = async () => {
62
+ try {
63
+ setMethodPaySupported({
64
+ ...methodPaySupported,
65
+ loading: true
66
+ })
67
+ const { error } = await initGooglePay({
68
+ testEnv: devMode,
69
+ merchantName: android_app_id,
70
+ countryCode: 'US',
71
+ billingAddressConfig: {
72
+ format: 'FULL',
73
+ isPhoneNumberRequired: true,
74
+ isRequired: false,
75
+ },
76
+ existingPaymentMethodRequired: false,
77
+ isEmailRequired: true,
78
+ });
79
+
80
+ if (error) {
81
+ setErrors(error.code + ' - ' + error.message);
82
+ setMethodPaySupported({
83
+ enabled: false,
84
+ loading: false
85
+ })
86
+ setPlaceByMethodPay(false)
87
+ return true;
88
+ }
89
+ setMethodPaySupported({
90
+ enabled: true,
91
+ loading: false
92
+ })
93
+ setPlaceByMethodPay(false)
94
+ setErrors('')
95
+ } catch (err: any) {
96
+ setErrors('Catch ' + err?.message)
97
+ setMethodPaySupported({
98
+ enabled: false,
99
+ loading: false
100
+ })
101
+ setPlaceByMethodPay(false)
102
+ }
103
+ }
104
+
98
105
  const createPaymentMethod = async () => {
99
106
  setMethodPaySupported({
100
107
  ...methodPaySupported,
101
108
  loading: true
102
109
  })
110
+ const initializeError = await initialize()
111
+ if (initializeError) return
103
112
  const { error, paymentMethod } = await createGooglePayPaymentMethod({
104
113
  amount: cartTotal ?? cart?.balance ?? cart?.total,
105
114
  currencyCode: configs?.stripe_currency?.value ?? 'USD',
@@ -3,6 +3,8 @@ import {
3
3
  useLanguage,
4
4
  useConfig,
5
5
  useUtils,
6
+ useToast,
7
+ ToastType,
6
8
  MultiCartsPaymethodsAndWallets as MultiCartsPaymethodsAndWalletsController
7
9
  } from 'ordering-components/native'
8
10
  import { useTheme } from 'styled-components/native'
@@ -45,7 +47,8 @@ const MultiCartsPaymethodsAndWalletsUI = (props: any) => {
45
47
  const [, t] = useLanguage()
46
48
  const [{ configs }] = useConfig()
47
49
  const [{ parsePrice }] = useUtils()
48
- const { confirmApplePayPayment } = useApplePay()
50
+ const [, { showToast }] = useToast();
51
+ const { confirmApplePayPayment } = useApplePay()
49
52
 
50
53
  const [addCardOpen, setAddCardOpen] = useState({ stripe: false, stripeConnect: false });
51
54
 
@@ -91,20 +94,38 @@ const MultiCartsPaymethodsAndWalletsUI = (props: any) => {
91
94
  }
92
95
 
93
96
  useEffect(() => {
94
- if (methodsPay.includes(paymethodSelected?.gateway)) {
95
- if (typeof paymethodSelected?.paymethod_data === 'string'){
96
- const sourceId = JSON.parse(paymethodSelected?.paymethod_data)?.source_id
97
+ if (methodsPay.includes(paymethodSelected?.gateway)) {
98
+ if (typeof paymethodSelected?.paymethod_data === 'string') {
99
+ const sourceId = JSON.parse(paymethodSelected?.paymethod_data)?.source_id
97
100
  sourceId && handlePlaceOrder(confirmApplePayPayment)
98
101
  }
99
- }
100
- }, [JSON.stringify(paymethodSelected)])
102
+ }
103
+ }, [JSON.stringify(paymethodSelected)])
104
+
105
+ useEffect(() => {
106
+ if (cartTotal === 0) {
107
+ handlePaymethodDataChange(null)
108
+ handleSelectPaymethod(null)
109
+ }
110
+ }, [cartTotal])
111
+
112
+ const handleChangePaymethod = (paymethod: any) => {
113
+ if (cartTotal > 0) {
114
+ handleSelectPaymethod(paymethod)
115
+ return
116
+ }
117
+ showToast(
118
+ ToastType.Error,
119
+ t('CART_BALANCE_ZERO', 'Sorry, the amount to pay is equal to zero and it is not necessary to select a payment method'))
120
+ ;
121
+ }
101
122
 
102
123
  const renderPaymethods = ({ item }: any) => {
103
124
  return (
104
125
  <>
105
126
  {item?.gateway === 'global_apple_pay' ? (
106
127
  <TouchableOpacity
107
- onPress={() => handleSelectPaymethod({ ...item, paymethod: { gateway: item.gateway }, paymethod_id: item?.id })}
128
+ onPress={() => handleChangePaymethod({ ...item, paymethod: { gateway: item.gateway }, paymethod_id: item?.id })}
108
129
  >
109
130
  <OIcon
110
131
  src={getPayIcon(item.gateway)}
@@ -115,7 +136,7 @@ const MultiCartsPaymethodsAndWalletsUI = (props: any) => {
115
136
  </TouchableOpacity>
116
137
  ) : (
117
138
  <TouchableOpacity
118
- onPress={() => handleSelectPaymethod({ ...item, paymethod: { gateway: item.gateway }, paymethod_id: item?.id })}
139
+ onPress={() => handleChangePaymethod({ ...item, paymethod: { gateway: item.gateway }, paymethod_id: item?.id })}
119
140
  >
120
141
  <PMItem
121
142
  key={item.id}
@@ -208,9 +229,9 @@ const MultiCartsPaymethodsAndWalletsUI = (props: any) => {
208
229
  handleSource={handlePaymethodDataChange}
209
230
  onCancel={() => setAddCardOpen({ ...addCardOpen, stripe: false })}
210
231
  setMethodPaySupported={setMethodPaySupported}
211
- methodPaySupported={methodPaySupported}
212
- placeByMethodPay={placeByMethodPay}
213
- setPlaceByMethodPay={setPlaceByMethodPay}
232
+ methodPaySupported={methodPaySupported}
233
+ placeByMethodPay={placeByMethodPay}
234
+ setPlaceByMethodPay={setPlaceByMethodPay}
214
235
  methodsPay={methodsPay}
215
236
  paymethod={paymethodSelected?.paymethod?.gateway}
216
237
  cartTotal={cartTotal}
@@ -1018,7 +1018,9 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
1018
1018
  )} */}
1019
1019
  </View>
1020
1020
  <OText>
1021
- -{parsePrice(event.amount, { isTruncable: true })}
1021
+ {configs.currency_position?.value === 'left'
1022
+ ? `${configs.format_number_currency?.value} -${parseNumber(event.amount, { isTruncable: true })}`
1023
+ : `-${parsePrice(event.amount, { isTruncable: true })}`}
1022
1024
  </OText>
1023
1025
  </View>
1024
1026
  ))}
@@ -126,6 +126,12 @@ const PaymentOptionsUI = (props: any) => {
126
126
  ;
127
127
  }
128
128
 
129
+ useEffect(() => {
130
+ if (cart?.balance === 0) {
131
+ handlePaymethodClick(null)
132
+ }
133
+ }, [cart?.balance])
134
+
129
135
  useEffect(() => {
130
136
  if (paymethodsList.paymethods.length === 1) {
131
137
  handlePaymethodClick && handlePaymethodClick(paymethodsList.paymethods[0])
@@ -339,7 +345,7 @@ const PaymentOptionsUI = (props: any) => {
339
345
  onPaymentChange={onPaymentChange}
340
346
  payType={isOpenMethod?.paymethod?.name}
341
347
  onSelectCard={handlePaymethodDataChange}
342
- addCardOpen={addCardOpen}
348
+ addCardOpen={addCardOpen}
343
349
  setAddCardOpen={setAddCardOpen}
344
350
  onCancel={() => handlePaymethodClick(null)}
345
351
  paymethodSelected={paymethodSelected?.data?.id}