@zonos/elements 1.3.174 → 1.3.176
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/dist/cjs/CheckoutConfig-f1442a60.js +35 -0
- package/dist/cjs/{cart-93ed3002.js → cart-e648a65f.js} +11 -5
- package/dist/cjs/index.cjs.js +67 -12
- package/dist/cjs/{paypal-8b49ef07.js → paypal-2390cfb2.js} +1 -1
- package/dist/cjs/zonos-address_7.cjs.entry.js +1 -1
- package/dist/cjs/zonos-cart-items_13.cjs.entry.js +2 -2
- package/dist/cjs/zonos-checkout.cjs.entry.js +57 -4
- package/dist/cjs/zonos-controller.cjs.entry.js +8 -1
- package/dist/cjs/zonos-country-flag.cjs.entry.js +1 -1
- package/dist/cjs/zonos-country-select_4.cjs.entry.js +1 -1
- package/dist/cjs/zonos-empty-state-payment_4.cjs.entry.js +2 -2
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +1 -1
- package/dist/cjs/zonos-hello.cjs.entry.js +4 -4
- package/dist/cjs/zonos-language-select_2.cjs.entry.js +1 -1
- package/dist/collection/components/utils/api/getShippingZones.js +8 -3
- package/dist/collection/components/utils/api/getZonosSettings.js +7 -0
- package/dist/collection/components/utils/api/trackConversionEvent.js +5 -2
- package/dist/collection/components/utils/hello/getProductsOnPage.js +4 -4
- package/dist/collection/scripts/_getCartInfoById.js +29 -0
- package/dist/collection/scripts/_zonosBase.js +8 -5
- package/dist/collection/scripts/cart/_setupCartDataWithSettings.js +28 -0
- package/dist/collection/types/generated/graphql.internal.types.js +3 -0
- package/dist/esm/CheckoutConfig-5479d192.js +31 -0
- package/dist/esm/{cart-54d84646.js → cart-dc171e7f.js} +12 -6
- package/dist/esm/index.js +68 -13
- package/dist/esm/{paypal-17a320c8.js → paypal-1beec534.js} +1 -1
- package/dist/esm/zonos-address_7.entry.js +1 -1
- package/dist/esm/zonos-cart-items_13.entry.js +2 -2
- package/dist/esm/zonos-checkout.entry.js +56 -3
- package/dist/esm/zonos-controller.entry.js +8 -1
- package/dist/esm/zonos-country-flag.entry.js +1 -1
- package/dist/esm/zonos-country-select_4.entry.js +1 -1
- package/dist/esm/zonos-empty-state-payment_4.entry.js +2 -2
- package/dist/esm/zonos-hello-dialog.entry.js +1 -1
- package/dist/esm/zonos-hello.entry.js +4 -4
- package/dist/esm/zonos-language-select_2.entry.js +1 -1
- package/dist/esm-es5/CheckoutConfig-5479d192.js +1 -0
- package/dist/esm-es5/cart-dc171e7f.js +1 -0
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/{paypal-17a320c8.js → paypal-1beec534.js} +1 -1
- package/dist/esm-es5/zonos-address_7.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_13.entry.js +1 -1
- package/dist/esm-es5/zonos-checkout.entry.js +1 -1
- package/dist/esm-es5/zonos-controller.entry.js +1 -1
- package/dist/esm-es5/zonos-country-flag.entry.js +1 -1
- package/dist/esm-es5/zonos-country-select_4.entry.js +1 -1
- package/dist/esm-es5/zonos-empty-state-payment_4.entry.js +1 -1
- package/dist/esm-es5/zonos-hello-dialog.entry.js +1 -1
- package/dist/esm-es5/zonos-hello.entry.js +1 -1
- package/dist/esm-es5/zonos-language-select_2.entry.js +1 -1
- package/dist/scripts/index.d.ts +199 -0
- package/dist/scripts/index.js +1 -1
- package/dist/scripts/loadZonos.js +1 -1
- package/dist/scripts/zonos.js +1 -1
- package/dist/types/scripts/_getCartInfoById.d.ts +7 -0
- package/dist/types/scripts/_zonosBase.d.ts +11 -1
- package/dist/types/scripts/cart/_setupCartDataWithSettings.d.ts +166 -0
- package/dist/types/types/checkout/api/NormalizedTempCart.d.ts +20 -1
- package/dist/types/types/generated/graphql.internal.types.d.ts +155 -0
- package/dist/types/types/generated/graphql.internal.types.ts +159 -0
- package/dist/types/types/utils/ZonosSettings.d.ts +1 -1
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/p-007a4d24.entry.js +1 -0
- package/dist/zonos-elements/{p-9f8b820e.system.entry.js → p-08fa3875.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-3d169241.system.entry.js → p-0a6aa4cf.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-d9779ea7.entry.js → p-0ef83bec.entry.js} +1 -1
- package/dist/zonos-elements/{p-ed8a8a44.entry.js → p-117eb67d.entry.js} +1 -1
- package/dist/zonos-elements/{p-28dcd7bb.entry.js → p-24d4f2ec.entry.js} +1 -1
- package/dist/zonos-elements/{p-d22c15be.entry.js → p-30ff0a71.entry.js} +1 -1
- package/dist/zonos-elements/p-35bfc9d1.system.entry.js +1 -0
- package/dist/zonos-elements/p-40e5359c.system.js +1 -0
- package/dist/zonos-elements/p-46f6e5e9.system.js +1 -1
- package/dist/zonos-elements/p-5372fed8.system.js +1 -0
- package/dist/zonos-elements/{p-c67f6666.system.entry.js → p-60ab9c4c.system.entry.js} +1 -1
- package/dist/zonos-elements/p-655bc743.system.entry.js +1 -0
- package/dist/zonos-elements/{p-6612e6f9.system.entry.js → p-6ef7451f.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-e11eecbf.system.entry.js → p-7dd0d6b4.system.entry.js} +1 -1
- package/dist/zonos-elements/p-80dd3fb6.entry.js +1 -0
- package/dist/zonos-elements/p-8ee34712.system.js +1 -0
- package/dist/zonos-elements/{p-d98fa14c.system.entry.js → p-a334b6d8.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-1b6d0895.system.entry.js → p-a7d2a768.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-78a95cee.entry.js → p-aa651c8f.entry.js} +1 -1
- package/dist/zonos-elements/{p-8e436df2.system.entry.js → p-bdf93de1.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-f80f24a0.js → p-d53968eb.js} +2 -2
- package/dist/zonos-elements/p-e3f9a12b.js +1 -0
- package/dist/zonos-elements/{p-0ee9b22a.entry.js → p-e9f8edbb.entry.js} +1 -1
- package/dist/zonos-elements/{p-8964d8f8.system.js → p-ef7d14a3.system.js} +1 -1
- package/dist/zonos-elements/p-f4d9f007.entry.js +1 -0
- package/dist/zonos-elements/{p-4c6dfe2e.entry.js → p-f4eaf289.entry.js} +1 -1
- package/dist/zonos-elements/p-fe253cc1.js +1 -0
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/CheckoutConfig-fb59baa3.js +0 -90
- package/dist/esm/CheckoutConfig-63b3ed06.js +0 -86
- package/dist/esm-es5/CheckoutConfig-63b3ed06.js +0 -1
- package/dist/esm-es5/cart-54d84646.js +0 -1
- package/dist/zonos-elements/p-19ac0f84.system.entry.js +0 -1
- package/dist/zonos-elements/p-416ac901.entry.js +0 -1
- package/dist/zonos-elements/p-4a87a92c.entry.js +0 -1
- package/dist/zonos-elements/p-75b771cf.js +0 -1
- package/dist/zonos-elements/p-84dd312c.system.js +0 -1
- package/dist/zonos-elements/p-869bbedc.js +0 -1
- package/dist/zonos-elements/p-a1d54022.system.js +0 -1
- package/dist/zonos-elements/p-b86b82eb.entry.js +0 -1
- package/dist/zonos-elements/p-d74ab632.system.entry.js +0 -1
- package/dist/zonos-elements/p-e0d3aeae.system.js +0 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const baseRe = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;
|
|
4
|
+
const uuidRe = new RegExp(`^${baseRe.source}$`);
|
|
5
|
+
const cartUuidRe = new RegExp(`^cart_${baseRe.source}$`);
|
|
6
|
+
const tsidRe = /^[a-zA-Z0-9]{2,}$/;
|
|
7
|
+
const cartTsidRe = /^cart_[a-zA-Z0-9]{2,}$/;
|
|
8
|
+
const _getIsValidCartId = (cartId) => {
|
|
9
|
+
if (!cartId) {
|
|
10
|
+
return { isDgsCartId: false, isLegacyCartId: false };
|
|
11
|
+
}
|
|
12
|
+
if (cartId.includes('undefined')) {
|
|
13
|
+
return { isDgsCartId: false, isLegacyCartId: false };
|
|
14
|
+
}
|
|
15
|
+
if (cartTsidRe.test(cartId)) {
|
|
16
|
+
return { isDgsCartId: true, isLegacyCartId: false };
|
|
17
|
+
}
|
|
18
|
+
if (tsidRe.test(cartId)) {
|
|
19
|
+
return { isDgsCartId: false, isLegacyCartId: true };
|
|
20
|
+
}
|
|
21
|
+
if (cartUuidRe.test(cartId)) {
|
|
22
|
+
return { isDgsCartId: true, isLegacyCartId: false };
|
|
23
|
+
}
|
|
24
|
+
if (uuidRe.test(cartId)) {
|
|
25
|
+
return { isDgsCartId: false, isLegacyCartId: true };
|
|
26
|
+
}
|
|
27
|
+
return { isDgsCartId: false, isLegacyCartId: false };
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const checkoutHiddenBtnSelector = 'zonos--checkout-hidden-button';
|
|
31
|
+
const domesticRedirectedBtnSelector = 'zonos--domestic-redirected-checkout-button';
|
|
32
|
+
|
|
33
|
+
exports._getIsValidCartId = _getIsValidCartId;
|
|
34
|
+
exports.checkoutHiddenBtnSelector = checkoutHiddenBtnSelector;
|
|
35
|
+
exports.domesticRedirectedBtnSelector = domesticRedirectedBtnSelector;
|
|
@@ -9898,13 +9898,18 @@ const getLocalization = async () => {
|
|
|
9898
9898
|
};
|
|
9899
9899
|
|
|
9900
9900
|
const getShippingZones = async () => {
|
|
9901
|
-
var _a, _b;
|
|
9901
|
+
var _a, _b, _c;
|
|
9902
|
+
if ((_a = window.Zonos.cartSettings) === null || _a === void 0 ? void 0 : _a.shippingZones) {
|
|
9903
|
+
return window.Zonos.cartSettings.shippingZones
|
|
9904
|
+
.flatMap(zone => zone === null || zone === void 0 ? void 0 : zone.countryCodes)
|
|
9905
|
+
.filter(Boolean);
|
|
9906
|
+
}
|
|
9902
9907
|
const { errors, json } = await handleFetch.handleFetch('/api/zonos-elements/shipping-zones');
|
|
9903
9908
|
if (errors.length || !json) {
|
|
9904
|
-
handleFetch.logError(`Error fetching shipping zones: ${(
|
|
9909
|
+
handleFetch.logError(`Error fetching shipping zones: ${(_b = errors.find(Boolean)) === null || _b === void 0 ? void 0 : _b.message}`);
|
|
9905
9910
|
return null;
|
|
9906
9911
|
}
|
|
9907
|
-
const shippingZones = (
|
|
9912
|
+
const shippingZones = (_c = json === null || json === void 0 ? void 0 : json.shippingZones) === null || _c === void 0 ? void 0 : _c.flatMap(zone => zone === null || zone === void 0 ? void 0 : zone.countryCodes).filter(Boolean);
|
|
9908
9913
|
return shippingZones || null;
|
|
9909
9914
|
};
|
|
9910
9915
|
|
|
@@ -10694,8 +10699,9 @@ const trackConversionEvent = async (eventName, metadata) => {
|
|
|
10694
10699
|
const isDevelopment = window.location.href.includes('zonos.com') ||
|
|
10695
10700
|
!!((_a = window.Zonos) === null || _a === void 0 ? void 0 : _a.zonosQaUrl) ||
|
|
10696
10701
|
!!((_b = window.Zonos) === null || _b === void 0 ? void 0 : _b.debug);
|
|
10697
|
-
|
|
10698
|
-
|
|
10702
|
+
const isTest = handleFetch.getIsTestMode() || handleFetch.getIsStagingMode();
|
|
10703
|
+
if ((isTest || isDevelopment) &&
|
|
10704
|
+
// if found, it means we want to test the conversion event in development site, or test mode and staging mode
|
|
10699
10705
|
!window.Zonos.zonosConversionTest) {
|
|
10700
10706
|
return;
|
|
10701
10707
|
}
|
package/dist/cjs/index.cjs.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const handleFetch = require('./handleFetch-969d05d8.js');
|
|
6
|
-
const CheckoutConfig = require('./CheckoutConfig-
|
|
6
|
+
const CheckoutConfig = require('./CheckoutConfig-f1442a60.js');
|
|
7
7
|
const TaxId = require('./TaxId-4632639d.js');
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -129,7 +129,7 @@ const getZonosQaUrl = () => {
|
|
|
129
129
|
return null;
|
|
130
130
|
}
|
|
131
131
|
const qaUrl = extractZonosQaUrl(window.location.href);
|
|
132
|
-
const cdnUrl = "https://v1.3.
|
|
132
|
+
const cdnUrl = "https://v1.3.176.js.zonos.com";
|
|
133
133
|
// when the qaUrl is not set and the built URL is from the test domain, use the test domain for testing
|
|
134
134
|
if (!qaUrl &&
|
|
135
135
|
(cdnUrl.includes('test.') ||
|
|
@@ -296,6 +296,58 @@ const getCartIdFromQueryParam = () => {
|
|
|
296
296
|
return cartId;
|
|
297
297
|
};
|
|
298
298
|
|
|
299
|
+
const getCartInfoById = async ({ cartId, retries, }) => {
|
|
300
|
+
const isTestMode = handleFetch.getIsTestMode();
|
|
301
|
+
const { errors, json, zonosMode } = await handleFetch.handleFetch('/api/zonos-elements/get-cart', {
|
|
302
|
+
body: {
|
|
303
|
+
isTestMode,
|
|
304
|
+
tempCartUUID: cartId,
|
|
305
|
+
},
|
|
306
|
+
headers: {
|
|
307
|
+
'Content-Type': 'application/json',
|
|
308
|
+
},
|
|
309
|
+
method: 'POST',
|
|
310
|
+
});
|
|
311
|
+
const failedResponse = !json || errors.length;
|
|
312
|
+
if (failedResponse && retries) {
|
|
313
|
+
handleFetch.log('[ZONOS - loadZonos] temp cart not ready, retrying in 1 second', 'info', {
|
|
314
|
+
retries,
|
|
315
|
+
});
|
|
316
|
+
// wait 1 second before retrying
|
|
317
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
318
|
+
return getCartInfoById({ cartId, retries: retries - 1 });
|
|
319
|
+
}
|
|
320
|
+
if (failedResponse) {
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
return Object.assign(Object.assign({}, json), { zonosMode });
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
const setupCartDataWithSettings = async (cartId) => {
|
|
327
|
+
const { isDgsCartId, isLegacyCartId } = CheckoutConfig._getIsValidCartId(cartId);
|
|
328
|
+
if (!isLegacyCartId && !isDgsCartId) {
|
|
329
|
+
handleFetch.logError('[ZONOS - loadZonos] invalid cart id');
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
const tempCartResult = await getCartInfoById({ cartId, retries: 5 });
|
|
333
|
+
handleFetch.log('[ZONOS - loadZonos] getting temp cart data', 'info', tempCartResult);
|
|
334
|
+
if (!tempCartResult) {
|
|
335
|
+
handleFetch.logError('[ZONOS - loadZonos] Error getting temp cart data, stop checkout process.');
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
window.Zonos.storeId = tempCartResult.cartData.storeId;
|
|
339
|
+
window.Zonos.zonosApiKey = tempCartResult.cartData.credentialToken;
|
|
340
|
+
window.Zonos.zonosMode = tempCartResult.zonosMode;
|
|
341
|
+
return {
|
|
342
|
+
cartData: tempCartResult.cartData,
|
|
343
|
+
settings: tempCartResult.settings,
|
|
344
|
+
storeFavicon: tempCartResult.storeFaviconUrl,
|
|
345
|
+
storeId: tempCartResult.cartData.storeId,
|
|
346
|
+
storeLogo: tempCartResult.storeLogoUrl,
|
|
347
|
+
zonosApiKey: tempCartResult.cartData.credentialToken,
|
|
348
|
+
};
|
|
349
|
+
};
|
|
350
|
+
|
|
299
351
|
var _a;
|
|
300
352
|
/**
|
|
301
353
|
* Get the load version and url based on the loadScriptSrc, if the domain that used to load `zonos.js` is in white listed domains, use currentLoadScriptUrl as the load url instead, if zonosQaUrl exists, it would also fall under the white listed domain
|
|
@@ -313,16 +365,17 @@ const zonosLoadUrl = (() => {
|
|
|
313
365
|
}
|
|
314
366
|
return null;
|
|
315
367
|
})();
|
|
316
|
-
const ZONOS_URL = "https://v1.3.
|
|
317
|
-
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.
|
|
318
|
-
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.3.
|
|
319
|
-
const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.
|
|
368
|
+
const ZONOS_URL = "https://v1.3.176.js.zonos.com";
|
|
369
|
+
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.176";
|
|
370
|
+
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.3.176";
|
|
371
|
+
const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.176";
|
|
320
372
|
const GOOGLE_FONT_URL = 'https://fonts.googleapis.com';
|
|
321
373
|
const GOOGLE_FONT_REGEX = /^https:\/\/fonts\.googleapis\.com/;
|
|
322
374
|
class Zonos {
|
|
323
375
|
}
|
|
324
376
|
_a = Zonos;
|
|
325
377
|
Zonos.doneInit = false;
|
|
378
|
+
Zonos.cartSettings = null;
|
|
326
379
|
// if query 'zonosDebug=1' param from url, debug mode is on
|
|
327
380
|
Zonos.debug = typeof window !== 'undefined' &&
|
|
328
381
|
!!window.location.search.match(/\?.*(&*)zonosDebug=1/);
|
|
@@ -330,7 +383,7 @@ Zonos.zonosConversionTest = typeof window !== 'undefined' &&
|
|
|
330
383
|
!!window.location.search.match(/\?.*(&*)zonosConversionTest/);
|
|
331
384
|
Zonos._paypalMockResponse = null;
|
|
332
385
|
Zonos.isBigCommerce = false;
|
|
333
|
-
Zonos.releaseDate = "
|
|
386
|
+
Zonos.releaseDate = "1743432435915";
|
|
334
387
|
Zonos.isLegacyCheckout = false;
|
|
335
388
|
Zonos.domain = typeof window !== 'undefined'
|
|
336
389
|
? // domain that embeds the iframe
|
|
@@ -346,10 +399,11 @@ Zonos.showBaseForeign = typeof window !== 'undefined' &&
|
|
|
346
399
|
Zonos.isNpm = true;
|
|
347
400
|
Zonos.zonosQaUrl = null;
|
|
348
401
|
Zonos.zonosQaUrlApi = null;
|
|
349
|
-
Zonos.version = `v${"1.3.
|
|
402
|
+
Zonos.version = `v${"1.3.176"}`;
|
|
350
403
|
Zonos.modeAlerted = false;
|
|
351
404
|
Zonos.cartData = null;
|
|
352
405
|
Zonos.paypal = null;
|
|
406
|
+
Zonos.zonosMode = null;
|
|
353
407
|
Zonos.getCurrentTimestamp = () => new Date().getTime();
|
|
354
408
|
Zonos.zonosController = null;
|
|
355
409
|
Zonos.loadTimeApiInfoList = [];
|
|
@@ -399,13 +453,14 @@ Zonos.init = async (params) => {
|
|
|
399
453
|
*/
|
|
400
454
|
if (!_a.cartData && _a.cartId) {
|
|
401
455
|
handleFetch.log('Initialize cart data');
|
|
402
|
-
const
|
|
403
|
-
if (!
|
|
456
|
+
const cartInfo = await setupCartDataWithSettings(_a.cartId);
|
|
457
|
+
if (!cartInfo) {
|
|
404
458
|
handleFetch.logError('Failed to get cart data');
|
|
405
459
|
return;
|
|
406
460
|
}
|
|
407
|
-
_a.cartData =
|
|
408
|
-
_a.zonosApiKey =
|
|
461
|
+
_a.cartData = cartInfo.cartData;
|
|
462
|
+
_a.zonosApiKey = cartInfo.zonosApiKey;
|
|
463
|
+
_a.cartSettings = cartInfo.settings;
|
|
409
464
|
}
|
|
410
465
|
// Try to request for test API key if the API key is production but query param isTestMode is provided
|
|
411
466
|
const testPublicCredential = await getWithTestPublicCredential();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const zonosStore = require('./zonosStore-3812b318.js');
|
|
4
|
-
const cart = require('./cart-
|
|
4
|
+
const cart = require('./cart-e648a65f.js');
|
|
5
5
|
const handleFetch = require('./handleFetch-969d05d8.js');
|
|
6
6
|
const isDarkColor = require('./isDarkColor-ec4a4e7d.js');
|
|
7
7
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-2f90486e.js');
|
|
6
|
-
const cart = require('./cart-
|
|
6
|
+
const cart = require('./cart-e648a65f.js');
|
|
7
7
|
const zonosStore = require('./zonosStore-3812b318.js');
|
|
8
8
|
const handleFetch = require('./handleFetch-969d05d8.js');
|
|
9
9
|
const containsNonLatinChars = require('./containsNonLatinChars-2be5129b.js');
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-2f90486e.js');
|
|
6
|
-
const cart = require('./cart-
|
|
6
|
+
const cart = require('./cart-e648a65f.js');
|
|
7
7
|
const classes = require('./classes-b7918f56.js');
|
|
8
|
-
const paypal = require('./paypal-
|
|
8
|
+
const paypal = require('./paypal-2390cfb2.js');
|
|
9
9
|
const zonosStore = require('./zonosStore-3812b318.js');
|
|
10
10
|
const handleFetch = require('./handleFetch-969d05d8.js');
|
|
11
11
|
const createCustomEvent = require('./createCustomEvent-7b6fad95.js');
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-2f90486e.js');
|
|
6
|
-
const cart = require('./cart-
|
|
7
|
-
const paypal = require('./paypal-
|
|
6
|
+
const cart = require('./cart-e648a65f.js');
|
|
7
|
+
const paypal = require('./paypal-2390cfb2.js');
|
|
8
8
|
const zonosStore = require('./zonosStore-3812b318.js');
|
|
9
9
|
const handleFetch = require('./handleFetch-969d05d8.js');
|
|
10
10
|
const classes = require('./classes-b7918f56.js');
|
|
@@ -12,7 +12,7 @@ const createCustomEvent = require('./createCustomEvent-7b6fad95.js');
|
|
|
12
12
|
const getBorderRadius = require('./getBorderRadius-94ef609c.js');
|
|
13
13
|
const isDarkColor = require('./isDarkColor-ec4a4e7d.js');
|
|
14
14
|
const styles = require('./styles-d1e64fb9.js');
|
|
15
|
-
const CheckoutConfig = require('./CheckoutConfig-
|
|
15
|
+
const CheckoutConfig = require('./CheckoutConfig-f1442a60.js');
|
|
16
16
|
const RemoveIcon = require('./RemoveIcon-081ac073.js');
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -250,6 +250,59 @@ const sendLoadNativeCheckoutLog = async ({ loadTime, }) => {
|
|
|
250
250
|
});
|
|
251
251
|
};
|
|
252
252
|
|
|
253
|
+
const getTempCartById = async ({ cartId, retries, }) => {
|
|
254
|
+
const isTestMode = handleFetch.getIsTestMode();
|
|
255
|
+
const { errors, json } = await handleFetch.handleFetch('/api/zonos-elements/get-temp-cart', {
|
|
256
|
+
body: {
|
|
257
|
+
isTestMode,
|
|
258
|
+
options: {
|
|
259
|
+
noOnlineStoreSettings: true,
|
|
260
|
+
},
|
|
261
|
+
tempCartUUID: cartId,
|
|
262
|
+
},
|
|
263
|
+
headers: {
|
|
264
|
+
'Content-Type': 'application/json',
|
|
265
|
+
},
|
|
266
|
+
method: 'POST',
|
|
267
|
+
});
|
|
268
|
+
const failedResponse = !json || errors.length;
|
|
269
|
+
if (failedResponse && retries) {
|
|
270
|
+
handleFetch.log('[ZONOS - loadZonos] temp cart not ready, retrying in 1 second', 'info', {
|
|
271
|
+
retries,
|
|
272
|
+
});
|
|
273
|
+
// wait 1 second before retrying
|
|
274
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
275
|
+
return getTempCartById({ cartId, retries: retries - 1 });
|
|
276
|
+
}
|
|
277
|
+
if (failedResponse) {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
return json;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const setupCartData = async (cartId) => {
|
|
284
|
+
const { isDgsCartId, isLegacyCartId } = CheckoutConfig._getIsValidCartId(cartId);
|
|
285
|
+
if (!isLegacyCartId && !isDgsCartId) {
|
|
286
|
+
handleFetch.logError('[ZONOS - loadZonos] invalid cart id');
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
const tempCartResult = await getTempCartById({ cartId, retries: 5 });
|
|
290
|
+
handleFetch.log('[ZONOS - loadZonos] getting temp cart data', 'info', tempCartResult);
|
|
291
|
+
if (!tempCartResult) {
|
|
292
|
+
handleFetch.logError('[ZONOS - loadZonos] Error getting temp cart data, stop checkout process.');
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
window.Zonos.storeId = tempCartResult.cartData.storeId;
|
|
296
|
+
window.Zonos.zonosApiKey = tempCartResult.cartData.credentialToken;
|
|
297
|
+
return {
|
|
298
|
+
cartData: tempCartResult.cartData,
|
|
299
|
+
storeFavicon: tempCartResult.storeFaviconUrl,
|
|
300
|
+
storeId: tempCartResult.cartData.storeId,
|
|
301
|
+
storeLogo: tempCartResult.storeLogoUrl,
|
|
302
|
+
zonosApiKey: tempCartResult.cartData.credentialToken,
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
|
|
253
306
|
const MessageIcon = `<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="https://www.w3.org/2000/svg">
|
|
254
307
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M2.25 4.5C2.25 3.25736 3.25736 2.25 4.5 2.25H13.5C14.7426 2.25 15.75 3.25736 15.75 4.5V10.5C15.75 11.7426 14.7426 12.75 13.5 12.75H8.25C8.01393 12.75 7.79164 12.8611 7.65 13.05L6.3 14.85C5.87508 15.4166 5.2082 15.75 4.5 15.75C3.25736 15.75 2.25 14.7426 2.25 13.5V4.5ZM4.5 3.75C4.08579 3.75 3.75 4.08579 3.75 4.5V13.5C3.75 13.9142 4.08579 14.25 4.5 14.25C4.73607 14.25 4.95836 14.1389 5.1 13.95L6.45 12.15C6.87492 11.5834 7.5418 11.25 8.25 11.25H13.5C13.9142 11.25 14.25 10.9142 14.25 10.5V4.5C14.25 4.08579 13.9142 3.75 13.5 3.75H4.5ZM5.25 6C5.25 5.58579 5.58579 5.25 6 5.25H12C12.4142 5.25 12.75 5.58579 12.75 6C12.75 6.41421 12.4142 6.75 12 6.75H6C5.58579 6.75 5.25 6.41421 5.25 6ZM5.25 9C5.25 8.58579 5.58579 8.25 6 8.25H8.25C8.66421 8.25 9 8.58579 9 9C9 9.41421 8.66421 9.75 8.25 9.75H6C5.58579 9.75 5.25 9.41421 5.25 9Z" fill="#4D505A"/>
|
|
255
308
|
</svg>
|
|
@@ -509,7 +562,7 @@ const ZonosCheckout = class {
|
|
|
509
562
|
cartId = cartIdResult;
|
|
510
563
|
}
|
|
511
564
|
window.Zonos.cartId = cartId;
|
|
512
|
-
const cartResult = await
|
|
565
|
+
const cartResult = await setupCartData(cartId);
|
|
513
566
|
const cartData = cartResult === null || cartResult === void 0 ? void 0 : cartResult.cartData;
|
|
514
567
|
if (!cartData) {
|
|
515
568
|
handleFetch.logError('Failed to build cart, please try again.');
|
|
@@ -3,13 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-2f90486e.js');
|
|
6
|
-
const cart = require('./cart-
|
|
6
|
+
const cart = require('./cart-e648a65f.js');
|
|
7
7
|
const zonosStore = require('./zonosStore-3812b318.js');
|
|
8
8
|
const handleFetch = require('./handleFetch-969d05d8.js');
|
|
9
9
|
require('./isDarkColor-ec4a4e7d.js');
|
|
10
10
|
require('./getBorderRadius-94ef609c.js');
|
|
11
11
|
|
|
12
12
|
const getZonosSettings = async () => {
|
|
13
|
+
if (window.Zonos.cartSettings) {
|
|
14
|
+
return {
|
|
15
|
+
errors: [],
|
|
16
|
+
json: window.Zonos.cartSettings,
|
|
17
|
+
zonosMode: window.Zonos.zonosMode,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
13
20
|
const { errors, json, zonosMode } = await handleFetch.handleFetch('/api/zonos-elements/zonos-settings');
|
|
14
21
|
if (errors.length) {
|
|
15
22
|
handleFetch.logError(`Error occurred when getting zonos settings. If this is not an unauthorized error, it will use user settings or default settings`);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-2f90486e.js');
|
|
6
|
-
const cart = require('./cart-
|
|
6
|
+
const cart = require('./cart-e648a65f.js');
|
|
7
7
|
const zonosStore = require('./zonosStore-3812b318.js');
|
|
8
8
|
const classes = require('./classes-b7918f56.js');
|
|
9
9
|
require('./handleFetch-969d05d8.js');
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-2f90486e.js');
|
|
6
|
-
const cart = require('./cart-
|
|
6
|
+
const cart = require('./cart-e648a65f.js');
|
|
7
7
|
const zonosStore = require('./zonosStore-3812b318.js');
|
|
8
8
|
const formatStringWithLinks = require('./formatStringWithLinks-52341fc7.js');
|
|
9
9
|
const isDarkColor = require('./isDarkColor-ec4a4e7d.js');
|
|
@@ -6,9 +6,9 @@ const index = require('./index-2f90486e.js');
|
|
|
6
6
|
const zonosStore = require('./zonosStore-3812b318.js');
|
|
7
7
|
const classes = require('./classes-b7918f56.js');
|
|
8
8
|
const getBorderRadius = require('./getBorderRadius-94ef609c.js');
|
|
9
|
-
const cart = require('./cart-
|
|
9
|
+
const cart = require('./cart-e648a65f.js');
|
|
10
10
|
const handleFetch = require('./handleFetch-969d05d8.js');
|
|
11
|
-
const paypal = require('./paypal-
|
|
11
|
+
const paypal = require('./paypal-2390cfb2.js');
|
|
12
12
|
require('./isDarkColor-ec4a4e7d.js');
|
|
13
13
|
|
|
14
14
|
const PaymentEmptyStateDarkIcon = `<svg width="536" height="200" viewBox="0 0 536 200" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-2f90486e.js');
|
|
6
|
-
const cart = require('./cart-
|
|
6
|
+
const cart = require('./cart-e648a65f.js');
|
|
7
7
|
const zonosStore = require('./zonosStore-3812b318.js');
|
|
8
8
|
const classes = require('./classes-b7918f56.js');
|
|
9
9
|
const formatStringWithLinks = require('./formatStringWithLinks-52341fc7.js');
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const index = require('./index-2f90486e.js');
|
|
6
6
|
const zonosStore = require('./zonosStore-3812b318.js');
|
|
7
|
-
const cart = require('./cart-
|
|
7
|
+
const cart = require('./cart-e648a65f.js');
|
|
8
8
|
const classes = require('./classes-b7918f56.js');
|
|
9
9
|
const handleFetch = require('./handleFetch-969d05d8.js');
|
|
10
10
|
const getHasMoreSpaceOnRight = require('./getHasMoreSpaceOnRight-4c94667f.js');
|
|
@@ -430,7 +430,7 @@ const getProductsOnPage = () => {
|
|
|
430
430
|
var _a, _b;
|
|
431
431
|
const { productAddToCartElementSelector, productDescriptionElementSelector, productTitleElementSelector, restrictionBehavior, } = zonosStore.zonosStore.helloSettings;
|
|
432
432
|
if (!productTitleElementSelector || !productDescriptionElementSelector) {
|
|
433
|
-
handleFetch.
|
|
433
|
+
handleFetch.log(`Hello could not check item restrictions - must provide title and description selectors.`);
|
|
434
434
|
}
|
|
435
435
|
const titleNodes = (productTitleElementSelector &&
|
|
436
436
|
cart.isValidSelector(productTitleElementSelector) &&
|
|
@@ -442,7 +442,7 @@ const getProductsOnPage = () => {
|
|
|
442
442
|
[];
|
|
443
443
|
if (titleNodes.length !== descriptionNodes.length) {
|
|
444
444
|
// If the title and description selectors don't match, kill item restrictions altogether
|
|
445
|
-
handleFetch.
|
|
445
|
+
handleFetch.log('Hello could not check item restrictions - Title and description selectors do not match');
|
|
446
446
|
return [];
|
|
447
447
|
}
|
|
448
448
|
const shouldDisableCart = restrictionBehavior === 'RESTRICT_AND_BLOCK';
|
|
@@ -453,7 +453,7 @@ const getProductsOnPage = () => {
|
|
|
453
453
|
[];
|
|
454
454
|
if (shouldDisableCart && cartButtonNodes.length !== descriptionNodes.length) {
|
|
455
455
|
// If the "add to cart" selectors don't match, log the error and continue
|
|
456
|
-
handleFetch.
|
|
456
|
+
handleFetch.log('Hello could not disable "Add to cart" buttons - Title and add to cart selectors do not match');
|
|
457
457
|
}
|
|
458
458
|
const mergedElements = [];
|
|
459
459
|
for (let i = 0; i < titleNodes.length; i++) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-2f90486e.js');
|
|
6
|
-
const cart = require('./cart-
|
|
6
|
+
const cart = require('./cart-e648a65f.js');
|
|
7
7
|
const zonosStore = require('./zonosStore-3812b318.js');
|
|
8
8
|
const ILanguage = require('./ILanguage-98b04442.js');
|
|
9
9
|
require('./handleFetch-969d05d8.js');
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { handleFetch } from "../handleFetch";
|
|
2
2
|
import { logError } from "../logging/logError";
|
|
3
3
|
export const getShippingZones = async () => {
|
|
4
|
-
var _a, _b;
|
|
4
|
+
var _a, _b, _c;
|
|
5
|
+
if ((_a = window.Zonos.cartSettings) === null || _a === void 0 ? void 0 : _a.shippingZones) {
|
|
6
|
+
return window.Zonos.cartSettings.shippingZones
|
|
7
|
+
.flatMap(zone => zone === null || zone === void 0 ? void 0 : zone.countryCodes)
|
|
8
|
+
.filter(Boolean);
|
|
9
|
+
}
|
|
5
10
|
const { errors, json } = await handleFetch('/api/zonos-elements/shipping-zones');
|
|
6
11
|
if (errors.length || !json) {
|
|
7
|
-
logError(`Error fetching shipping zones: ${(
|
|
12
|
+
logError(`Error fetching shipping zones: ${(_b = errors.find(Boolean)) === null || _b === void 0 ? void 0 : _b.message}`);
|
|
8
13
|
return null;
|
|
9
14
|
}
|
|
10
|
-
const shippingZones = (
|
|
15
|
+
const shippingZones = (_c = json === null || json === void 0 ? void 0 : json.shippingZones) === null || _c === void 0 ? void 0 : _c.flatMap(zone => zone === null || zone === void 0 ? void 0 : zone.countryCodes).filter(Boolean);
|
|
11
16
|
return shippingZones || null;
|
|
12
17
|
};
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { handleFetch } from "../handleFetch";
|
|
2
2
|
import { logError } from "../logging/logError";
|
|
3
3
|
export const getZonosSettings = async () => {
|
|
4
|
+
if (window.Zonos.cartSettings) {
|
|
5
|
+
return {
|
|
6
|
+
errors: [],
|
|
7
|
+
json: window.Zonos.cartSettings,
|
|
8
|
+
zonosMode: window.Zonos.zonosMode,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
4
11
|
const { errors, json, zonosMode } = await handleFetch('/api/zonos-elements/zonos-settings');
|
|
5
12
|
if (errors.length) {
|
|
6
13
|
logError(`Error occurred when getting zonos settings. If this is not an unauthorized error, it will use user settings or default settings`);
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { cartStore } from "../../store/checkout/cart";
|
|
2
2
|
import { localizationStore } from "../../store/hello/localization";
|
|
3
3
|
import { zonosStore } from "../../store/zonosStore";
|
|
4
|
+
import { getIsStagingMode } from "../checkout/getIsStagingMode";
|
|
5
|
+
import { getIsTestMode } from "../checkout/getIsTestMode";
|
|
4
6
|
import { handleFetch } from "../handleFetch";
|
|
5
7
|
export const trackConversionEvent = async (eventName, metadata) => {
|
|
6
8
|
var _a, _b;
|
|
7
9
|
const isDevelopment = window.location.href.includes('zonos.com') ||
|
|
8
10
|
!!((_a = window.Zonos) === null || _a === void 0 ? void 0 : _a.zonosQaUrl) ||
|
|
9
11
|
!!((_b = window.Zonos) === null || _b === void 0 ? void 0 : _b.debug);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
const isTest = getIsTestMode() || getIsStagingMode();
|
|
13
|
+
if ((isTest || isDevelopment) &&
|
|
14
|
+
// if found, it means we want to test the conversion event in development site, or test mode and staging mode
|
|
12
15
|
!window.Zonos.zonosConversionTest) {
|
|
13
16
|
return;
|
|
14
17
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { zonosStore } from "../../store/zonosStore";
|
|
2
2
|
import { isValidSelector } from "../isValidSelector";
|
|
3
|
-
import {
|
|
3
|
+
import { log } from "../logging/log";
|
|
4
4
|
export const getProductsOnPage = () => {
|
|
5
5
|
var _a, _b;
|
|
6
6
|
const { productAddToCartElementSelector, productDescriptionElementSelector, productTitleElementSelector, restrictionBehavior, } = zonosStore.helloSettings;
|
|
7
7
|
if (!productTitleElementSelector || !productDescriptionElementSelector) {
|
|
8
|
-
|
|
8
|
+
log(`Hello could not check item restrictions - must provide title and description selectors.`);
|
|
9
9
|
}
|
|
10
10
|
const titleNodes = (productTitleElementSelector &&
|
|
11
11
|
isValidSelector(productTitleElementSelector) &&
|
|
@@ -17,7 +17,7 @@ export const getProductsOnPage = () => {
|
|
|
17
17
|
[];
|
|
18
18
|
if (titleNodes.length !== descriptionNodes.length) {
|
|
19
19
|
// If the title and description selectors don't match, kill item restrictions altogether
|
|
20
|
-
|
|
20
|
+
log('Hello could not check item restrictions - Title and description selectors do not match');
|
|
21
21
|
return [];
|
|
22
22
|
}
|
|
23
23
|
const shouldDisableCart = restrictionBehavior === 'RESTRICT_AND_BLOCK';
|
|
@@ -28,7 +28,7 @@ export const getProductsOnPage = () => {
|
|
|
28
28
|
[];
|
|
29
29
|
if (shouldDisableCart && cartButtonNodes.length !== descriptionNodes.length) {
|
|
30
30
|
// If the "add to cart" selectors don't match, log the error and continue
|
|
31
|
-
|
|
31
|
+
log('Hello could not disable "Add to cart" buttons - Title and add to cart selectors do not match');
|
|
32
32
|
}
|
|
33
33
|
const mergedElements = [];
|
|
34
34
|
for (let i = 0; i < titleNodes.length; i++) {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getIsTestMode } from "../components/utils/checkout/getIsTestMode";
|
|
2
|
+
import { handleFetch } from "../components/utils/handleFetch";
|
|
3
|
+
import { log } from "../components/utils/logging/log";
|
|
4
|
+
export const getCartInfoById = async ({ cartId, retries, }) => {
|
|
5
|
+
const isTestMode = getIsTestMode();
|
|
6
|
+
const { errors, json, zonosMode } = await handleFetch('/api/zonos-elements/get-cart', {
|
|
7
|
+
body: {
|
|
8
|
+
isTestMode,
|
|
9
|
+
tempCartUUID: cartId,
|
|
10
|
+
},
|
|
11
|
+
headers: {
|
|
12
|
+
'Content-Type': 'application/json',
|
|
13
|
+
},
|
|
14
|
+
method: 'POST',
|
|
15
|
+
});
|
|
16
|
+
const failedResponse = !json || errors.length;
|
|
17
|
+
if (failedResponse && retries) {
|
|
18
|
+
log('[ZONOS - loadZonos] temp cart not ready, retrying in 1 second', 'info', {
|
|
19
|
+
retries,
|
|
20
|
+
});
|
|
21
|
+
// wait 1 second before retrying
|
|
22
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
23
|
+
return getCartInfoById({ cartId, retries: retries - 1 });
|
|
24
|
+
}
|
|
25
|
+
if (failedResponse) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return Object.assign(Object.assign({}, json), { zonosMode });
|
|
29
|
+
};
|
|
@@ -7,7 +7,7 @@ import { getWithTestPublicCredential } from "./_getWithTestPublicCredential";
|
|
|
7
7
|
import { getZonosQaUrl } from "./_getZonosQaUrl";
|
|
8
8
|
import { zonosLoadStripe } from "./_loadStripe";
|
|
9
9
|
import { getCartIdFromQueryParam } from "./cart/_getCartIdFromParam";
|
|
10
|
-
import {
|
|
10
|
+
import { setupCartDataWithSettings } from "./cart/_setupCartDataWithSettings";
|
|
11
11
|
import { checkoutHiddenBtnSelector, } from "../types/checkout/CheckoutConfig";
|
|
12
12
|
/**
|
|
13
13
|
* Get the load version and url based on the loadScriptSrc, if the domain that used to load `zonos.js` is in white listed domains, use currentLoadScriptUrl as the load url instead, if zonosQaUrl exists, it would also fall under the white listed domain
|
|
@@ -35,6 +35,7 @@ export class Zonos {
|
|
|
35
35
|
}
|
|
36
36
|
_a = Zonos;
|
|
37
37
|
Zonos.doneInit = false;
|
|
38
|
+
Zonos.cartSettings = null;
|
|
38
39
|
// if query 'zonosDebug=1' param from url, debug mode is on
|
|
39
40
|
Zonos.debug = typeof window !== 'undefined' &&
|
|
40
41
|
!!window.location.search.match(/\?.*(&*)zonosDebug=1/);
|
|
@@ -62,6 +63,7 @@ Zonos.version = `v${process.env.NEXT_PUBLIC_ZONOS_PACKAGE_VERSION}`;
|
|
|
62
63
|
Zonos.modeAlerted = false;
|
|
63
64
|
Zonos.cartData = null;
|
|
64
65
|
Zonos.paypal = null;
|
|
66
|
+
Zonos.zonosMode = null;
|
|
65
67
|
Zonos.getCurrentTimestamp = () => new Date().getTime();
|
|
66
68
|
Zonos.zonosController = null;
|
|
67
69
|
Zonos.loadTimeApiInfoList = [];
|
|
@@ -111,13 +113,14 @@ Zonos.init = async (params) => {
|
|
|
111
113
|
*/
|
|
112
114
|
if (!_a.cartData && _a.cartId) {
|
|
113
115
|
log('Initialize cart data');
|
|
114
|
-
const
|
|
115
|
-
if (!
|
|
116
|
+
const cartInfo = await setupCartDataWithSettings(_a.cartId);
|
|
117
|
+
if (!cartInfo) {
|
|
116
118
|
logError('Failed to get cart data');
|
|
117
119
|
return;
|
|
118
120
|
}
|
|
119
|
-
_a.cartData =
|
|
120
|
-
_a.zonosApiKey =
|
|
121
|
+
_a.cartData = cartInfo.cartData;
|
|
122
|
+
_a.zonosApiKey = cartInfo.zonosApiKey;
|
|
123
|
+
_a.cartSettings = cartInfo.settings;
|
|
121
124
|
}
|
|
122
125
|
// Try to request for test API key if the API key is production but query param isTestMode is provided
|
|
123
126
|
const testPublicCredential = await getWithTestPublicCredential();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { log } from "../../components/utils/logging/log";
|
|
2
|
+
import { logError } from "../../components/utils/logging/logError";
|
|
3
|
+
import { getCartInfoById } from "../_getCartInfoBy";
|
|
4
|
+
import { _getIsValidCartId } from "./_getIsValidCart";
|
|
5
|
+
export const setupCartDataWithSettings = async (cartId) => {
|
|
6
|
+
const { isDgsCartId, isLegacyCartId } = _getIsValidCartId(cartId);
|
|
7
|
+
if (!isLegacyCartId && !isDgsCartId) {
|
|
8
|
+
logError('[ZONOS - loadZonos] invalid cart id');
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const tempCartResult = await getCartInfoById({ cartId, retries: 5 });
|
|
12
|
+
log('[ZONOS - loadZonos] getting temp cart data', 'info', tempCartResult);
|
|
13
|
+
if (!tempCartResult) {
|
|
14
|
+
logError('[ZONOS - loadZonos] Error getting temp cart data, stop checkout process.');
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
window.Zonos.storeId = tempCartResult.cartData.storeId;
|
|
18
|
+
window.Zonos.zonosApiKey = tempCartResult.cartData.credentialToken;
|
|
19
|
+
window.Zonos.zonosMode = tempCartResult.zonosMode;
|
|
20
|
+
return {
|
|
21
|
+
cartData: tempCartResult.cartData,
|
|
22
|
+
settings: tempCartResult.settings,
|
|
23
|
+
storeFavicon: tempCartResult.storeFaviconUrl,
|
|
24
|
+
storeId: tempCartResult.cartData.storeId,
|
|
25
|
+
storeLogo: tempCartResult.storeLogoUrl,
|
|
26
|
+
zonosApiKey: tempCartResult.cartData.credentialToken,
|
|
27
|
+
};
|
|
28
|
+
};
|