ordering-ui-react-native 0.18.81 → 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.81",
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',