@akinon/next 1.45.0 → 1.47.0-rc.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 (53) hide show
  1. package/CHANGELOG.md +367 -0
  2. package/api/client.ts +39 -9
  3. package/assets/styles/index.css +49 -0
  4. package/assets/styles/index.css.map +1 -0
  5. package/assets/styles/index.scss +50 -26
  6. package/components/file-input.tsx +8 -0
  7. package/components/index.ts +1 -0
  8. package/components/input.tsx +21 -7
  9. package/components/link.tsx +17 -13
  10. package/components/pagination.tsx +1 -2
  11. package/components/price.tsx +11 -4
  12. package/components/selected-payment-option-view.tsx +26 -38
  13. package/data/client/account.ts +10 -9
  14. package/data/client/address.ts +32 -8
  15. package/data/client/api.ts +2 -2
  16. package/data/client/b2b.ts +35 -2
  17. package/data/client/basket.ts +6 -5
  18. package/data/client/checkout.ts +47 -4
  19. package/data/client/wishlist.ts +70 -2
  20. package/data/server/category.ts +2 -2
  21. package/data/server/list.ts +2 -2
  22. package/data/server/product.ts +15 -13
  23. package/data/server/special-page.ts +2 -2
  24. package/data/urls.ts +17 -3
  25. package/hooks/index.ts +2 -1
  26. package/hooks/use-message-listener.ts +24 -0
  27. package/hooks/use-payment-options.ts +2 -1
  28. package/lib/cache-handler.mjs +33 -0
  29. package/lib/cache.ts +18 -6
  30. package/middlewares/default.ts +50 -2
  31. package/middlewares/locale.ts +32 -30
  32. package/middlewares/pretty-url.ts +4 -0
  33. package/middlewares/url-redirection.ts +4 -0
  34. package/package.json +5 -4
  35. package/plugins.d.ts +1 -0
  36. package/redux/middlewares/checkout.ts +70 -11
  37. package/redux/reducers/checkout.ts +24 -5
  38. package/redux/reducers/config.ts +2 -0
  39. package/routes/pretty-url.tsx +194 -0
  40. package/types/commerce/account.ts +1 -0
  41. package/types/commerce/address.ts +1 -1
  42. package/types/commerce/b2b.ts +12 -2
  43. package/types/commerce/checkout.ts +30 -0
  44. package/types/commerce/misc.ts +2 -0
  45. package/types/commerce/order.ts +12 -0
  46. package/types/index.ts +30 -2
  47. package/utils/app-fetch.ts +1 -1
  48. package/utils/generate-commerce-search-params.ts +6 -2
  49. package/utils/index.ts +27 -6
  50. package/utils/menu-generator.ts +2 -2
  51. package/utils/redirection-iframe.ts +85 -0
  52. package/utils/server-translation.ts +5 -1
  53. package/with-pz-config.js +11 -1
@@ -14,12 +14,13 @@ import {
14
14
  CheckoutCreditPaymentOption,
15
15
  PreOrder,
16
16
  RetailStore,
17
- ShippingOption
17
+ ShippingOption,
18
+ DataSource,
19
+ AttributeBasedShippingOption
18
20
  } from '../../types';
19
21
 
