@akinon/next 1.0.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/.prettierrc +13 -0
- package/api/auth.ts +217 -0
- package/api/cache.ts +44 -0
- package/api/client.ts +157 -0
- package/api/logout.ts +42 -0
- package/assets/styles/index.scss +24 -0
- package/bin/pz-install-plugins.js +33 -0
- package/components/client-root.tsx +69 -0
- package/components/image.tsx +133 -0
- package/components/mobile-app-toggler.tsx +15 -0
- package/components/oauth-login.tsx +24 -0
- package/components/plugin-module.tsx +78 -0
- package/components/pz-providers.tsx +24 -0
- package/components/pz-root.tsx +21 -0
- package/components/redirect-three-d/content/index.tsx +64 -0
- package/components/redirect-three-d/index.tsx +17 -0
- package/components/selected-payment-option-view.tsx +66 -0
- package/components/trans.tsx +39 -0
- package/data/client/account.ts +188 -0
- package/data/client/address.ts +107 -0
- package/data/client/api.ts +42 -0
- package/data/client/basket.ts +85 -0
- package/data/client/checkout.ts +477 -0
- package/data/client/misc.ts +101 -0
- package/data/client/product.ts +90 -0
- package/data/client/user.ts +83 -0
- package/data/client/wishlist.ts +79 -0
- package/data/server/category.ts +121 -0
- package/data/server/flatpage.ts +21 -0
- package/data/server/index.ts +8 -0
- package/data/server/list.ts +56 -0
- package/data/server/menu.ts +35 -0
- package/data/server/product.ts +86 -0
- package/data/server/seo.ts +48 -0
- package/data/server/special-page.ts +42 -0
- package/data/server/widget.ts +27 -0
- package/data/urls.ts +184 -0
- package/hocs/client/index.ts +1 -0
- package/hocs/client/with-segment-defaults.tsx +26 -0
- package/hocs/server/index.ts +1 -0
- package/hocs/server/with-segment-defaults.tsx +83 -0
- package/hooks/index.ts +8 -0
- package/hooks/use-captcha.tsx +76 -0
- package/hooks/use-common-product-attributes.ts +36 -0
- package/hooks/use-debounce.ts +20 -0
- package/hooks/use-localization.ts +63 -0
- package/hooks/use-media-query.ts +36 -0
- package/hooks/use-on-click-outside.tsx +28 -0
- package/hooks/use-router.ts +45 -0
- package/hooks/use-translation.ts +14 -0
- package/lib/cache.ts +185 -0
- package/localization/index.ts +5 -0
- package/localization/provider.tsx +58 -0
- package/middlewares/currency.ts +55 -0
- package/middlewares/default.ts +224 -0
- package/middlewares/index.ts +29 -0
- package/middlewares/locale.ts +61 -0
- package/middlewares/oauth-login.ts +78 -0
- package/middlewares/pretty-url.ts +94 -0
- package/middlewares/redirection-payment.ts +117 -0
- package/middlewares/three-d-redirection.ts +122 -0
- package/middlewares/url-redirection.ts +61 -0
- package/package.json +20 -0
- package/plugins.js +7 -0
- package/redux/hooks.ts +7 -0
- package/redux/middlewares/checkout.ts +231 -0
- package/redux/middlewares/index.ts +50 -0
- package/redux/reducers/checkout.ts +164 -0
- package/redux/reducers/config.ts +28 -0
- package/redux/reducers/header.ts +59 -0
- package/redux/reducers/index.ts +15 -0
- package/redux/reducers/root.ts +61 -0
- package/tailwind/rtl.js +137 -0
- package/types/commerce/account.ts +68 -0
- package/types/commerce/address.ts +94 -0
- package/types/commerce/basket.ts +43 -0
- package/types/commerce/category.ts +114 -0
- package/types/commerce/checkout.ts +132 -0
- package/types/commerce/flatpage.ts +7 -0
- package/types/commerce/index.ts +10 -0
- package/types/commerce/misc.ts +127 -0
- package/types/commerce/order.ts +108 -0
- package/types/commerce/product.ts +110 -0
- package/types/commerce/widget.ts +28 -0
- package/types/gtm.ts +16 -0
- package/types/index.ts +207 -0
- package/types/next-auth.d.ts +24 -0
- package/utils/app-fetch.ts +62 -0
- package/utils/generate-commerce-search-params.ts +22 -0
- package/utils/get-currency.ts +29 -0
- package/utils/image-loader.ts +31 -0
- package/utils/index.ts +132 -0
- package/utils/localization.ts +29 -0
- package/utils/log.ts +138 -0
- package/utils/menu-generator.ts +27 -0
- package/utils/mobile-3d-iframe.ts +58 -0
- package/utils/server-translation.ts +57 -0
- package/utils/server-variables.ts +9 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { buildClientRequestUrl } from '../../utils';
|
|
2
|
+
import { api } from './api';
|
|
3
|
+
import { address, misc } from '../urls';
|
|
4
|
+
import { Address, City, Country, District, Township } from '../../types';
|
|
5
|
+
|
|
6
|
+
interface GetResponse<T> {
|
|
7
|
+
count: number;
|
|
8
|
+
next: null;
|
|
9
|
+
previous: null;
|
|
10
|
+
results: T[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const addressApi = api.injectEndpoints({
|
|
14
|
+
endpoints: (builder) => ({
|
|
15
|
+
getAddresses: builder.query<GetResponse<Address>, void>({
|
|
16
|
+
query: () => buildClientRequestUrl(address.getAddresses),
|
|
17
|
+
providesTags: ['Addresses']
|
|
18
|
+
}),
|
|
19
|
+
getCountries: builder.query<GetResponse<Country>, void>({
|
|
20
|
+
query: () => buildClientRequestUrl(address.countries)
|
|
21
|
+
}),
|
|
22
|
+
getCities: builder.query<GetResponse<City>, string>({
|
|
23
|
+
query: (country) => buildClientRequestUrl(address.getCities(country))
|
|
24
|
+
}),
|
|
25
|
+
getTownships: builder.query<GetResponse<Township>, string>({
|
|
26
|
+
query: (city) => buildClientRequestUrl(address.getTownships(city))
|
|
27
|
+
}),
|
|
28
|
+
getDistricts: builder.query<GetResponse<District>, string>({
|
|
29
|
+
query: (township) => buildClientRequestUrl(address.getDistricts(township))
|
|
30
|
+
}),
|
|
31
|
+
getRetailStore: builder.query<GetResponse<any>, void>({
|
|
32
|
+
query: () => buildClientRequestUrl(address.getRetailStore)
|
|
33
|
+
}),
|
|
34
|
+
getRetailStoreCities: builder.query<GetResponse<any>, string>({
|
|
35
|
+
query: (country) => buildClientRequestUrl(address.getRetailStoreCities(country))
|
|
36
|
+
}),
|
|
37
|
+
getRetailStoreTownships: builder.query<GetResponse<any>, string>({
|
|
38
|
+
query: (city) => buildClientRequestUrl(address.getRetailStoreTownships(city))
|
|
39
|
+
}),
|
|
40
|
+
addAddress: builder.mutation<Address, Partial<Address>>({
|
|
41
|
+
query: (body) => ({
|
|
42
|
+
url: buildClientRequestUrl(address.base, {
|
|
43
|
+
contentType: 'application/json'
|
|
44
|
+
}),
|
|
45
|
+
method: 'POST',
|
|
46
|
+
body: {
|
|
47
|
+
...body,
|
|
48
|
+
type: body.is_corporate === 'true' ? 'corporate' : 'personal'
|
|
49
|
+
}
|
|
50
|
+
}),
|
|
51
|
+
invalidatesTags: ['Addresses', 'Checkout'] // TODO: Invalidate one of these tags when necessary (e.g. Address page invalidates Addresses tag, Checkout page invalidates Checkout tag)
|
|
52
|
+
}),
|
|
53
|
+
editAddress: builder.mutation<Address, Partial<Address>>({
|
|
54
|
+
query: ({ pk, ...body }) => ({
|
|
55
|
+
url: buildClientRequestUrl(address.editAddress(pk), {
|
|
56
|
+
contentType: 'application/json'
|
|
57
|
+
}),
|
|
58
|
+
method: 'PATCH',
|
|
59
|
+
body: {
|
|
60
|
+
...body,
|
|
61
|
+
user: body.user?.pk,
|
|
62
|
+
type: body.is_corporate === 'true' ? 'corporate' : 'personal'
|
|
63
|
+
}
|
|
64
|
+
}),
|
|
65
|
+
invalidatesTags: ['Addresses', 'Checkout'] // TODO: Invalidate one of these tags when necessary (e.g. Address page invalidates Addresses tag, Checkout page invalidates Checkout tag)
|
|
66
|
+
}),
|
|
67
|
+
removeAddress: builder.mutation<void, number>({
|
|
68
|
+
query: (id) => ({
|
|
69
|
+
url: buildClientRequestUrl(address.removeAddress(id)),
|
|
70
|
+
method: 'DELETE'
|
|
71
|
+
}),
|
|
72
|
+
invalidatesTags: ['Addresses', 'Checkout'] // TODO: Invalidate one of these tags when necessary (e.g. Address page invalidates Addresses tag, Checkout page invalidates Checkout tag)
|
|
73
|
+
}),
|
|
74
|
+
setDefaultAddress: builder.mutation<Address, Partial<Address>>({
|
|
75
|
+
query: ({ pk, primary }) => ({
|
|
76
|
+
url: buildClientRequestUrl(address.setDefaultAddress(pk), {
|
|
77
|
+
contentType: 'application/json'
|
|
78
|
+
}),
|
|
79
|
+
method: 'PATCH',
|
|
80
|
+
body: { primary }
|
|
81
|
+
}),
|
|
82
|
+
invalidatesTags: ['Addresses']
|
|
83
|
+
}),
|
|
84
|
+
getStores: builder.query<GetResponse<Address>, void>({
|
|
85
|
+
query: () => ({
|
|
86
|
+
url: buildClientRequestUrl(misc.stores)
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
}),
|
|
90
|
+
overrideExisting: true
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
export const {
|
|
94
|
+
useGetAddressesQuery,
|
|
95
|
+
useGetCountriesQuery,
|
|
96
|
+
useGetCitiesQuery,
|
|
97
|
+
useGetTownshipsQuery,
|
|
98
|
+
useGetDistrictsQuery,
|
|
99
|
+
useGetRetailStoreQuery,
|
|
100
|
+
useGetRetailStoreCitiesQuery,
|
|
101
|
+
useGetRetailStoreTownshipsQuery,
|
|
102
|
+
useAddAddressMutation,
|
|
103
|
+
useEditAddressMutation,
|
|
104
|
+
useRemoveAddressMutation,
|
|
105
|
+
useSetDefaultAddressMutation,
|
|
106
|
+
useGetStoresQuery
|
|
107
|
+
} = addressApi;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createApi, fetchBaseQuery, retry } from '@reduxjs/toolkit/query/react';
|
|
2
|
+
import settings from 'settings';
|
|
3
|
+
import { getCookie } from '../../utils';
|
|
4
|
+
|
|
5
|
+
export const api = createApi({
|
|
6
|
+
reducerPath: 'api',
|
|
7
|
+
baseQuery: retry(fetchBaseQuery({
|
|
8
|
+
prepareHeaders: async (headers) => {
|
|
9
|
+
const csrfCookie = getCookie('csrftoken');
|
|
10
|
+
const activeLocale = getCookie('pz-locale');
|
|
11
|
+
const localeApiValue = settings.localization.locales.find(
|
|
12
|
+
(locale) => locale.value === activeLocale
|
|
13
|
+
)?.apiValue;
|
|
14
|
+
const activeCurrency = getCookie('pz-currency');
|
|
15
|
+
|
|
16
|
+
headers.set('Accept-Language', `${localeApiValue}`);
|
|
17
|
+
headers.set('x-currency', `${activeCurrency}`);
|
|
18
|
+
|
|
19
|
+
if (csrfCookie) {
|
|
20
|
+
headers.set('x-csrftoken', `${csrfCookie}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return headers;
|
|
24
|
+
},
|
|
25
|
+
credentials: 'include'
|
|
26
|
+
}), {
|
|
27
|
+
maxRetries: 3
|
|
28
|
+
}),
|
|
29
|
+
tagTypes: [
|
|
30
|
+
'Basket',
|
|
31
|
+
'Product',
|
|
32
|
+
'Checkout',
|
|
33
|
+
'Favorite',
|
|
34
|
+
'Addresses',
|
|
35
|
+
'Profile'
|
|
36
|
+
],
|
|
37
|
+
endpoints: () => ({}) // it must be a function to be able to use `injectEndpoints`
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const {
|
|
41
|
+
util: { invalidateTags }
|
|
42
|
+
} = api;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { api } from './api';
|
|
2
|
+
import { Basket } from '../../types';
|
|
3
|
+
import { buildClientRequestUrl } from '../../utils';
|
|
4
|
+
import { basket } from '../urls';
|
|
5
|
+
|
|
6
|
+
export type UpdateQuantityResponse = {
|
|
7
|
+
basket: Basket;
|
|
8
|
+
osessionid: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type UpdateQuantityRequest = {
|
|
12
|
+
product: number;
|
|
13
|
+
quantity: number;
|
|
14
|
+
attributes: any;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const basketApi = api.injectEndpoints({
|
|
18
|
+
endpoints: (build) => ({
|
|
19
|
+
getBasket: build.query<Basket, void>({
|
|
20
|
+
query: () =>
|
|
21
|
+
buildClientRequestUrl(basket.getBasket, {
|
|
22
|
+
contentType: 'application/json'
|
|
23
|
+
}),
|
|
24
|
+
transformResponse: (response: { basket: Basket }) => response.basket,
|
|
25
|
+
providesTags: ['Basket']
|
|
26
|
+
}),
|
|
27
|
+
updateQuantity: build.mutation<
|
|
28
|
+
UpdateQuantityResponse,
|
|
29
|
+
UpdateQuantityRequest
|
|
30
|
+
>({
|
|
31
|
+
query: (body) => ({
|
|
32
|
+
url: buildClientRequestUrl(basket.getBasket, {
|
|
33
|
+
contentType: 'application/json'
|
|
34
|
+
}),
|
|
35
|
+
method: 'PUT',
|
|
36
|
+
body
|
|
37
|
+
})
|
|
38
|
+
}),
|
|
39
|
+
clearBasket: build.mutation<Basket, void>({
|
|
40
|
+
query: (body) => ({
|
|
41
|
+
url: buildClientRequestUrl(basket.getBasket, {
|
|
42
|
+
useTrailingSlash: false,
|
|
43
|
+
contentType: 'application/json'
|
|
44
|
+
}),
|
|
45
|
+
method: 'DELETE',
|
|
46
|
+
body
|
|
47
|
+
}),
|
|
48
|
+
transformResponse: (response: { basket: Basket }) => response.basket,
|
|
49
|
+
invalidatesTags: ['Basket']
|
|
50
|
+
}),
|
|
51
|
+
applyVoucherCode: build.mutation<Basket, { voucher_code: string }>({
|
|
52
|
+
query: (body) => ({
|
|
53
|
+
url: buildClientRequestUrl(basket.getBasket, {
|
|
54
|
+
useTrailingSlash: false,
|
|
55
|
+
contentType: 'application/json'
|
|
56
|
+
}),
|
|
57
|
+
method: 'PATCH',
|
|
58
|
+
body
|
|
59
|
+
}),
|
|
60
|
+
transformResponse: (response: { basket: Basket }) => response.basket
|
|
61
|
+
}),
|
|
62
|
+
removeVoucherCode: build.mutation<Basket, void>({
|
|
63
|
+
query: () => ({
|
|
64
|
+
url: buildClientRequestUrl(basket.getBasket, {
|
|
65
|
+
useTrailingSlash: false,
|
|
66
|
+
contentType: 'application/json'
|
|
67
|
+
}),
|
|
68
|
+
method: 'PATCH',
|
|
69
|
+
body: {
|
|
70
|
+
remove_voucher_code: true
|
|
71
|
+
}
|
|
72
|
+
}),
|
|
73
|
+
transformResponse: (response: { basket: Basket }) => response.basket
|
|
74
|
+
})
|
|
75
|
+
}),
|
|
76
|
+
overrideExisting: true
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export const {
|
|
80
|
+
useGetBasketQuery,
|
|
81
|
+
useUpdateQuantityMutation,
|
|
82
|
+
useClearBasketMutation,
|
|
83
|
+
useApplyVoucherCodeMutation,
|
|
84
|
+
useRemoveVoucherCodeMutation
|
|
85
|
+
} = basketApi;
|
|
@@ -0,0 +1,477 @@
|
|
|
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
|
+
}
|
|
46
|
+
|
|
47
|
+
interface GetContractResponse {
|
|
48
|
+
result: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface ApplePaySelectParams {
|
|
52
|
+
agreement: boolean;
|
|
53
|
+
validationURL: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface ApplePayQueryParams {
|
|
57
|
+
agreement: boolean;
|
|
58
|
+
paymentToken: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface PayOnDeliveryParams {
|
|
62
|
+
agreement: string;
|
|
63
|
+
paymentType: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const checkoutApi = api.injectEndpoints({
|
|
67
|
+
endpoints: (build) => ({
|
|
68
|
+
fetchCheckout: build.query<CheckoutResponse, void>({
|
|
69
|
+
query: () => ({
|
|
70
|
+
url: buildClientRequestUrl(checkout.fetchCheckout, {})
|
|
71
|
+
}),
|
|
72
|
+
providesTags: ['Checkout']
|
|
73
|
+
}),
|
|
74
|
+
fetchCheckoutResult: build.query<{ order: Order }, string>({
|
|
75
|
+
query: (token: string) =>
|
|
76
|
+
buildClientRequestUrl(checkout.fetchCheckoutResult(token))
|
|
77
|
+
}),
|
|
78
|
+
get3dRedirectForm: build.query<{ result: string }, void>({
|
|
79
|
+
query: () =>
|
|
80
|
+
buildClientRequestUrl(checkout.get3dRedirectForm, {
|
|
81
|
+
responseType: 'text'
|
|
82
|
+
})
|
|
83
|
+
}),
|
|
84
|
+
getContract: build.query<GetContractResponse, string>({
|
|
85
|
+
query: (slug: string) =>
|
|
86
|
+
buildClientRequestUrl(checkout.getContract(slug), {
|
|
87
|
+
responseType: 'text'
|
|
88
|
+
})
|
|
89
|
+
}),
|
|
90
|
+
completeCreditCardPayment: build.mutation<
|
|
91
|
+
CheckoutResponse,
|
|
92
|
+
CompleteCreditCardParams
|
|
93
|
+
>({
|
|
94
|
+
query: ({
|
|
95
|
+
card_holder,
|
|
96
|
+
card_cvv,
|
|
97
|
+
card_number,
|
|
98
|
+
card_month,
|
|
99
|
+
card_year
|
|
100
|
+
}) => ({
|
|
101
|
+
url: buildClientRequestUrl(checkout.completeCreditCardPayment, {
|
|
102
|
+
useFormData: true
|
|
103
|
+
}),
|
|
104
|
+
method: 'POST',
|
|
105
|
+
body: {
|
|
106
|
+
agreement: '1',
|
|
107
|
+
use_three_d: '1',
|
|
108
|
+
card_cvv,
|
|
109
|
+
card_holder,
|
|
110
|
+
card_month,
|
|
111
|
+
card_number,
|
|
112
|
+
card_year
|
|
113
|
+
}
|
|
114
|
+
}),
|
|
115
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
116
|
+
dispatch(setPaymentStepBusy(true));
|
|
117
|
+
await queryFulfilled;
|
|
118
|
+
dispatch(setPaymentStepBusy(false));
|
|
119
|
+
},
|
|
120
|
+
invalidatesTags: ['Basket']
|
|
121
|
+
}),
|
|
122
|
+
completeFundsTransfer: build.mutation<CheckoutResponse, void>({
|
|
123
|
+
query: () => ({
|
|
124
|
+
url: buildClientRequestUrl(checkout.completeFundsTransfer, {
|
|
125
|
+
useFormData: true
|
|
126
|
+
}),
|
|
127
|
+
method: 'POST',
|
|
128
|
+
body: {
|
|
129
|
+
agreement: '1'
|
|
130
|
+
}
|
|
131
|
+
}),
|
|
132
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
133
|
+
dispatch(setPaymentStepBusy(true));
|
|
134
|
+
await queryFulfilled;
|
|
135
|
+
dispatch(setPaymentStepBusy(false));
|
|
136
|
+
},
|
|
137
|
+
invalidatesTags: ['Basket']
|
|
138
|
+
}),
|
|
139
|
+
guestLogin: build.mutation<CheckoutResponse, GuestLoginFormParams>({
|
|
140
|
+
query: ({ user_email, phone_number }) => ({
|
|
141
|
+
url: buildClientRequestUrl(checkout.guestLogin, {
|
|
142
|
+
useFormData: true
|
|
143
|
+
}),
|
|
144
|
+
method: 'POST',
|
|
145
|
+
body: {
|
|
146
|
+
user_email,
|
|
147
|
+
phone_number
|
|
148
|
+
}
|
|
149
|
+
}),
|
|
150
|
+
invalidatesTags: ['Checkout']
|
|
151
|
+
}),
|
|
152
|
+
setDeliveryOption: build.mutation<CheckoutResponse, number>({
|
|
153
|
+
query: (pk: number) => ({
|
|
154
|
+
url: buildClientRequestUrl(checkout.setDeliveryOption, {
|
|
155
|
+
useFormData: true
|
|
156
|
+
}),
|
|
157
|
+
method: 'POST',
|
|
158
|
+
body: {
|
|
159
|
+
delivery_option: String(pk)
|
|
160
|
+
}
|
|
161
|
+
}),
|
|
162
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
163
|
+
dispatch(setShippingStepBusy(true));
|
|
164
|
+
await queryFulfilled;
|
|
165
|
+
dispatch(setShippingStepBusy(false));
|
|
166
|
+
}
|
|
167
|
+
}),
|
|
168
|
+
setAddresses: build.mutation<CheckoutResponse, SetAddressesParams>({
|
|
169
|
+
query: ({ shippingAddressPk, billingAddressPk }) => ({
|
|
170
|
+
url: buildClientRequestUrl(checkout.setAddresses, {
|
|
171
|
+
useFormData: true
|
|
172
|
+
}),
|
|
173
|
+
method: 'POST',
|
|
174
|
+
body: {
|
|
175
|
+
shipping_address: String(shippingAddressPk),
|
|
176
|
+
billing_address: String(billingAddressPk)
|
|
177
|
+
}
|
|
178
|
+
}),
|
|
179
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
180
|
+
dispatch(setShippingStepBusy(true));
|
|
181
|
+
await queryFulfilled;
|
|
182
|
+
dispatch(setShippingStepBusy(false));
|
|
183
|
+
}
|
|
184
|
+
}),
|
|
185
|
+
setShippingOption: build.mutation<CheckoutResponse, number>({
|
|
186
|
+
query: (pk: number) => ({
|
|
187
|
+
url: buildClientRequestUrl(checkout.setShippingOption, {
|
|
188
|
+
useFormData: true
|
|
189
|
+
}),
|
|
190
|
+
method: 'POST',
|
|
191
|
+
body: {
|
|
192
|
+
shipping_option: String(pk)
|
|
193
|
+
}
|
|
194
|
+
}),
|
|
195
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
196
|
+
dispatch(setShippingStepBusy(true));
|
|
197
|
+
await queryFulfilled;
|
|
198
|
+
dispatch(setShippingStepBusy(false));
|
|
199
|
+
}
|
|
200
|
+
}),
|
|
201
|
+
setRetailStore: build.mutation<CheckoutResponse, SetRetailStoreParams>({
|
|
202
|
+
query: ({ retailStorePk, billingAddressPk }) => ({
|
|
203
|
+
url: buildClientRequestUrl(
|
|
204
|
+
'/orders/checkout?page=RetailStoreSelectionPage',
|
|
205
|
+
{
|
|
206
|
+
useFormData: true
|
|
207
|
+
}
|
|
208
|
+
),
|
|
209
|
+
method: 'POST',
|
|
210
|
+
body: {
|
|
211
|
+
retail_store: Number(retailStorePk),
|
|
212
|
+
billing_address: Number(billingAddressPk)
|
|
213
|
+
}
|
|
214
|
+
})
|
|
215
|
+
}),
|
|
216
|
+
setPaymentOption: build.mutation<CheckoutResponse, number>({
|
|
217
|
+
query: (pk: number) => ({
|
|
218
|
+
url: buildClientRequestUrl(checkout.setPaymentOption, {
|
|
219
|
+
useFormData: true
|
|
220
|
+
}),
|
|
221
|
+
method: 'POST',
|
|
222
|
+
body: {
|
|
223
|
+
payment_option: String(pk)
|
|
224
|
+
}
|
|
225
|
+
}),
|
|
226
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
227
|
+
dispatch(setPaymentStepBusy(true));
|
|
228
|
+
dispatch(setInstallmentOptions([]));
|
|
229
|
+
dispatch(setBankAccounts([]));
|
|
230
|
+
await queryFulfilled;
|
|
231
|
+
dispatch(setPaymentStepBusy(false));
|
|
232
|
+
}
|
|
233
|
+
}),
|
|
234
|
+
setBinNumber: build.mutation<CheckoutResponse, string>({
|
|
235
|
+
query: (binNumber: string) => {
|
|
236
|
+
const paymentOption =
|
|
237
|
+
store.getState().checkout?.preOrder?.payment_option;
|
|
238
|
+
const binNumberUrl =
|
|
239
|
+
paymentOption?.payment_type === 'masterpass'
|
|
240
|
+
? checkout.setMasterpassBinNumber
|
|
241
|
+
: checkout.setBinNumber;
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
url: buildClientRequestUrl(binNumberUrl, {
|
|
245
|
+
useFormData: true
|
|
246
|
+
}),
|
|
247
|
+
method: 'POST',
|
|
248
|
+
body: {
|
|
249
|
+
bin_number: binNumber
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
},
|
|
253
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
254
|
+
dispatch(setPaymentStepBusy(true));
|
|
255
|
+
await queryFulfilled;
|
|
256
|
+
dispatch(setPaymentStepBusy(false));
|
|
257
|
+
}
|
|
258
|
+
}),
|
|
259
|
+
setInstallmentOption: build.mutation<CheckoutResponse, number>({
|
|
260
|
+
query: (pk: number) => {
|
|
261
|
+
const paymentOption =
|
|
262
|
+
store.getState().checkout?.preOrder?.payment_option;
|
|
263
|
+
const installmentOption =
|
|
264
|
+
paymentOption?.payment_type === 'masterpass'
|
|
265
|
+
? checkout.setMasterPassInstallmentOption
|
|
266
|
+
: checkout.setInstallmentOption;
|
|
267
|
+
return {
|
|
268
|
+
url: buildClientRequestUrl(installmentOption, {
|
|
269
|
+
useFormData: true
|
|
270
|
+
}),
|
|
271
|
+
method: 'POST',
|
|
272
|
+
body: {
|
|
273
|
+
installment: String(pk)
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
},
|
|
277
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
278
|
+
dispatch(setPaymentStepBusy(true));
|
|
279
|
+
await queryFulfilled;
|
|
280
|
+
dispatch(setPaymentStepBusy(false));
|
|
281
|
+
}
|
|
282
|
+
}),
|
|
283
|
+
setFundsTransferOption: build.mutation<CheckoutResponse, number>({
|
|
284
|
+
query: (pk: number) => ({
|
|
285
|
+
url: buildClientRequestUrl(checkout.setFundsTransferOption, {
|
|
286
|
+
useFormData: true
|
|
287
|
+
}),
|
|
288
|
+
method: 'POST',
|
|
289
|
+
body: {
|
|
290
|
+
bank_account: String(pk)
|
|
291
|
+
}
|
|
292
|
+
}),
|
|
293
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
294
|
+
dispatch(setPaymentStepBusy(true));
|
|
295
|
+
await queryFulfilled;
|
|
296
|
+
dispatch(setPaymentStepBusy(false));
|
|
297
|
+
dispatch(setSelectedBankAccountPk(arg));
|
|
298
|
+
}
|
|
299
|
+
}),
|
|
300
|
+
completeRedirectionPayment: build.mutation<CheckoutResponse, void>({
|
|
301
|
+
query: () => ({
|
|
302
|
+
url: buildClientRequestUrl(checkout.completeRedirectionPayment, {
|
|
303
|
+
useFormData: true
|
|
304
|
+
}),
|
|
305
|
+
method: 'POST',
|
|
306
|
+
body: {
|
|
307
|
+
agreement: true
|
|
308
|
+
}
|
|
309
|
+
}),
|
|
310
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
311
|
+
dispatch(setPaymentStepBusy(true));
|
|
312
|
+
await queryFulfilled;
|
|
313
|
+
dispatch(setPaymentStepBusy(false));
|
|
314
|
+
}
|
|
315
|
+
}),
|
|
316
|
+
applePaymentSelect: build.mutation<CheckoutResponse, ApplePaySelectParams>({
|
|
317
|
+
query: ({ agreement, validationURL }) => ({
|
|
318
|
+
url: buildClientRequestUrl(checkout.confirmationPaymentSelect, {
|
|
319
|
+
useFormData: true
|
|
320
|
+
}),
|
|
321
|
+
method: 'POST',
|
|
322
|
+
body: {
|
|
323
|
+
agreement,
|
|
324
|
+
validationURL
|
|
325
|
+
}
|
|
326
|
+
}),
|
|
327
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
328
|
+
dispatch(setPaymentStepBusy(true));
|
|
329
|
+
await queryFulfilled;
|
|
330
|
+
dispatch(setPaymentStepBusy(false));
|
|
331
|
+
}
|
|
332
|
+
}),
|
|
333
|
+
appleQuery: build.mutation<CheckoutResponse, ApplePayQueryParams>({
|
|
334
|
+
query: ({ agreement, paymentToken }) => ({
|
|
335
|
+
url: buildClientRequestUrl(checkout.confirmationQuery, {
|
|
336
|
+
useFormData: true
|
|
337
|
+
}),
|
|
338
|
+
method: 'POST',
|
|
339
|
+
body: {
|
|
340
|
+
agreement,
|
|
341
|
+
payment_token: paymentToken
|
|
342
|
+
}
|
|
343
|
+
}),
|
|
344
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
345
|
+
dispatch(setPaymentStepBusy(true));
|
|
346
|
+
await queryFulfilled;
|
|
347
|
+
dispatch(setPaymentStepBusy(false));
|
|
348
|
+
}
|
|
349
|
+
}),
|
|
350
|
+
completeConfirmation: build.mutation<CheckoutResponse, void>({
|
|
351
|
+
query: () => ({
|
|
352
|
+
url: buildClientRequestUrl(checkout.confirmationComplete, {
|
|
353
|
+
useFormData: true
|
|
354
|
+
}),
|
|
355
|
+
method: 'POST',
|
|
356
|
+
body: {
|
|
357
|
+
agreement: true
|
|
358
|
+
}
|
|
359
|
+
}),
|
|
360
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
361
|
+
dispatch(setPaymentStepBusy(true));
|
|
362
|
+
await queryFulfilled;
|
|
363
|
+
dispatch(setPaymentStepBusy(false));
|
|
364
|
+
}
|
|
365
|
+
}),
|
|
366
|
+
setCompletePayOnDelivery: build.mutation<
|
|
367
|
+
CheckoutResponse,
|
|
368
|
+
PayOnDeliveryParams
|
|
369
|
+
>({
|
|
370
|
+
query: ({ paymentType }) => ({
|
|
371
|
+
url: buildClientRequestUrl(
|
|
372
|
+
`${checkout.fetchCheckout}?page=PayOnDeliveryPage`,
|
|
373
|
+
{ useFormData: true }
|
|
374
|
+
),
|
|
375
|
+
method: 'POST',
|
|
376
|
+
body: {
|
|
377
|
+
agreement: '1',
|
|
378
|
+
paymentType
|
|
379
|
+
}
|
|
380
|
+
}),
|
|
381
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
382
|
+
dispatch(setPaymentStepBusy(true));
|
|
383
|
+
await queryFulfilled;
|
|
384
|
+
dispatch(setPaymentStepBusy(false));
|
|
385
|
+
}
|
|
386
|
+
}),
|
|
387
|
+
setPayOnDeliveryChoice: build.mutation<CheckoutResponse, string>({
|
|
388
|
+
query: (body) => ({
|
|
389
|
+
url: buildClientRequestUrl(
|
|
390
|
+
`${checkout.fetchCheckout}?page=PayOnDeliveryPaymentChoicePage`,
|
|
391
|
+
{ useFormData: true }
|
|
392
|
+
),
|
|
393
|
+
method: 'POST',
|
|
394
|
+
body: {
|
|
395
|
+
payment_choice: body
|
|
396
|
+
}
|
|
397
|
+
}),
|
|
398
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
399
|
+
dispatch(setPaymentStepBusy(true));
|
|
400
|
+
await queryFulfilled;
|
|
401
|
+
dispatch(setPaymentStepBusy(false));
|
|
402
|
+
}
|
|
403
|
+
}),
|
|
404
|
+
completeLoyaltyPayment: build.mutation<CheckoutResponse, void>({
|
|
405
|
+
query: () => ({
|
|
406
|
+
url: buildClientRequestUrl(checkout.completeLoyaltyPayment, {
|
|
407
|
+
useFormData: true
|
|
408
|
+
}),
|
|
409
|
+
method: 'POST',
|
|
410
|
+
body: {
|
|
411
|
+
agreement: true
|
|
412
|
+
}
|
|
413
|
+
}),
|
|
414
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
415
|
+
dispatch(setPaymentStepBusy(true));
|
|
416
|
+
await queryFulfilled;
|
|
417
|
+
dispatch(setPaymentStepBusy(false));
|
|
418
|
+
}
|
|
419
|
+
}),
|
|
420
|
+
getCheckoutLoyaltyBalance: build.query<CheckoutResponse, void>({
|
|
421
|
+
query: () => ({
|
|
422
|
+
url: buildClientRequestUrl(checkout.loyaltyMoneyUsage)
|
|
423
|
+
})
|
|
424
|
+
}),
|
|
425
|
+
payWithLoyaltyBalance: build.mutation<any, string>({
|
|
426
|
+
query: (amount) => ({
|
|
427
|
+
url: buildClientRequestUrl(checkout.loyaltyMoneyUsage, {
|
|
428
|
+
useFormData: true
|
|
429
|
+
}),
|
|
430
|
+
method: 'POST',
|
|
431
|
+
body: {
|
|
432
|
+
loyalty_amount_to_use: amount
|
|
433
|
+
}
|
|
434
|
+
})
|
|
435
|
+
}),
|
|
436
|
+
setOrderNote: build.mutation<CheckoutResponse, string>({
|
|
437
|
+
query: (notes) => ({
|
|
438
|
+
url: buildClientRequestUrl(checkout.setOrderNote, {
|
|
439
|
+
useFormData: true
|
|
440
|
+
}),
|
|
441
|
+
method: 'POST',
|
|
442
|
+
body: {
|
|
443
|
+
notes
|
|
444
|
+
}
|
|
445
|
+
})
|
|
446
|
+
})
|
|
447
|
+
}),
|
|
448
|
+
overrideExisting: false
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
export const {
|
|
452
|
+
useFetchCheckoutQuery,
|
|
453
|
+
useFetchCheckoutResultQuery,
|
|
454
|
+
useGet3dRedirectFormQuery,
|
|
455
|
+
useGetContractQuery,
|
|
456
|
+
useCompleteCreditCardPaymentMutation,
|
|
457
|
+
useCompleteFundsTransferMutation,
|
|
458
|
+
useGuestLoginMutation,
|
|
459
|
+
useSetDeliveryOptionMutation,
|
|
460
|
+
useSetAddressesMutation,
|
|
461
|
+
useSetShippingOptionMutation,
|
|
462
|
+
useSetPaymentOptionMutation,
|
|
463
|
+
useSetBinNumberMutation,
|
|
464
|
+
useSetInstallmentOptionMutation,
|
|
465
|
+
useSetFundsTransferOptionMutation,
|
|
466
|
+
useSetRetailStoreMutation,
|
|
467
|
+
useCompleteRedirectionPaymentMutation,
|
|
468
|
+
useApplePaymentSelectMutation,
|
|
469
|
+
useAppleQueryMutation,
|
|
470
|
+
useCompleteConfirmationMutation,
|
|
471
|
+
useSetCompletePayOnDeliveryMutation,
|
|
472
|
+
useSetPayOnDeliveryChoiceMutation,
|
|
473
|
+
useCompleteLoyaltyPaymentMutation,
|
|
474
|
+
useGetCheckoutLoyaltyBalanceQuery,
|
|
475
|
+
usePayWithLoyaltyBalanceMutation,
|
|
476
|
+
useSetOrderNoteMutation
|
|
477
|
+
} = checkoutApi;
|