@akinon/pz-flow-payment 1.100.0 → 1.101.0-rc.73
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 +31 -0
- package/package.json +1 -1
- package/src/views/index.tsx +116 -50
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @akinon/pz-flow-payment
|
|
2
2
|
|
|
3
|
+
## 1.101.0-rc.73
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 1b9e9be: BRDG-14604: Refactor FlowPayment component to utilize RTK Query mutations for payment options and wallet selection, enhancing session management and initialization 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
|
+
|
|
3
11
|
## 1.100.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
|
@@ -25,6 +33,29 @@
|
|
|
25
33
|
### Minor Changes
|
|
26
34
|
|
|
27
35
|
- 69e4cc5: BRDG-14604: Refactor FlowPayment component to optimize flow initialization and cleanup logic
|
|
36
|
+
- d8be48fb: ZERO-3422: Update fetch method to use dynamic request method in wallet complete redirection middleware
|
|
37
|
+
- 8b1d24eb: ZERO-3422: Update fetch method to use dynamic request method in wallet complete redirection middleware
|
|
38
|
+
|
|
39
|
+
## 1.96.0-rc.60
|
|
40
|
+
|
|
41
|
+
## 1.96.0-rc.59
|
|
42
|
+
|
|
43
|
+
## 1.96.0-rc.58
|
|
44
|
+
|
|
45
|
+
## 1.96.0-rc.57
|
|
46
|
+
|
|
47
|
+
## 1.96.0-rc.56
|
|
48
|
+
|
|
49
|
+
### Minor Changes
|
|
50
|
+
|
|
51
|
+
- 69e4cc5: BRDG-14604: Refactor FlowPayment component to optimize flow initialization and cleanup logic
|
|
52
|
+
|
|
53
|
+
## 1.96.0-rc.55
|
|
54
|
+
|
|
55
|
+
### Minor Changes
|
|
56
|
+
|
|
57
|
+
- d8be48fb: ZERO-3422: Update fetch method to use dynamic request method in wallet complete redirection middleware
|
|
58
|
+
- 8b1d24eb: ZERO-3422: Update fetch method to use dynamic request method in wallet complete redirection middleware
|
|
28
59
|
|
|
29
60
|
## 1.95.0
|
|
30
61
|
|
package/package.json
CHANGED
package/src/views/index.tsx
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { checkoutApi } from '@akinon/next/data/client/checkout';
|
|
2
2
|
import { useAppDispatch, useAppSelector } from '@akinon/next/redux/hooks';
|
|
3
|
+
import {
|
|
4
|
+
useSetPaymentOptionMutation,
|
|
5
|
+
useSetWalletSelectionPageMutation,
|
|
6
|
+
useSetWalletPaymentPageMutation
|
|
7
|
+
} from '@akinon/next/data/client/checkout';
|
|
3
8
|
import {
|
|
4
9
|
ComponentOptions,
|
|
5
10
|
CustomTranslations,
|
|
@@ -61,35 +66,38 @@ export default function FlowPayment({
|
|
|
61
66
|
const isInitializingRef = useRef<boolean>(false);
|
|
62
67
|
const walletPaymentInitialized = useRef<boolean>(false);
|
|
63
68
|
|
|
69
|
+
// RTK Query mutations
|
|
70
|
+
const [setPaymentOption] = useSetPaymentOptionMutation();
|
|
71
|
+
const [setWalletSelectionPage] = useSetWalletSelectionPageMutation();
|
|
72
|
+
const [setWalletPaymentPage] = useSetWalletPaymentPageMutation();
|
|
73
|
+
|
|
64
74
|
// Memoize the amount to track actual changes
|
|
65
75
|
const currentAmount = useMemo(() => {
|
|
66
76
|
return preOrder.total_amount;
|
|
67
77
|
}, [preOrder.total_amount]);
|
|
68
78
|
|
|
69
79
|
const initWalletSelection = async () => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
payment_option: preOrder.payment_option?.pk
|
|
73
|
-
})
|
|
74
|
-
).unwrap();
|
|
80
|
+
if (!walletPaymentInitialized.current) {
|
|
81
|
+
walletPaymentInitialized.current = true;
|
|
75
82
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
const walletSelectionPageResponse = await dispatch(
|
|
84
|
+
checkoutApi.endpoints.setWalletSelectionPage.initiate({
|
|
85
|
+
payment_option: preOrder.payment_option?.pk
|
|
86
|
+
})
|
|
87
|
+
).unwrap();
|
|
80
88
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
const walletPaymentPageContext =
|
|
90
|
+
walletSelectionPageResponse.context_list.find(
|
|
91
|
+
(c) => c.page_name === 'WalletPaymentPage'
|
|
92
|
+
);
|
|
84
93
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
dispatch(checkoutApi.endpoints.setWalletPaymentPage.initiate({}));
|
|
94
|
+
if (walletPaymentPageContext) {
|
|
95
|
+
dispatch(checkoutApi.endpoints.setWalletPaymentPage.initiate({}));
|
|
96
|
+
}
|
|
89
97
|
}
|
|
90
98
|
};
|
|
91
99
|
|
|
92
|
-
const
|
|
100
|
+
const refreshPaymentSessionAndInitFlow = async ({
|
|
93
101
|
publicKey
|
|
94
102
|
}: {
|
|
95
103
|
publicKey: string;
|
|
@@ -99,13 +107,70 @@ export default function FlowPayment({
|
|
|
99
107
|
return;
|
|
100
108
|
}
|
|
101
109
|
|
|
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
|
-
}
|
|
106
|
-
|
|
107
110
|
isInitializingRef.current = true;
|
|
108
111
|
|
|
112
|
+
try {
|
|
113
|
+
// Step 1: Re-set the current payment option to refresh the session with new amount
|
|
114
|
+
if (preOrder.payment_option?.pk) {
|
|
115
|
+
const paymentOptionResponse = await setPaymentOption(
|
|
116
|
+
preOrder.payment_option.pk
|
|
117
|
+
).unwrap();
|
|
118
|
+
|
|
119
|
+
// Check if WalletSelectionPage is available in the context list
|
|
120
|
+
const walletSelectionPageContext =
|
|
121
|
+
paymentOptionResponse.context_list?.find(
|
|
122
|
+
(c) => c.page_name === 'WalletSelectionPage'
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
if (!walletSelectionPageContext) {
|
|
126
|
+
console.warn(
|
|
127
|
+
'WalletSelectionPage not found in payment option response context list'
|
|
128
|
+
);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Step 2: Set wallet selection page
|
|
134
|
+
const walletSelectionResponse = await setWalletSelectionPage({
|
|
135
|
+
payment_option: preOrder.payment_option?.pk
|
|
136
|
+
}).unwrap();
|
|
137
|
+
|
|
138
|
+
const walletPaymentPageContext =
|
|
139
|
+
walletSelectionResponse.context_list?.find(
|
|
140
|
+
(c) => c.page_name === 'WalletPaymentPage'
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
if (!walletPaymentPageContext) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Step 3: Set wallet payment page to get updated payment session
|
|
148
|
+
const walletPaymentResponse = await setWalletPaymentPage({}).unwrap();
|
|
149
|
+
|
|
150
|
+
// Step 4: Initialize flow component with fresh payment session
|
|
151
|
+
await initFlowPaymentWebComponents({
|
|
152
|
+
publicKey,
|
|
153
|
+
paymentSession:
|
|
154
|
+
walletPaymentResponse?.pre_order?.context_extras ||
|
|
155
|
+
preOrder.context_extras
|
|
156
|
+
});
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.error(
|
|
159
|
+
'Error refreshing payment session and initializing flow:',
|
|
160
|
+
error
|
|
161
|
+
);
|
|
162
|
+
} finally {
|
|
163
|
+
isInitializingRef.current = false;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const initFlowPaymentWebComponents = async ({
|
|
168
|
+
publicKey,
|
|
169
|
+
paymentSession
|
|
170
|
+
}: {
|
|
171
|
+
publicKey: string;
|
|
172
|
+
paymentSession?: any;
|
|
173
|
+
}) => {
|
|
109
174
|
try {
|
|
110
175
|
// Destroy existing flow component if it exists
|
|
111
176
|
if (flowComponentRef.current) {
|
|
@@ -123,27 +188,7 @@ export default function FlowPayment({
|
|
|
123
188
|
container.innerHTML = '';
|
|
124
189
|
}
|
|
125
190
|
|
|
126
|
-
//
|
|
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
|
|
191
|
+
// Update the last amount reference
|
|
147
192
|
lastAmountRef.current = currentAmount;
|
|
148
193
|
|
|
149
194
|
const checkout = await loadCheckoutWebComponents({
|
|
@@ -151,7 +196,8 @@ export default function FlowPayment({
|
|
|
151
196
|
environment: options?.environment || 'production',
|
|
152
197
|
locale: options?.locale || 'en',
|
|
153
198
|
translations: options?.translations,
|
|
154
|
-
paymentSession:
|
|
199
|
+
paymentSession:
|
|
200
|
+
paymentSession || (preOrder.context_extras as PaymentSessionResponse),
|
|
155
201
|
appearance: options?.appearance,
|
|
156
202
|
componentOptions: options?.componentOptions
|
|
157
203
|
? { flow: options.componentOptions }
|
|
@@ -166,8 +212,6 @@ export default function FlowPayment({
|
|
|
166
212
|
}
|
|
167
213
|
} catch (error) {
|
|
168
214
|
console.error('Error initializing flow payment components:', error);
|
|
169
|
-
} finally {
|
|
170
|
-
isInitializingRef.current = false;
|
|
171
215
|
}
|
|
172
216
|
};
|
|
173
217
|
|
|
@@ -175,6 +219,7 @@ export default function FlowPayment({
|
|
|
175
219
|
initWalletSelection();
|
|
176
220
|
}, []);
|
|
177
221
|
|
|
222
|
+
// Initial flow component initialization
|
|
178
223
|
useEffect(() => {
|
|
179
224
|
if (
|
|
180
225
|
!preOrder.wallet_method ||
|
|
@@ -185,16 +230,37 @@ export default function FlowPayment({
|
|
|
185
230
|
return;
|
|
186
231
|
}
|
|
187
232
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
233
|
+
// Only initialize if component doesn't exist yet (initial mount)
|
|
234
|
+
if (!flowComponentRef.current) {
|
|
235
|
+
initFlowPaymentWebComponents({
|
|
236
|
+
publicKey: walletPaymentData.data.public_key
|
|
237
|
+
});
|
|
238
|
+
}
|
|
191
239
|
}, [
|
|
192
240
|
preOrder.wallet_method,
|
|
193
241
|
preOrder.token,
|
|
194
|
-
currentAmount, // Use memoized amount instead of preOrder.total_amount
|
|
195
242
|
walletPaymentData?.data?.public_key
|
|
196
243
|
]);
|
|
197
244
|
|
|
245
|
+
// Handle amount changes by refreshing payment session
|
|
246
|
+
useEffect(() => {
|
|
247
|
+
if (
|
|
248
|
+
!preOrder.wallet_method ||
|
|
249
|
+
!preOrder.token ||
|
|
250
|
+
!walletPaymentData?.data?.public_key ||
|
|
251
|
+
preOrder.wallet_method !== 'checkout_flow'
|
|
252
|
+
) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Only refresh if component exists and amount has changed
|
|
257
|
+
if (flowComponentRef.current && lastAmountRef.current !== currentAmount) {
|
|
258
|
+
refreshPaymentSessionAndInitFlow({
|
|
259
|
+
publicKey: walletPaymentData.data.public_key
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}, [currentAmount]);
|
|
263
|
+
|
|
198
264
|
// Cleanup function when component unmounts
|
|
199
265
|
useEffect(() => {
|
|
200
266
|
return () => {
|