@akinon/next 1.118.0-rc.7 → 1.118.0-rc.9

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,17 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.118.0-rc.9
4
+
5
+ ### Minor Changes
6
+
7
+ - 01ee41f1: ZERO-4102: Implement a post-checkout flow by dynamically determining checkout paths and managing a pz-post-checkout-flow cookie.
8
+
9
+ ## 1.118.0-rc.8
10
+
11
+ ### Minor Changes
12
+
13
+ - 31b4a266: ZERO-4102: Add support for post-checkout redirect in middleware
14
+
3
15
  ## 1.118.0-rc.7
4
16
 
5
17
  ## 1.118.0-rc.6
@@ -17,7 +17,7 @@ import {
17
17
  SendSmsType,
18
18
  VerifySmsType
19
19
  } from '../../types';
20
- import { buildClientRequestUrl } from '../../utils';
20
+ import { buildClientRequestUrl, getCookie } from '../../utils';
21
21
  import { api } from './api';
22
22
  import { checkout } from '../urls';
23
23
  import type { AppDispatch, AppStore } from 'redux/store';
@@ -87,6 +87,18 @@ export interface PayOnDeliveryParams {
87
87
  paymentType: string;
88
88
  }
89
89
 
90
+ const buildCheckoutRequestUrl = (
91
+ path: string,
92
+ options?: Parameters<typeof buildClientRequestUrl>[1]
93
+ ) => {
94
+ const effectivePath =
95
+ getCookie('pz-post-checkout-flow') === 'true' &&
96
+ /^\/orders\/checkout(\/|\?|$)/.test(path)
97
+ ? path.replace('/orders/checkout', '/orders/post-checkout')
98
+ : path;
99
+ return buildClientRequestUrl(effectivePath, options);
100
+ };
101
+
90
102
  const completeMasterpassPayment = async (
91
103
  params: CompleteCreditCardParams,
92
104
  dispatch: AppDispatch,
@@ -186,41 +198,41 @@ export const checkoutApi = api.injectEndpoints({
186
198
  endpoints: (build) => ({
187
199
  fetchCheckout: build.query<CheckoutResponse, void>({
188
200
  query: () => ({
189
- url: buildClientRequestUrl(checkout.fetchCheckout, {})
201
+ url: buildCheckoutRequestUrl(checkout.fetchCheckout, {})
190
202
  }),
191
203
  providesTags: ['Checkout']
192
204
  }),
193
205
  resetCheckoutState: build.query<CheckoutResponse, void>({
194
206
  query: () => ({
195
- url: buildClientRequestUrl(checkout.guestLogin, {})
207
+ url: buildCheckoutRequestUrl(checkout.guestLogin, {})
196
208
  })
197
209
  }),
198
210
  fetchCheckoutResult: build.query<{ order: Order }, string>({
199
211
  query: (token: string) =>
200
- buildClientRequestUrl(checkout.fetchCheckoutResult(token))
212
+ buildCheckoutRequestUrl(checkout.fetchCheckoutResult(token))
201
213
  }),
202
214
  get3dRedirectForm: build.query<{ result: string }, void>({
203
215
  query: () =>
204
- buildClientRequestUrl(checkout.get3dRedirectForm, {
216
+ buildCheckoutRequestUrl(checkout.get3dRedirectForm, {
205
217
  responseType: 'text'
206
218
  })
207
219
  }),
208
220
  getContract: build.query<GetContractResponse, string>({
209
221
  query: (slug: string) =>
210
- buildClientRequestUrl(checkout.getContract(slug), {
222
+ buildCheckoutRequestUrl(checkout.getContract(slug), {
211
223
  responseType: 'text'
212
224
  })
213
225
  }),
214
226
  getCoupons: build.query<CheckoutResponse, void>({
215
227
  query: () => ({
216
- url: buildClientRequestUrl(checkout.couponSelectionPage)
228
+ url: buildCheckoutRequestUrl(checkout.couponSelectionPage)
217
229
  })
218
230
  }),
219
231
 
220
232
  setCoupon: build.mutation<CheckoutResponse, { pk: number; action: string }>(
221
233
  {
222
234
  query: ({ pk, action }) => ({
223
- url: buildClientRequestUrl(checkout.couponSelectionPage, {
235
+ url: buildCheckoutRequestUrl(checkout.couponSelectionPage, {
224
236
  useFormData: true
225
237
  }),
226
238
  method: 'POST',
@@ -256,7 +268,7 @@ export const checkoutApi = api.injectEndpoints({
256
268
 
257
269
  if (paymentOption?.payment_type === 'masterpass') {
258
270
  const result = await baseQuery({
259
- url: buildClientRequestUrl(checkout.getMasterpassOrderNo, {
271
+ url: buildCheckoutRequestUrl(checkout.getMasterpassOrderNo, {
260
272
  useFormData: true
261
273
  }),
262
274
  method: 'POST'
@@ -279,7 +291,7 @@ export const checkoutApi = api.injectEndpoints({
279
291
  }
280
292
 
281
293
  const result = await baseQuery({
282
- url: buildClientRequestUrl(checkout.completeCreditCardPayment, {
294
+ url: buildCheckoutRequestUrl(checkout.completeCreditCardPayment, {
283
295
  useFormData: true
284
296
  }),
285
297
  method: 'POST',
@@ -315,7 +327,7 @@ export const checkoutApi = api.injectEndpoints({
315
327
  }
316
328
  >({
317
329
  query: ({ token }) => ({
318
- url: buildClientRequestUrl(checkout.completeMasterpassPayment, {
330
+ url: buildCheckoutRequestUrl(checkout.completeMasterpassPayment, {
319
331
  useFormData: true
320
332
  }),
321
333
  method: 'POST',
@@ -332,7 +344,7 @@ export const checkoutApi = api.injectEndpoints({
332
344
  }),
333
345
  completeFundsTransfer: build.mutation<CheckoutResponse, void>({
334
346
  query: () => ({
335
- url: buildClientRequestUrl(checkout.completeFundsTransfer, {
347
+ url: buildCheckoutRequestUrl(checkout.completeFundsTransfer, {
336
348
  useFormData: true
337
349
  }),
338
350
  method: 'POST',
@@ -349,7 +361,7 @@ export const checkoutApi = api.injectEndpoints({
349
361
  }),
350
362
  guestLogin: build.mutation<CheckoutResponse, GuestLoginFormParams>({
351
363
  query: ({ user_email, phone_number }) => ({
352
- url: buildClientRequestUrl(checkout.guestLogin, {
364
+ url: buildCheckoutRequestUrl(checkout.guestLogin, {
353
365
  useFormData: true
354
366
  }),
355
367
  method: 'POST',
@@ -362,7 +374,7 @@ export const checkoutApi = api.injectEndpoints({
362
374
  }),
363
375
  setDeliveryOption: build.mutation<CheckoutResponse, number>({
364
376
  query: (pk: number) => ({
365
- url: buildClientRequestUrl(checkout.setDeliveryOption, {
377
+ url: buildCheckoutRequestUrl(checkout.setDeliveryOption, {
366
378
  useFormData: true
367
379
  }),
368
380
  method: 'POST',
@@ -378,7 +390,7 @@ export const checkoutApi = api.injectEndpoints({
378
390
  }),
379
391
  setAddresses: build.mutation<CheckoutResponse, SetAddressesParams>({
380
392
  query: ({ shippingAddressPk, billingAddressPk }) => ({
381
- url: buildClientRequestUrl(checkout.setAddresses, {
393
+ url: buildCheckoutRequestUrl(checkout.setAddresses, {
382
394
  useFormData: true
383
395
  }),
384
396
  method: 'POST',
@@ -395,7 +407,7 @@ export const checkoutApi = api.injectEndpoints({
395
407
  }),
396
408
  setShippingOption: build.mutation<CheckoutResponse, number>({
397
409
  query: (pk: number) => ({
398
- url: buildClientRequestUrl(checkout.setShippingOption, {
410
+ url: buildCheckoutRequestUrl(checkout.setShippingOption, {
399
411
  useFormData: true
400
412
  }),
401
413
  method: 'POST',
@@ -411,7 +423,7 @@ export const checkoutApi = api.injectEndpoints({
411
423
  }),
412
424
  setDataSourceShippingOptions: build.mutation<CheckoutResponse, number[]>({
413
425
  query: (pks) => ({
414
- url: buildClientRequestUrl(checkout.setDataSourceShippingOption, {
426
+ url: buildCheckoutRequestUrl(checkout.setDataSourceShippingOption, {
415
427
  useFormData: true
416
428
  }),
417
429
  method: 'POST',
@@ -427,7 +439,7 @@ export const checkoutApi = api.injectEndpoints({
427
439
  }),
428
440
  setRetailStore: build.mutation<CheckoutResponse, SetRetailStoreParams>({
429
441
  query: ({ retailStorePk, billingAddressPk }) => ({
430
- url: buildClientRequestUrl(
442
+ url: buildCheckoutRequestUrl(
431
443
  '/orders/checkout?page=RetailStoreSelectionPage',
432
444
  {
433
445
  useFormData: true
@@ -442,13 +454,13 @@ export const checkoutApi = api.injectEndpoints({
442
454
  }),
443
455
  fetchPaymentOptions: build.query<CheckoutResponse, void>({
444
456
  query: () => ({
445
- url: buildClientRequestUrl(checkout.setPaymentOption)
457
+ url: buildCheckoutRequestUrl(checkout.setPaymentOption)
446
458
  }),
447
459
  providesTags: ['PaymentOptions']
448
460
  }),
449
461
  setPaymentOption: build.mutation<CheckoutResponse, number>({
450
462
  query: (pk: number) => ({
451
- url: buildClientRequestUrl(checkout.setPaymentOption, {
463
+ url: buildCheckoutRequestUrl(checkout.setPaymentOption, {
452
464
  useFormData: true
453
465
  }),
454
466
  method: 'POST',
@@ -474,7 +486,7 @@ export const checkoutApi = api.injectEndpoints({
474
486
  }
475
487
  >({
476
488
  query: ({ payment_option: pk, validationURL }) => ({
477
- url: buildClientRequestUrl(checkout.setWalletSelectionPage, {
489
+ url: buildCheckoutRequestUrl(checkout.setWalletSelectionPage, {
478
490
  useFormData: true
479
491
  }),
480
492
  method: 'POST',
@@ -498,7 +510,7 @@ export const checkoutApi = api.injectEndpoints({
498
510
  }
499
511
  >({
500
512
  query: (requestBody) => ({
501
- url: buildClientRequestUrl(checkout.setWalletPaymentPage, {
513
+ url: buildCheckoutRequestUrl(checkout.setWalletPaymentPage, {
502
514
  useFormData: true
503
515
  }),
504
516
  method: 'POST',
@@ -519,7 +531,7 @@ export const checkoutApi = api.injectEndpoints({
519
531
  }
520
532
  >({
521
533
  query: ({ success, ...additionalParams }) => ({
522
- url: buildClientRequestUrl(checkout.setWalletCompletePage, {
534
+ url: buildCheckoutRequestUrl(checkout.setWalletCompletePage, {
523
535
  useFormData: true
524
536
  }),
525
537
  method: 'POST',
@@ -545,7 +557,7 @@ export const checkoutApi = api.injectEndpoints({
545
557
  : checkout.setBinNumber;
546
558
 
547
559
  const result = await baseQuery({
548
- url: buildClientRequestUrl(binNumberUrl, {
560
+ url: buildCheckoutRequestUrl(binNumberUrl, {
549
561
  useFormData: true
550
562
  }),
551
563
  method: 'POST',
@@ -573,7 +585,7 @@ export const checkoutApi = api.injectEndpoints({
573
585
  : checkout.setInstallmentOption;
574
586
 
575
587
  const result = await baseQuery({
576
- url: buildClientRequestUrl(installmentOption, {
588
+ url: buildCheckoutRequestUrl(installmentOption, {
577
589
  useFormData: true
578
590
  }),
579
591
  method: 'POST',
@@ -591,7 +603,7 @@ export const checkoutApi = api.injectEndpoints({
591
603
  }),
592
604
  setFundsTransferOption: build.mutation<CheckoutResponse, number>({
593
605
  query: (pk: number) => ({
594
- url: buildClientRequestUrl(checkout.setFundsTransferOption, {
606
+ url: buildCheckoutRequestUrl(checkout.setFundsTransferOption, {
595
607
  useFormData: true
596
608
  }),
597
609
  method: 'POST',
@@ -608,7 +620,7 @@ export const checkoutApi = api.injectEndpoints({
608
620
  }),
609
621
  setCreditPaymentOption: build.mutation<CheckoutResponse, number>({
610
622
  query: (pk: number) => ({
611
- url: buildClientRequestUrl(checkout.setCreditPaymentOption, {
623
+ url: buildCheckoutRequestUrl(checkout.setCreditPaymentOption, {
612
624
  useFormData: true
613
625
  }),
614
626
  method: 'POST',
@@ -625,7 +637,7 @@ export const checkoutApi = api.injectEndpoints({
625
637
  }),
626
638
  confirmationCreditPayment: build.mutation<CheckoutResponse, void>({
627
639
  query: () => ({
628
- url: buildClientRequestUrl(checkout.confirmationCreditPayment, {
640
+ url: buildCheckoutRequestUrl(checkout.confirmationCreditPayment, {
629
641
  useFormData: true
630
642
  }),
631
643
  method: 'POST',
@@ -641,7 +653,7 @@ export const checkoutApi = api.injectEndpoints({
641
653
  }),
642
654
  completeRedirectionPayment: build.mutation<CheckoutResponse, void>({
643
655
  query: () => ({
644
- url: buildClientRequestUrl(checkout.completeRedirectionPayment, {
656
+ url: buildCheckoutRequestUrl(checkout.completeRedirectionPayment, {
645
657
  useFormData: true
646
658
  }),
647
659
  method: 'POST',
@@ -657,7 +669,7 @@ export const checkoutApi = api.injectEndpoints({
657
669
  }),
658
670
  applePaymentSelect: build.mutation<CheckoutResponse, ApplePaySelectParams>({
659
671
  query: ({ agreement, validationURL }) => ({
660
- url: buildClientRequestUrl(checkout.confirmationPaymentSelect, {
672
+ url: buildCheckoutRequestUrl(checkout.confirmationPaymentSelect, {
661
673
  useFormData: true
662
674
  }),
663
675
  method: 'POST',
@@ -674,7 +686,7 @@ export const checkoutApi = api.injectEndpoints({
674
686
  }),
675
687
  appleQuery: build.mutation<CheckoutResponse, ApplePayQueryParams>({
676
688
  query: ({ agreement, paymentToken }) => ({
677
- url: buildClientRequestUrl(checkout.confirmationQuery, {
689
+ url: buildCheckoutRequestUrl(checkout.confirmationQuery, {
678
690
  useFormData: true
679
691
  }),
680
692
  method: 'POST',
@@ -691,7 +703,7 @@ export const checkoutApi = api.injectEndpoints({
691
703
  }),
692
704
  completeConfirmation: build.mutation<CheckoutResponse, void>({
693
705
  query: () => ({
694
- url: buildClientRequestUrl(checkout.confirmationComplete, {
706
+ url: buildCheckoutRequestUrl(checkout.confirmationComplete, {
695
707
  useFormData: true
696
708
  }),
697
709
  method: 'POST',
@@ -710,7 +722,7 @@ export const checkoutApi = api.injectEndpoints({
710
722
  PayOnDeliveryParams
711
723
  >({
712
724
  query: ({ paymentType }) => ({
713
- url: buildClientRequestUrl(
725
+ url: buildCheckoutRequestUrl(
714
726
  `${checkout.fetchCheckout}?page=PayOnDeliveryPage`,
715
727
  { useFormData: true }
716
728
  ),
@@ -728,7 +740,7 @@ export const checkoutApi = api.injectEndpoints({
728
740
  }),
729
741
  setPayOnDeliveryChoice: build.mutation<CheckoutResponse, string>({
730
742
  query: (body) => ({
731
- url: buildClientRequestUrl(
743
+ url: buildCheckoutRequestUrl(
732
744
  `${checkout.fetchCheckout}?page=PayOnDeliveryPaymentChoicePage`,
733
745
  { useFormData: true }
734
746
  ),
@@ -745,7 +757,7 @@ export const checkoutApi = api.injectEndpoints({
745
757
  }),
746
758
  completeLoyaltyPayment: build.mutation<CheckoutResponse, void>({
747
759
  query: () => ({
748
- url: buildClientRequestUrl(checkout.completeLoyaltyPayment, {
760
+ url: buildCheckoutRequestUrl(checkout.completeLoyaltyPayment, {
749
761
  useFormData: true
750
762
  }),
751
763
  method: 'POST',
@@ -761,12 +773,12 @@ export const checkoutApi = api.injectEndpoints({
761
773
  }),
762
774
  getCheckoutLoyaltyBalance: build.query<CheckoutResponse, void>({
763
775
  query: () => ({
764
- url: buildClientRequestUrl(checkout.loyaltyMoneyUsage)
776
+ url: buildCheckoutRequestUrl(checkout.loyaltyMoneyUsage)
765
777
  })
766
778
  }),
767
779
  payWithLoyaltyBalance: build.mutation<any, string>({
768
780
  query: (amount) => ({
769
- url: buildClientRequestUrl(checkout.loyaltyMoneyUsage, {
781
+ url: buildCheckoutRequestUrl(checkout.loyaltyMoneyUsage, {
770
782
  useFormData: true
771
783
  }),
772
784
  method: 'POST',
@@ -797,7 +809,7 @@ export const checkoutApi = api.injectEndpoints({
797
809
  }),
798
810
  setOrderNote: build.mutation<CheckoutResponse, string>({
799
811
  query: (notes) => ({
800
- url: buildClientRequestUrl(checkout.setOrderNote, {
812
+ url: buildCheckoutRequestUrl(checkout.setOrderNote, {
801
813
  useFormData: true
802
814
  }),
803
815
  method: 'POST',
@@ -817,7 +829,7 @@ export const checkoutApi = api.injectEndpoints({
817
829
  };
818
830
 
819
831
  return {
820
- url: buildClientRequestUrl(checkout.deliveryBagsPage, {
832
+ url: buildCheckoutRequestUrl(checkout.deliveryBagsPage, {
821
833
  useFormData: true
822
834
  }),
823
835
  method: 'POST',
@@ -830,7 +842,7 @@ export const checkoutApi = api.injectEndpoints({
830
842
  Record<string, number>
831
843
  >({
832
844
  query: (options) => ({
833
- url: buildClientRequestUrl(checkout.setAttributeBasedShippingOption, {
845
+ url: buildCheckoutRequestUrl(checkout.setAttributeBasedShippingOption, {
834
846
  useFormData: true
835
847
  }),
836
848
  method: 'POST',
@@ -849,7 +861,7 @@ export const checkoutApi = api.injectEndpoints({
849
861
  { extra_field: ExtraField }
850
862
  >({
851
863
  query: ({ extra_field }) => ({
852
- url: buildClientRequestUrl(checkout.setOrderSelectionPage, {
864
+ url: buildCheckoutRequestUrl(checkout.setOrderSelectionPage, {
853
865
  useFormData: true
854
866
  }),
855
867
  method: 'POST',
@@ -860,7 +872,7 @@ export const checkoutApi = api.injectEndpoints({
860
872
  }),
861
873
  fetchLoyaltyData: build.query<CheckoutResponse, void>({
862
874
  query: () => ({
863
- url: buildClientRequestUrl(checkout.loyaltyCardPage, {
875
+ url: buildCheckoutRequestUrl(checkout.loyaltyCardPage, {
864
876
  accept: 'application/json',
865
877
  contentType: 'application/json'
866
878
  }),
@@ -869,7 +881,7 @@ export const checkoutApi = api.injectEndpoints({
869
881
  }),
870
882
  setLoyaltyData: build.mutation<CheckoutResponse, number | string>({
871
883
  query: (amount) => ({
872
- url: buildClientRequestUrl(checkout.loyaltyCardPage, {
884
+ url: buildCheckoutRequestUrl(checkout.loyaltyCardPage, {
873
885
  useFormData: true
874
886
  }),
875
887
  method: 'POST',
@@ -880,7 +892,7 @@ export const checkoutApi = api.injectEndpoints({
880
892
  }),
881
893
  sendSms: build.mutation<CheckoutResponse, SendSmsType>({
882
894
  query: (body) => ({
883
- url: buildClientRequestUrl(checkout.sendSmsPage, {
895
+ url: buildCheckoutRequestUrl(checkout.sendSmsPage, {
884
896
  useFormData: true
885
897
  }),
886
898
  method: 'POST',
@@ -889,7 +901,7 @@ export const checkoutApi = api.injectEndpoints({
889
901
  }),
890
902
  verifySms: build.mutation<CheckoutResponse, VerifySmsType>({
891
903
  query: (body) => ({
892
- url: buildClientRequestUrl(checkout.verifySmsPage, {
904
+ url: buildCheckoutRequestUrl(checkout.verifySmsPage, {
893
905
  useFormData: true
894
906
  }),
895
907
  method: 'POST',
@@ -905,7 +917,7 @@ export const checkoutApi = api.injectEndpoints({
905
917
  });
906
918
 
907
919
  return {
908
- url: buildClientRequestUrl(checkout.saveSampleProducts),
920
+ url: buildCheckoutRequestUrl(checkout.saveSampleProducts),
909
921
  method: 'POST',
910
922
  body: formData
911
923
  };
@@ -4,6 +4,7 @@ import { Buffer } from 'buffer';
4
4
  import logger from '../utils/log';
5
5
  import { getUrlPathWithLocale } from '../utils/localization';
6
6
  import { PzNextRequest } from '.';
7
+ import { getCheckoutPath } from '../utils';
7
8
 
8
9
  const streamToString = async (stream: ReadableStream<Uint8Array> | null) => {
9
10
  if (stream) {
@@ -40,7 +41,8 @@ const withCompleteGpay =
40
41
  return middleware(req, event);
41
42
  }
42
43
 
43
- const requestUrl = `${Settings.commerceUrl}/orders/checkout/${url.search}`;
44
+ const isPostCheckout = req.cookies.get('pz-post-checkout-flow')?.value === 'true';
45
+ const requestUrl = `${Settings.commerceUrl}${getCheckoutPath(isPostCheckout)}${url.search}`;
44
46
  const requestHeaders = {
45
47
  'X-Requested-With': 'XMLHttpRequest',
46
48
  'Content-Type': 'application/x-www-form-urlencoded',
@@ -5,6 +5,7 @@ import logger from '../utils/log';
5
5
  import { getUrlPathWithLocale } from '../utils/localization';
6
6
  import { PzNextRequest } from '.';
7
7
  import { ServerVariables } from '../utils/server-variables';
8
+ import { getCheckoutPath } from '../utils';
8
9
 
9
10
  const streamToString = async (stream: ReadableStream<Uint8Array> | null) => {
10
11
  if (stream) {
@@ -41,7 +42,8 @@ const withCompleteMasterpass =
41
42
  return middleware(req, event);
42
43
  }
43
44
 
44
- const requestUrl = `${Settings.commerceUrl}/orders/checkout/${url.search}`;
45
+ const isPostCheckout = req.cookies.get('pz-post-checkout-flow')?.value === 'true';
46
+ const requestUrl = `${Settings.commerceUrl}${getCheckoutPath(isPostCheckout)}${url.search}`;
45
47
  const requestHeaders = {
46
48
  'X-Requested-With': 'XMLHttpRequest',
47
49
  'Content-Type': 'application/x-www-form-urlencoded',
@@ -4,6 +4,7 @@ import { Buffer } from 'buffer';
4
4
  import logger from '../utils/log';
5
5
  import { getUrlPathWithLocale } from '../utils/localization';
6
6
  import { PzNextRequest } from '.';
7
+ import { getCheckoutPath } from '../utils';
7
8
 
8
9
  const streamToString = async (stream: ReadableStream<Uint8Array> | null) => {
9
10
  if (stream) {
@@ -39,7 +40,8 @@ const withCompleteWallet =
39
40
  return middleware(req, event);
40
41
  }
41
42
 
42
- const requestUrl = `${Settings.commerceUrl}/orders/checkout/${url.search}`;
43
+ const isPostCheckout = req.cookies.get('pz-post-checkout-flow')?.value === 'true';
44
+ const requestUrl = `${Settings.commerceUrl}${getCheckoutPath(isPostCheckout)}${url.search}`;
43
45
  const requestHeaders = {
44
46
  'X-Requested-With': 'XMLHttpRequest',
45
47
  'Content-Type': 'application/x-www-form-urlencoded',
@@ -26,6 +26,8 @@ import { getUrlPathWithLocale } from '../utils/localization';
26
26
  import getRootHostname from '../utils/get-root-hostname';
27
27
  import { LocaleUrlStrategy } from '../localization';
28
28
 
29
+ const POST_CHECKOUT_COOKIE_MAX_AGE_MS = 1000 * 60 * 30; // 30 minutes
30
+
29
31
  const withPzDefault =
30
32
  (middleware: NextMiddleware) =>
31
33
  async (req: PzNextRequest, event: NextFetchEvent) => {
@@ -102,6 +104,7 @@ const withPzDefault =
102
104
  if (
103
105
  req.nextUrl.pathname.includes('/orders/hooks/') ||
104
106
  req.nextUrl.pathname.includes('/orders/checkout-with-token/') ||
107
+ req.nextUrl.pathname.includes('/orders/post-checkout-redirect/') ||
105
108
  req.nextUrl.pathname.includes('/hooks/cash_register/complete/') ||
106
109
  req.nextUrl.pathname.includes('/hooks/cash_register/pre_order/')
107
110
  ) {
@@ -153,21 +156,35 @@ const withPzDefault =
153
156
  );
154
157
  }
155
158
 
156
- // If commerce redirects to /orders/checkout/ without locale
159
+ // If commerce redirects to /orders/checkout/ or /orders/post-checkout/ without locale
160
+ const isPostCheckout = !!req.nextUrl.pathname.match(
161
+ new RegExp('^/orders/post-checkout/$')
162
+ );
163
+ const checkoutLocalePath = getUrlPathWithLocale(
164
+ '/orders/checkout/',
165
+ req.cookies.get('pz-locale')?.value
166
+ );
157
167
  if (
158
- req.nextUrl.pathname.match(new RegExp('^/orders/checkout/$')) &&
159
- req.nextUrl.searchParams.size === 0 &&
160
- getUrlPathWithLocale(
161
- '/orders/checkout/',
162
- req.cookies.get('pz-locale')?.value
163
- ) !== req.nextUrl.pathname
168
+ isPostCheckout ||
169
+ (req.nextUrl.pathname.match(new RegExp('^/orders/checkout/$')) &&
170
+ req.nextUrl.searchParams.size === 0 &&
171
+ checkoutLocalePath !== req.nextUrl.pathname)
164
172
  ) {
165
- const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
166
- '/orders/checkout/',
167
- req.cookies.get('pz-locale')?.value
168
- )}`;
173
+ const response = NextResponse.redirect(
174
+ `${url.origin}${checkoutLocalePath}`,
175
+ 303
176
+ );
177
+
178
+ if (isPostCheckout) {
179
+ response.cookies.set('pz-post-checkout-flow', 'true', {
180
+ path: '/',
181
+ sameSite: 'none',
182
+ secure: true,
183
+ expires: new Date(Date.now() + POST_CHECKOUT_COOKIE_MAX_AGE_MS)
184
+ });
185
+ }
169
186
 
170
- return NextResponse.redirect(redirectUrlWithLocale, 303);
187
+ return response;
171
188
  }
172
189
 
173
190
  // Dynamically handle any payment gateway without specifying names
@@ -427,6 +444,25 @@ const withPzDefault =
427
444
  );
428
445
  }
429
446
 
447
+ if (
448
+ req.cookies.get(
449
+ 'pz-post-checkout-flow'
450
+ )
451
+ ) {
452
+ if (
453
+ pathnameWithoutLocale.startsWith(
454
+ '/orders/completed/'
455
+ ) ||
456
+ pathnameWithoutLocale.startsWith(
457
+ '/basket'
458
+ )
459
+ ) {
460
+ middlewareResult.cookies.delete(
461
+ 'pz-post-checkout-flow'
462
+ );
463
+ }
464
+ }
465
+
430
466
  if (process.env.ACC_APP_VERSION) {
431
467
  middlewareResult.headers.set(
432
468
  'acc-app-version',
@@ -3,6 +3,7 @@ import Settings from 'settings';
3
3
  import logger from '../utils/log';
4
4
  import { getUrlPathWithLocale } from '../utils/localization';
5
5
  import { PzNextRequest } from '.';
6
+ import { getCheckoutPath } from '../utils';
6
7
 
7
8
  const withMasterpassRestCallback =
8
9
  (middleware: NextMiddleware) =>
@@ -19,7 +20,9 @@ const withMasterpassRestCallback =
19
20
  }
20
21
 
21
22
  try {
22
- const requestUrl = new URL('/orders/checkout/', Settings.commerceUrl);
23
+ const isPostCheckout = req.cookies.get('pz-post-checkout-flow')?.value === 'true';
24
+ const requestUrl = new URL(getCheckoutPath(isPostCheckout), Settings.commerceUrl);
25
+
23
26
  url.searchParams.forEach((value, key) => {
24
27
  requestUrl.searchParams.set(key, value);
25
28
  });
@@ -4,6 +4,7 @@ import Settings from 'settings';
4
4
  import logger from '../utils/log';
5
5
  import { PzNextRequest } from '.';
6
6
  import { getUrlPathWithLocale } from '../utils/localization';
7
+ import { getCheckoutPath } from '../utils';
7
8
 
8
9
  const streamToString = async (stream: ReadableStream<Uint8Array> | null) => {
9
10
  if (stream) {
@@ -41,7 +42,8 @@ const withRedirectionPayment =
41
42
  return middleware(req, event);
42
43
  }
43
44
 
44
- const requestUrl = `${Settings.commerceUrl}/orders/checkout/${url.search}`;
45
+ const isPostCheckout = req.cookies.get('pz-post-checkout-flow')?.value === 'true';
46
+ const requestUrl = `${Settings.commerceUrl}${getCheckoutPath(isPostCheckout)}${url.search}`;
45
47
  const requestHeaders = {
46
48
  'X-Requested-With': 'XMLHttpRequest',
47
49
  'Content-Type': 'application/x-www-form-urlencoded',
@@ -5,6 +5,7 @@ import logger from '../utils/log';
5
5
  import { getUrlPathWithLocale } from '../utils/localization';
6
6
  import { PzNextRequest } from '.';
7
7
  import { ServerVariables } from '../utils/server-variables';
8
+ import { getCheckoutPath } from '../utils';
8
9
 
9
10
  const streamToString = async (stream: ReadableStream<Uint8Array> | null) => {
10
11
  if (stream) {
@@ -41,7 +42,8 @@ const withSavedCardRedirection =
41
42
  return middleware(req, event);
42
43
  }
43
44
 
44
- const requestUrl = `${Settings.commerceUrl}/orders/checkout/${url.search}`;
45
+ const isPostCheckout = req.cookies.get('pz-post-checkout-flow')?.value === 'true';
46
+ const requestUrl = `${Settings.commerceUrl}${getCheckoutPath(isPostCheckout)}${url.search}`;
45
47
  const requestHeaders = {
46
48
  'X-Requested-With': 'XMLHttpRequest',
47
49
  'Content-Type': 'application/x-www-form-urlencoded',
@@ -4,6 +4,7 @@ import { Buffer } from 'buffer';
4
4
  import logger from '../utils/log';
5
5
  import { getUrlPathWithLocale } from '../utils/localization';
6
6
  import { PzNextRequest } from '.';
7
+ import { getCheckoutPath } from '../utils';
7
8
 
8
9
  const streamToString = async (stream: ReadableStream<Uint8Array> | null) => {
9
10
  if (stream) {
@@ -40,7 +41,8 @@ const withThreeDRedirection =
40
41
  return middleware(req, event);
41
42
  }
42
43
 
43
- const requestUrl = `${Settings.commerceUrl}/orders/checkout/${url.search}`;
44
+ const isPostCheckout = req.cookies.get('pz-post-checkout-flow')?.value === 'true';
45
+ const requestUrl = `${Settings.commerceUrl}${getCheckoutPath(isPostCheckout)}${url.search}`;
44
46
  const requestHeaders = {
45
47
  'X-Requested-With': 'XMLHttpRequest',
46
48
  'Content-Type': 'application/x-www-form-urlencoded',
@@ -4,6 +4,7 @@ import { Buffer } from 'buffer';
4
4
  import logger from '../utils/log';
5
5
  import { getUrlPathWithLocale } from '../utils/localization';
6
6
  import { PzNextRequest } from '.';
7
+ import { getCheckoutPath } from '../utils';
7
8
 
8
9
  const streamToString = async (stream: ReadableStream<Uint8Array> | null) => {
9
10
  if (stream) {
@@ -39,7 +40,8 @@ const withWalletCompleteRedirection =
39
40
  return middleware(req, event);
40
41
  }
41
42
 
42
- const requestUrl = `${Settings.commerceUrl}/orders/checkout/${url.search}`;
43
+ const isPostCheckout = req.cookies.get('pz-post-checkout-flow')?.value === 'true';
44
+ const requestUrl = `${Settings.commerceUrl}${getCheckoutPath(isPostCheckout)}${url.search}`;
43
45
  const requestHeaders = {
44
46
  'X-Requested-With': 'XMLHttpRequest',
45
47
  'Content-Type': 'application/x-www-form-urlencoded',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "1.118.0-rc.7",
4
+ "version": "1.118.0-rc.9",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -35,7 +35,7 @@
35
35
  "set-cookie-parser": "2.6.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@akinon/eslint-plugin-projectzero": "1.118.0-rc.7",
38
+ "@akinon/eslint-plugin-projectzero": "1.118.0-rc.9",
39
39
  "@babel/core": "7.26.10",
40
40
  "@babel/preset-env": "7.26.9",
41
41
  "@babel/preset-typescript": "7.27.0",
@@ -0,0 +1,3 @@
1
+ export const getCheckoutPath = (isPostCheckout: boolean): string => {
2
+ return isPostCheckout ? '/orders/post-checkout/' : '/orders/checkout/';
3
+ };
package/utils/index.ts CHANGED
@@ -7,6 +7,7 @@ export * from './get-currency';
7
7
  export * from './menu-generator';
8
8
  export * from './generate-commerce-search-params';
9
9
  export * from './get-currency-label';
10
+ export * from './get-checkout-path';
10
11
 
11
12
  export function getCookie(name: string) {
12
13
  if (typeof document === 'undefined') {