@akinon/pz-flow-payment 1.108.0-rc.0 → 1.108.0-rc.10

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,49 @@
1
1
  # @akinon/pz-flow-payment
2
2
 
3
+ ## 1.108.0-rc.10
4
+
5
+ ### Minor Changes
6
+
7
+ - 59ed7a7e: ZERO-3640: Add order number state and update FlowPayment component for wallet payment response handling
8
+
9
+ ## 1.108.0-rc.9
10
+
11
+ ## 1.108.0-rc.8
12
+
13
+ ### Minor Changes
14
+
15
+ - f85464e9: ZERO-3640: Fix API call to use hyphenated key for payment ID in FlowPayment component
16
+
17
+ ## 1.108.0-rc.7
18
+
19
+ ## 1.108.0-rc.6
20
+
21
+ ## 1.108.0-rc.5
22
+
23
+ ### Minor Changes
24
+
25
+ - 31a2d35: ZERO-3640: Refactor checkout API call to include useFormData option; update FlowPayment component for improved error handling and code readability
26
+
27
+ ## 1.108.0-rc.4
28
+
29
+ ### Minor Changes
30
+
31
+ - d8883ce: ZERO-3640: Refactor wallet completion handling to accept additional parameters; update related API calls
32
+
33
+ ## 1.108.0-rc.3
34
+
35
+ ### Minor Changes
36
+
37
+ - e00b4a8: ZERO-3640: Refactor wallet selection initialization and error handling; streamline payment session management
38
+
39
+ ## 1.108.0-rc.2
40
+
41
+ ## 1.108.0-rc.1
42
+
43
+ ### Minor Changes
44
+
45
+ - 21d88c1: ZERO-3640: Remove redundant API calls
46
+
3
47
  ## 1.108.0-rc.0
4
48
 
5
49
  ### Minor Changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/pz-flow-payment",
3
3
  "license": "MIT",
4
- "version": "1.108.0-rc.0",
4
+ "version": "1.108.0-rc.10",
5
5
  "main": "src/index.tsx",
