@akinon/pz-flow-payment 1.108.0-rc.1 → 1.108.0-rc.3

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-flow-payment
2
2
 
3
+ ## 1.108.0-rc.3
4
+
5
+ ### Minor Changes
6
+
7
+ - e00b4a8: ZERO-3640: Refactor wallet selection initialization and error handling; streamline payment session management
8
+
9
+ ## 1.108.0-rc.2
10
+
3
11
  ## 1.108.0-rc.1
4
12
 
5
13
  ### Minor Changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/pz-flow-payment",
3
3
  "license": "MIT",
4
- "version": "1.108.0-rc.1",
4
+ "version": "1.108.0-rc.3",
5
5
  "main": "src/index.tsx",
6
6
  "dependencies": {
7
7
  "@checkout.com/checkout-web-components": "0.7.0-beta"
@@ -77,8 +77,8 @@ export default function FlowPayment({
77
77
  const flowComponentRef = useRef<any>(null);
78
78
  const lastAmountRef = useRef<string | null>(null);
79
79
  const isInitializingRef = useRef<boolean>(false);
80
- const walletPaymentInitialized = useRef<boolean>(false);
81
80
  const [errors, setErrors] = useState<any>(null);
81
+ const [walletSelectionReady, setWalletSelectionReady] = useState<boolean>(false);
82
82
 
83
83
  // Memoize the amount to track actual changes
84
84
  const currentAmount = useMemo(() => {
@@ -98,14 +98,26 @@ export default function FlowPayment({
98
98
  );
99
99
 
100
100
  if (!walletPaymentPageContext) {
101
+ setErrors('Payment method not available. Please try a different payment option.');
102
+ setWalletSelectionReady(false);
101
103
  return;
102
104
  }
103
105
 
104
- // FIX: Only call setWalletPaymentPage if not already initialized
105
- if (!walletPaymentInitialized.current) {
106
- walletPaymentInitialized.current = true;
107
- dispatch(checkoutApi.endpoints.setWalletPaymentPage.initiate({}));
106
+ // Initialize wallet payment page to get payment session data
107
+ const walletPaymentPageResponse = await dispatch(
108
+ checkoutApi.endpoints.setWalletPaymentPage.initiate({
109
+ payment_method: 'checkout_flow',
110
+ wallet_method: preOrder.wallet_method
111
+ })
112
+ ).unwrap();
113
+
114
+ if (walletPaymentPageResponse.errors) {
115
+ setErrors(walletPaymentPageResponse.errors);
116
+ setWalletSelectionReady(false);
117
+ return;
108
118
  }
119
+
120
+ setWalletSelectionReady(true);
109
121
  };
110
122
 
111
123
  const handlePaymentSuccess = async (paymentData: any) => {
@@ -184,24 +196,13 @@ export default function FlowPayment({
184
196
  container.innerHTML = '';
185
197
  }
186
198
 
187
- // FIX: Use existing payment session instead of making another API call
199
+ // FIX: Use existing payment session from preOrder.context_extras
188
200
  let paymentSession = preOrder.context_extras;
189
201
 
190
- // Only get fresh payment data if we don't have a valid session
191
- if (!paymentSession && lastAmountRef.current !== currentAmount) {
192
- // Check if another call is already in progress
193
- if (!walletPaymentInitialized.current) {
194
- walletPaymentInitialized.current = true;
195
- const walletPaymentResponse = await dispatch(
196
- checkoutApi.endpoints.setWalletPaymentPage.initiate({})
197
- ).unwrap();
198
- paymentSession =
199
- walletPaymentResponse?.pre_order?.context_extras ||
200
- preOrder.context_extras;
201
- } else {
202
- // Use existing context_extras if another call was already made
203
- paymentSession = preOrder.context_extras;
204
- }
202
+ // If we don't have payment session data, we need to wait for it
203
+ if (!paymentSession) {
204
+ console.warn('FlowPayment: Payment session not available yet, component will retry when data is ready');
205
+ return;
205
206
  }
206
207
 
207
208
  // Update the last amount reference after getting fresh data
@@ -246,10 +247,21 @@ export default function FlowPayment({
246
247
  useEffect(() => {
247
248
  if (
248
249
  !preOrder.wallet_method ||
249
- !preOrder.token ||
250
250
  !walletPaymentData?.data?.public_key ||
251
- preOrder.wallet_method !== 'checkout_flow'
251
+ preOrder.wallet_method !== 'checkout_flow' ||
252
+ !walletSelectionReady ||
253
+ !preOrder.context_extras
252
254
  ) {
255
+ console.log('====================================');
256
+ console.log('FlowPayment: Missing required data to initialize payment components.', {
257
+ wallet_method: preOrder.wallet_method,
258
+ token: preOrder.token,
259
+ public_key: walletPaymentData?.data?.public_key,
260
+ walletSelectionReady,
261
+ context_extras: preOrder.context_extras
262
+ });
263
+ console.log('====================================');
264
+
253
265
  return;
254
266
  }
255
267
 
@@ -260,7 +272,9 @@ export default function FlowPayment({
260
272
  preOrder.wallet_method,
261
273
  preOrder.token,
262
274
  currentAmount, // Use memoized amount instead of preOrder.total_amount
263
- walletPaymentData?.data?.public_key
275
+ walletPaymentData?.data?.public_key,
276
+ walletSelectionReady,
277
+ preOrder.context_extras // Add payment session dependency
264
278
  ]);
265
279
 
266
280
  // Cleanup function when component unmounts
@@ -273,8 +287,6 @@ export default function FlowPayment({
273
287
  console.warn('Error destroying flow component on unmount:', error);
274
288
  }
275
289
  }
276
- // Reset initialization flag on unmount
277
- walletPaymentInitialized.current = false;
278
290
  };
279
291
  }, []);
280
292