@akinon/pz-gpay 1.96.0-rc.58 → 1.96.0-rc.60

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @akinon/pz-gpay
2
2
 
3
+ ## 1.96.0-rc.60
4
+
5
+ ## 1.96.0-rc.59
6
+
7
+ ### Minor Changes
8
+
9
+ - 4c23847: ZERO-3623 :Enhance GPay integration: add loading state to custom UI rendering and error handling
10
+
3
11
  ## 1.96.0-rc.58
4
12
 
5
13
  ## 1.96.0-rc.57
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/pz-gpay",
3
- "version": "1.96.0-rc.58",
3
+ "version": "1.96.0-rc.60",
4
4
  "license": "MIT",
5
5
  "main": "src/index.tsx",
6
6
  "peerDependencies": {
package/readme.md CHANGED
@@ -106,7 +106,7 @@ const GPay = () => {
106
106
  ],
107
107
  button: 'Pay Now'
108
108
  },
109
- customUIRender: ({ handleSubmit, onSubmit, translations }) => (
109
+ customUIRender: ({ handleSubmit, onSubmit, translations, loading }) => (
110
110
  <form
111
111
  onSubmit={handleSubmit(onSubmit)}
112
112
  className="p-6 bg-white rounded-md space-y-4"
@@ -121,7 +121,11 @@ const GPay = () => {
121
121
  type="submit"
122
122
  className="w-full h-10 bg-black text-white rounded"
123
123
  >
124
- {translations.button}
124
+ {loading ? (
125
+ <LoaderSpinner className="w-5 h-5" />
126
+ ) : (
127
+ translations.button
128
+ )}
125
129
  </button>
126
130
  </form>
127
131
  )
@@ -44,6 +44,7 @@ type GPayOptionProps = {
44
44
  control: Control<GPayForm>;
45
45
  errors: FieldErrors<GPayForm>;
46
46
  translations: GPayTranslations;
47
+ loading: boolean;
47
48
  }) => ReactElement;
48
49
  };
49
50
 
@@ -78,19 +79,32 @@ export function GPayOption(props: GPayOptionProps) {
78
79
  });
79
80
 
80
81
  const [setPaymentOption] = useSetPaymentOptionMutation();
81
- const [setGPayMethod] = useSetGPayMethodMutation();
82
- const [setCompleteGPay] = useSetCompleteGPayMutation();
82
+ const [setGPayMethod, { isLoading: isGPayMethodLoading }] =
83
+ useSetGPayMethodMutation();
84
+ const [setCompleteGPay, { isLoading: isCompleteGPayLoading }] =
85
+ useSetCompleteGPayMutation();
83
86
 
84
87
  const onSubmit: SubmitHandler<GPayForm> = async () => {
85
- if (isPaymentStepBusy) return;
86
-
87
88
  setFormError(null);
88
- await setGPayMethod();
89
89
 
90
- const response = await setCompleteGPay().unwrap();
90
+ try {
91
+ await setGPayMethod().unwrap();
92
+ } catch (e) {
93
+ setFormError(translations.error);
94
+ return;
95
+ }
91
96
 
92
- if (response?.errors?.non_field_errors) {
93
- setFormError(response.errors.non_field_errors);
97
+ try {
98
+ const data = await setCompleteGPay().unwrap();
99
+ if (data?.errors?.non_field_errors) {
100
+ setFormError(data.errors.non_field_errors);
101
+ }
102
+ } catch (e: any) {
103
+ const msg =
104
+ e?.data?.errors?.non_field_errors ??
105
+ e?.data?.detail ??
106
+ translations.error;
107
+ setFormError(msg);
94
108
  }
95
109
  };
96
110
 
@@ -113,7 +127,8 @@ export function GPayOption(props: GPayOptionProps) {
113
127
  onSubmit,
114
128
  control,
115
129
  errors: formErrors,
116
- translations
130
+ translations,
131
+ loading: isGPayMethodLoading || isCompleteGPayLoading || isPaymentStepBusy
117
132
  });
118
133
  }
119
134