@akinon/next 1.13.0 → 1.14.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.
Files changed (133) hide show
  1. package/.editorconfig +7 -0
  2. package/.eslintrc.js +40 -40
  3. package/.prettierrc +13 -13
  4. package/CHANGELOG.md +19 -0
  5. package/api/auth.ts +231 -231
  6. package/api/cache.ts +44 -44
  7. package/api/client.ts +174 -174
  8. package/api/logout.ts +42 -42
  9. package/assets/styles/index.scss +28 -28
  10. package/bin/pz-check-dependencies.js +98 -98
  11. package/bin/pz-install-plugins.js +33 -33
  12. package/bin/pz-install-theme.js +58 -58
  13. package/bin/pz-postbuild.js +1 -1
  14. package/bin/pz-postdev.js +1 -1
  15. package/bin/pz-postinstall.js +6 -6
  16. package/bin/pz-poststart.js +1 -1
  17. package/bin/pz-prebuild.js +4 -4
  18. package/bin/pz-predev.js +4 -4
  19. package/bin/pz-prestart.js +1 -1
  20. package/bin/run-script.js +44 -44
  21. package/components/accordion.tsx +52 -0
  22. package/components/button.tsx +46 -0
  23. package/components/client-root.tsx +19 -19
  24. package/components/icon.tsx +18 -18
  25. package/components/image.tsx +133 -133
  26. package/components/index.ts +17 -1
  27. package/components/input.tsx +110 -0
  28. package/components/lazy-component.tsx +33 -33
  29. package/components/loader-spinner.tsx +23 -23
  30. package/components/mobile-app-toggler.tsx +26 -26
  31. package/components/oauth-login.tsx +24 -24
  32. package/components/plugin-module.tsx +11 -8
  33. package/components/price.tsx +55 -0
  34. package/components/pz-providers.tsx +24 -24
  35. package/components/pz-root.tsx +21 -21
  36. package/components/radio.tsx +18 -18
  37. package/components/react-portal.tsx +45 -45
  38. package/components/redirect-three-d/content/index.tsx +74 -74
  39. package/components/redirect-three-d/index.tsx +17 -17
  40. package/components/selected-payment-option-view.tsx +7 -0
  41. package/components/trans.tsx +39 -39
  42. package/data/client/account.ts +208 -208
  43. package/data/client/address.ts +107 -107
  44. package/data/client/api.ts +85 -84
  45. package/data/client/b2b.ts +106 -106
  46. package/data/client/basket.ts +82 -82
  47. package/data/client/checkout.ts +516 -479
  48. package/data/client/misc.ts +101 -101
  49. package/data/client/product.ts +89 -89
  50. package/data/client/user.ts +99 -99
  51. package/data/client/wishlist.ts +118 -88
  52. package/data/server/category.ts +132 -128
  53. package/data/server/flatpage.ts +21 -21
  54. package/data/server/form.ts +22 -22
  55. package/data/server/index.ts +10 -10
  56. package/data/server/landingpage.ts +24 -24
  57. package/data/server/list.ts +67 -62
  58. package/data/server/menu.ts +35 -35
  59. package/data/server/product.ts +86 -86
  60. package/data/server/seo.ts +48 -48
  61. package/data/server/special-page.ts +47 -47
  62. package/data/server/widget.ts +27 -27
  63. package/data/urls.ts +221 -210
  64. package/hocs/client/index.ts +1 -1
  65. package/hocs/client/with-segment-defaults.tsx +25 -25
  66. package/hocs/server/index.ts +1 -1
  67. package/hocs/server/with-segment-defaults.tsx +85 -85
  68. package/hooks/index.ts +10 -10
  69. package/hooks/use-captcha.tsx +76 -76
  70. package/hooks/use-common-product-attributes.ts +36 -36
  71. package/hooks/use-debounce.ts +20 -20
  72. package/hooks/use-localization.ts +78 -78
  73. package/hooks/use-media-query.ts +36 -36
  74. package/hooks/use-mobile-iframe-handler.ts +23 -23
  75. package/hooks/use-on-click-outside.tsx +28 -28
  76. package/hooks/use-payment-options.ts +12 -16
  77. package/hooks/use-router.ts +45 -45
  78. package/hooks/use-translation.ts +14 -14
  79. package/lib/cache.ts +215 -215
  80. package/localization/index.ts +5 -5
  81. package/localization/provider.tsx +58 -58
  82. package/middlewares/currency.ts +100 -100
  83. package/middlewares/default.ts +256 -256
  84. package/middlewares/index.ts +29 -29
  85. package/middlewares/locale.ts +68 -68
  86. package/middlewares/oauth-login.ts +79 -79
  87. package/middlewares/pretty-url.ts +104 -104
  88. package/middlewares/redirection-payment.ts +160 -160
  89. package/middlewares/three-d-redirection.ts +159 -159
  90. package/middlewares/url-redirection.ts +65 -65
  91. package/package.json +2 -2
  92. package/plugins.js +2 -1
  93. package/redux/hooks.ts +7 -7
  94. package/redux/middlewares/checkout.ts +265 -260
  95. package/redux/middlewares/index.ts +50 -50
  96. package/redux/reducers/checkout.ts +184 -171
  97. package/redux/reducers/config.ts +28 -28
  98. package/redux/reducers/header.ts +59 -59
  99. package/redux/reducers/index.ts +14 -14
  100. package/redux/reducers/root.ts +61 -61
  101. package/sentry/index.ts +27 -27
  102. package/tailwind/rtl.js +137 -137
  103. package/types/commerce/account.ts +64 -64
  104. package/types/commerce/address.ts +94 -94
  105. package/types/commerce/b2b.ts +117 -117
  106. package/types/commerce/basket.ts +43 -43
  107. package/types/commerce/category.ts +114 -114
  108. package/types/commerce/checkout.ts +143 -136
  109. package/types/commerce/flatpage.ts +7 -7
  110. package/types/commerce/form.ts +66 -66
  111. package/types/commerce/index.ts +12 -12
  112. package/types/commerce/landingpage.ts +7 -7
  113. package/types/commerce/misc.ts +127 -127
  114. package/types/commerce/order.ts +119 -119
  115. package/types/commerce/product.ts +109 -109
  116. package/types/commerce/widget.ts +28 -28
  117. package/types/gtm.ts +16 -16
  118. package/types/index.ts +274 -237
  119. package/types/metadata.ts +7 -7
  120. package/types/next-auth.d.ts +24 -24
  121. package/utils/app-fetch.ts +69 -69
  122. package/utils/deep-merge.js +24 -24
  123. package/utils/generate-commerce-search-params.ts +22 -22
  124. package/utils/get-currency.ts +29 -29
  125. package/utils/image-loader.ts +31 -31
  126. package/utils/index.ts +150 -150
  127. package/utils/localization.ts +29 -29
  128. package/utils/log.ts +138 -138
  129. package/utils/menu-generator.ts +27 -27
  130. package/utils/mobile-3d-iframe.ts +77 -77
  131. package/utils/server-translation.ts +57 -57
  132. package/utils/server-variables.ts +9 -9
  133. package/with-pz-config.js +94 -94