20
22
  export interface CheckoutState {
21
- // TODO: Add types
22
- errors: any;
23
+ errors: Record<string, string[]>;
23
24
  hasGiftBox: boolean;
24
25
  canGuestPurchase: boolean;
25
26
  steps: {
@@ -37,6 +38,7 @@ export interface CheckoutState {
37
38
  addressList: Address[];
38
39
  deliveryOptions: DeliveryOption[];
39
40
  shippingOptions: ShippingOption[];
41
+ dataSourceShippingOptions: DataSource[];
40
42
  paymentOptions: PaymentOption[];
41
43
  creditPaymentOptions: CheckoutCreditPaymentOption[];
42
44
  selectedCreditPaymentPk: number;
@@ -47,6 +49,8 @@ export interface CheckoutState {
47
49
  selectedBankAccountPk: number;
48
50
  loyaltyBalance?: string;
49
51
  retailStores: RetailStore[];
52
+ attributeBasedShippingOptions: AttributeBasedShippingOption[];
53
+ selectedShippingOptions: Record<string, number>;
50
54
  }
51
55
 
52
56
  const initialState: CheckoutState = {
@@ -68,6 +72,7 @@ const initialState: CheckoutState = {
68
72
  addressList: [],
69
73
  deliveryOptions: [],
70
74
  shippingOptions: [],
75
+ dataSourceShippingOptions: [],
71
76
  paymentOptions: [],
72
77
  creditPaymentOptions: [],
73
78
  selectedCreditPaymentPk: null,
@@ -76,7 +81,9 @@ const initialState: CheckoutState = {
76
81
  installmentOptions: [],
77
82
  bankAccounts: [],
78
83
  selectedBankAccountPk: null,
79
- retailStores: []
84
+ retailStores: [],
85
+ attributeBasedShippingOptions: [],
86
+ selectedShippingOptions: {}
80
87
  };
81
88
 
82
89
  const checkoutSlice = createSlice({
@@ -122,6 +129,9 @@ const checkoutSlice = createSlice({
122
129
  setShippingOptions(state, { payload }) {
123
130
  state.shippingOptions = payload;
124
131
  },
132
+ setDataSourceShippingOptions(state, { payload }) {
133
+ state.dataSourceShippingOptions = payload;
134
+ },
125
135
  setPaymentOptions(state, { payload }) {
126
136
  state.paymentOptions = payload;
127
137
  },
@@ -151,6 +161,12 @@ const checkoutSlice = createSlice({
151
161
  },
152
162
  setRetailStores(state, { payload }) {
153
163
  state.retailStores = payload;
164
+ },
165
+ setAttributeBasedShippingOptions(state, { payload }) {
166
+ state.attributeBasedShippingOptions = payload;
167
+ },
168
+ setSelectedShippingOptions: (state, { payload }) => {
169
+ state.selectedShippingOptions = payload;
154
170
  }
155
171
  }
156
172
  });
@@ -169,6 +185,7 @@ export const {
169
185
  setAddressList,
170
186
  setDeliveryOptions,
171
187
  setShippingOptions,
188
+ setDataSourceShippingOptions,
172
189
  setPaymentOptions,
173
190
  setCreditPaymentOptions,
174
191
  setSelectedCreditPaymentPk,
@@ -178,7 +195,9 @@ export const {
178
195
  setBankAccounts,
179
196
  setSelectedBankAccountPk,
180
197
  setLoyaltyBalance,
181
- setRetailStores
198
+ setRetailStores,
199
+ setAttributeBasedShippingOptions,
200
+ setSelectedShippingOptions
182
201
  } = checkoutSlice.actions;
183
202
 
184
203
  export default checkoutSlice.reducer;
@@ -6,6 +6,8 @@ import { Config } from '../../types';
6
6
  const initialState: Config = {
7
7
  user_phone_regex: '^(05)\\d{9}$',
8
8
  user_phone_format: '05999999999',
9
+ user_post_code_regex: '^\\d{5}$',
10
+ user_post_code_format: '99999',
9
11
  country: {
10
12
  pk: 1,
11
13
  name: 'Türkiye',
@@ -0,0 +1,194 @@
1
+ import { URLS } from '@akinon/next/data/urls';
2
+ import { Metadata, PageProps } from '@akinon/next/types';
3
+ import logger from '@akinon/next/utils/log';
4
+ import { notFound } from 'next/navigation';
5
+
6
+ type PrettyUrlResult = {
7
+ matched: boolean;
8
+ path?: string;
9
+ pk?: number;
10
+ };
11
+
12
+ const resolvePrettyUrlHandler =
13
+ (pathname: string, ip: string | null) => async () => {
14
+ let results = [] as { old_path: string }[];
15
+ let prettyUrlResult: PrettyUrlResult = {
16
+ matched: false
17
+ };
18
+
19
+ try {
20
+ const requestUrl = URLS.misc.prettyUrls(`/${pathname}/`);
21
+
22
+ logger.debug(`Resolving pretty url`, { pathname, requestUrl, ip });
23
+
24
+ const start = Date.now();
25
+ const apiResponse = await fetch(requestUrl, {
26
+ next: {
27
+ revalidate: 0
28
+ }
29
+ });
30
+ const data = await apiResponse.json();
31
+ ({ results } = data);
32
+ const end = Date.now();
33
+ console.warn('Pretty url response time', end - start, requestUrl);
34
+
35
+ const matched = results.length > 0;
36
+ const [{ old_path: path } = { old_path: '' }] = results;
37
+ let pk;
38
+
39
+ if (matched) {
40
+ const pkRegex = /\/(\d+)\/$/;
41
+ const match = path.match(pkRegex);
42
+ pk = match ? parseInt(match[1]) : undefined;
43
+ }
44
+
45
+ prettyUrlResult = {
46
+ matched,
47
+ path,
48
+ pk
49
+ };
50
+
51
+ logger.trace('Pretty url result', { prettyUrlResult, ip });
52
+ } catch (error) {
53
+ logger.error('Error resolving pretty url', { error, pathname, ip });
54
+ }
55
+
56
+ return prettyUrlResult;
57
+ };
58
+
59
+ export async function generateMetadata({ params }: PageProps) {
60
+ let result: Metadata = {};
61
+ const { prettyurl } = params;
62
+ const pageSlug = prettyurl
63
+ .filter((x) => !x.startsWith('searchparams'))
64
+ .join('/');
65
+
66
+ const searchParams = Object.fromEntries(
67
+ new URLSearchParams(
68
+ decodeURIComponent(
69
+ prettyurl
70
+ .find((x) => x.startsWith('searchparams'))
71
+ ?.replace('searchparams%7C', '')
72
+ ) ?? {}
73
+ ).entries()
74
+ );
75
+
76
+ const prettyUrlResult = await resolvePrettyUrlHandler(pageSlug, null)();
77
+
78
+ if (!prettyUrlResult.matched) {
79
+ return notFound();
80
+ }
81
+
82
+ const commonProps = {
83
+ params: {
84
+ ...params,
85
+ pk: prettyUrlResult.pk
86
+ },
87
+ searchParams
88
+ };
89
+
90
+ try {
91
+ if (prettyUrlResult.path.startsWith('/product/')) {
92
+ await import('@product/[pk]/page').then(async (module) => {
93
+ result = await module['generateMetadata']?.(commonProps);
94
+ });
95
+ }
96
+
97
+ if (prettyUrlResult.path.startsWith('/group-product/')) {
98
+ await import('@group-product/[pk]/page').then(async (module) => {
99
+ result = await module['generateMetadata']?.(commonProps);
100
+ });
101
+ }
102
+
103
+ if (prettyUrlResult.path.startsWith('/category/')) {
104
+ await import('@category/[pk]/page').then(async (module) => {
105
+ result = await module['generateMetadata']?.(commonProps);
106
+ });
107
+ }
108
+
109
+ if (prettyUrlResult.path.startsWith('/special-page/')) {
110
+ await import('@special-page/[pk]/page').then(async (module) => {
111
+ result = await module['generateMetadata']?.(commonProps);
112
+ });
113
+ }
114
+
115
+ if (prettyUrlResult.path.startsWith('/flat-page/')) {
116
+ await import('@flat-page/[pk]/page').then(async (module) => {
117
+ result = await module['generateMetadata']?.(commonProps);
118
+ });
119
+ }
120
+ // eslint-disable-next-line no-empty
121
+ } catch (error) {}
122
+
123
+ return result;
124
+ }
125
+
126
+ export const dynamic = 'force-static';
127
+ export const revalidate = 300;
128
+
129
+ export default async function Page({ params }) {
130
+ const { prettyurl } = params;
131
+ const pageSlug = prettyurl
132
+ .filter((x) => !x.startsWith('searchparams'))
133
+ .join('/');
134
+
135
+ const urlSearchParams = new URLSearchParams(
136
+ decodeURIComponent(
137
+ prettyurl
138
+ .find((x) => x.startsWith('searchparams'))
139
+ ?.replace('searchparams%7C', '')
140
+ ) ?? {}
141
+ );
142
+
143
+ const searchParams = {};
144
+
145
+ for (const [key, value] of urlSearchParams.entries() as unknown as Array<
146
+ [string, string]
147
+ >) {
148
+ if (!searchParams[key]) {
149
+ searchParams[key] = [];
150
+ }
151
+ searchParams[key].push(value);
152
+ }
153
+
154
+ const result = await resolvePrettyUrlHandler(pageSlug, null)();
155
+
156
+ if (!result.matched) {
157
+ return notFound();
158
+ }
159
+
160
+ const commonProps = {
161
+ params: {
162
+ ...params,
163
+ pk: result.pk
164
+ },
165
+ searchParams
166
+ };
167
+
168
+ if (result.path.startsWith('/category/')) {
169
+ const CategoryPage = (await import('@category/[pk]/page')).default;
170
+ return <CategoryPage {...commonProps} />;
171
+ }
172
+
173
+ if (result.path.startsWith('/product/')) {
174
+ const ProductPage = (await import('@product/[pk]/page')).default;
175
+ return <ProductPage {...commonProps} />;
176
+ }
177
+
178
+ if (result.path.startsWith('/group-product/')) {
179
+ const GroupProduct = (await import('@group-product/[pk]/page')).default;
180
+ return <GroupProduct {...commonProps} />;
181
+ }
182
+
183
+ if (result.path.startsWith('/special-page/')) {
184
+ const SpecialPage = (await import('@special-page/[pk]/page')).default;
185
+ return <SpecialPage {...commonProps} />;
186
+ }
187
+
188
+ if (result.path.startsWith('/flat-page/')) {
189
+ const FlatPage = (await import('@flat-page/[pk]/page')).default;
190
+ return <FlatPage {...commonProps} />;
191
+ }
192
+
193
+ return null;
194
+ }
@@ -61,4 +61,5 @@ export type ContactFormType = {
61
61
  order?: string;
62
62
  country_code?: string;
63
63
  order_needed?: boolean;
64
+ file?: FileList
64
65
  };
@@ -17,7 +17,7 @@ export type AddressFormType = {
17
17
  line: string;
18
18
  postcode: string;
19
19
  company_name?: string;
20
- tax_no?: number;
20
+ tax_no?: string;
21
21
  tax_office?: string;
22
22
  e_bill_taxpayer?: boolean;
23
23
  country_code?: string;
@@ -72,7 +72,7 @@ export type BasketItemType = {
72
72
  divisions: BasketItemDivision[];
73
73
  product: ProductB2b;
74
74
  product_remote_id: number;
75
- }
75
+ };
76
76
 
77
77
  export type BasketParams = {
78
78
  division: string;
@@ -91,7 +91,7 @@ export type CreateQuotationParams = {
91
91
  export type UpdateProductParams = {
92
92
  product_remote_id: number;
93
93
  division: number;
94
- quantity: number
94
+ quantity: number;
95
95
  };
96
96
 
97
97
  export type DeleteProductParams = {
@@ -115,3 +115,13 @@ export type DraftResponse = {
115
115
  total_amount: number;
116
116
  total_quantity: number;
117
117
  };
118
+
119
+ export type BasketStatusResponse = {
120
+ is_ready: boolean;
121
+ status: string;
122
+ url: string;
123
+ };
124
+
125
+ export type ExportBasketResponse = {
126
+ cache_key: string;
127
+ };
@@ -33,6 +33,23 @@ export interface ShippingOption {
33
33
  slug: string;
34
34
  }
35
35
 
36
+ export interface DataSource {
37
+ pk: number;
38
+ name: string;
39
+ data_source_shipping_options: DataSourceShippingOption[];
40
+ }
41
+
42
+ export interface DataSourceShippingOption {
43
+ pk: number;
44
+ shipping_amount: string;
45
+ shipping_option_name: string;
46
+ shipping_option_logo: string | null;
47
+ data_source: {
48
+ pk: number;
49
+ title: string | null;
50
+ };
51
+ }
52
+
36
53
  export interface CheckoutAddressType {
37
54
  label: string;
38
55
  text: string;
@@ -78,6 +95,8 @@ export interface PreOrder {
78
95
  retail_store?: RetailStore;
79
96
  gift_box?: GiftBox;
80
97
  credit_payment_option?: CheckoutCreditPaymentOption;
98
+ data_source_shipping_options: any;
99
+ attribute_based_shipping_options?: AttributeBasedShippingOption[];
81
100
  }
82
101
 
83
102
  export interface GuestLoginFormParams {
@@ -117,6 +136,7 @@ export interface CheckoutContext {
117
136
  redirect_url?: string;
118
137
  context_data?: any;
119
138
  balance?: string;
139
+ attribute_based_shipping_options?: AttributeBasedShippingOption[];
120
140
  [key: string]: any;
121
141
  };
122
142
  }
@@ -142,3 +162,13 @@ export interface BankAccount {
142
162
  pk: number;
143
163
  sort_order: number;
144
164
  }
165
+
166
+ export interface AttributeBasedShippingOption {
167
+ pk: number;
168
+ shipping_amount: string | null;
169
+ shipping_option_name: string | null;
170
+ shipping_option_logo: string | null;
171
+ attribute_value: string | null;
172
+ attribute_key: string;
173
+ [key: string]: any;
174
+ }
@@ -2,6 +2,8 @@ import { District } from './address';
2
2
  export interface Config {
3
3
  user_phone_regex: string;
4
4
  user_phone_format: string;
5
+ user_post_code_regex: string;
6
+ user_post_code_format: string;
5
7
  country: {
6
8
  pk: number;
7
9
  name: string;
@@ -52,6 +52,10 @@ export interface OrderItem {
52
52
  quantity: string;
53
53
  unit_price: string;
54
54
  total_amount: string;
55
+ attributes: {
56
+ gift_note: string;
57
+ [key: string]: any;
58
+ };
55
59
  }
56
60
 
57
61
  export interface Order {
@@ -105,6 +109,14 @@ export interface Order {
105
109
  shipping_option: number;
106
110
  tracking_number: string;
107
111
  tracking_url: string;
112
+ [key: string]: any;
113
+ bank: {
114
+ pk: number;
115
+ name: string;
116
+ slug: string;
117
+ logo: string;
118
+ [key: string]: any;
119
+ };
108
120
  }
109
121
 
110
122
  export interface Quotations {
package/types/index.ts CHANGED
@@ -2,7 +2,7 @@ import { LocaleUrlStrategy } from '../localization';
2
2
  import { PzNextRequest } from '../middlewares';
3
3
  import { Control, FieldError } from 'react-hook-form';
4
4
  import { ReactNode } from 'react';
5
-
5
+ import { UsePaginationType } from '../hooks/use-pagination';
6
6
  declare global {
7
7
  interface Window {
8
8
  // we did it like this because declare types needs to be identical, if not it will fail
@@ -68,9 +68,17 @@ export interface Currency {
68
68
  * @see https://en.wikipedia.org/wiki/ISO_4217
69
69
  */
70
70
  code: string;
71
+ /**
72
+ * Number of decimal places to display.
73
+ *
74
+ * @example
75
+ * decimalScale: 3
76
+ */
77
+ decimalScale?: number;
71
78
  }
72
79
 
73
80
  export interface Settings {
81
+ usePrettyUrlRoute?: boolean;
74
82
  commerceUrl: string;
75
83
  redis: {
76
84
  defaultExpirationTime: number;
@@ -216,7 +224,7 @@ export type Translations = { [key: string]: object };
216
224
 
217
225
  export interface PageProps<T = any> {
218
226
  params: T;
219
- searchParams: URLSearchParams;
227
+ searchParams: { [key: string]: string | string[] | undefined };
220
228
  }
221
229
 
222
230
  export interface LayoutProps<T = any> extends PageProps<T> {
@@ -250,6 +258,8 @@ export interface ButtonProps
250
258
  appearance?: 'filled' | 'outlined' | 'ghost';
251
259
  }
252
260
 
261
+ export type FileInputProps = React.HTMLProps<HTMLInputElement>;
262
+
253
263
  export interface PriceProps {
254
264
  currencyCode?: string;
255
265
  useCurrencySymbol?: boolean;
@@ -283,3 +293,21 @@ export interface AccordionProps {
283
293
  export interface PluginModuleComponentProps {
284
294
  settings?: Record<string, any>;
285
295
  }
296
+
297
+ export interface PaginationProps {
298
+ total: number | undefined;
299
+ limit?: number | undefined;
300
+ currentPage: number | undefined;
301
+ numberOfPages?: number | undefined;
302
+ containerClassName?: string;
303
+ moreButtonClassName?: string;
304
+ prevClassName?: string;
305
+ nextClassName?: string;
306
+ pageClassName?: string;
307
+ threshold?: number | undefined;
308
+ delta?: number | undefined;
309
+ render?: (pagination: UsePaginationType) => ReactNode;
310
+ type?: 'infinite' | 'list' | 'more';
311
+ onPageChange?: (page: number) => void;
312
+ direction?: 'next' | 'prev';
313
+ }
@@ -41,7 +41,7 @@ const appFetch = async <T>(
41
41
  };
42
42
 
43
43
  init.next = {
44
- revalidate: 60
44
+ revalidate: Settings.usePrettyUrlRoute ? 0 : 60
45
45
  };
46
46
 
47
47
  logger.debug(`FETCH START ${url}`, { requestURL, init, ip });
@@ -1,11 +1,15 @@
1
1
  import logger from './log';
2
2
 
3
- export const generateCommerceSearchParams = (searchParams?: URLSearchParams) => {
3
+ export const generateCommerceSearchParams = (searchParams?: {
4
+ [key: string]: string | string[] | undefined;
5
+ }) => {
4
6
  if (!searchParams) {
5
7
  return null;
6
8
  }
7
9
 
8
- const urlSerchParams = new URLSearchParams(searchParams);
10
+ const urlSerchParams = new URLSearchParams(
11
+ searchParams as Record<string, string>
12
+ );
9
13
 
10
14
  Object.entries(searchParams).forEach(([key, value]) => {
11
15
  if (typeof value === 'object') {
package/utils/index.ts CHANGED
@@ -63,18 +63,33 @@ export function getTranslateFn(path: string, translations: any) {
63
63
 
64
64
  export function buildClientRequestUrl(
65
65
  path: string,
66
- options?: ClientRequestOptions
66
+ options?: ClientRequestOptions & { cache?: boolean }
67
67
  ) {
68
68
  let url = `/api/client${path}`;
69
69
 
70
+ let hasQuery = url.includes('?');
71
+
70
72
  if (options) {
71
- if (url.includes('?')) {
72
- url += '&';
73
- } else {
74
- url += '?';
73
+ const { cache, ...otherOptions } = options;
74
+
75
+ if (Object.keys(otherOptions).length > 0) {
76
+ if (hasQuery) {
77
+ url += '&';
78
+ } else {
79
+ url += '?';
80
+ hasQuery = true;
81
+ }
82
+ url += `options=${encodeURIComponent(JSON.stringify(otherOptions))}`;
75
83
  }
76
84
 
77
- url += `options=${encodeURIComponent(JSON.stringify(options))}`;
85
+ if (cache === false) {
86
+ if (hasQuery) {
87
+ url += '&';
88
+ } else {
89
+ url += '?';
90
+ }
91
+ url += `t=${Date.now()}`;
92
+ }
78
93
  }
79
94
 
80
95
  return url;
@@ -102,6 +117,12 @@ export function buildCDNUrl(url: string, config?: CDNOptions) {
102
117
  ''
103
118
  );
104
119
 
120
+ const noOptionFileExtension = url?.split('.').pop()?.toLowerCase() ?? '';
121
+
122
+ if (noOptionFileExtension === 'svg' || noOptionFileExtension === 'gif') {
123
+ return url;
124
+ }
125
+
105
126
  let options = '';
106
127
 
107
128
  if (config) {
@@ -13,8 +13,8 @@ export const menuGenerator = (arr: MenuItemType[]) => {
13
13
  });
14
14
 
15
15
  Object.values(data).forEach((item) => {
16
- if (item.parent) {
17
- data[item.parent.pk].children.push(item);
16
+ if (item.parent_pk) {
17
+ data[item.parent_pk].children.push(item);
18
18
  } else {
19
19
  tree.push(item);
20
20
  }
@@ -0,0 +1,85 @@
1
+ const iframeURLChange = (iframe, callback) => {
2
+ iframe.addEventListener('load', () => {
3
+ setTimeout(() => {
4
+ if (iframe?.contentWindow?.location) {
5
+ callback(iframe.contentWindow.location);
6
+ }
7
+ }, 0);
8
+ });
9
+ };
10
+
11
+ const removeIframe = async () => {
12
+ const iframeSelector = document.querySelector(
13
+ '.checkout-payment-redirection-iframe-wrapper'
14
+ );
15
+
16
+ const redirectionPaymentWrapper = document.querySelector(
17
+ '.checkout-redirection-payment-wrapper'
18
+ );
19
+
20
+ const form = redirectionPaymentWrapper.querySelector('form') as HTMLElement;
21
+
22
+ if (!iframeSelector) {
23
+ return;
24
+ }
25
+
26
+ iframeSelector.remove();
27
+
28
+ if (form) {
29
+ form.style.display = 'block';
30
+ }
31
+
32
+ location.reload();
33
+ };
34
+
35
+ export const showRedirectionIframe = (redirectUrl: string) => {
36
+ const iframeWrapper = document.createElement('div');
37
+ const iframe = document.createElement('iframe');
38
+ const closeButton = document.createElement('div');
39
+ const redirectionPaymentWrapper = document.querySelector(
40
+ '.checkout-redirection-payment-wrapper'
41
+ );
42
+ const form = redirectionPaymentWrapper.querySelector('form') as HTMLElement;
43
+
44
+ iframeWrapper.className = 'checkout-payment-redirection-iframe-wrapper';
45
+ closeButton.className = 'close-button';
46
+
47
+ iframe.setAttribute('src', redirectUrl);
48
+ closeButton.innerHTML = '&#x2715';
49
+ closeButton.addEventListener('click', removeIframe);
50
+
51
+ iframeWrapper.append(iframe, closeButton);
52
+
53
+ if (form) {
54
+ form.style.display = 'none';
55
+ }
56
+
57
+ redirectionPaymentWrapper.appendChild(iframeWrapper);
58
+
59
+ iframeURLChange(iframe, (location) => {
60
+ if (location.origin !== window.location.origin) {
61
+ return false;
62
+ }
63
+
64
+ const searchParams = new URLSearchParams(location.search);
65
+ const isOrderCompleted = location.href.includes('/orders/completed');
66
+
67
+ if (isOrderCompleted) {
68
+ (window.parent as any)?.postMessage?.(
69
+ JSON.stringify({
70
+ url: location.pathname
71
+ })
72
+ );
73
+ }
74
+
75
+ if (
76
+ searchParams.has('success') ||
77
+ isOrderCompleted ||
78
+ location.href.includes('/orders/checkout')
79
+ ) {
80
+ setTimeout(() => {
81
+ removeIframe();
82
+ }, 0);
83
+ }
84
+ });
85
+ };