@akinon/pz-flow-payment 2.0.7 → 2.0.8-rc.0

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,11 @@
1
1
  # @akinon/pz-flow-payment
2
2
 
3
+ ## 2.0.8-rc.0
4
+
5
+ ### Patch Changes
6
+
7
+ - b02e7a7a: BRDG-16653: Re-init wallet selection when loyalty amount changes
8
+
3
9
  ## 2.0.7
4
10
 
5
11
  ## 2.0.6
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/pz-flow-payment",
3
3
  "license": "MIT",
4
- "version": "2.0.7",
4
+ "version": "2.0.8-rc.0",
5
5
  "main": "src/index.tsx",
6
6
  "dependencies": {
7
7
  "@checkout.com/checkout-web-components": "0.7.0-beta"
@@ -76,7 +76,10 @@ export default function FlowPayment({
76
76
  const dispatch = useAppDispatch();
77
77
  const flowComponentRef = useRef<any>(null);
78
78
  const lastAmountRef = useRef<string | null>(null);
79
+ const lastSessionRef = useRef<unknown>(null);
80
+ const prevUnpaidRef = useRef(parseFloat(preOrder.unpaid_amount || '0') || 0);
79
81
  const isInitializingRef = useRef<boolean>(false);
82
+ const walletInitInFlightRef = useRef<boolean>(false);
80
83
  const [errors, setErrors] = useState<any>(null);
81
84
  const [walletSelectionReady, setWalletSelectionReady] =
82
85
  useState<boolean>(false);
@@ -88,45 +91,51 @@ export default function FlowPayment({
88
91
  }, [preOrder.total_amount]);
89
92
 
90
93
  const initWalletSelection = async () => {
91
- const walletSelectionPageResponse = await dispatch(
92
- checkoutApi.endpoints.setWalletSelectionPage.initiate({
93
- payment_option: preOrder.payment_option?.pk
94
- })
95
- ).unwrap();
96
-
97
- const walletPaymentPageContext =
98
- walletSelectionPageResponse.context_list.find(
99
- (c) => c.page_name === 'WalletPaymentPage'
100
- );
101
-
102
- if (!walletPaymentPageContext) {
103
- setErrors(
104
- 'Payment method not available. Please try a different payment option.'
105
- );
106
- setWalletSelectionReady(false);
107
- return;
108
- }
94
+ if (walletInitInFlightRef.current) return;
95
+ walletInitInFlightRef.current = true;
96
+ setWalletSelectionReady(false);
109
97
 
110
- // Initialize wallet payment page to get payment session data
111
- const walletPaymentPageResponse = await dispatch(
112
- checkoutApi.endpoints.setWalletPaymentPage.initiate({
113
- payment_method: 'checkout_flow',
114
- wallet_method: preOrder.wallet_method
115
- })
116
- ).unwrap();
117
-
118
- if (walletPaymentPageResponse.errors) {
119
- setErrors(walletPaymentPageResponse.errors);
120
- setWalletSelectionReady(false);
121
- return;
122
- }
98
+ try {
99
+ const walletSelectionPageResponse = await dispatch(
100
+ checkoutApi.endpoints.setWalletSelectionPage.initiate({
101
+ payment_option: preOrder.payment_option?.pk
102
+ })
103
+ ).unwrap();
123
104
 
124
- // Store the order number from the wallet payment page response
125
- if (walletPaymentPageResponse.pre_order?.number) {
126
- setOrderNumber(walletPaymentPageResponse.pre_order.number);
127
- }
105
+ const walletPaymentPageContext =
106
+ walletSelectionPageResponse.context_list.find(
107
+ (c) => c.page_name === 'WalletPaymentPage'
108
+ );
109
+
110
+ if (!walletPaymentPageContext) {
111
+ setErrors(
112
+ 'Payment method not available. Please try a different payment option.'
113
+ );
114
+ return;
115
+ }
116
+
117
+ // Initialize wallet payment page to get payment session data
118
+ const walletPaymentPageResponse = await dispatch(
119
+ checkoutApi.endpoints.setWalletPaymentPage.initiate({
120
+ payment_method: 'checkout_flow',
121
+ wallet_method: preOrder.wallet_method
122
+ })
123
+ ).unwrap();
124
+
125
+ if (walletPaymentPageResponse.errors) {
126
+ setErrors(walletPaymentPageResponse.errors);
127
+ return;
128
+ }
129
+
130
+ // Store the order number from the wallet payment page response
131
+ if (walletPaymentPageResponse.pre_order?.number) {
132
+ setOrderNumber(walletPaymentPageResponse.pre_order.number);
133
+ }
128
134
 
129
- setWalletSelectionReady(true);
135
+ setWalletSelectionReady(true);
136
+ } finally {
137
+ walletInitInFlightRef.current = false;
138
+ }
130
139
  };
131
140
 
132
141
  // Reset payment state and get a fresh orderNumber + payment session for retry
@@ -193,9 +202,13 @@ export default function FlowPayment({
193
202
  return;
194
203
  }
195
204
 
196
- // Check if amount has actually changed
197
- if (lastAmountRef.current === currentAmount && flowComponentRef.current) {
198
- return; // Don't recreate component if amount hasn't changed
205
+ // Skip if neither amount nor payment session has changed
206
+ if (
207
+ lastAmountRef.current === currentAmount &&
208
+ lastSessionRef.current === preOrder.context_extras &&
209
+ flowComponentRef.current
210
+ ) {
211
+ return;
199
212
  }
200
213
 
201
214
  isInitializingRef.current = true;
@@ -228,8 +241,9 @@ export default function FlowPayment({
228
241
  return;
229
242
  }
230
243
 
231
- // Update the last amount reference after getting fresh data
244
+ // Update tracking refs after getting fresh data
232
245
  lastAmountRef.current = currentAmount;
246
+ lastSessionRef.current = paymentSession;
233
247
 
234
248
  const checkout = await loadCheckoutWebComponents({
235
249
  publicKey,
@@ -267,6 +281,14 @@ export default function FlowPayment({
267
281
  initWalletSelection();
268
282
  }, []);
269
283
 
284
+ // Re-init wallet selection when unpaid amount actually changes
285
+ useEffect(() => {
286
+ const current = parseFloat(preOrder.unpaid_amount || '0') || 0;
287
+ if (prevUnpaidRef.current === current) return;
288
+ prevUnpaidRef.current = current;
289
+ initWalletSelection();
290
+ }, [preOrder.unpaid_amount]);
291
+
270
292
  useEffect(() => {
271
293
  if (
272
294
  !preOrder.wallet_method ||