@akinon/pz-flow-payment 2.0.9-rc.0 → 2.0.10-beta.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,10 +1,8 @@
1
1
  # @akinon/pz-flow-payment
2
2
 
3
- ## 2.0.9-rc.0
3
+ ## 2.0.10-beta.0
4
4
 
5
- ### Patch Changes
6
-
7
- - b02e7a7a: BRDG-16653: Re-init wallet selection when loyalty amount changes
5
+ ## 2.0.9
8
6
 
9
7
  ## 2.0.8
10
8
 
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.9-rc.0",
4
+ "version": "2.0.10-beta.0",
5
5
  "main": "src/index.tsx",
6
6
  "dependencies": {
7
7
  "@checkout.com/checkout-web-components": "0.7.0-beta"
@@ -76,10 +76,7 @@ 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);
81
79
  const isInitializingRef = useRef<boolean>(false);
82
- const walletInitInFlightRef = useRef<boolean>(false);
83
80
  const [errors, setErrors] = useState<any>(null);
84
81
  const [walletSelectionReady, setWalletSelectionReady] =
85
82
  useState<boolean>(false);
@@ -91,51 +88,45 @@ export default function FlowPayment({
91
88
  }, [preOrder.total_amount]);
92
89
 
93
90
  const initWalletSelection = async () => {
94
- if (walletInitInFlightRef.current) return;
95
- walletInitInFlightRef.current = true;
96
- setWalletSelectionReady(false);
97
-
98
- try {
99
- const walletSelectionPageResponse = await dispatch(
100
- checkoutApi.endpoints.setWalletSelectionPage.initiate({
101
- payment_option: preOrder.payment_option?.pk
102
- })
103
- ).unwrap();
104
-
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
- }
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
+ }
129
109
 
130
- // Store the order number from the wallet payment page response
131
- if (walletPaymentPageResponse.pre_order?.number) {
132
- setOrderNumber(walletPaymentPageResponse.pre_order.number);
133
- }
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
+ }
134
123
 
135
- setWalletSelectionReady(true);
136
- } finally {
137
- walletInitInFlightRef.current = false;
124
+ // Store the order number from the wallet payment page response
125
+ if (walletPaymentPageResponse.pre_order?.number) {
126
+ setOrderNumber(walletPaymentPageResponse.pre_order.number);
138
127
  }
128
+
129
+ setWalletSelectionReady(true);
139
130
  };
140
131
 
141
132
  // Reset payment state and get a fresh orderNumber + payment session for retry
@@ -202,13 +193,9 @@ export default function FlowPayment({
202
193
  return;
203
194
  }
204
195
 
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;
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
212
199
  }
213
200
 
214
201
  isInitializingRef.current = true;
@@ -241,9 +228,8 @@ export default function FlowPayment({
241
228
  return;
242
229
  }
243
230
 
244
- // Update tracking refs after getting fresh data
231
+ // Update the last amount reference after getting fresh data
245
232
  lastAmountRef.current = currentAmount;
246
- lastSessionRef.current = paymentSession;
247
233
 
248
234
  const checkout = await loadCheckoutWebComponents({
249
235
  publicKey,
@@ -281,14 +267,6 @@ export default function FlowPayment({
281
267
  initWalletSelection();
282
268
  }, []);
283
269
 
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
-
292
270
  useEffect(() => {
293
271
  if (
294
272
  !preOrder.wallet_method ||