6
6
  "dependencies": {
7
7
  "@checkout.com/checkout-web-components": "0.7.0-beta"
@@ -77,10 +77,10 @@ export default function FlowPayment({
77
77
  const flowComponentRef = useRef<any>(null);
78
78
  const lastAmountRef = useRef<string | null>(null);
79
79
  const isInitializingRef = useRef<boolean>(false);
80
- const walletPaymentInitialized = useRef<boolean>(false);
81
80
  const [errors, setErrors] = useState<any>(null);
82
-
83
- const environment = options?.environment || 'sandbox';
81
+ const [walletSelectionReady, setWalletSelectionReady] =
82
+ useState<boolean>(false);
83
+ const [orderNumber, setOrderNumber] = useState<string | null>(null);
84
84
 
85
85
  // Memoize the amount to track actual changes
86
86
  const currentAmount = useMemo(() => {
@@ -100,63 +100,69 @@ export default function FlowPayment({
100
100
  );
101
101
 
102
102
  if (!walletPaymentPageContext) {
103
+ setErrors(
104
+ 'Payment method not available. Please try a different payment option.'
105
+ );
106
+ setWalletSelectionReady(false);
103
107
  return;
104
108
  }
105
109
 
106
- // FIX: Only call setWalletPaymentPage if not already initialized
107
- if (!walletPaymentInitialized.current) {
108
- walletPaymentInitialized.current = true;
109
- dispatch(checkoutApi.endpoints.setWalletPaymentPage.initiate({}));
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;
110
122
  }
123
+
124
+ // Store the order number from the wallet payment page response
125
+ if (walletPaymentPageResponse.pre_order?.number) {
126
+ setOrderNumber(walletPaymentPageResponse.pre_order.number);
127
+ }
128
+
129
+ setWalletSelectionReady(true);
111
130
  };
112
131
 
113
132
  const handlePaymentSuccess = async (paymentData: any) => {
114
133
  setErrors(null);
115
134
 
116
135
  try {
117
- const walletPaymentPageResponse = await dispatch(
118
- checkoutApi.endpoints.setWalletPaymentPage.initiate({
119
- payment_token: JSON.stringify(paymentData)
136
+ const ckoPaymentId = paymentData?.id;
137
+ const isSuccess = paymentData?.status === 'Approved';
138
+
139
+ const paymentCompleteResponse = await dispatch(
140
+ checkoutApi.endpoints.setWalletCompletePage.initiate({
141
+ success: isSuccess,
142
+ 'cko-payment-id': ckoPaymentId,
143
+ oid: orderNumber
120
144
  })
121
145
  ).unwrap();
122
146
 
123
- if (walletPaymentPageResponse.errors) {
124
- setErrors(walletPaymentPageResponse.errors);
147
+ if (paymentCompleteResponse.errors) {
148
+ setErrors(paymentCompleteResponse.errors);
125
149
  return;
126
150
  }
127
151
 
128
152
  if (
129
- walletPaymentPageResponse.context_list.find(
130
- (c) => c.page_name === 'WalletCompletePage'
153
+ paymentCompleteResponse.context_list.find(
154
+ (c) => c.page_name === 'ThankYouPage'
131
155
  )
132
156
  ) {
133
- const paymentCompleteResponse = await dispatch(
134
- checkoutApi.endpoints.setWalletCompletePage.initiate(true)
135
- ).unwrap();
157
+ const redirectUrl = paymentCompleteResponse.context_list.find(
158
+ (c) => c.page_name === 'ThankYouPage'
159
+ )?.page_context.context_data.redirect_url;
136
160
 
137
- if (paymentCompleteResponse.errors) {
138
- setErrors(paymentCompleteResponse.errors);
139
- return;
140
- }
161
+ const redirectUrlWithLocale = `${
162
+ window.location.origin
163
+ }${getUrlPathWithLocale(redirectUrl, getCookie('pz-locale') || 'en')}`;
141
164
 
142
- if (
143
- paymentCompleteResponse.context_list.find(
144
- (c) => c.page_name === 'ThankYouPage'
145
- )
146
- ) {
147
- const redirectUrl = paymentCompleteResponse.context_list.find(
148
- (c) => c.page_name === 'ThankYouPage'
149
- )?.page_context.context_data.redirect_url;
150
-
151
- const redirectUrlWithLocale = `${
152
- window.location.origin
153
- }${getUrlPathWithLocale(
154
- redirectUrl,
155
- getCookie('pz-locale') || 'en'
156
- )}`;
157
-
158
- window.location.href = redirectUrlWithLocale;
159
- }
165
+ window.location.href = redirectUrlWithLocale;
160
166
  }
161
167
  } catch (error) {
162
168
  console.error('Error processing payment completion:', error);
@@ -203,24 +209,15 @@ export default function FlowPayment({
203
209
  container.innerHTML = '';
204
210
  }
205
211
 
206
- // FIX: Use existing payment session instead of making another API call
212
+ // FIX: Use existing payment session from preOrder.context_extras
207
213
  let paymentSession = preOrder.context_extras;
208
214
 
209
- // Only get fresh payment data if we don't have a valid session
210
- if (!paymentSession && lastAmountRef.current !== currentAmount) {
211
- // Check if another call is already in progress
212
- if (!walletPaymentInitialized.current) {
213
- walletPaymentInitialized.current = true;
214
- const walletPaymentResponse = await dispatch(
215
- checkoutApi.endpoints.setWalletPaymentPage.initiate({})
216
- ).unwrap();
217
- paymentSession =
218
- walletPaymentResponse?.pre_order?.context_extras ||
219
- preOrder.context_extras;
220
- } else {
221
- // Use existing context_extras if another call was already made
222
- paymentSession = preOrder.context_extras;
223
- }
215
+ // If we don't have payment session data, we need to wait for it
216
+ if (!paymentSession) {
217
+ console.warn(
218
+ 'FlowPayment: Payment session not available yet, component will retry when data is ready'
219
+ );
220
+ return;
224
221
  }
225
222
 
226
223
  // Update the last amount reference after getting fresh data
@@ -265,9 +262,10 @@ export default function FlowPayment({
265
262
  useEffect(() => {
266
263
  if (
267
264
  !preOrder.wallet_method ||
268
- !preOrder.token ||
269
265
  !walletPaymentData?.data?.public_key ||
270
- preOrder.wallet_method !== 'checkout_flow'
266
+ preOrder.wallet_method !== 'checkout_flow' ||
267
+ !walletSelectionReady ||
268
+ !preOrder.context_extras
271
269
  ) {
272
270
  return;
273
271
  }
@@ -279,7 +277,9 @@ export default function FlowPayment({
279
277
  preOrder.wallet_method,
280
278
  preOrder.token,
281
279
  currentAmount, // Use memoized amount instead of preOrder.total_amount
282
- walletPaymentData?.data?.public_key
280
+ walletPaymentData?.data?.public_key,
281
+ walletSelectionReady,
282
+ preOrder.context_extras // Add payment session dependency
283
283
  ]);
284
284
 
285
285
  // Cleanup function when component unmounts
@@ -292,8 +292,6 @@ export default function FlowPayment({
292
292
  console.warn('Error destroying flow component on unmount:', error);
293
293
  }
294
294
  }
295
- // Reset initialization flag on unmount
296
- walletPaymentInitialized.current = false;
297
295
  };
298
296
  }, []);
299
297