@akinon/pz-flow-payment 1.96.0-rc.56 → 1.96.0-snapshot-ZERO-35861-20250908151109

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,17 +1,6 @@
1
1
  # @akinon/pz-flow-payment
2
2
 
3
- ## 1.96.0-rc.56
4
-
5
- ### Minor Changes
6
-
7
- - 69e4cc5: BRDG-14604: Refactor FlowPayment component to optimize flow initialization and cleanup logic
8
-
9
- ## 1.96.0-rc.55
10
-
11
- ### Minor Changes
12
-
13
- - d8be48fb: ZERO-3422: Update fetch method to use dynamic request method in wallet complete redirection middleware
14
- - 8b1d24eb: ZERO-3422: Update fetch method to use dynamic request method in wallet complete redirection middleware
3
+ ## 1.96.0-snapshot-ZERO-35861-20250908151109
15
4
 
16
5
  ## 1.95.0
17
6
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/pz-flow-payment",
3
3
  "license": "MIT",
4
- "version": "1.96.0-rc.56",
4
+ "version": "1.96.0-snapshot-ZERO-35861-20250908151109",
5
5
  "main": "src/index.tsx",
6
6
  "dependencies": {
7
7
  "@checkout.com/checkout-web-components": "0.7.0-beta"
@@ -8,7 +8,7 @@ import {
8
8
  PaymentSessionResponse
9
9
  } from '@checkout.com/checkout-web-components';
10
10
  import { RootState } from '@theme/redux/store';
11
- import { useEffect, useRef, useMemo } from 'react';
11
+ import { useEffect } from 'react';
12
12
 
13
13
  export default function FlowPayment({
14
14
  options
@@ -56,14 +56,6 @@ export default function FlowPayment({
56
56
  (state: RootState) => state.checkout
57
57
  );
58
58
  const dispatch = useAppDispatch();
59
- const flowComponentRef = useRef<any>(null);
60
- const lastAmountRef = useRef<string | null>(null);
61
- const isInitializingRef = useRef<boolean>(false);
62
-
63
- // Memoize the amount to track actual changes
64
- const currentAmount = useMemo(() => {
65
- return preOrder.total_amount;
66
- }, [preOrder.total_amount]);
67
59
 
68
60
  const initWalletSelection = async () => {
69
61
  const walletSelectionPageResponse = await dispatch(
@@ -89,73 +81,21 @@ export default function FlowPayment({
89
81
  }: {
90
82
  publicKey: string;
91
83
  }) => {
92
- // Prevent multiple simultaneous initializations
93
- if (isInitializingRef.current) {
94
- return;
95
- }
84
+ const checkout = await loadCheckoutWebComponents({
85
+ publicKey,
86
+ environment: options?.environment || 'production',
87
+ locale: options?.locale || 'en',
88
+ translations: options?.translations,
89
+ paymentSession: preOrder.context_extras as PaymentSessionResponse,
90
+ appearance: options?.appearance,
91
+ componentOptions: options?.componentOptions
92
+ ? { flow: options.componentOptions }
93
+ : undefined
94
+ });
96
95
 
97
- // Check if amount has actually changed
98
- if (lastAmountRef.current === currentAmount && flowComponentRef.current) {
99
- return; // Don't recreate component if amount hasn't changed
100
- }
96
+ const flowComponent = checkout.create('flow');
101
97
 
102
- isInitializingRef.current = true;
103
-
104
- try {
105
- // Destroy existing flow component if it exists
106
- if (flowComponentRef.current) {
107
- try {
108
- flowComponentRef.current.destroy();
109
- } catch (error) {
110
- console.warn('Error destroying flow component:', error);
111
- }
112
- flowComponentRef.current = null;
113
- }
114
-
115
- // Clear any existing flow component before creating a new one
116
- const container = document.getElementById('flow-container');
117
- if (container) {
118
- container.innerHTML = '';
119
- }
120
-
121
- // Only get fresh payment data when amount has changed from the last recorded amount
122
- let paymentSession = preOrder.context_extras;
123
-
124
- if (lastAmountRef.current !== currentAmount || !paymentSession) {
125
- const walletPaymentResponse = await dispatch(
126
- checkoutApi.endpoints.setWalletPaymentPage.initiate({})
127
- ).unwrap();
128
- paymentSession =
129
- walletPaymentResponse?.pre_order?.context_extras ||
130
- preOrder.context_extras;
131
- }
132
-
133
- // Update the last amount reference after getting fresh data
134
- lastAmountRef.current = currentAmount;
135
-
136
- const checkout = await loadCheckoutWebComponents({
137
- publicKey,
138
- environment: options?.environment || 'production',
139
- locale: options?.locale || 'en',
140
- translations: options?.translations,
141
- paymentSession: paymentSession as PaymentSessionResponse,
142
- appearance: options?.appearance,
143
- componentOptions: options?.componentOptions
144
- ? { flow: options.componentOptions }
145
- : undefined
146
- });
147
-
148
- const flowComponent = checkout.create('flow');
149
- flowComponentRef.current = flowComponent;
150
-
151
- if (container) {
152
- flowComponent.mount(container);
153
- }
154
- } catch (error) {
155
- console.error('Error initializing flow payment components:', error);
156
- } finally {
157
- isInitializingRef.current = false;
158
- }
98
+ flowComponent.mount(document.getElementById('flow-container')!);
159
99
  };
160
100
 
161
101
  useEffect(() => {
@@ -178,22 +118,8 @@ export default function FlowPayment({
178
118
  }, [
179
119
  preOrder.wallet_method,
180
120
  preOrder.token,
181
- currentAmount, // Use memoized amount instead of preOrder.total_amount
182
121
  walletPaymentData?.data?.public_key
183
122
  ]);
184
123
 
185
- // Cleanup function when component unmounts
186
- useEffect(() => {
187
- return () => {
188
- if (flowComponentRef.current) {
189
- try {
190
- flowComponentRef.current.destroy();
191
- } catch (error) {
192
- console.warn('Error destroying flow component on unmount:', error);
193
- }
194
- }
195
- };
196
- }, []);
197
-
198
124
  return <div id="flow-container" className="flow-payment-container"></div>;
199
125
  }