@@ -1,479 +1,516 @@
1
- import {
2
- setBankAccounts,
3
- setInstallmentOptions,
4
- setPaymentStepBusy,
5
- setSelectedBankAccountPk,
6
- setShippingStepBusy
7
- } from '../../redux/reducers/checkout';
8
- import {
9
- CheckoutContext,
10
- GuestLoginFormParams,
11
- Order,
12
- PreOrder
13
- } from '../../types';
14
- import { buildClientRequestUrl } from '../../utils';
15
- import { api } from './api';
16
- import { checkout } from '../urls';
17
- import { store } from 'redux/store';
18
-
19
- interface CheckoutResponse {
20
- pre_order?: PreOrder;
21
- errors: {
22
- non_field_errors: string;
23
- };
24
- context_list?: CheckoutContext[];
25
- template_name?: string;
26
- redirect_url?: string;
27
- }
28
-
29
- interface SetAddressesParams {
30
- shippingAddressPk: number;
31
- billingAddressPk: number;
32
- }
33
-
34
- interface SetRetailStoreParams {
35
- retailStorePk: number;
36
- billingAddressPk: number;
37
- }
38
-
39
- interface CompleteCreditCardParams {
40
- card_holder: string;
41
- card_cvv: string;
42
- card_number: string;
43
- card_month: string;
44
- card_year: string;
45
- use_three_d?: boolean;
46
- }
47
-
48
- interface GetContractResponse {
49
- result: string;
50
- }
51
-
52
- interface ApplePaySelectParams {
53
- agreement: boolean;
54
- validationURL: string;
55
- }
56
-
57
- interface ApplePayQueryParams {
58
- agreement: boolean;
59
- paymentToken: string;
60
- }
61
-
62
- export interface PayOnDeliveryParams {
63
- agreement: string;
64
- paymentType: string;
65
- }
66
-
67
- export const checkoutApi = api.injectEndpoints({
68
- endpoints: (build) => ({
69
- fetchCheckout: build.query<CheckoutResponse, void>({
70
- query: () => ({
71
- url: buildClientRequestUrl(checkout.fetchCheckout, {})
72
- }),
73
- providesTags: ['Checkout']
74
- }),
75
- fetchCheckoutResult: build.query<{ order: Order }, string>({
76
- query: (token: string) =>
77
- buildClientRequestUrl(checkout.fetchCheckoutResult(token))
78
- }),
79
- get3dRedirectForm: build.query<{ result: string }, void>({
80
- query: () =>
81
- buildClientRequestUrl(checkout.get3dRedirectForm, {
82
- responseType: 'text'
83
- })
84
- }),
85
- getContract: build.query<GetContractResponse, string>({
86
- query: (slug: string) =>
87
- buildClientRequestUrl(checkout.getContract(slug), {
88
- responseType: 'text'
89
- })
90
- }),
91
- completeCreditCardPayment: build.mutation<
92
- CheckoutResponse,
93
- CompleteCreditCardParams
94
- >({
95
- query: ({
96
- card_holder,
97
- card_cvv,
98
- card_number,
99
- card_month,
100
- card_year,
101
- use_three_d = true
102
- }) => ({
103
- url: buildClientRequestUrl(checkout.completeCreditCardPayment, {
104
- useFormData: true
105
- }),
106
- method: 'POST',
107
- body: {
108
- agreement: '1',
109
- use_three_d: use_three_d ? '1' : '0',
110
- card_cvv,
111
- card_holder,
112
- card_month,
113
- card_number,
114
- card_year
115
- }
116
- }),
117
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
118
- dispatch(setPaymentStepBusy(true));
119
- await queryFulfilled;
120
- dispatch(setPaymentStepBusy(false));
121
- },
122
- invalidatesTags: ['Basket']
123
- }),
124
- completeFundsTransfer: build.mutation<CheckoutResponse, void>({
125
- query: () => ({
126
- url: buildClientRequestUrl(checkout.completeFundsTransfer, {
127
- useFormData: true
128
- }),
129
- method: 'POST',
130
- body: {
131
- agreement: '1'
132
- }
133
- }),
134
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
135
- dispatch(setPaymentStepBusy(true));
136
- await queryFulfilled;
137
- dispatch(setPaymentStepBusy(false));
138
- },
139
- invalidatesTags: ['Basket']
140
- }),
141
- guestLogin: build.mutation<CheckoutResponse, GuestLoginFormParams>({
142
- query: ({ user_email, phone_number }) => ({
143
- url: buildClientRequestUrl(checkout.guestLogin, {
144
- useFormData: true
145
- }),
146
- method: 'POST',
147
- body: {
148
- user_email,
149
- phone_number
150
- }
151
- }),
152
- invalidatesTags: ['Checkout']
153
- }),
154
- setDeliveryOption: build.mutation<CheckoutResponse, number>({
155
- query: (pk: number) => ({
156
- url: buildClientRequestUrl(checkout.setDeliveryOption, {
157
- useFormData: true
158
- }),
159
- method: 'POST',
160
- body: {
161
- delivery_option: String(pk)
162
- }
163
- }),
164
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
165
- dispatch(setShippingStepBusy(true));
166
- await queryFulfilled;
167
- dispatch(setShippingStepBusy(false));
168
- }
169
- }),
170
- setAddresses: build.mutation<CheckoutResponse, SetAddressesParams>({
171
- query: ({ shippingAddressPk, billingAddressPk }) => ({
172
- url: buildClientRequestUrl(checkout.setAddresses, {
173
- useFormData: true
174
- }),
175
- method: 'POST',
176
- body: {
177
- shipping_address: String(shippingAddressPk),
178
- billing_address: String(billingAddressPk)
179
- }
180
- }),
181
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
182
- dispatch(setShippingStepBusy(true));
183
- await queryFulfilled;
184
- dispatch(setShippingStepBusy(false));
185
- }
186
- }),
187
- setShippingOption: build.mutation<CheckoutResponse, number>({
188
- query: (pk: number) => ({
189
- url: buildClientRequestUrl(checkout.setShippingOption, {
190
- useFormData: true
191
- }),
192
- method: 'POST',
193
- body: {
194
- shipping_option: String(pk)
195
- }
196
- }),
197
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
198
- dispatch(setShippingStepBusy(true));
199
- await queryFulfilled;
200
- dispatch(setShippingStepBusy(false));
201
- }
202
- }),
203
- setRetailStore: build.mutation<CheckoutResponse, SetRetailStoreParams>({
204
- query: ({ retailStorePk, billingAddressPk }) => ({
205
- url: buildClientRequestUrl(
206
- '/orders/checkout?page=RetailStoreSelectionPage',
207
- {
208
- useFormData: true
209
- }
210
- ),
211
- method: 'POST',
212
- body: {
213
- retail_store: Number(retailStorePk),
214
- billing_address: Number(billingAddressPk)
215
- }
216
- })
217
- }),
218
- setPaymentOption: build.mutation<CheckoutResponse, number>({
219
- query: (pk: number) => ({
220
- url: buildClientRequestUrl(checkout.setPaymentOption, {
221
- useFormData: true
222
- }),
223
- method: 'POST',
224
- body: {
225
- payment_option: String(pk)
226
- }
227
- }),
228
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
229
- dispatch(setPaymentStepBusy(true));
230
- dispatch(setInstallmentOptions([]));
231
- dispatch(setBankAccounts([]));
232
- await queryFulfilled;
233
- dispatch(setPaymentStepBusy(false));
234
- }
235
- }),
236
- setBinNumber: build.mutation<CheckoutResponse, string>({
237
- query: (binNumber: string) => {
238
- const paymentOption =
239
- store.getState().checkout?.preOrder?.payment_option;
240
- const binNumberUrl =
241
- paymentOption?.payment_type === 'masterpass'
242
- ? checkout.setMasterpassBinNumber
243
- : checkout.setBinNumber;
244
-
245
- return {
246
- url: buildClientRequestUrl(binNumberUrl, {
247
- useFormData: true
248
- }),
249
- method: 'POST',
250
- body: {
251
- bin_number: binNumber
252
- }
253
- };
254
- },
255
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
256
- dispatch(setPaymentStepBusy(true));
257
- await queryFulfilled;
258
- dispatch(setPaymentStepBusy(false));
259
- }
260
- }),
261
- setInstallmentOption: build.mutation<CheckoutResponse, number>({
262
- query: (pk: number) => {
263
- const paymentOption =
264
- store.getState().checkout?.preOrder?.payment_option;
265
- const installmentOption =
266
- paymentOption?.payment_type === 'masterpass'
267
- ? checkout.setMasterPassInstallmentOption
268
- : checkout.setInstallmentOption;
269
- return {
270
- url: buildClientRequestUrl(installmentOption, {
271
- useFormData: true
272
- }),
273
- method: 'POST',
274
- body: {
275
- installment: String(pk)
276
- }
277
- };
278
- },
279
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
280
- dispatch(setPaymentStepBusy(true));
281
- await queryFulfilled;
282
- dispatch(setPaymentStepBusy(false));
283
- }
284
- }),
285
- setFundsTransferOption: build.mutation<CheckoutResponse, number>({
286
- query: (pk: number) => ({
287
- url: buildClientRequestUrl(checkout.setFundsTransferOption, {
288
- useFormData: true
289
- }),
290
- method: 'POST',
291
- body: {
292
- bank_account: String(pk)
293
- }
294
- }),
295
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
296
- dispatch(setPaymentStepBusy(true));
297
- await queryFulfilled;
298
- dispatch(setPaymentStepBusy(false));
299
- dispatch(setSelectedBankAccountPk(arg));
300
- }
301
- }),
302
- completeRedirectionPayment: build.mutation<CheckoutResponse, void>({
303
- query: () => ({
304
- url: buildClientRequestUrl(checkout.completeRedirectionPayment, {
305
- useFormData: true
306
- }),
307
- method: 'POST',
308
- body: {
309
- agreement: true
310
- }
311
- }),
312
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
313
- dispatch(setPaymentStepBusy(true));
314
- await queryFulfilled;
315
- dispatch(setPaymentStepBusy(false));
316
- }
317
- }),
318
- applePaymentSelect: build.mutation<CheckoutResponse, ApplePaySelectParams>({
319
- query: ({ agreement, validationURL }) => ({
320
- url: buildClientRequestUrl(checkout.confirmationPaymentSelect, {
321
- useFormData: true
322
- }),
323
- method: 'POST',
324
- body: {
325
- agreement,
326
- validationURL
327
- }
328
- }),
329
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
330
- dispatch(setPaymentStepBusy(true));
331
- await queryFulfilled;
332
- dispatch(setPaymentStepBusy(false));
333
- }
334
- }),
335
- appleQuery: build.mutation<CheckoutResponse, ApplePayQueryParams>({
336
- query: ({ agreement, paymentToken }) => ({
337
- url: buildClientRequestUrl(checkout.confirmationQuery, {
338
- useFormData: true
339
- }),
340
- method: 'POST',
341
- body: {
342
- agreement,
343
- payment_token: paymentToken
344
- }
345
- }),
346
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
347
- dispatch(setPaymentStepBusy(true));
348
- await queryFulfilled;
349
- dispatch(setPaymentStepBusy(false));
350
- }
351
- }),
352
- completeConfirmation: build.mutation<CheckoutResponse, void>({
353
- query: () => ({
354
- url: buildClientRequestUrl(checkout.confirmationComplete, {
355
- useFormData: true
356
- }),
357
- method: 'POST',
358
- body: {
359
- agreement: true
360
- }
361
- }),
362
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
363
- dispatch(setPaymentStepBusy(true));
364
- await queryFulfilled;
365
- dispatch(setPaymentStepBusy(false));
366
- }
367
- }),
368
- setCompletePayOnDelivery: build.mutation<
369
- CheckoutResponse,
370
- PayOnDeliveryParams
371
- >({
372
- query: ({ paymentType }) => ({
373
- url: buildClientRequestUrl(
374
- `${checkout.fetchCheckout}?page=PayOnDeliveryPage`,
375
- { useFormData: true }
376
- ),
377
- method: 'POST',
378
- body: {
379
- agreement: '1',
380
- paymentType
381
- }
382
- }),
383
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
384
- dispatch(setPaymentStepBusy(true));
385
- await queryFulfilled;
386
- dispatch(setPaymentStepBusy(false));
387
- }
388
- }),
389
- setPayOnDeliveryChoice: build.mutation<CheckoutResponse, string>({
390
- query: (body) => ({
391
- url: buildClientRequestUrl(
392
- `${checkout.fetchCheckout}?page=PayOnDeliveryPaymentChoicePage`,
393
- { useFormData: true }
394
- ),
395
- method: 'POST',
396
- body: {
397
- payment_choice: body
398
- }
399
- }),
400
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
401
- dispatch(setPaymentStepBusy(true));
402
- await queryFulfilled;
403
- dispatch(setPaymentStepBusy(false));
404
- }
405
- }),
406
- completeLoyaltyPayment: build.mutation<CheckoutResponse, void>({
407
- query: () => ({
408
- url: buildClientRequestUrl(checkout.completeLoyaltyPayment, {
409
- useFormData: true
410
- }),
411
- method: 'POST',
412
- body: {
413
- agreement: true
414
- }
415
- }),
416
- async onQueryStarted(arg, { dispatch, queryFulfilled }) {
417
- dispatch(setPaymentStepBusy(true));
418
- await queryFulfilled;
419
- dispatch(setPaymentStepBusy(false));
420
- }
421
- }),
422
- getCheckoutLoyaltyBalance: build.query<CheckoutResponse, void>({
423
- query: () => ({
424
- url: buildClientRequestUrl(checkout.loyaltyMoneyUsage)
425
- })
426
- }),
427
- payWithLoyaltyBalance: build.mutation<any, string>({
428
- query: (amount) => ({
429
- url: buildClientRequestUrl(checkout.loyaltyMoneyUsage, {
430
- useFormData: true
431
- }),
432
- method: 'POST',
433
- body: {
434
- loyalty_amount_to_use: amount
435
- }
436
- })
437
- }),
438
- setOrderNote: build.mutation<CheckoutResponse, string>({
439
- query: (notes) => ({
440
- url: buildClientRequestUrl(checkout.setOrderNote, {
441
- useFormData: true
442
- }),
443
- method: 'POST',
444
- body: {
445
- notes
446
- }
447
- })
448
- })
449
- }),
450
- overrideExisting: false
451
- });
452
-
453
- export const {
454
- useFetchCheckoutQuery,
455
- useFetchCheckoutResultQuery,
456
- useGet3dRedirectFormQuery,
457
- useGetContractQuery,
458
- useCompleteCreditCardPaymentMutation,
459
- useCompleteFundsTransferMutation,
460
- useGuestLoginMutation,
461
- useSetDeliveryOptionMutation,
462
- useSetAddressesMutation,
463
- useSetShippingOptionMutation,
464
- useSetPaymentOptionMutation,
465
- useSetBinNumberMutation,
466
- useSetInstallmentOptionMutation,
467
- useSetFundsTransferOptionMutation,
468
- useSetRetailStoreMutation,
469
- useCompleteRedirectionPaymentMutation,
470
- useApplePaymentSelectMutation,
471
- useAppleQueryMutation,
472
- useCompleteConfirmationMutation,
473
- useSetCompletePayOnDeliveryMutation,
474
- useSetPayOnDeliveryChoiceMutation,
475
- useCompleteLoyaltyPaymentMutation,
476
- useGetCheckoutLoyaltyBalanceQuery,
477
- usePayWithLoyaltyBalanceMutation,
478
- useSetOrderNoteMutation
479
- } = checkoutApi;
1
+ import {
2
+ setBankAccounts,
3
+ setInstallmentOptions,
4
+ setPaymentStepBusy,
5
+ setSelectedBankAccountPk,
6
+ setSelectedCreditPaymentPk,
7
+ setShippingStepBusy
8
+ } from '../../redux/reducers/checkout';
9
+ import {
10
+ CheckoutContext,
11
+ GuestLoginFormParams,
12
+ Order,
13
+ PreOrder
14
+ } from '../../types';
15
+ import { buildClientRequestUrl } from '../../utils';
16
+ import { api } from './api';
17
+ import { checkout } from '../urls';
18
+ import { store } from 'redux/store';
19
+
20
+ interface CheckoutResponse {
21
+ pre_order?: PreOrder;
22
+ errors: {
23
+ non_field_errors: string;
24
+ };
25
+ context_list?: CheckoutContext[];
26
+ template_name?: string;
27
+ redirect_url?: string;
28
+ }
29
+
30
+ interface SetAddressesParams {
31
+ shippingAddressPk: number;
32
+ billingAddressPk: number;
33
+ }
34
+
35
+ interface SetRetailStoreParams {
36
+ retailStorePk: number;
37
+ billingAddressPk: number;
38
+ }
39
+
40
+ interface CompleteCreditCardParams {
41
+ card_holder: string;
42
+ card_cvv: string;
43
+ card_number: string;
44
+ card_month: string;
45
+ card_year: string;
46
+ use_three_d?: boolean;
47
+ }
48
+
49
+ interface GetContractResponse {
50
+ result: string;
51
+ }
52
+
53
+ interface ApplePaySelectParams {
54
+ agreement: boolean;
55
+ validationURL: string;
56
+ }
57
+
58
+ interface ApplePayQueryParams {
59
+ agreement: boolean;
60
+ paymentToken: string;
61
+ }
62
+
63
+ export interface PayOnDeliveryParams {
64
+ agreement: string;
65
+ paymentType: string;
66
+ }
67
+
68
+ export const checkoutApi = api.injectEndpoints({
69
+ endpoints: (build) => ({
70
+ fetchCheckout: build.query<CheckoutResponse, void>({
71
+ query: () => ({
72
+ url: buildClientRequestUrl(checkout.fetchCheckout, {})
73
+ }),
74
+ providesTags: ['Checkout']
75
+ }),
76
+ fetchCheckoutResult: build.query<{ order: Order }, string>({
77
+ query: (token: string) =>
78
+ buildClientRequestUrl(checkout.fetchCheckoutResult(token))
79
+ }),
80
+ get3dRedirectForm: build.query<{ result: string }, void>({
81
+ query: () =>
82
+ buildClientRequestUrl(checkout.get3dRedirectForm, {
83
+ responseType: 'text'
84
+ })
85
+ }),
86
+ getContract: build.query<GetContractResponse, string>({
87
+ query: (slug: string) =>
88
+ buildClientRequestUrl(checkout.getContract(slug), {
89
+ responseType: 'text'
90
+ })
91
+ }),
92
+ completeCreditCardPayment: build.mutation<
93
+ CheckoutResponse,
94
+ CompleteCreditCardParams
95
+ >({
96
+ query: ({
97
+ card_holder,
98
+ card_cvv,
99
+ card_number,
100
+ card_month,
101
+ card_year,
102
+ use_three_d = true
103
+ }) => ({
104
+ url: buildClientRequestUrl(checkout.completeCreditCardPayment, {
105
+ useFormData: true
106
+ }),
107
+ method: 'POST',
108
+ body: {
109
+ agreement: '1',
110
+ use_three_d: use_three_d ? '1' : '0',
111
+ card_cvv,
112
+ card_holder,
113
+ card_month,
114
+ card_number,
115
+ card_year
116
+ }
117
+ }),
118
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
119
+ dispatch(setPaymentStepBusy(true));
120
+ await queryFulfilled;
121
+ dispatch(setPaymentStepBusy(false));
122
+ },
123
+ invalidatesTags: ['Basket']
124
+ }),
125
+ completeFundsTransfer: build.mutation<CheckoutResponse, void>({
126
+ query: () => ({
127
+ url: buildClientRequestUrl(checkout.completeFundsTransfer, {
128
+ useFormData: true
129
+ }),
130
+ method: 'POST',
131
+ body: {
132
+ agreement: '1'
133
+ }
134
+ }),
135
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
136
+ dispatch(setPaymentStepBusy(true));
137
+ await queryFulfilled;
138
+ dispatch(setPaymentStepBusy(false));
139
+ },
140
+ invalidatesTags: ['Basket']
141
+ }),
142
+ guestLogin: build.mutation<CheckoutResponse, GuestLoginFormParams>({
143
+ query: ({ user_email, phone_number }) => ({
144
+ url: buildClientRequestUrl(checkout.guestLogin, {
145
+ useFormData: true
146
+ }),
147
+ method: 'POST',
148
+ body: {
149
+ user_email,
150
+ phone_number
151
+ }
152
+ }),
153
+ invalidatesTags: ['Checkout']
154
+ }),
155
+ setDeliveryOption: build.mutation<CheckoutResponse, number>({
156
+ query: (pk: number) => ({
157
+ url: buildClientRequestUrl(checkout.setDeliveryOption, {
158
+ useFormData: true
159
+ }),
160
+ method: 'POST',
161
+ body: {
162
+ delivery_option: String(pk)
163
+ }
164
+ }),
165
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
166
+ dispatch(setShippingStepBusy(true));
167
+ await queryFulfilled;
168
+ dispatch(setShippingStepBusy(false));
169
+ }
170
+ }),
171
+ setAddresses: build.mutation<CheckoutResponse, SetAddressesParams>({
172
+ query: ({ shippingAddressPk, billingAddressPk }) => ({
173
+ url: buildClientRequestUrl(checkout.setAddresses, {
174
+ useFormData: true
175
+ }),
176
+ method: 'POST',
177
+ body: {
178
+ shipping_address: String(shippingAddressPk),
179
+ billing_address: String(billingAddressPk)
180
+ }
181
+ }),
182
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
183
+ dispatch(setShippingStepBusy(true));
184
+ await queryFulfilled;
185
+ dispatch(setShippingStepBusy(false));
186
+ }
187
+ }),
188
+ setShippingOption: build.mutation<CheckoutResponse, number>({
189
+ query: (pk: number) => ({
190
+ url: buildClientRequestUrl(checkout.setShippingOption, {
191
+ useFormData: true
192
+ }),
193
+ method: 'POST',
194
+ body: {
195
+ shipping_option: String(pk)
196
+ }
197
+ }),
198
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
199
+ dispatch(setShippingStepBusy(true));
200
+ await queryFulfilled;
201
+ dispatch(setShippingStepBusy(false));
202
+ }
203
+ }),
204
+ setRetailStore: build.mutation<CheckoutResponse, SetRetailStoreParams>({
205
+ query: ({ retailStorePk, billingAddressPk }) => ({
206
+ url: buildClientRequestUrl(
207
+ '/orders/checkout?page=RetailStoreSelectionPage',
208
+ {
209
+ useFormData: true
210
+ }
211
+ ),
212
+ method: 'POST',
213
+ body: {
214
+ retail_store: Number(retailStorePk),
215
+ billing_address: Number(billingAddressPk)
216
+ }
217
+ })
218
+ }),
219
+ setPaymentOption: build.mutation<CheckoutResponse, number>({
220
+ query: (pk: number) => ({
221
+ url: buildClientRequestUrl(checkout.setPaymentOption, {
222
+ useFormData: true
223
+ }),
224
+ method: 'POST',
225
+ body: {
226
+ payment_option: String(pk)
227
+ }
228
+ }),
229
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
230
+ dispatch(setPaymentStepBusy(true));
231
+ dispatch(setInstallmentOptions([]));
232
+ dispatch(setBankAccounts([]));
233
+ dispatch(setSelectedBankAccountPk(null));
234
+ await queryFulfilled;
235
+ dispatch(setPaymentStepBusy(false));
236
+ }
237
+ }),
238
+ setBinNumber: build.mutation<CheckoutResponse, string>({
239
+ query: (binNumber: string) => {
240
+ const paymentOption =
241
+ store.getState().checkout?.preOrder?.payment_option;
242
+ const binNumberUrl =
243
+ paymentOption?.payment_type === 'masterpass'
244
+ ? checkout.setMasterpassBinNumber
245
+ : checkout.setBinNumber;
246
+
247
+ return {
248
+ url: buildClientRequestUrl(binNumberUrl, {
249
+ useFormData: true
250
+ }),
251
+ method: 'POST',
252
+ body: {
253
+ bin_number: binNumber
254
+ }
255
+ };
256
+ },
257
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
258
+ dispatch(setPaymentStepBusy(true));
259
+ await queryFulfilled;
260
+ dispatch(setPaymentStepBusy(false));
261
+ }
262
+ }),
263
+ setInstallmentOption: build.mutation<CheckoutResponse, number>({
264
+ query: (pk: number) => {
265
+ const paymentOption =
266
+ store.getState().checkout?.preOrder?.payment_option;
267
+ const installmentOption =
268
+ paymentOption?.payment_type === 'masterpass'
269
+ ? checkout.setMasterPassInstallmentOption
270
+ : checkout.setInstallmentOption;
271
+ return {
272
+ url: buildClientRequestUrl(installmentOption, {
273
+ useFormData: true
274
+ }),
275
+ method: 'POST',
276
+ body: {
277
+ installment: String(pk)
278
+ }
279
+ };
280
+ },
281
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
282
+ dispatch(setPaymentStepBusy(true));
283
+ await queryFulfilled;
284
+ dispatch(setPaymentStepBusy(false));
285
+ }
286
+ }),
287
+ setFundsTransferOption: build.mutation<CheckoutResponse, number>({
288
+ query: (pk: number) => ({
289
+ url: buildClientRequestUrl(checkout.setFundsTransferOption, {
290
+ useFormData: true
291
+ }),
292
+ method: 'POST',
293
+ body: {
294
+ bank_account: String(pk)
295
+ }
296
+ }),
297
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
298
+ dispatch(setPaymentStepBusy(true));
299
+ await queryFulfilled;
300
+ dispatch(setPaymentStepBusy(false));
301
+ dispatch(setSelectedBankAccountPk(arg));
302
+ }
303
+ }),
304
+ setCreditPaymentOption: build.mutation<CheckoutResponse, number>({
305
+ query: (pk: number) => ({
306
+ url: buildClientRequestUrl(checkout.setCreditPaymentOption, {
307
+ useFormData: true
308
+ }),
309
+ method: 'POST',
310
+ body: {
311
+ credit_payment_option: pk
312
+ }
313
+ }),
314
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
315
+ dispatch(setPaymentStepBusy(true));
316
+ await queryFulfilled;
317
+ dispatch(setPaymentStepBusy(false));
318
+ dispatch(setSelectedCreditPaymentPk(arg));
319
+ }
320
+ }),
321
+ confirmationCreditPayment: build.mutation<CheckoutResponse, void>({
322
+ query: () => ({
323
+ url: buildClientRequestUrl(checkout.confirmationCreditPayment, {
324
+ useFormData: true
325
+ }),
326
+ method: 'POST',
327
+ body: {
328
+ agreement: true,
329
+ }
330
+ }),
331
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
332
+ dispatch(setPaymentStepBusy(true));
333
+ await queryFulfilled;
334
+ dispatch(setPaymentStepBusy(false));
335
+ }
336
+ }),
337
+ completeRedirectionPayment: build.mutation<CheckoutResponse, void>({
338
+ query: () => ({
339
+ url: buildClientRequestUrl(checkout.completeRedirectionPayment, {
340
+ useFormData: true
341
+ }),
342
+ method: 'POST',
343
+ body: {
344
+ agreement: true
345
+ }
346
+ }),
347
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
348
+ dispatch(setPaymentStepBusy(true));
349
+ await queryFulfilled;
350
+ dispatch(setPaymentStepBusy(false));
351
+ }
352
+ }),
353
+ applePaymentSelect: build.mutation<CheckoutResponse, ApplePaySelectParams>({
354
+ query: ({ agreement, validationURL }) => ({
355
+ url: buildClientRequestUrl(checkout.confirmationPaymentSelect, {
356
+ useFormData: true
357
+ }),
358
+ method: 'POST',
359
+ body: {
360
+ agreement,
361
+ validationURL
362
+ }
363
+ }),
364
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
365
+ dispatch(setPaymentStepBusy(true));
366
+ await queryFulfilled;
367
+ dispatch(setPaymentStepBusy(false));
368
+ }
369
+ }),
370
+ appleQuery: build.mutation<CheckoutResponse, ApplePayQueryParams>({
371
+ query: ({ agreement, paymentToken }) => ({
372
+ url: buildClientRequestUrl(checkout.confirmationQuery, {
373
+ useFormData: true
374
+ }),
375
+ method: 'POST',
376
+ body: {
377
+ agreement,
378
+ payment_token: paymentToken
379
+ }
380
+ }),
381
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
382
+ dispatch(setPaymentStepBusy(true));
383
+ await queryFulfilled;
384
+ dispatch(setPaymentStepBusy(false));
385
+ }
386
+ }),
387
+ completeConfirmation: build.mutation<CheckoutResponse, void>({
388
+ query: () => ({
389
+ url: buildClientRequestUrl(checkout.confirmationComplete, {
390
+ useFormData: true
391
+ }),
392
+ method: 'POST',
393
+ body: {
394
+ agreement: true
395
+ }
396
+ }),
397
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
398
+ dispatch(setPaymentStepBusy(true));
399
+ await queryFulfilled;
400
+ dispatch(setPaymentStepBusy(false));
401
+ }
402
+ }),
403
+ setCompletePayOnDelivery: build.mutation<
404
+ CheckoutResponse,
405
+ PayOnDeliveryParams
406
+ >({
407
+ query: ({ paymentType }) => ({
408
+ url: buildClientRequestUrl(
409
+ `${checkout.fetchCheckout}?page=PayOnDeliveryPage`,
410
+ { useFormData: true }
411
+ ),
412
+ method: 'POST',
413
+ body: {
414
+ agreement: '1',
415
+ paymentType
416
+ }
417
+ }),
418
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
419
+ dispatch(setPaymentStepBusy(true));
420
+ await queryFulfilled;
421
+ dispatch(setPaymentStepBusy(false));
422
+ }
423
+ }),
424
+ setPayOnDeliveryChoice: build.mutation<CheckoutResponse, string>({
425
+ query: (body) => ({
426
+ url: buildClientRequestUrl(
427
+ `${checkout.fetchCheckout}?page=PayOnDeliveryPaymentChoicePage`,
428
+ { useFormData: true }
429
+ ),
430
+ method: 'POST',
431
+ body: {
432
+ payment_choice: body
433
+ }
434
+ }),
435
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
436
+ dispatch(setPaymentStepBusy(true));
437
+ await queryFulfilled;
438
+ dispatch(setPaymentStepBusy(false));
439
+ }
440
+ }),
441
+ completeLoyaltyPayment: build.mutation<CheckoutResponse, void>({
442
+ query: () => ({
443
+ url: buildClientRequestUrl(checkout.completeLoyaltyPayment, {
444
+ useFormData: true
445
+ }),
446
+ method: 'POST',
447
+ body: {
448
+ agreement: true
449
+ }
450
+ }),
451
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
452
+ dispatch(setPaymentStepBusy(true));
453
+ await queryFulfilled;
454
+ dispatch(setPaymentStepBusy(false));
455
+ }
456
+ }),
457
+ getCheckoutLoyaltyBalance: build.query<CheckoutResponse, void>({
458
+ query: () => ({
459
+ url: buildClientRequestUrl(checkout.loyaltyMoneyUsage)
460
+ })
461
+ }),
462
+ payWithLoyaltyBalance: build.mutation<any, string>({
463
+ query: (amount) => ({
464
+ url: buildClientRequestUrl(checkout.loyaltyMoneyUsage, {
465
+ useFormData: true
466
+ }),
467
+ method: 'POST',
468
+ body: {
469
+ loyalty_amount_to_use: amount
470
+ }
471
+ })
472
+ }),
473
+ setOrderNote: build.mutation<CheckoutResponse, string>({
474
+ query: (notes) => ({
475
+ url: buildClientRequestUrl(checkout.setOrderNote, {
476
+ useFormData: true
477
+ }),
478
+ method: 'POST',
479
+ body: {
480
+ notes
481
+ }
482
+ })
483
+ })
484
+ }),
485
+ overrideExisting: false
486
+ });
487
+
488
+ export const {
489
+ useFetchCheckoutQuery,
490
+ useFetchCheckoutResultQuery,
491
+ useGet3dRedirectFormQuery,
492
+ useGetContractQuery,
493
+ useCompleteCreditCardPaymentMutation,
494
+ useCompleteFundsTransferMutation,
495
+ useGuestLoginMutation,
496
+ useSetDeliveryOptionMutation,
497
+ useSetAddressesMutation,
498
+ useSetShippingOptionMutation,
499
+ useSetPaymentOptionMutation,
500
+ useSetBinNumberMutation,
501
+ useSetInstallmentOptionMutation,
502
+ useSetFundsTransferOptionMutation,
503
+ useSetRetailStoreMutation,
504
+ useSetCreditPaymentOptionMutation,
505
+ useConfirmationCreditPaymentMutation,
506
+ useCompleteRedirectionPaymentMutation,
507
+ useApplePaymentSelectMutation,
508
+ useAppleQueryMutation,
509
+ useCompleteConfirmationMutation,
510
+ useSetCompletePayOnDeliveryMutation,
511
+ useSetPayOnDeliveryChoiceMutation,
512
+ useCompleteLoyaltyPaymentMutation,
513
+ useGetCheckoutLoyaltyBalanceQuery,
514
+ usePayWithLoyaltyBalanceMutation,
515
+ useSetOrderNoteMutation
516
+ } = checkoutApi;