@akinon/pz-flow-payment 1.96.0-snapshot-ZERO-35861-20250908151109 → 1.96.0-snapshot-ZERO-3620-20250915165755
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 +36 -1
- package/package.json +1 -1
- package/src/views/index.tsx +104 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
# @akinon/pz-flow-payment
|
|
2
2
|
|
|
3
|
-
## 1.96.0-snapshot-ZERO-
|
|
3
|
+
## 1.96.0-snapshot-ZERO-3620-20250915165755
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 69e4cc5: BRDG-14604: Refactor FlowPayment component to optimize flow initialization and cleanup logic
|
|
8
|
+
- d8be48fb: ZERO-3422: Update fetch method to use dynamic request method in wallet complete redirection middleware
|
|
9
|
+
- 8b1d24eb: ZERO-3422: Update fetch method to use dynamic request method in wallet complete redirection middleware
|
|
10
|
+
|
|
11
|
+
## 1.96.0-rc.61
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- 69e4cc5: BRDG-14604: Refactor FlowPayment component to optimize flow initialization and cleanup logic
|
|
16
|
+
- d8be48fb: ZERO-3422: Update fetch method to use dynamic request method in wallet complete redirection middleware
|
|
17
|
+
- 8b1d24eb: ZERO-3422: Update fetch method to use dynamic request method in wallet complete redirection middleware
|
|
18
|
+
|
|
19
|
+
## 1.96.0-rc.60
|
|
20
|
+
|
|
21
|
+
## 1.96.0-rc.59
|
|
22
|
+
|
|
23
|
+
## 1.96.0-rc.58
|
|
24
|
+
|
|
25
|
+
## 1.96.0-rc.57
|
|
26
|
+
|
|
27
|
+
## 1.96.0-rc.56
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- 69e4cc5: BRDG-14604: Refactor FlowPayment component to optimize flow initialization and cleanup logic
|
|
32
|
+
|
|
33
|
+
## 1.96.0-rc.55
|
|
34
|
+
|
|
35
|
+
### Minor Changes
|
|
36
|
+
|
|
37
|
+
- d8be48fb: ZERO-3422: Update fetch method to use dynamic request method in wallet complete redirection middleware
|
|
38
|
+
- 8b1d24eb: ZERO-3422: Update fetch method to use dynamic request method in wallet complete redirection middleware
|
|
4
39
|
|
|
5
40
|
## 1.95.0
|
|
6
41
|
|
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-snapshot-ZERO-
|
|
4
|
+
"version": "1.96.0-snapshot-ZERO-3620-20250915165755",
|
|
5
5
|
"main": "src/index.tsx",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@checkout.com/checkout-web-components": "0.7.0-beta"
|
package/src/views/index.tsx
CHANGED
|
@@ -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 } from 'react';
|
|
11
|
+
import { useEffect, useRef, useMemo } from 'react';
|
|
12
12
|
|
|
13
13
|
export default function FlowPayment({
|
|
14
14
|
options
|
|
@@ -56,6 +56,15 @@ 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
|
+
const walletPaymentInitialized = useRef<boolean>(false);
|
|
63
|
+
|
|
64
|
+
// Memoize the amount to track actual changes
|
|
65
|
+
const currentAmount = useMemo(() => {
|
|
66
|
+
return preOrder.total_amount;
|
|
67
|
+
}, [preOrder.total_amount]);
|
|
59
68
|
|
|
60
69
|
const initWalletSelection = async () => {
|
|
61
70
|
const walletSelectionPageResponse = await dispatch(
|
|
@@ -73,7 +82,11 @@ export default function FlowPayment({
|
|
|
73
82
|
return;
|
|
74
83
|
}
|
|
75
84
|
|
|
76
|
-
|
|
85
|
+
// FIX: Only call setWalletPaymentPage if not already initialized
|
|
86
|
+
if (!walletPaymentInitialized.current) {
|
|
87
|
+
walletPaymentInitialized.current = true;
|
|
88
|
+
dispatch(checkoutApi.endpoints.setWalletPaymentPage.initiate({}));
|
|
89
|
+
}
|
|
77
90
|
};
|
|
78
91
|
|
|
79
92
|
const initFlowPaymentWebComponents = async ({
|
|
@@ -81,21 +94,81 @@ export default function FlowPayment({
|
|
|
81
94
|
}: {
|
|
82
95
|
publicKey: string;
|
|
83
96
|
}) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
});
|
|
97
|
+
// Prevent multiple simultaneous initializations
|
|
98
|
+
if (isInitializingRef.current) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
95
101
|
|
|
96
|
-
|
|
102
|
+
// Check if amount has actually changed
|
|
103
|
+
if (lastAmountRef.current === currentAmount && flowComponentRef.current) {
|
|
104
|
+
return; // Don't recreate component if amount hasn't changed
|
|
105
|
+
}
|
|
97
106
|
|
|
98
|
-
|
|
107
|
+
isInitializingRef.current = true;
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
// Destroy existing flow component if it exists
|
|
111
|
+
if (flowComponentRef.current) {
|
|
112
|
+
try {
|
|
113
|
+
flowComponentRef.current.destroy();
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.warn('Error destroying flow component:', error);
|
|
116
|
+
}
|
|
117
|
+
flowComponentRef.current = null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Clear any existing flow component before creating a new one
|
|
121
|
+
const container = document.getElementById('flow-container');
|
|
122
|
+
if (container) {
|
|
123
|
+
container.innerHTML = '';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// FIX: Use existing payment session instead of making another API call
|
|
127
|
+
let paymentSession = preOrder.context_extras;
|
|
128
|
+
|
|
129
|
+
// Only get fresh payment data if we don't have a valid session
|
|
130
|
+
if (!paymentSession && lastAmountRef.current !== currentAmount) {
|
|
131
|
+
// Check if another call is already in progress
|
|
132
|
+
if (!walletPaymentInitialized.current) {
|
|
133
|
+
walletPaymentInitialized.current = true;
|
|
134
|
+
const walletPaymentResponse = await dispatch(
|
|
135
|
+
checkoutApi.endpoints.setWalletPaymentPage.initiate({})
|
|
136
|
+
).unwrap();
|
|
137
|
+
paymentSession =
|
|
138
|
+
walletPaymentResponse?.pre_order?.context_extras ||
|
|
139
|
+
preOrder.context_extras;
|
|
140
|
+
} else {
|
|
141
|
+
// Use existing context_extras if another call was already made
|
|
142
|
+
paymentSession = preOrder.context_extras;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Update the last amount reference after getting fresh data
|
|
147
|
+
lastAmountRef.current = currentAmount;
|
|
148
|
+
|
|
149
|
+
const checkout = await loadCheckoutWebComponents({
|
|
150
|
+
publicKey,
|
|
151
|
+
environment: options?.environment || 'production',
|
|
152
|
+
locale: options?.locale || 'en',
|
|
153
|
+
translations: options?.translations,
|
|
154
|
+
paymentSession: paymentSession as PaymentSessionResponse,
|
|
155
|
+
appearance: options?.appearance,
|
|
156
|
+
componentOptions: options?.componentOptions
|
|
157
|
+
? { flow: options.componentOptions }
|
|
158
|
+
: undefined
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const flowComponent = checkout.create('flow');
|
|
162
|
+
flowComponentRef.current = flowComponent;
|
|
163
|
+
|
|
164
|
+
if (container) {
|
|
165
|
+
flowComponent.mount(container);
|
|
166
|
+
}
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.error('Error initializing flow payment components:', error);
|
|
169
|
+
} finally {
|
|
170
|
+
isInitializingRef.current = false;
|
|
171
|
+
}
|
|
99
172
|
};
|
|
100
173
|
|
|
101
174
|
useEffect(() => {
|
|
@@ -118,8 +191,24 @@ export default function FlowPayment({
|
|
|
118
191
|
}, [
|
|
119
192
|
preOrder.wallet_method,
|
|
120
193
|
preOrder.token,
|
|
194
|
+
currentAmount, // Use memoized amount instead of preOrder.total_amount
|
|
121
195
|
walletPaymentData?.data?.public_key
|
|
122
196
|
]);
|
|
123
197
|
|
|
198
|
+
// Cleanup function when component unmounts
|
|
199
|
+
useEffect(() => {
|
|
200
|
+
return () => {
|
|
201
|
+
if (flowComponentRef.current) {
|
|
202
|
+
try {
|
|
203
|
+
flowComponentRef.current.destroy();
|
|
204
|
+
} catch (error) {
|
|
205
|
+
console.warn('Error destroying flow component on unmount:', error);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// Reset initialization flag on unmount
|
|
209
|
+
walletPaymentInitialized.current = false;
|
|
210
|
+
};
|
|
211
|
+
}, []);
|
|
212
|
+
|
|
124
213
|
return <div id="flow-container" className="flow-payment-container"></div>;
|
|
125
214
|
}
|