ordering-ui-react-native 0.17.38-release → 0.17.39-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.17.38-release",
3
+ "version": "0.17.39-release",
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']
@@ -30,53 +31,15 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
30
31
  if (Platform.OS === 'ios') {
31
32
  return
32
33
  }
33
- const initialize = async () => {
34
- try {
35
- setMethodPaySupported({
36
- ...methodPaySupported,
37
- loading: true
38
- })
39
- const { error } = await initGooglePay({
40
- testEnv: devMode,
41
- merchantName: android_app_id,
42
- countryCode: 'US',
43
- billingAddressConfig: {
44
- format: 'FULL',
45
- isPhoneNumberRequired: true,
46
- isRequired: false,
47
- },
48
- existingPaymentMethodRequired: false,
49
- isEmailRequired: true,
50
- });
51
-
52
- if (error) {
53
- setErrors(error.code + ' - ' + error.message);
54
- setMethodPaySupported({
55
- enabled: false,
56
- loading: false
57
- })
58
- setPlaceByMethodPay(false)
59
- return;
60
- }
61
- setMethodPaySupported({
62
- enabled: true,
63
- loading: false
64
- })
65
- setPlaceByMethodPay(false)
66
- setErrors('')
67
- } catch (err: any) {
68
- setErrors('Catch ' + err?.message)
69
- setMethodPaySupported({
70
- enabled: false,
71
- loading: false
72
- })
73
- setPlaceByMethodPay(false)
74
- }
75
- }
76
- if (googlePay.includes(paymethod) && !methodPaySupported?.enabled) {
77
- initialize();
34
+ if (!loadingCart) {
35
+ setMethodPaySupported({
36
+ enabled: true,
37
+ loading: false
38
+ })
39
+ setPlaceByMethodPay(false)
40
+ setErrors('')
78
41
  }
79
- }, [initGooglePay, paymethod]);
42
+ }, [paymethod, loadingCart]);
80
43
 
81
44
  useEffect(() => {
82
45
  if (applePay.includes(paymethod) && !paymethod) return
@@ -90,11 +53,57 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
90
53
  }
91
54
  }, [paymethod])
92
55
 
56
+ const initialize = async () => {
57
+ try {
58
+ setMethodPaySupported({
59
+ ...methodPaySupported,
60
+ loading: true
61
+ })
62
+ const { error } = await initGooglePay({
63
+ testEnv: devMode,
64
+ merchantName: android_app_id,
65
+ countryCode: 'US',
66
+ billingAddressConfig: {
67
+ format: 'FULL',
68
+ isPhoneNumberRequired: true,
69
+ isRequired: false,
70
+ },
71
+ existingPaymentMethodRequired: false,
72
+ isEmailRequired: true,
73
+ });
74
+
75
+ if (error) {
76
+ setErrors(error.code + ' - ' + error.message);
77
+ setMethodPaySupported({
78
+ enabled: false,
79
+ loading: false
80
+ })
81
+ setPlaceByMethodPay(false)
82
+ return true;
83
+ }
84
+ setMethodPaySupported({
85
+ enabled: true,
86
+ loading: false
87
+ })
88
+ setPlaceByMethodPay(false)
89
+ setErrors('')
90
+ } catch (err: any) {
91
+ setErrors('Catch ' + err?.message)
92
+ setMethodPaySupported({
93
+ enabled: false,
94
+ loading: false
95
+ })
96
+ setPlaceByMethodPay(false)
97
+ }
98
+ }
99
+
93
100
  const createPaymentMethod = async () => {
94
101
  setMethodPaySupported({
95
102
  ...methodPaySupported,
96
103
  loading: true
97
104
  })
105
+ const initializeError = await initialize()
106
+ if (initializeError) return
98
107
  const { error, paymentMethod } = await createGooglePayPaymentMethod({
99
108
  amount: cartTotal ?? cart?.balance ?? cart?.total,
100
109
  currencyCode: configs?.stripe_currency?.value ?? 'USD',
@@ -220,6 +220,16 @@ const MultiCheckoutUI = (props: any) => {
220
220
  }
221
221
  }, [cartUuid])
222
222
 
223
+ useEffect(() => {
224
+ if(paymethodSelected?.gateway === 'global_google_pay'){
225
+ setMethodPaySupported({
226
+ enabled: true,
227
+ loading: false,
228
+ message: null
229
+ })
230
+ }
231
+ }, [paymethodSelected])
232
+
223
233
  return (
224
234
  <>
225
235
  <Container noPadding>