@zonos/elements 1.3.201 → 1.3.202
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/VarianceTest-0cb1e118.js +12 -0
- package/dist/cjs/cart-637ba3d0.js +1943 -0
- package/dist/cjs/{debounce-d393fafe.js → debounce-94e1b7ff.js} +1 -1
- package/dist/cjs/{getBorderRadius-3d0a563e.js → getBorderRadius-8d3b1049.js} +1 -1
- package/dist/cjs/index.cjs.js +10 -8
- package/dist/cjs/{isDarkColor-92a10a85.js → isDarkColor-bcf49625.js} +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{cart-e73cde62.js → localization-2f17c95f.js} +74 -1941
- package/dist/cjs/{paypal-39bbbd1a.js → paypal-0eceff03.js} +10 -9
- package/dist/cjs/zonos-address_11.cjs.entry.js +98 -72
- package/dist/cjs/zonos-badge.cjs.entry.js +2 -1
- package/dist/cjs/zonos-banner.cjs.entry.js +2 -1
- package/dist/cjs/zonos-button_3.cjs.entry.js +4 -3
- package/dist/cjs/zonos-card.cjs.entry.js +3 -2
- package/dist/cjs/{zonos-cart-items_13.cjs.entry.js → zonos-cart-items_14.cjs.entry.js} +99 -80
- package/dist/cjs/zonos-checkout.cjs.entry.js +395 -50
- package/dist/cjs/zonos-collapse.cjs.entry.js +2 -1
- package/dist/cjs/zonos-component.cjs.entry.js +1 -1
- package/dist/cjs/zonos-controller.cjs.entry.js +13 -11
- package/dist/cjs/zonos-country-flag.cjs.entry.js +4 -5
- package/dist/cjs/zonos-country-select_4.cjs.entry.js +13 -13
- package/dist/cjs/zonos-elements.cjs.js +1 -1
- package/dist/cjs/zonos-empty-state-payment_4.cjs.entry.js +10 -8
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +41 -42
- package/dist/cjs/zonos-hello.cjs.entry.js +30 -31
- package/dist/cjs/zonos-input.cjs.entry.js +3 -2
- package/dist/cjs/zonos-language-select_2.cjs.entry.js +8 -9
- package/dist/cjs/zonos-logo.cjs.entry.js +4 -3
- package/dist/cjs/zonos-shipping-rich-radio.cjs.entry.js +3 -2
- package/dist/cjs/zonos-stripe-input.cjs.entry.js +8 -7
- package/dist/cjs/zonos-text.cjs.entry.js +2 -1
- package/dist/cjs/zonos-toggle.cjs.entry.js +4 -3
- package/dist/cjs/zonos-tooltip.cjs.entry.js +2 -2
- package/dist/cjs/zonos-v-stack.cjs.entry.js +4 -3
- package/dist/cjs/{zonosStore-c466b127.js → zonosStore-9264749e.js} +15 -5
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js +18 -17
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +235 -15
- package/dist/collection/components/checkout/zonos-checkout/zonos-customer-info/zonos-customer-info.js +3 -3
- package/dist/collection/components/checkout/zonos-checkout/zonos-shipping/zonos-shipping.js +2 -1
- package/dist/collection/components/common/zonos-loading-overlay/zonos-loading-overlay.css +62 -0
- package/dist/collection/components/common/zonos-loading-overlay/zonos-loading-overlay.js +90 -0
- package/dist/collection/components/common/zonos-logo/zonos-logo.js +2 -2
- package/dist/collection/components/common/zonos-rest-state/zonos-rest-state.js +3 -3
- package/dist/collection/components/common/zonos-select-dialog-header/zonos-select-dialog-header.js +2 -2
- package/dist/collection/components/common/zonos-stripe-input/zonos-stripe-input.js +4 -4
- package/dist/collection/components/common/zonos-stripe-phone-input/zonos-stripe-phone-input.js +5 -5
- package/dist/collection/components/common/zonos-stripe-select/zonos-stripe-select.js +5 -5
- package/dist/collection/components/common/zonos-toggle/zonos-toggle.js +2 -2
- package/dist/collection/components/common/zonos-tooltip/zonos-tooltip.js +2 -2
- package/dist/collection/components/common/zonos-v-stack/zonos-v-stack.js +2 -2
- package/dist/collection/components/common/zonos-virtual-scroll/zonos-virtual-scroll.js +2 -2
- package/dist/collection/components/component-template/zonos-component/zonos-component.js +1 -1
- package/dist/collection/components/hello/zonos-hello-dialog/zonos-hello-dialog-footer/zonos-hello-dialog-footer.js +2 -2
- package/dist/collection/components/hello/zonos-hello-dialog/zonos-hello-dialog.js +4 -4
- package/dist/collection/components/main/zonos-controller.js +3 -3
- package/dist/collection/components/paypal/zonos-paypal-payment.js +1 -1
- package/dist/collection/components/store/checkout/cart.js +15 -16
- package/dist/collection/components/store/checkout/paypal.js +2 -1
- package/dist/collection/components/store/checkout/stripe.js +16 -11
- package/dist/collection/components/store/hello/localization.js +5 -5
- package/dist/collection/components/store/storageStore.js +32 -0
- package/dist/collection/components/store/zonosStore.js +12 -6
- package/dist/collection/components/stripe/zonos-address/zonos-address.js +18 -6
- package/dist/collection/components/stripe/zonos-custom-address/zonos-address-suggestions/zonos-address-suggestions.js +2 -2
- package/dist/collection/components/stripe/zonos-custom-address/zonos-custom-address.js +19 -7
- package/dist/collection/components/stripe/zonos-payment/zonos-payment.js +3 -3
- package/dist/collection/components/utils/api/getCheckoutSession.js +3 -3
- package/dist/collection/components/utils/api/placeTestOrder.js +2 -1
- package/dist/collection/components/utils/api/prepCalculateLandedCost.js +3 -2
- package/dist/collection/components/utils/api/selectVarianceTest.js +20 -0
- package/dist/collection/components/utils/buildCartUrl.js +44 -0
- package/dist/collection/components/utils/getLegacyQueryParams.js +42 -0
- package/dist/collection/components/utils/varianceTest/filterExpiredTests.js +6 -0
- package/dist/collection/components/utils/varianceTest/filterValidTests.js +23 -0
- package/dist/collection/components/utils/varianceTest/getSelectedTestVariant.js +6 -0
- package/dist/collection/components/utils/varianceTest/hasAtLeastOneAvailableTestKey.js +14 -0
- package/dist/collection/components/utils/varianceTest/isInAvailableTestKey.js +4 -0
- package/dist/collection/components/utils/varianceTest/isTestEnabled.js +4 -0
- package/dist/collection/components/utils/varianceTest/isTestKeysAllVariantSelected.js +6 -0
- package/dist/collection/components/utils/varianceTest/mergeTest.js +13 -0
- package/dist/collection/scripts/_getZonosQaUrl.js +2 -2
- package/dist/collection/types/checkout/api/VarianceTest.js +8 -0
- package/dist/collection/types/generated/graphql.internal.types.js +12 -0
- package/dist/collection/types/index.js +1 -0
- package/dist/esm/VarianceTest-fef2d958.js +10 -0
- package/dist/esm/cart-b7c15b61.js +1907 -0
- package/dist/esm/{debounce-a2121722.js → debounce-3a9f27a0.js} +1 -1
- package/dist/esm/{getBorderRadius-413e97eb.js → getBorderRadius-78b28b4d.js} +1 -1
- package/dist/esm/index.js +9 -8
- package/dist/esm/{isDarkColor-4c7b2ffc.js → isDarkColor-31dd7dff.js} +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{cart-f79c8021.js → localization-bf7224aa.js} +70 -1907
- package/dist/esm/{paypal-6d4667d1.js → paypal-932fd3dd.js} +5 -4
- package/dist/esm/zonos-address_11.entry.js +54 -28
- package/dist/esm/zonos-badge.entry.js +2 -1
- package/dist/esm/zonos-banner.entry.js +2 -1
- package/dist/esm/zonos-button_3.entry.js +4 -3
- package/dist/esm/zonos-card.entry.js +3 -2
- package/dist/esm/{zonos-cart-items_13.entry.js → zonos-cart-items_14.entry.js} +48 -30
- package/dist/esm/zonos-checkout.entry.js +363 -18
- package/dist/esm/zonos-collapse.entry.js +2 -1
- package/dist/esm/zonos-component.entry.js +1 -1
- package/dist/esm/zonos-controller.entry.js +8 -6
- package/dist/esm/zonos-country-flag.entry.js +3 -4
- package/dist/esm/zonos-country-select_4.entry.js +8 -8
- package/dist/esm/zonos-elements.js +1 -1
- package/dist/esm/zonos-empty-state-payment_4.entry.js +10 -8
- package/dist/esm/zonos-hello-dialog.entry.js +7 -8
- package/dist/esm/zonos-hello.entry.js +4 -5
- package/dist/esm/zonos-input.entry.js +3 -2
- package/dist/esm/zonos-language-select_2.entry.js +5 -6
- package/dist/esm/zonos-logo.entry.js +4 -3
- package/dist/esm/zonos-shipping-rich-radio.entry.js +3 -2
- package/dist/esm/zonos-stripe-input.entry.js +8 -7
- package/dist/esm/zonos-text.entry.js +2 -1
- package/dist/esm/zonos-toggle.entry.js +4 -3
- package/dist/esm/zonos-tooltip.entry.js +2 -2
- package/dist/esm/zonos-v-stack.entry.js +4 -3
- package/dist/esm/{zonosStore-cdabc848.js → zonosStore-d10a829f.js} +15 -5
- package/dist/esm-es5/VarianceTest-fef2d958.js +1 -0
- package/dist/esm-es5/cart-b7c15b61.js +1 -0
- package/dist/esm-es5/{debounce-a2121722.js → debounce-3a9f27a0.js} +1 -1
- package/dist/esm-es5/{getBorderRadius-413e97eb.js → getBorderRadius-78b28b4d.js} +1 -1
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/{isDarkColor-4c7b2ffc.js → isDarkColor-31dd7dff.js} +1 -1
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/localization-bf7224aa.js +1 -0
- package/dist/esm-es5/{paypal-6d4667d1.js → paypal-932fd3dd.js} +2 -2
- package/dist/esm-es5/zonos-address_11.entry.js +1 -1
- package/dist/esm-es5/zonos-badge.entry.js +1 -1
- package/dist/esm-es5/zonos-banner.entry.js +1 -1
- package/dist/esm-es5/zonos-button_3.entry.js +1 -1
- package/dist/esm-es5/zonos-card.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_14.entry.js +1 -0
- package/dist/esm-es5/zonos-checkout.entry.js +1 -1
- package/dist/esm-es5/zonos-collapse.entry.js +1 -1
- package/dist/esm-es5/zonos-component.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-elements.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-input.entry.js +1 -1
- package/dist/esm-es5/zonos-language-select_2.entry.js +1 -1
- package/dist/esm-es5/zonos-logo.entry.js +1 -1
- package/dist/esm-es5/zonos-shipping-rich-radio.entry.js +1 -1
- package/dist/esm-es5/zonos-stripe-input.entry.js +1 -1
- package/dist/esm-es5/zonos-text.entry.js +1 -1
- package/dist/esm-es5/zonos-toggle.entry.js +1 -1
- package/dist/esm-es5/zonos-tooltip.entry.js +1 -1
- package/dist/esm-es5/zonos-v-stack.entry.js +1 -1
- package/dist/esm-es5/zonosStore-d10a829f.js +1 -0
- package/dist/scripts/index.d.ts +839 -765
- package/dist/scripts/index.js +1 -1
- package/dist/scripts/loadZonos.js +1 -1
- package/dist/scripts/zonos.js +1 -1
- package/dist/types/components/checkout/zonos-checkout/zonos-checkout.d.ts +16 -0
- package/dist/types/components/common/zonos-loading-overlay/zonos-loading-overlay.d.ts +16 -0
- package/dist/types/components/store/checkout/cart.d.ts +0 -1
- package/dist/types/components/store/checkout/stripe.d.ts +2 -2
- package/dist/types/components/store/hello/localization.d.ts +2 -2
- package/dist/types/components/store/storageStore.d.ts +13 -0
- package/dist/types/components/store/zonosStore.d.ts +7 -2
- package/dist/types/components/stripe/zonos-address/zonos-address.d.ts +2 -0
- package/dist/types/components/stripe/zonos-custom-address/zonos-custom-address.d.ts +2 -0
- package/dist/types/components/utils/api/selectVarianceTest.d.ts +6 -0
- package/dist/types/components/utils/buildCartUrl.d.ts +10 -0
- package/dist/types/components/utils/getLegacyQueryParams.d.ts +2 -0
- package/dist/types/components/utils/varianceTest/filterExpiredTests.d.ts +2 -0
- package/dist/types/components/utils/varianceTest/filterValidTests.d.ts +9 -0
- package/dist/types/components/utils/varianceTest/getSelectedTestVariant.d.ts +2 -0
- package/dist/types/components/utils/varianceTest/hasAtLeastOneAvailableTestKey.d.ts +8 -0
- package/dist/types/components/utils/varianceTest/isInAvailableTestKey.d.ts +2 -0
- package/dist/types/components/utils/varianceTest/isTestEnabled.d.ts +2 -0
- package/dist/types/components/utils/varianceTest/isTestKeysAllVariantSelected.d.ts +9 -0
- package/dist/types/components/utils/varianceTest/mergeTest.d.ts +5 -0
- package/dist/types/components.d.ts +51 -0
- package/dist/types/scripts/cart/_setupCartDataWithSettings.d.ts +7 -0
- package/dist/types/types/checkout/CheckoutConfig.d.ts +13 -1
- package/dist/types/types/checkout/api/CheckoutSession.d.ts +7 -0
- package/dist/types/types/checkout/api/VarianceTest.d.ts +30 -0
- package/dist/types/types/generated/graphql.internal.types.d.ts +163 -0
- package/dist/types/types/generated/graphql.internal.types.ts +199 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/utils/ZonosSettings.d.ts +7 -6
- package/dist/zonos-elements/assets/RemoveIcon.svg +1 -1
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/{p-609c32a3.system.entry.js → p-01987cb2.system.entry.js} +1 -1
- package/dist/zonos-elements/p-04a01cb1.js +1 -0
- package/dist/zonos-elements/p-04b43dd5.entry.js +1 -0
- package/dist/zonos-elements/p-0f77d087.system.entry.js +1 -0
- package/dist/zonos-elements/{p-7831b52c.system.entry.js → p-1dcdb65f.system.entry.js} +1 -1
- package/dist/zonos-elements/p-26a634a5.system.entry.js +1 -0
- package/dist/zonos-elements/p-27987298.system.entry.js +1 -0
- package/dist/zonos-elements/p-2af2eb6f.system.entry.js +1 -0
- package/dist/zonos-elements/p-2b8f787a.entry.js +1 -0
- package/dist/zonos-elements/p-30cfa524.entry.js +1 -0
- package/dist/zonos-elements/p-32320d9a.system.js +1 -0
- package/dist/zonos-elements/p-3284f459.system.entry.js +1 -0
- package/dist/zonos-elements/{p-13796f98.js → p-3d82a352.js} +1 -1
- package/dist/zonos-elements/p-452070af.system.entry.js +1 -0
- package/dist/zonos-elements/p-45ebc788.entry.js +1 -0
- package/dist/zonos-elements/p-4c81112f.entry.js +1 -0
- package/dist/zonos-elements/p-4efa8187.js +1 -0
- package/dist/zonos-elements/p-5170bc41.entry.js +1 -0
- package/dist/zonos-elements/p-5a2dd041.system.js +1 -0
- package/dist/zonos-elements/p-5c74e5c9.system.entry.js +1 -0
- package/dist/zonos-elements/p-5d0f7364.system.js +1 -0
- package/dist/zonos-elements/p-6a52a2bc.system.entry.js +1 -0
- package/dist/zonos-elements/p-715d0f59.system.entry.js +1 -0
- package/dist/zonos-elements/{p-b8d87932.js → p-72f37935.js} +1 -1
- package/dist/zonos-elements/p-7ae5cd60.entry.js +1 -0
- package/dist/zonos-elements/p-80bbd9c0.system.entry.js +1 -0
- package/dist/zonos-elements/p-851c642e.system.entry.js +1 -0
- package/dist/zonos-elements/{p-4300d944.entry.js → p-8d870d4c.entry.js} +1 -1
- package/dist/zonos-elements/p-98b65387.entry.js +1 -0
- package/dist/zonos-elements/p-9af5e93a.entry.js +1 -0
- package/dist/zonos-elements/p-aa1193bc.entry.js +1 -0
- package/dist/zonos-elements/{p-5de59662.js → p-aae60057.js} +2 -2
- package/dist/zonos-elements/p-ab176281.system.entry.js +1 -0
- package/dist/zonos-elements/p-b52aba52.entry.js +1 -0
- package/dist/zonos-elements/p-bc220d35.system.js +1 -0
- package/dist/zonos-elements/p-bc8bda92.entry.js +1 -0
- package/dist/zonos-elements/p-be5afc91.system.entry.js +1 -0
- package/dist/zonos-elements/p-bec2a3ce.entry.js +1 -0
- package/dist/zonos-elements/p-c291bac1.entry.js +1 -0
- package/dist/zonos-elements/p-c3d2422e.entry.js +1 -0
- package/dist/zonos-elements/{p-f28eb1dd.system.js → p-c50b3100.system.js} +1 -1
- package/dist/zonos-elements/p-c58acd4c.system.entry.js +1 -0
- package/dist/zonos-elements/p-c5fcbc92.system.entry.js +1 -0
- package/dist/zonos-elements/p-c767242b.entry.js +1 -0
- package/dist/zonos-elements/p-c9aa902e.system.entry.js +1 -0
- package/dist/zonos-elements/p-cb823c4d.system.js +1 -0
- package/dist/zonos-elements/{p-7d5d89f2.system.js → p-d2466fbd.system.js} +2 -2
- package/dist/zonos-elements/{p-d422ad1d.system.js → p-d42dfd32.system.js} +1 -1
- package/dist/zonos-elements/p-d46349d3.system.entry.js +1 -0
- package/dist/zonos-elements/p-d60ca44b.system.entry.js +1 -0
- package/dist/zonos-elements/{p-b2241919.entry.js → p-d6a10007.entry.js} +1 -1
- package/dist/zonos-elements/p-db025dfc.system.entry.js +1 -0
- package/dist/zonos-elements/p-db3968a2.js +1 -0
- package/dist/zonos-elements/p-dcd6acd4.system.entry.js +1 -0
- package/dist/zonos-elements/p-dd1cfa74.entry.js +1 -0
- package/dist/zonos-elements/p-df4c46a6.entry.js +1 -0
- package/dist/zonos-elements/{p-4593324c.js → p-e26c9e83.js} +1 -1
- package/dist/zonos-elements/p-e68d5219.entry.js +1 -0
- package/dist/zonos-elements/p-ea6d87a1.system.js +1 -1
- package/dist/zonos-elements/p-ef3e05e5.system.js +1 -0
- package/dist/zonos-elements/p-f255e822.js +1 -0
- package/dist/zonos-elements/p-f655ec36.entry.js +1 -0
- package/dist/zonos-elements/{p-e91b244c.entry.js → p-f891d470.entry.js} +1 -1
- package/dist/zonos-elements/p-f8d0d488.system.entry.js +1 -0
- package/dist/zonos-elements/{p-240ee490.system.entry.js → p-fbe36bc8.system.entry.js} +1 -1
- package/dist/zonos-elements/p-fcc2e712.entry.js +1 -0
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +1 -1
- package/dist/esm-es5/cart-f79c8021.js +0 -1
- package/dist/esm-es5/zonos-cart-items_13.entry.js +0 -1
- package/dist/esm-es5/zonosStore-cdabc848.js +0 -1
- package/dist/zonos-elements/p-0302a254.entry.js +0 -1
- package/dist/zonos-elements/p-06ed3582.system.js +0 -1
- package/dist/zonos-elements/p-147ca395.entry.js +0 -1
- package/dist/zonos-elements/p-1998d8b3.entry.js +0 -1
- package/dist/zonos-elements/p-1eddec23.entry.js +0 -1
- package/dist/zonos-elements/p-20030bf5.system.js +0 -1
- package/dist/zonos-elements/p-24a2e899.system.entry.js +0 -1
- package/dist/zonos-elements/p-264f46a5.entry.js +0 -1
- package/dist/zonos-elements/p-2882b9f4.entry.js +0 -1
- package/dist/zonos-elements/p-2c915112.system.entry.js +0 -1
- package/dist/zonos-elements/p-327aebf5.entry.js +0 -1
- package/dist/zonos-elements/p-33488109.system.entry.js +0 -1
- package/dist/zonos-elements/p-337fab4e.js +0 -1
- package/dist/zonos-elements/p-3ddecaa4.system.entry.js +0 -1
- package/dist/zonos-elements/p-48f70043.system.entry.js +0 -1
- package/dist/zonos-elements/p-49a31b14.system.entry.js +0 -1
- package/dist/zonos-elements/p-4cd867d5.js +0 -1
- package/dist/zonos-elements/p-55711b80.system.entry.js +0 -1
- package/dist/zonos-elements/p-578bf5d7.entry.js +0 -1
- package/dist/zonos-elements/p-5c061a35.entry.js +0 -1
- package/dist/zonos-elements/p-6096c1c5.entry.js +0 -1
- package/dist/zonos-elements/p-65a8f19d.entry.js +0 -1
- package/dist/zonos-elements/p-6adc6e27.entry.js +0 -1
- package/dist/zonos-elements/p-6cd9b6a1.system.entry.js +0 -1
- package/dist/zonos-elements/p-79070ee6.entry.js +0 -1
- package/dist/zonos-elements/p-7bb9c330.entry.js +0 -1
- package/dist/zonos-elements/p-82aa4f9f.system.entry.js +0 -1
- package/dist/zonos-elements/p-8540f3e2.system.entry.js +0 -1
- package/dist/zonos-elements/p-8a9d4605.system.entry.js +0 -1
- package/dist/zonos-elements/p-932bed54.system.entry.js +0 -1
- package/dist/zonos-elements/p-94e3e50d.system.entry.js +0 -1
- package/dist/zonos-elements/p-9f6dd86a.entry.js +0 -1
- package/dist/zonos-elements/p-a64ab131.system.entry.js +0 -1
- package/dist/zonos-elements/p-aac95779.system.entry.js +0 -1
- package/dist/zonos-elements/p-ad3c5358.entry.js +0 -1
- package/dist/zonos-elements/p-af6af82e.system.js +0 -1
- package/dist/zonos-elements/p-b66b3306.system.entry.js +0 -1
- package/dist/zonos-elements/p-b6afcf3f.system.entry.js +0 -1
- package/dist/zonos-elements/p-b8d91f99.entry.js +0 -1
- package/dist/zonos-elements/p-c770044a.system.entry.js +0 -1
- package/dist/zonos-elements/p-d4842d10.system.entry.js +0 -1
- package/dist/zonos-elements/p-d6c3aec8.system.entry.js +0 -1
- package/dist/zonos-elements/p-daf73a4c.system.js +0 -1
- package/dist/zonos-elements/p-de388ea0.entry.js +0 -1
- package/dist/zonos-elements/p-e14d89de.entry.js +0 -1
- package/dist/zonos-elements/p-f6e587bb.entry.js +0 -1
- package/dist/zonos-elements/p-f818bdf5.entry.js +0 -1
- package/dist/zonos-elements/p-fce6bffe.system.entry.js +0 -1
|
@@ -0,0 +1,1907 @@
|
|
|
1
|
+
import { z as zonosStore, c as createStore } from './zonosStore-d10a829f.js';
|
|
2
|
+
import { s as storageStore, l as localizationStore, t as translate, f as filterValidTests, b as storageStoreSetEnabledVariantTestKeys } from './localization-bf7224aa.js';
|
|
3
|
+
import { l as log, f as fallbackApiList, h as handleFetch, g as getIsTestMode, a as getIsStagingMode, s as sendErrorLog, d as allLogs, b as logError, j as jsonParse } from './handleFetch-621e45bc.js';
|
|
4
|
+
import { i as isDarkColor } from './isDarkColor-31dd7dff.js';
|
|
5
|
+
import { g as getBorderRadius } from './getBorderRadius-78b28b4d.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Extract value from translated object
|
|
9
|
+
*/
|
|
10
|
+
const getTranslatedAddress = ({ currentAddress, translatedAddress, }) => {
|
|
11
|
+
var _a, _b, _c, _d, _e, _f;
|
|
12
|
+
const { city, country, line1, line2, postal_code, state } = currentAddress.value.address;
|
|
13
|
+
const name = currentAddress.value.name ||
|
|
14
|
+
[currentAddress.value.firstName, currentAddress.value.lastName].join(' ');
|
|
15
|
+
return {
|
|
16
|
+
city: ((_a = translatedAddress.city) === null || _a === void 0 ? void 0 : _a[city]) || city,
|
|
17
|
+
country: country,
|
|
18
|
+
line1: ((_b = translatedAddress.line1) === null || _b === void 0 ? void 0 : _b[line1]) || line1,
|
|
19
|
+
line2: ((_c = translatedAddress.line2) === null || _c === void 0 ? void 0 : _c[line2 || '']) || line2 || '',
|
|
20
|
+
name: ((_d = translatedAddress.name) === null || _d === void 0 ? void 0 : _d[name]) || name,
|
|
21
|
+
phone: currentAddress.value.phone || '',
|
|
22
|
+
postal_code: ((_e = translatedAddress.postal_code) === null || _e === void 0 ? void 0 : _e[postal_code]) || postal_code,
|
|
23
|
+
state: ((_f = translatedAddress.state) === null || _f === void 0 ? void 0 : _f[state]) || state,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Similar to prepCalculateLandedCost except it only uses cart ID
|
|
28
|
+
*/
|
|
29
|
+
const prepCartCalculateLandedCost = (cartId) => {
|
|
30
|
+
var _a;
|
|
31
|
+
const isE2ETest = new URLSearchParams(window.location.search).get('zonosE2ETest') === '1';
|
|
32
|
+
// maybe we don't need email now for prefetch the landed cost
|
|
33
|
+
const stripeLinkData = stripeStore.stripeLinkEventData;
|
|
34
|
+
const stripeAddressData = stripeStore.stripeAddressEventData;
|
|
35
|
+
const stripeBillingAddressData = stripeStore.stripeShippingSameAsBilling
|
|
36
|
+
? stripeStore.stripeAddressEventData
|
|
37
|
+
: stripeStore.stripeBillingAddressEventData;
|
|
38
|
+
if (!(stripeAddressData === null || stripeAddressData === void 0 ? void 0 : stripeAddressData.complete) || !(stripeBillingAddressData === null || stripeBillingAddressData === void 0 ? void 0 : stripeBillingAddressData.complete)) {
|
|
39
|
+
throw new Error('Missing stripe address data');
|
|
40
|
+
}
|
|
41
|
+
// Attempt to get translated address if available
|
|
42
|
+
const translatedShippingAddress = getTranslatedAddress({
|
|
43
|
+
currentAddress: stripeAddressData,
|
|
44
|
+
translatedAddress: stripeStore.translatedAddress.address,
|
|
45
|
+
});
|
|
46
|
+
const shippingFirstName = translatedShippingAddress.name.split(' ')[0] || '';
|
|
47
|
+
const shippingLastName = translatedShippingAddress.name.split(' ').splice(1).join(' ') || '';
|
|
48
|
+
const translatedBillingAddress = getTranslatedAddress({
|
|
49
|
+
currentAddress: stripeBillingAddressData,
|
|
50
|
+
translatedAddress: stripeStore.translatedAddress.address,
|
|
51
|
+
});
|
|
52
|
+
const billingFirstName = translatedBillingAddress.name.split(' ')[0] || '';
|
|
53
|
+
const billingLastName = translatedBillingAddress.name.split(' ').splice(1).join(' ') || '';
|
|
54
|
+
return {
|
|
55
|
+
billingAddress: {
|
|
56
|
+
addressLine1: translatedBillingAddress.line1,
|
|
57
|
+
addressLine2: translatedBillingAddress.line2 || '',
|
|
58
|
+
city: translatedBillingAddress.city,
|
|
59
|
+
country: translatedBillingAddress.country,
|
|
60
|
+
postalCode: translatedBillingAddress.postal_code,
|
|
61
|
+
state: translatedBillingAddress.state,
|
|
62
|
+
},
|
|
63
|
+
billingContact: {
|
|
64
|
+
// firstName and lastName should be valid now since stripe only mark
|
|
65
|
+
// the address as complete when both fields are filled.
|
|
66
|
+
firstName: billingFirstName,
|
|
67
|
+
lastName: billingLastName,
|
|
68
|
+
phone: translatedBillingAddress.phone,
|
|
69
|
+
},
|
|
70
|
+
// Use the first item's currency code
|
|
71
|
+
cartCurrencyCode: (_a = cartStore.items[0]) === null || _a === void 0 ? void 0 : _a.currencyCode,
|
|
72
|
+
cartId,
|
|
73
|
+
checkoutSessionId: storageStore.checkoutSessionId || '',
|
|
74
|
+
contact: {
|
|
75
|
+
companyName: stripeStore.companyName,
|
|
76
|
+
email: stripeLinkData === null || stripeLinkData === void 0 ? void 0 : stripeLinkData.value.email,
|
|
77
|
+
// firstName and lastName should be valid now since stripe only mark
|
|
78
|
+
// the address as complete when both fields are filled.
|
|
79
|
+
firstName: shippingFirstName,
|
|
80
|
+
lastName: shippingLastName,
|
|
81
|
+
phone: translatedShippingAddress.phone,
|
|
82
|
+
},
|
|
83
|
+
isTest: !!isE2ETest,
|
|
84
|
+
landedCostAdjustments: cartStore.promoCode
|
|
85
|
+
? [
|
|
86
|
+
{
|
|
87
|
+
amount: 0,
|
|
88
|
+
productId: null,
|
|
89
|
+
promoCode: cartStore.promoCode,
|
|
90
|
+
sku: null,
|
|
91
|
+
type: 'PROMO_CODE',
|
|
92
|
+
},
|
|
93
|
+
]
|
|
94
|
+
: [],
|
|
95
|
+
shipToTaxId: stripeStore.taxId,
|
|
96
|
+
shippingAddress: {
|
|
97
|
+
addressLine1: translatedShippingAddress.line1,
|
|
98
|
+
addressLine2: translatedShippingAddress.line2,
|
|
99
|
+
city: translatedShippingAddress.city,
|
|
100
|
+
country: translatedShippingAddress.country,
|
|
101
|
+
postalCode: translatedShippingAddress.postal_code,
|
|
102
|
+
state: translatedShippingAddress.state,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
const prepCalculateLandedCost = () => {
|
|
107
|
+
const isE2ETest = new URLSearchParams(window.location.search).get('zonosE2ETest') === '1';
|
|
108
|
+
// maybe we don't need email now for prefetch the landed cost
|
|
109
|
+
const stripeLinkData = stripeStore.stripeLinkEventData;
|
|
110
|
+
const stripeAddressData = stripeStore.stripeAddressEventData;
|
|
111
|
+
const stripeBillingAddressData = stripeStore.stripeShippingSameAsBilling
|
|
112
|
+
? stripeStore.stripeAddressEventData
|
|
113
|
+
: stripeStore.stripeBillingAddressEventData;
|
|
114
|
+
log({ stripeAddressData, stripeBillingAddressData }, 'info');
|
|
115
|
+
if (!(stripeAddressData === null || stripeAddressData === void 0 ? void 0 : stripeAddressData.complete) || !(stripeBillingAddressData === null || stripeBillingAddressData === void 0 ? void 0 : stripeBillingAddressData.complete)) {
|
|
116
|
+
throw new Error('Missing stripe address data');
|
|
117
|
+
}
|
|
118
|
+
// Attempt to get translated address if available
|
|
119
|
+
const translatedShippingAddress = getTranslatedAddress({
|
|
120
|
+
currentAddress: stripeAddressData,
|
|
121
|
+
translatedAddress: stripeStore.translatedAddress.address,
|
|
122
|
+
});
|
|
123
|
+
const shippingFirstName = translatedShippingAddress.name.split(' ')[0] || '';
|
|
124
|
+
const shippingLastName = translatedShippingAddress.name.split(' ').splice(1).join(' ') || '';
|
|
125
|
+
const translatedBillingAddress = getTranslatedAddress({
|
|
126
|
+
currentAddress: stripeBillingAddressData,
|
|
127
|
+
translatedAddress: stripeStore.translatedAddress.address,
|
|
128
|
+
});
|
|
129
|
+
const billingFirstName = translatedBillingAddress.name.split(' ')[0] || '';
|
|
130
|
+
const billingLastName = translatedBillingAddress.name.split(' ').splice(1).join(' ') || '';
|
|
131
|
+
const convertedCartAdjuments = cartStore.adjustments.map(adjustment => ({
|
|
132
|
+
amount: adjustment.amount,
|
|
133
|
+
name: adjustment.description || null,
|
|
134
|
+
productId: adjustment.productId,
|
|
135
|
+
sku: adjustment.sku,
|
|
136
|
+
type: adjustment.type,
|
|
137
|
+
}));
|
|
138
|
+
const adjustments = cartStore.promoCode
|
|
139
|
+
? [
|
|
140
|
+
{
|
|
141
|
+
amount: 0,
|
|
142
|
+
productId: null,
|
|
143
|
+
promoCode: cartStore.promoCode,
|
|
144
|
+
sku: null,
|
|
145
|
+
type: 'PROMO_CODE',
|
|
146
|
+
},
|
|
147
|
+
...convertedCartAdjuments,
|
|
148
|
+
]
|
|
149
|
+
: convertedCartAdjuments;
|
|
150
|
+
return {
|
|
151
|
+
billingAddress: {
|
|
152
|
+
addressLine1: translatedBillingAddress.line1,
|
|
153
|
+
addressLine2: translatedBillingAddress.line2 || '',
|
|
154
|
+
city: translatedBillingAddress.city,
|
|
155
|
+
country: translatedBillingAddress.country,
|
|
156
|
+
postalCode: translatedBillingAddress.postal_code,
|
|
157
|
+
state: translatedBillingAddress.state,
|
|
158
|
+
},
|
|
159
|
+
billingContact: {
|
|
160
|
+
// firstName and lastName should be valid now since stripe only mark
|
|
161
|
+
// the address as complete when both fields are filled.
|
|
162
|
+
firstName: billingFirstName,
|
|
163
|
+
lastName: billingLastName,
|
|
164
|
+
phone: translatedBillingAddress.phone,
|
|
165
|
+
},
|
|
166
|
+
checkoutSessionId: storageStore.checkoutSessionId || '',
|
|
167
|
+
contact: {
|
|
168
|
+
companyName: stripeStore.companyName,
|
|
169
|
+
email: stripeLinkData === null || stripeLinkData === void 0 ? void 0 : stripeLinkData.value.email,
|
|
170
|
+
// firstName and lastName should be valid now since stripe only mark
|
|
171
|
+
// the address as complete when both fields are filled.
|
|
172
|
+
firstName: shippingFirstName,
|
|
173
|
+
lastName: shippingLastName,
|
|
174
|
+
phone: translatedShippingAddress.phone,
|
|
175
|
+
},
|
|
176
|
+
isTest: isE2ETest,
|
|
177
|
+
items: cartStore.items,
|
|
178
|
+
landedCostAdjustments: adjustments,
|
|
179
|
+
shipToTaxId: stripeStore.taxId,
|
|
180
|
+
shippingAddress: {
|
|
181
|
+
addressLine1: translatedShippingAddress.line1,
|
|
182
|
+
addressLine2: translatedShippingAddress.line2,
|
|
183
|
+
city: translatedShippingAddress.city,
|
|
184
|
+
country: translatedShippingAddress.country,
|
|
185
|
+
postalCode: translatedShippingAddress.postal_code,
|
|
186
|
+
state: translatedShippingAddress.state,
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const triggerBuildLandedCost = async (buildLandedCost) => {
|
|
192
|
+
var _a, _b, _c, _d, _e;
|
|
193
|
+
const data = prepCalculateLandedCost();
|
|
194
|
+
const landedCost = await buildLandedCost({
|
|
195
|
+
billingAddress: data.billingAddress,
|
|
196
|
+
billingContact: data.billingContact,
|
|
197
|
+
checkoutSessionId: data.checkoutSessionId,
|
|
198
|
+
contact: data.contact,
|
|
199
|
+
landedCostAdjustments: data.landedCostAdjustments,
|
|
200
|
+
// zonosApiKey should always be available
|
|
201
|
+
publicCredential: window.Zonos.zonosApiKey || '',
|
|
202
|
+
shippingAddress: data.shippingAddress,
|
|
203
|
+
zonosApiRoute: fallbackApiList['vercel'],
|
|
204
|
+
});
|
|
205
|
+
if (!landedCost ||
|
|
206
|
+
// Only show errors if there are no rate back (checkoutSessionWorkflow) and there are errors
|
|
207
|
+
(!((_a = landedCost.checkoutSessionWorkflow) === null || _a === void 0 ? void 0 : _a.length) && ((_b = landedCost.errors) === null || _b === void 0 ? void 0 : _b.length))) {
|
|
208
|
+
throw new Error(`Failed to build landed cost: ${((_d = (_c = landedCost === null || landedCost === void 0 ? void 0 : landedCost.errors) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.message) || 'Unknown error'}`);
|
|
209
|
+
}
|
|
210
|
+
// Validate the landed cost object to make sure the returned value from buildLandedCost has a valid schema
|
|
211
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/validate-landed-cost', {
|
|
212
|
+
body: landedCost,
|
|
213
|
+
headers: {
|
|
214
|
+
'Content-Type': 'application/json',
|
|
215
|
+
},
|
|
216
|
+
method: 'POST',
|
|
217
|
+
});
|
|
218
|
+
if (!json || errors.length) {
|
|
219
|
+
throw new Error(`Invalid landed cost object: ${((_e = errors.find(Boolean)) === null || _e === void 0 ? void 0 : _e.message) || 'Unknown error'}`);
|
|
220
|
+
}
|
|
221
|
+
return landedCost;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const calculateLandedCost = async (abortController) => {
|
|
225
|
+
var _a;
|
|
226
|
+
// If buildLandedCost callback is supplied, use that instead of our regular request to '/calculate-landed-cost'
|
|
227
|
+
const buildLandedCost = zonosStore.checkoutSettings.buildLandedCost;
|
|
228
|
+
if (buildLandedCost) {
|
|
229
|
+
const json = await triggerBuildLandedCost(buildLandedCost);
|
|
230
|
+
return json;
|
|
231
|
+
}
|
|
232
|
+
// request to get landed cost info
|
|
233
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/calculate-landed-cost', {
|
|
234
|
+
body: prepCalculateLandedCost(),
|
|
235
|
+
method: 'POST',
|
|
236
|
+
signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
|
|
237
|
+
});
|
|
238
|
+
if (errors.length || !json) {
|
|
239
|
+
const isAbortedRequest = ((_a = errors[0]) === null || _a === void 0 ? void 0 : _a.message) === 'The user aborted a request.';
|
|
240
|
+
if (isAbortedRequest) {
|
|
241
|
+
throw new Error('The landed cost calculation request was aborted to initiate a new one.');
|
|
242
|
+
}
|
|
243
|
+
// We want to show any successful quotes even if there are errors
|
|
244
|
+
errors.forEach(error => {
|
|
245
|
+
// eslint-disable-next-line no-console
|
|
246
|
+
console.warn(`Error calculating landed cost: ${error.message}`);
|
|
247
|
+
});
|
|
248
|
+
if (!json) {
|
|
249
|
+
throw new Error('Failed to calculate landed cost');
|
|
250
|
+
}
|
|
251
|
+
return json;
|
|
252
|
+
}
|
|
253
|
+
return json;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const cartCalculateLandedCost = async ({ abortController, cartId, }) => {
|
|
257
|
+
var _a;
|
|
258
|
+
// request to get landed cost info
|
|
259
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/cart-calculate-landed-cost', {
|
|
260
|
+
body: prepCartCalculateLandedCost(cartId),
|
|
261
|
+
method: 'POST',
|
|
262
|
+
signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
|
|
263
|
+
});
|
|
264
|
+
if (errors.length || !json) {
|
|
265
|
+
const isAbortedRequest = ((_a = errors[0]) === null || _a === void 0 ? void 0 : _a.message) === 'The user aborted a request.';
|
|
266
|
+
const errorMessage = isAbortedRequest
|
|
267
|
+
? 'The landed cost calculation request was aborted to initiate a new one.'
|
|
268
|
+
: 'Failed to calculate landed cost';
|
|
269
|
+
throw new Error(errorMessage);
|
|
270
|
+
}
|
|
271
|
+
return json;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
275
|
+
var t = {};
|
|
276
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
277
|
+
t[p] = s[p];
|
|
278
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
279
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
280
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
281
|
+
t[p[i]] = s[p[i]];
|
|
282
|
+
}
|
|
283
|
+
return t;
|
|
284
|
+
};
|
|
285
|
+
const calculateLandedCostNormalized = async (abortController) => {
|
|
286
|
+
const cartId = window.Zonos.cartId;
|
|
287
|
+
// Calculate landed cost as usual if no cartId is available
|
|
288
|
+
if (!cartId) {
|
|
289
|
+
const landedCostResult = await calculateLandedCost(abortController);
|
|
290
|
+
return landedCostResult;
|
|
291
|
+
}
|
|
292
|
+
// Calculate landed cost using cartId
|
|
293
|
+
const _a = await cartCalculateLandedCost({
|
|
294
|
+
abortController,
|
|
295
|
+
cartId,
|
|
296
|
+
}), { cartWorkflow } = _a, rest = __rest(_a, ["cartWorkflow"]);
|
|
297
|
+
return Object.assign(Object.assign({}, rest), { itemCreateWorkflow: cartWorkflow.items });
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const trackConversionEvent = async ({ checkoutSessionId, eventName, metadata, }) => {
|
|
301
|
+
var _a, _b;
|
|
302
|
+
const eventCreated = Date.now();
|
|
303
|
+
const trackLogMetadata = [...window.Zonos.trackEventLogs];
|
|
304
|
+
window.Zonos.trackEventLogs.push({
|
|
305
|
+
checkoutSessionId,
|
|
306
|
+
eventCreated,
|
|
307
|
+
eventName,
|
|
308
|
+
});
|
|
309
|
+
const isDevelopment =
|
|
310
|
+
// if the url includes zonos.com and not hosted checkout (checkout.zonos.com), it means we are on the development site (dashboard, preview zonos domain or main zonos.com)
|
|
311
|
+
(window.location.href.includes('zonos.com') &&
|
|
312
|
+
!window.location.href.includes('checkout.zonos.com')) ||
|
|
313
|
+
!!((_a = window.Zonos) === null || _a === void 0 ? void 0 : _a.zonosQaUrl) ||
|
|
314
|
+
!!((_b = window.Zonos) === null || _b === void 0 ? void 0 : _b.debug);
|
|
315
|
+
const isTest = getIsTestMode() || getIsStagingMode();
|
|
316
|
+
if ((isTest || isDevelopment) &&
|
|
317
|
+
// if found, it means we want to test the conversion event in development site, or test mode and staging mode
|
|
318
|
+
!window.Zonos.zonosConversionTest) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const countryCode = localizationStore.selectedCountryCode;
|
|
322
|
+
const organizationId = zonosStore.organizationId;
|
|
323
|
+
if (!checkoutSessionId) {
|
|
324
|
+
void sendErrorLog({
|
|
325
|
+
endpoint: 'trackConversionEventMetric',
|
|
326
|
+
errors: [`Event "${eventName}" - No checkout session id found`],
|
|
327
|
+
metadata: {
|
|
328
|
+
allLogs,
|
|
329
|
+
checkoutSessionId,
|
|
330
|
+
eventName,
|
|
331
|
+
metadata,
|
|
332
|
+
organizationId,
|
|
333
|
+
trackEventLogs: trackLogMetadata,
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
// checkoutSessionId is required for tracking conversion events to work properly
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
if (!organizationId) {
|
|
340
|
+
void sendErrorLog({
|
|
341
|
+
endpoint: 'trackConversionEventMetric',
|
|
342
|
+
errors: [`Event "${eventName}" - No organization id found`],
|
|
343
|
+
metadata: {
|
|
344
|
+
allLogs,
|
|
345
|
+
checkoutSessionId,
|
|
346
|
+
eventName,
|
|
347
|
+
metadata,
|
|
348
|
+
organizationId,
|
|
349
|
+
trackEventLogs: trackLogMetadata,
|
|
350
|
+
},
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
const body = {
|
|
354
|
+
checkoutSessionId,
|
|
355
|
+
countryCode,
|
|
356
|
+
eventCreated,
|
|
357
|
+
eventName,
|
|
358
|
+
metadata: Object.assign(Object.assign({}, metadata), { trackEventLogs: trackLogMetadata }),
|
|
359
|
+
organizationId,
|
|
360
|
+
};
|
|
361
|
+
await handleFetch('/api/zonos-elements/track-conversion-event', {
|
|
362
|
+
body,
|
|
363
|
+
method: 'POST',
|
|
364
|
+
});
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* This function generates an object that contains the fields of an address that have invalid characters.
|
|
369
|
+
*
|
|
370
|
+
* @param {Object} params - The parameters for the function.
|
|
371
|
+
* @param {Address | null} params.address - The address to check for invalid characters.
|
|
372
|
+
* @param {ReturnType<typeof containsNonLatinChars> | null} params.invalidAdddressList - The list of address fields that contain invalid characters.
|
|
373
|
+
*
|
|
374
|
+
* @returns {Partial<Address> | undefined} - An object that contains the fields of the address that have invalid characters. If no fields have invalid characters, the function returns undefined.
|
|
375
|
+
*/
|
|
376
|
+
const getExcludeAddressFieldsObject = ({ address, invalidAdddressList, }) => {
|
|
377
|
+
if (!address) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
// if there are no invalid characters, return an empty object
|
|
381
|
+
if (!invalidAdddressList) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
const excludeFields = {};
|
|
385
|
+
if (invalidAdddressList.city) {
|
|
386
|
+
excludeFields.city = address.city;
|
|
387
|
+
}
|
|
388
|
+
if (invalidAdddressList.line1) {
|
|
389
|
+
excludeFields.line1 = address.line1;
|
|
390
|
+
}
|
|
391
|
+
if (invalidAdddressList.line2) {
|
|
392
|
+
excludeFields.line2 = address.line2;
|
|
393
|
+
}
|
|
394
|
+
if (invalidAdddressList.postal_code) {
|
|
395
|
+
excludeFields.postal_code = address.postal_code;
|
|
396
|
+
}
|
|
397
|
+
if (invalidAdddressList.state) {
|
|
398
|
+
excludeFields.state = address.state;
|
|
399
|
+
}
|
|
400
|
+
if (invalidAdddressList.name) {
|
|
401
|
+
excludeFields.name = address.name;
|
|
402
|
+
}
|
|
403
|
+
// return null if there are no fields to exclude
|
|
404
|
+
return Object.keys(excludeFields).length ? excludeFields : undefined;
|
|
405
|
+
};
|
|
406
|
+
/**
|
|
407
|
+
* This function builds the request body for validating an address. It checks if the address and billing address are ready and if they contain any invalid characters.
|
|
408
|
+
* If there are non-latin character to translate, returns an object with the address fields that have invalid characters, the destination country, and the first and last name.
|
|
409
|
+
* If the conditions are not met, it returns null.
|
|
410
|
+
*
|
|
411
|
+
* @param {Object} params - The parameters for the function.
|
|
412
|
+
* @param {ReturnType<typeof containsNonLatinChars> | null} params.addressInvalidCharactersList - The list of address fields that contain invalid characters.
|
|
413
|
+
* @param {ReturnType<typeof containsNonLatinChars> | null} params.billingAddressInvalidCharactersList - The list of billing address fields that contain invalid characters.
|
|
414
|
+
* @param {StripeAddressEventData} params.stripeAddressEventData - The Stripe event data for the address.
|
|
415
|
+
* @param {StripeAddressEventData} params.stripeBillingAddressEventData - The Stripe event data for the billing address.
|
|
416
|
+
* @param {boolean} params.stripeShippingSameAsBilling - A flag indicating whether the shipping address is the same as the billing address.
|
|
417
|
+
*
|
|
418
|
+
* @returns {ValidateAddressRequest | null} - An object that contains the address fields that have invalid characters, the destination country, and the first and last name. If the conditions are not met, the function returns null.
|
|
419
|
+
*/
|
|
420
|
+
const buildTranslateRequest = ({ addressInvalidCharactersList, billingAddressInvalidCharactersList, stripeAddressEventData, stripeBillingAddressEventData, stripeShippingSameAsBilling, }) => {
|
|
421
|
+
var _a, _b, _c, _d;
|
|
422
|
+
const isStripeAddressReady = !!(stripeAddressEventData === null || stripeAddressEventData === void 0 ? void 0 : stripeAddressEventData.complete);
|
|
423
|
+
const isStripeBillingAddressReady = stripeShippingSameAsBilling
|
|
424
|
+
? isStripeAddressReady
|
|
425
|
+
: !!(stripeBillingAddressEventData === null || stripeBillingAddressEventData === void 0 ? void 0 : stripeBillingAddressEventData.complete);
|
|
426
|
+
// only translate if both address and billing address are ready
|
|
427
|
+
if (!isStripeAddressReady || !isStripeBillingAddressReady) {
|
|
428
|
+
return null;
|
|
429
|
+
}
|
|
430
|
+
// only translate if there are invalid characters
|
|
431
|
+
if (!addressInvalidCharactersList && !billingAddressInvalidCharactersList) {
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
const stripeAddressValue = stripeAddressEventData.value;
|
|
435
|
+
const stripeBillingAddressValue = (stripeBillingAddressEventData === null || stripeBillingAddressEventData === void 0 ? void 0 : stripeBillingAddressEventData.value) || null;
|
|
436
|
+
// Returns undefined if the name is Latin so it won't be included in the request body
|
|
437
|
+
const firstName = stripeAddressValue.firstName || ((_a = stripeAddressValue.name) === null || _a === void 0 ? void 0 : _a.split(' ')[0]);
|
|
438
|
+
const lastName = stripeAddressValue.lastName || ((_b = stripeAddressValue.name) === null || _b === void 0 ? void 0 : _b.split(' ')[1]);
|
|
439
|
+
const name = `${firstName} ${lastName}`;
|
|
440
|
+
const billingFirstName = stripeAddressValue.firstName ||
|
|
441
|
+
((_c = stripeBillingAddressValue === null || stripeBillingAddressValue === void 0 ? void 0 : stripeBillingAddressValue.name) === null || _c === void 0 ? void 0 : _c.split(' ')[0]);
|
|
442
|
+
const billingLastName = stripeAddressValue.lastName ||
|
|
443
|
+
((_d = stripeBillingAddressValue === null || stripeBillingAddressValue === void 0 ? void 0 : stripeBillingAddressValue.name) === null || _d === void 0 ? void 0 : _d.split(' ')[1]);
|
|
444
|
+
const billingName = billingFirstName && billingLastName
|
|
445
|
+
? `${billingFirstName} ${billingLastName}`
|
|
446
|
+
: '';
|
|
447
|
+
const address = stripeAddressValue.address;
|
|
448
|
+
const billingAddress = stripeBillingAddressValue === null || stripeBillingAddressValue === void 0 ? void 0 : stripeBillingAddressValue.address;
|
|
449
|
+
return {
|
|
450
|
+
address: getExcludeAddressFieldsObject({
|
|
451
|
+
address: Object.assign(Object.assign({}, address), { name }),
|
|
452
|
+
invalidAdddressList: addressInvalidCharactersList,
|
|
453
|
+
}),
|
|
454
|
+
// only include billing address if it's different from the shipping address
|
|
455
|
+
billingAddress: !stripeShippingSameAsBilling
|
|
456
|
+
? getExcludeAddressFieldsObject({
|
|
457
|
+
address: billingAddress
|
|
458
|
+
? Object.assign(Object.assign({}, billingAddress), { name: billingName }) : null,
|
|
459
|
+
invalidAdddressList: billingAddressInvalidCharactersList,
|
|
460
|
+
})
|
|
461
|
+
: undefined,
|
|
462
|
+
destinationCountry: address.country,
|
|
463
|
+
};
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Sorts service levels with lower cost first
|
|
468
|
+
*/
|
|
469
|
+
const sortServiceLevelOptionsByAmount = (serviceLevels) => {
|
|
470
|
+
const sortedServiceLevels = serviceLevels.sort((a, b) => {
|
|
471
|
+
return a.amount - b.amount;
|
|
472
|
+
});
|
|
473
|
+
return sortedServiceLevels;
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
const getCheckoutSession = async () => {
|
|
477
|
+
if (!storageStore.checkoutSessionId) {
|
|
478
|
+
return {
|
|
479
|
+
errors: [{ message: 'No checkout session id found' }],
|
|
480
|
+
json: null,
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
const searchParams = new URLSearchParams();
|
|
484
|
+
searchParams.set('checkoutSessionId', storageStore.checkoutSessionId);
|
|
485
|
+
const { errors, json } = await handleFetch(`/api/zonos-elements/get-checkout-session?${searchParams.toString()}`);
|
|
486
|
+
return { errors, json };
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Validate checkout session before confirming payment
|
|
491
|
+
*/
|
|
492
|
+
const validateCheckoutSession = async () => {
|
|
493
|
+
var _a;
|
|
494
|
+
// get checkout session info
|
|
495
|
+
const { errors, json } = await getCheckoutSession();
|
|
496
|
+
if (errors.length || !json) {
|
|
497
|
+
logError('Failed to retrieve checkout session info before confirming payment ', errors);
|
|
498
|
+
void sendErrorLog({
|
|
499
|
+
endpoint: 'validateCheckoutSession',
|
|
500
|
+
errors: errors.map(error => error.message),
|
|
501
|
+
metadata: { allLogs },
|
|
502
|
+
});
|
|
503
|
+
return {
|
|
504
|
+
errorMessage: translate('Unable to retrieve the checkout session at the moment. Please try again or contact our support team.'),
|
|
505
|
+
valid: false,
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
// Make sure landed cost is found in the checkout session
|
|
509
|
+
if (!((_a = json.checkoutSession.landedCost) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
510
|
+
logError('Landed cost is not found in the checkout session before confirming payment.');
|
|
511
|
+
void sendErrorLog({
|
|
512
|
+
endpoint: 'validateCheckoutSession',
|
|
513
|
+
errors: ['No landed cost found before confirming payment'],
|
|
514
|
+
metadata: { allLogs },
|
|
515
|
+
});
|
|
516
|
+
return {
|
|
517
|
+
errorMessage: translate('No shipment rating selected. Please go back to the "Shipping" step and select a shipment rating to proceed.'),
|
|
518
|
+
valid: false,
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
return { errorMessage: '', valid: true };
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
const addressRuleStyle = ({ theme, }) => {
|
|
525
|
+
const defaultStyle = {
|
|
526
|
+
'.AccordionItem': {
|
|
527
|
+
color: 'var(--colorText)',
|
|
528
|
+
},
|
|
529
|
+
'.AccordionItem--selected': {
|
|
530
|
+
color: 'var(--colorText)',
|
|
531
|
+
},
|
|
532
|
+
'.Action': {
|
|
533
|
+
color: 'var(--colorText)',
|
|
534
|
+
},
|
|
535
|
+
'.Input': {
|
|
536
|
+
boxShadow: 'none',
|
|
537
|
+
fontSize: zonosStore.appearance.fontSizeInputValue
|
|
538
|
+
? `${zonosStore.appearance.fontSizeInputValue}px`
|
|
539
|
+
: undefined,
|
|
540
|
+
// need to reset everything and the paddingTop to default, otherwise the paddingTop will not be updated.
|
|
541
|
+
padding: '0',
|
|
542
|
+
paddingBottom: '8px',
|
|
543
|
+
paddingLeft: '16px',
|
|
544
|
+
paddingRight: '8px',
|
|
545
|
+
// any value here will be add up to the default paddingTop (20px).
|
|
546
|
+
paddingTop: '6px',
|
|
547
|
+
},
|
|
548
|
+
'.Label--resting': {
|
|
549
|
+
fontSize: zonosStore.appearance.fontSizeInputLabel
|
|
550
|
+
? `${zonosStore.appearance.fontSizeInputLabel}px`
|
|
551
|
+
: undefined,
|
|
552
|
+
},
|
|
553
|
+
'.PickerItem--highlight': {
|
|
554
|
+
boxShadow: '0 0 0 2px var(--colorBackground)',
|
|
555
|
+
},
|
|
556
|
+
'.PickerItem--highlight:hover': {
|
|
557
|
+
backgroundColor: 'var(--colorBackground)',
|
|
558
|
+
boxShadow: 'none',
|
|
559
|
+
},
|
|
560
|
+
'.PickerItem--new': {
|
|
561
|
+
color: 'var(--colorText)',
|
|
562
|
+
},
|
|
563
|
+
'.Tab--selected': {
|
|
564
|
+
borderStyle: 'solid',
|
|
565
|
+
borderWidth: '1px',
|
|
566
|
+
},
|
|
567
|
+
};
|
|
568
|
+
switch (theme) {
|
|
569
|
+
case 'DARK': {
|
|
570
|
+
return Object.assign(Object.assign({}, defaultStyle), { '.Action': Object.assign(Object.assign({}, defaultStyle['.Action']), { color: 'white' }), '.PickerItem--new': Object.assign(Object.assign({}, defaultStyle['.PickerItem--new']), { color: 'white' }) });
|
|
571
|
+
}
|
|
572
|
+
default:
|
|
573
|
+
return defaultStyle;
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
const defaultVariable = ({ borderStyle, theme, }) => {
|
|
578
|
+
switch (theme) {
|
|
579
|
+
case 'DARK':
|
|
580
|
+
return {
|
|
581
|
+
borderRadius: getBorderRadius({ overrideBorderStyle: borderStyle }),
|
|
582
|
+
colorBackground: '#101117',
|
|
583
|
+
colorBackgroundText: '#C5C6CA',
|
|
584
|
+
colorText: '#C5C6CA',
|
|
585
|
+
colorTextPlaceholder: '#C5C6CA',
|
|
586
|
+
};
|
|
587
|
+
default:
|
|
588
|
+
return {
|
|
589
|
+
borderRadius: getBorderRadius({ overrideBorderStyle: borderStyle }),
|
|
590
|
+
iconMenuColor: 'var(--colorText)',
|
|
591
|
+
iconMenuHoverColor: 'var(--colorText)',
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
const { onChange: stripeStoreOnChange, reset: reset$1, state: stripeStore, } = createStore(() => ({
|
|
597
|
+
checkoutSettlementCurrency: 'USD',
|
|
598
|
+
clientSecret: sessionStorage.getItem('zonos--client-secret') || '',
|
|
599
|
+
companyName: '',
|
|
600
|
+
customAddressErrors: {
|
|
601
|
+
city: '',
|
|
602
|
+
firstName: '',
|
|
603
|
+
lastName: '',
|
|
604
|
+
line1: '',
|
|
605
|
+
phone: '',
|
|
606
|
+
postalCode: '',
|
|
607
|
+
showError: false,
|
|
608
|
+
state: '',
|
|
609
|
+
},
|
|
610
|
+
customBillingAddressErrors: {
|
|
611
|
+
city: '',
|
|
612
|
+
firstName: '',
|
|
613
|
+
lastName: '',
|
|
614
|
+
line1: '',
|
|
615
|
+
phone: '',
|
|
616
|
+
postalCode: '',
|
|
617
|
+
showError: false,
|
|
618
|
+
state: '',
|
|
619
|
+
},
|
|
620
|
+
customErrorMessage: null,
|
|
621
|
+
customerProfile: null,
|
|
622
|
+
fetchingLandedCostAbortController: null,
|
|
623
|
+
hasPaymentError: false,
|
|
624
|
+
isFetchingLandedCost: false,
|
|
625
|
+
isFetchingSession: false,
|
|
626
|
+
shouldInventoryRefund: false,
|
|
627
|
+
shouldRenderPayInUsdButton: false,
|
|
628
|
+
/**
|
|
629
|
+
* Default to skip payment intent, only create payment intent when "skipPaymentIntent" in url's query params is set "0"
|
|
630
|
+
* @default true
|
|
631
|
+
*/
|
|
632
|
+
skipPaymentIntent: new URLSearchParams(window.location.search).get('skipPaymentIntent') === '0'
|
|
633
|
+
? false
|
|
634
|
+
: true,
|
|
635
|
+
stripe: null,
|
|
636
|
+
stripeAddressElement: null,
|
|
637
|
+
stripeAddressEventData: null,
|
|
638
|
+
stripeAddressUsedWhenFetchingLC: null,
|
|
639
|
+
stripeAddressUsedWhenValidatingAddress: null,
|
|
640
|
+
stripeBillingAddressElement: null,
|
|
641
|
+
stripeBillingAddressEventData: null,
|
|
642
|
+
stripeBillingAddressUsedWhenFetchingLC: null,
|
|
643
|
+
stripeBillingAddressUsedWhenValidatingAddress: null,
|
|
644
|
+
stripeCustomerSessionClientSecret: null,
|
|
645
|
+
stripeElements: null,
|
|
646
|
+
stripeElementsForBillingAddress: null,
|
|
647
|
+
stripeElementsOptions: null,
|
|
648
|
+
stripeLinkElement: null,
|
|
649
|
+
stripeLinkEventData: null,
|
|
650
|
+
stripeLinkUsedWhenFetchingLC: null,
|
|
651
|
+
stripePaymentElement: null,
|
|
652
|
+
stripePaymentEventData: null,
|
|
653
|
+
stripeShippingSameAsBilling: true,
|
|
654
|
+
taxId: '',
|
|
655
|
+
taxIdUsedWhenFetchingLC: '',
|
|
656
|
+
translatedAddress: {
|
|
657
|
+
address: {},
|
|
658
|
+
billingAddress: {},
|
|
659
|
+
firstName: {},
|
|
660
|
+
lastName: {},
|
|
661
|
+
name: {},
|
|
662
|
+
},
|
|
663
|
+
}));
|
|
664
|
+
const getStripeOptions = ({ clientSecret, overrideBorderRadius, overridePrimaryColor, overrideSecondaryColor, overrideTheme, paypalEnabled, }) => {
|
|
665
|
+
const primaryColor = overridePrimaryColor || zonosStore.appearance.colorPrimary;
|
|
666
|
+
const secondaryColor = overrideSecondaryColor || zonosStore.appearance.colorSecondary;
|
|
667
|
+
const themeBasedColor = primaryColor && isDarkColor(primaryColor) ? 'night' : 'flat';
|
|
668
|
+
// if overrideTheme is provided, use it. Otherwise, use theme based on primary color
|
|
669
|
+
const theme = overrideTheme === 'DARK' ? 'night' : 'flat';
|
|
670
|
+
const paypalPaymentType = paypalEnabled ? ['external_paypal'] : [];
|
|
671
|
+
return {
|
|
672
|
+
appearance: {
|
|
673
|
+
labels: 'floating',
|
|
674
|
+
rules: Object.assign({}, addressRuleStyle({ theme: overrideTheme || 'LIGHT' })),
|
|
675
|
+
// get contrast theme color base on primary color
|
|
676
|
+
theme: overrideTheme ? theme : themeBasedColor,
|
|
677
|
+
variables: Object.assign(Object.assign({}, defaultVariable({
|
|
678
|
+
borderStyle: overrideBorderRadius,
|
|
679
|
+
theme: 'LIGHT',
|
|
680
|
+
})), {
|
|
681
|
+
// use the button background color for input glow color
|
|
682
|
+
colorPrimary: secondaryColor }),
|
|
683
|
+
},
|
|
684
|
+
// Client secret can be undefined since we will load other elements that doesn't require client secret first, then load client secret and render one that requires it later
|
|
685
|
+
clientSecret: clientSecret || undefined,
|
|
686
|
+
customerSessionClientSecret: stripeStore.stripeCustomerSessionClientSecret || undefined,
|
|
687
|
+
externalPaymentMethodTypes: [...paypalPaymentType],
|
|
688
|
+
locale: localizationStore.selectedLocale,
|
|
689
|
+
};
|
|
690
|
+
};
|
|
691
|
+
const stripeStoreCleanupDomesticShippingSession = () => {
|
|
692
|
+
window.sessionStorage.removeItem('zonos--bigcommerce-domestic-checkout-shipping');
|
|
693
|
+
};
|
|
694
|
+
// Save shipping address to session storage
|
|
695
|
+
const stripeStoreSaveDomesticShippingSession = (props) => {
|
|
696
|
+
window.sessionStorage.setItem('zonos--bigcommerce-domestic-checkout-shipping', JSON.stringify(props));
|
|
697
|
+
};
|
|
698
|
+
const stripeStoreGetDomesticShippingSession = () => {
|
|
699
|
+
const session = window.sessionStorage.getItem('zonos--bigcommerce-domestic-checkout-shipping');
|
|
700
|
+
return jsonParse(session);
|
|
701
|
+
};
|
|
702
|
+
const initStripeElements = async (props) => {
|
|
703
|
+
var _a, _b;
|
|
704
|
+
const clientSecret = stripeStore.clientSecret;
|
|
705
|
+
if (!stripeStore.stripe) {
|
|
706
|
+
log('Skip. Stripe is not initialized');
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
const stripeOptions = getStripeOptions({
|
|
710
|
+
clientSecret,
|
|
711
|
+
overrideBorderRadius: props === null || props === void 0 ? void 0 : props.overrideBorderRadius,
|
|
712
|
+
overridePrimaryColor: props === null || props === void 0 ? void 0 : props.overridePrimaryColor,
|
|
713
|
+
overrideSecondaryColor: props === null || props === void 0 ? void 0 : props.overrideSecondaryColor,
|
|
714
|
+
overrideTheme: props === null || props === void 0 ? void 0 : props.overrideTheme,
|
|
715
|
+
paypalEnabled: props === null || props === void 0 ? void 0 : props.paypalEnabled,
|
|
716
|
+
});
|
|
717
|
+
// compare with the previous options to see if we need to update
|
|
718
|
+
const isSameOptions = JSON.stringify(stripeOptions) ===
|
|
719
|
+
JSON.stringify(stripeStore.stripeElementsOptions);
|
|
720
|
+
if (!stripeStore.stripeElements ||
|
|
721
|
+
!stripeStore.stripeElementsForBillingAddress) {
|
|
722
|
+
// init stripe elements if it doesn't exist
|
|
723
|
+
stripeStore.stripeElements = (_a = stripeStore.stripe) === null || _a === void 0 ? void 0 : _a.elements(stripeOptions);
|
|
724
|
+
// save stripe elements options for later comparison
|
|
725
|
+
stripeStore.stripeElementsOptions = stripeOptions;
|
|
726
|
+
log('Stripe elements initialized');
|
|
727
|
+
// init stripe elements for billing address
|
|
728
|
+
stripeStore.stripeElementsForBillingAddress =
|
|
729
|
+
(_b = stripeStore.stripe) === null || _b === void 0 ? void 0 : _b.elements(stripeOptions);
|
|
730
|
+
log('Stripe elements for billing address initialized');
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
if (!isSameOptions) {
|
|
734
|
+
// update elements with new option if it already exists
|
|
735
|
+
stripeStore.stripeElements.update(stripeOptions);
|
|
736
|
+
// update elements for stripe billing address
|
|
737
|
+
stripeStore.stripeElementsForBillingAddress.update(stripeOptions);
|
|
738
|
+
// save stripe elements options for later comparison
|
|
739
|
+
stripeStore.stripeElementsOptions = stripeOptions;
|
|
740
|
+
void stripeStore.stripeElements.fetchUpdates();
|
|
741
|
+
}
|
|
742
|
+
log('Stripe elements updated');
|
|
743
|
+
};
|
|
744
|
+
const stripeStoreReset = () => {
|
|
745
|
+
// clean clientSecret so that we can start the new one.
|
|
746
|
+
sessionStorage.removeItem('zonos--client-secret');
|
|
747
|
+
// cleanup stripe elements
|
|
748
|
+
reset$1();
|
|
749
|
+
// set stripe back to window.Zonos.stripe
|
|
750
|
+
stripeStore.stripe = window.Zonos.stripe;
|
|
751
|
+
};
|
|
752
|
+
const checkIsAddressOutdatedForValidation = () => {
|
|
753
|
+
var _a, _b, _c, _d;
|
|
754
|
+
const isAddressDataDirty = JSON.stringify((_a = stripeStore.stripeAddressUsedWhenValidatingAddress) === null || _a === void 0 ? void 0 : _a.value) !== JSON.stringify((_b = stripeStore.stripeAddressEventData) === null || _b === void 0 ? void 0 : _b.value);
|
|
755
|
+
const isBillingAddressDataDirty = !stripeStore.stripeShippingSameAsBilling &&
|
|
756
|
+
JSON.stringify((_c = stripeStore.stripeBillingAddressEventData) === null || _c === void 0 ? void 0 : _c.value) !==
|
|
757
|
+
JSON.stringify((_d = stripeStore.stripeBillingAddressUsedWhenValidatingAddress) === null || _d === void 0 ? void 0 : _d.value);
|
|
758
|
+
return isAddressDataDirty || isBillingAddressDataDirty;
|
|
759
|
+
};
|
|
760
|
+
const checkIsAddressOutdatedForLCPrefetch = () => {
|
|
761
|
+
var _a, _b, _c, _d, _e, _f;
|
|
762
|
+
const isLinkDataDirty = JSON.stringify((_a = stripeStore.stripeLinkUsedWhenFetchingLC) === null || _a === void 0 ? void 0 : _a.value) !==
|
|
763
|
+
JSON.stringify((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.value);
|
|
764
|
+
const isAddressDataDirty = JSON.stringify((_c = stripeStore.stripeAddressUsedWhenFetchingLC) === null || _c === void 0 ? void 0 : _c.value) !==
|
|
765
|
+
JSON.stringify((_d = stripeStore.stripeAddressEventData) === null || _d === void 0 ? void 0 : _d.value);
|
|
766
|
+
const isBillingAddressDataDirty = !stripeStore.stripeShippingSameAsBilling &&
|
|
767
|
+
JSON.stringify((_e = stripeStore.stripeBillingAddressEventData) === null || _e === void 0 ? void 0 : _e.value) !==
|
|
768
|
+
JSON.stringify((_f = stripeStore.stripeBillingAddressUsedWhenFetchingLC) === null || _f === void 0 ? void 0 : _f.value);
|
|
769
|
+
return isLinkDataDirty || isAddressDataDirty || isBillingAddressDataDirty;
|
|
770
|
+
};
|
|
771
|
+
/**
|
|
772
|
+
* Check if the address and email info used when fetching landed cost with the current email and address info are different
|
|
773
|
+
* Purpose is to resend the request if the info used when fetching landed cost is different from the current info
|
|
774
|
+
*/
|
|
775
|
+
const isPrefetchInfoOutdated = () => {
|
|
776
|
+
var _a;
|
|
777
|
+
// Mark the landed cost is outdated since the item total amount has changed (items total didn't match with the cart subtotal)
|
|
778
|
+
const isTotalAmountChanged = cartStore.landedCostData &&
|
|
779
|
+
((_a = cartStore.landedCostData.find(Boolean)) === null || _a === void 0 ? void 0 : _a.subtotals.items) !==
|
|
780
|
+
cartStore.subtotal;
|
|
781
|
+
const isAddressOutdated = checkIsAddressOutdatedForLCPrefetch();
|
|
782
|
+
// Auto prefetch landed cost if tax id is updated
|
|
783
|
+
const isTaxIdDirty = stripeStore.taxIdUsedWhenFetchingLC !== stripeStore.taxId;
|
|
784
|
+
return (
|
|
785
|
+
// if landed cost data is not available, we need to fetch it
|
|
786
|
+
!cartStore.landedCostData ||
|
|
787
|
+
isAddressOutdated ||
|
|
788
|
+
isTotalAmountChanged ||
|
|
789
|
+
isTaxIdDirty);
|
|
790
|
+
};
|
|
791
|
+
const stripeCalculateLandedCost = async () => {
|
|
792
|
+
var _a;
|
|
793
|
+
const abortController = new AbortController();
|
|
794
|
+
stripeStore.fetchingLandedCostAbortController = abortController;
|
|
795
|
+
// Reset cart items to non-restricted state and restricted item list
|
|
796
|
+
cartStoreResetCartItems();
|
|
797
|
+
const { checkoutSessionWorkflow, errors, itemCreateWorkflow, landedCostCalculateWorkflow, partyCreateWorkflow, shipmentRatingCalculateWorkflow, } = await calculateLandedCostNormalized(abortController);
|
|
798
|
+
// update the error message with customized error message that rule is applying to and disabled shippment rating if there is any
|
|
799
|
+
cartStore.customQuotingError =
|
|
800
|
+
((_a = errors === null || errors === void 0 ? void 0 : errors.find(error => { var _a; return ((_a = error.extensions) === null || _a === void 0 ? void 0 : _a.ruleMessageType) === 'CUSTOM'; })) === null || _a === void 0 ? void 0 : _a.message) || null;
|
|
801
|
+
cartStore.shippingData = sortServiceLevelOptionsByAmount((shipmentRatingCalculateWorkflow === null || shipmentRatingCalculateWorkflow === void 0 ? void 0 : shipmentRatingCalculateWorkflow.filter(Boolean)) || []);
|
|
802
|
+
// check and update cart items with restrictions
|
|
803
|
+
cartStoreCheckItemRestrictions(itemCreateWorkflow);
|
|
804
|
+
// reset abort controller after we are done
|
|
805
|
+
stripeStore.fetchingLandedCostAbortController = null;
|
|
806
|
+
cartStore.partiesData = (partyCreateWorkflow === null || partyCreateWorkflow === void 0 ? void 0 : partyCreateWorkflow.filter(Boolean)) || [];
|
|
807
|
+
// update cart store with landed cost info
|
|
808
|
+
cartStore.landedCostData =
|
|
809
|
+
(checkoutSessionWorkflow === null || checkoutSessionWorkflow === void 0 ? void 0 : checkoutSessionWorkflow.map(checkoutSession => {
|
|
810
|
+
const foundLandedCost = landedCostCalculateWorkflow === null || landedCostCalculateWorkflow === void 0 ? void 0 : landedCostCalculateWorkflow.find(item => (item === null || item === void 0 ? void 0 : item.id) === checkoutSession.landedCostId);
|
|
811
|
+
if (!foundLandedCost) {
|
|
812
|
+
return null;
|
|
813
|
+
}
|
|
814
|
+
return Object.assign(Object.assign({}, checkoutSession), { landedCost: foundLandedCost });
|
|
815
|
+
}).filter(Boolean)) || [];
|
|
816
|
+
// Send event when we get the quote back after the customer clicked "Continue to shipping"
|
|
817
|
+
const checkoutSessionId = storageStore.checkoutSessionId;
|
|
818
|
+
if (checkoutSessionWorkflow === null || checkoutSessionWorkflow === void 0 ? void 0 : checkoutSessionWorkflow.length) {
|
|
819
|
+
void trackConversionEvent({
|
|
820
|
+
checkoutSessionId,
|
|
821
|
+
eventName: 'checkout_quoteReceived',
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
// update adjustmentTotal
|
|
825
|
+
// highlight promocode input error if promocode is applied but no adjustment applied in landed cost
|
|
826
|
+
const isInvalidPromoCode = cartStore.promoCodeApplied &&
|
|
827
|
+
!cartStore.landedCostData.find(item => {
|
|
828
|
+
var _a;
|
|
829
|
+
return (_a = item.landedCost.appliedAdjustments) === null || _a === void 0 ? void 0 : _a.find(_item => _item.type === 'PROMO_CODE');
|
|
830
|
+
});
|
|
831
|
+
cartStore.promoCodeError = isInvalidPromoCode;
|
|
832
|
+
// When promocode is valid, set promoCode to session storage so if user close the modal, we can still reapply for them
|
|
833
|
+
if (!isInvalidPromoCode) {
|
|
834
|
+
sessionStorage.setItem('zonos--promo-code', cartStore.promoCode);
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
const stripeStorePrefetchLandedCost = async (params) => {
|
|
838
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
839
|
+
const retries = (params === null || params === void 0 ? void 0 : params.retries) || 0;
|
|
840
|
+
const applyingPromocode = !!(params === null || params === void 0 ? void 0 : params.applyingPromocode);
|
|
841
|
+
const stripeAddressReady = !!((_a = stripeStore.stripeAddressEventData) === null || _a === void 0 ? void 0 : _a.complete);
|
|
842
|
+
const stripeLinkReady = !!((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.complete);
|
|
843
|
+
const stripeBillingAddressReady = stripeStore.stripeShippingSameAsBilling
|
|
844
|
+
? !!((_c = stripeStore.stripeLinkEventData) === null || _c === void 0 ? void 0 : _c.complete)
|
|
845
|
+
: !!((_d = stripeStore.stripeBillingAddressEventData) === null || _d === void 0 ? void 0 : _d.complete);
|
|
846
|
+
const shouldRefetch = isPrefetchInfoOutdated();
|
|
847
|
+
if (shouldRefetch) {
|
|
848
|
+
// if the info used when fetching landed cost is different from the current info, abort the previous request
|
|
849
|
+
(_e = stripeStore.fetchingLandedCostAbortController) === null || _e === void 0 ? void 0 : _e.abort();
|
|
850
|
+
stripeStore.fetchingLandedCostAbortController = null;
|
|
851
|
+
}
|
|
852
|
+
// Do not fetch if we are not ready or data is not outdated
|
|
853
|
+
if ((!shouldRefetch && !applyingPromocode) ||
|
|
854
|
+
!stripeAddressReady ||
|
|
855
|
+
!stripeLinkReady ||
|
|
856
|
+
!stripeBillingAddressReady) {
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
// If there is retries, stop loading for a moment and then showing the spinner again (this is just so customer can see that checkout is doing something and not stuck)
|
|
860
|
+
if (retries) {
|
|
861
|
+
stripeStore.isFetchingLandedCost = false;
|
|
862
|
+
setTimeout(() => {
|
|
863
|
+
stripeStore.isFetchingLandedCost = true;
|
|
864
|
+
}, 300);
|
|
865
|
+
}
|
|
866
|
+
else {
|
|
867
|
+
stripeStore.isFetchingLandedCost = true;
|
|
868
|
+
}
|
|
869
|
+
if (stripeStore.stripeAddressEventData) {
|
|
870
|
+
stripeStore.stripeAddressUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeAddressEventData);
|
|
871
|
+
}
|
|
872
|
+
if (stripeStore.stripeBillingAddressEventData) {
|
|
873
|
+
stripeStore.stripeBillingAddressUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeBillingAddressEventData);
|
|
874
|
+
}
|
|
875
|
+
if (stripeStore.stripeLinkEventData) {
|
|
876
|
+
stripeStore.stripeLinkUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeLinkEventData);
|
|
877
|
+
}
|
|
878
|
+
stripeStore.taxIdUsedWhenFetchingLC = stripeStore.taxId;
|
|
879
|
+
try {
|
|
880
|
+
// Reset cart items to non-restricted state and restricted item list
|
|
881
|
+
cartStoreResetCartItems();
|
|
882
|
+
// fetch and apply landed cost
|
|
883
|
+
await stripeCalculateLandedCost();
|
|
884
|
+
// This is the cheapest service level since we already sorted them after fetching landed cost
|
|
885
|
+
const cheapestServiceLevel = (_f = cartStore.shippingData) === null || _f === void 0 ? void 0 : _f.find(Boolean);
|
|
886
|
+
// Landed cost that matches with service level
|
|
887
|
+
const matchLandedCost = (_g = cartStore.landedCostData) === null || _g === void 0 ? void 0 : _g.find(x => x.landedCost.shipmentRating.id === (cheapestServiceLevel === null || cheapestServiceLevel === void 0 ? void 0 : cheapestServiceLevel.id));
|
|
888
|
+
// apply new subtotal and total, this is mainly to show items in the presentment currency
|
|
889
|
+
const subtotals = !!matchLandedCost ? matchLandedCost.subtotals : null;
|
|
890
|
+
if (subtotals) {
|
|
891
|
+
// prefetch landed cost will not update shipping and taxes since we haven't selected shipping method yet
|
|
892
|
+
cartStoreApplySubtotals({
|
|
893
|
+
method: (matchLandedCost === null || matchLandedCost === void 0 ? void 0 : matchLandedCost.landedCost.method) || 'DDP',
|
|
894
|
+
subtotals,
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
catch (err) {
|
|
899
|
+
// default to empty array if we failed to fetch landed cost, so we can show the error message
|
|
900
|
+
cartStore.landedCostData = [];
|
|
901
|
+
cartStore.shippingData = [];
|
|
902
|
+
const excludeErrors = [
|
|
903
|
+
'The landed cost calculation request was aborted to initiate a new one.',
|
|
904
|
+
];
|
|
905
|
+
if (err instanceof Error &&
|
|
906
|
+
err.message &&
|
|
907
|
+
!excludeErrors.includes(err.message)) {
|
|
908
|
+
if (retries < 1) {
|
|
909
|
+
// retry fetching landed cost one more time
|
|
910
|
+
await stripeStorePrefetchLandedCost(Object.assign(Object.assign({}, params), { retries: (retries || 0) + 1 }));
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
const shipToAddress = (_h = stripeStore.stripeAddressUsedWhenFetchingLC) === null || _h === void 0 ? void 0 : _h.value;
|
|
914
|
+
void sendErrorLog({
|
|
915
|
+
endpoint: `Failed to fetch landed cost (${retries} retries)`,
|
|
916
|
+
errors: [err.message],
|
|
917
|
+
metadata: {
|
|
918
|
+
cartId: window.Zonos.cartId,
|
|
919
|
+
shipToAddress,
|
|
920
|
+
},
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
logError(err);
|
|
924
|
+
}
|
|
925
|
+
stripeStore.isFetchingLandedCost = false;
|
|
926
|
+
};
|
|
927
|
+
const stripeStoreApplyPromoCode = async () => {
|
|
928
|
+
var _a, _b;
|
|
929
|
+
await stripeStorePrefetchLandedCost({
|
|
930
|
+
applyingPromocode: true,
|
|
931
|
+
});
|
|
932
|
+
// Go back to shipping step if we are in payment step so user can reselect shipping method
|
|
933
|
+
if (cartStore.step === 'payment') {
|
|
934
|
+
cartStorePreviousStep();
|
|
935
|
+
}
|
|
936
|
+
// This is the cheapest service level since we already sorted them after fetching landed cost
|
|
937
|
+
const cheapestServiceLevel = (_a = cartStore.shippingData) === null || _a === void 0 ? void 0 : _a.find(Boolean);
|
|
938
|
+
// Landed cost that matches with service level
|
|
939
|
+
const matchLandedCost = (_b = cartStore.landedCostData) === null || _b === void 0 ? void 0 : _b.find(x => x.landedCost.id === (cheapestServiceLevel === null || cheapestServiceLevel === void 0 ? void 0 : cheapestServiceLevel.id));
|
|
940
|
+
if (!cheapestServiceLevel || !matchLandedCost) {
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
await cartStoreUpdateSelectedShippingOption(cheapestServiceLevel, matchLandedCost.landedCostId);
|
|
944
|
+
};
|
|
945
|
+
const stripeStoreResetPromoCode = () => {
|
|
946
|
+
cartStore.promoCode = '';
|
|
947
|
+
sessionStorage.removeItem('zonos--promo-code');
|
|
948
|
+
// reset promocode error state
|
|
949
|
+
cartStore.promoCodeError = false;
|
|
950
|
+
cartStore.promoCodeApplied = false;
|
|
951
|
+
};
|
|
952
|
+
const stripeStoreRemovePromoCode = async () => {
|
|
953
|
+
// Go back to shipping step if we are in payment step so user can reselect shipping method
|
|
954
|
+
if (cartStore.step === 'payment') {
|
|
955
|
+
cartStorePreviousStep();
|
|
956
|
+
}
|
|
957
|
+
stripeStoreResetPromoCode();
|
|
958
|
+
await stripeStoreApplyPromoCode();
|
|
959
|
+
};
|
|
960
|
+
const stripeStoreMessageBasedOnStatus = (status) => {
|
|
961
|
+
let messages = [];
|
|
962
|
+
let isError = true;
|
|
963
|
+
// Inspect the PaymentIntent `status` to indicate the status of the payment
|
|
964
|
+
// to your customer.
|
|
965
|
+
//
|
|
966
|
+
// Some payment methods will [immediately succeed or fail][0] upon
|
|
967
|
+
// confirmation, while others will first enter a `processing` state.
|
|
968
|
+
//
|
|
969
|
+
// [0]: https://stripe.com/docs/payments/payment-methods#payment-notification
|
|
970
|
+
switch (status) {
|
|
971
|
+
case 'succeeded': {
|
|
972
|
+
messages = [
|
|
973
|
+
translate('Your payment went through successfully! Thank you for shopping with us! We hope you had an enjoyable experience and your support means the world to us.'),
|
|
974
|
+
'',
|
|
975
|
+
translate("We've sent an email confirmation of the order details for your review. And our team is carefully preparing your order so it arrives on time."),
|
|
976
|
+
];
|
|
977
|
+
isError = false;
|
|
978
|
+
break;
|
|
979
|
+
}
|
|
980
|
+
case 'requires_capture':
|
|
981
|
+
case 'processing': {
|
|
982
|
+
messages = [
|
|
983
|
+
translate("Payment processing. We'll update you when payment is received."),
|
|
984
|
+
];
|
|
985
|
+
isError = false;
|
|
986
|
+
break;
|
|
987
|
+
}
|
|
988
|
+
case 'requires_payment_method': {
|
|
989
|
+
messages = [
|
|
990
|
+
translate('Payment failed. Please try another payment method.'),
|
|
991
|
+
];
|
|
992
|
+
break;
|
|
993
|
+
}
|
|
994
|
+
case 'requires_action': {
|
|
995
|
+
isError = false;
|
|
996
|
+
messages = [
|
|
997
|
+
translate('Your selected payment method requires additional verification. Please follow the instructions provided by your payment provider to complete the transaction.'),
|
|
998
|
+
];
|
|
999
|
+
}
|
|
1000
|
+
default: {
|
|
1001
|
+
messages = [translate('Something went wrong.')];
|
|
1002
|
+
break;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
return {
|
|
1006
|
+
isError,
|
|
1007
|
+
messages,
|
|
1008
|
+
};
|
|
1009
|
+
};
|
|
1010
|
+
/**
|
|
1011
|
+
* Handle inventory check and returns error message if the callback provided.
|
|
1012
|
+
*/
|
|
1013
|
+
const stripeStoreHandleInventoryCheck = async () => {
|
|
1014
|
+
var _a, _b;
|
|
1015
|
+
const { onInventoryCheck } = zonosStore.checkoutSettings;
|
|
1016
|
+
const hasReferenceId = !!((_b = (_a = window.Zonos.cartData) === null || _a === void 0 ? void 0 : _a.metadata.find(meta => meta.key === 'referenceId')) === null || _b === void 0 ? void 0 : _b.value);
|
|
1017
|
+
// default inventory check is only available for legacy checkout and store has referenceId in metadata
|
|
1018
|
+
if (window.Zonos.isLegacyCheckout &&
|
|
1019
|
+
window.Zonos.cartData &&
|
|
1020
|
+
hasReferenceId) {
|
|
1021
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/legacy/inventory-check', {
|
|
1022
|
+
body: {
|
|
1023
|
+
cartData: window.Zonos.cartData,
|
|
1024
|
+
},
|
|
1025
|
+
method: 'POST',
|
|
1026
|
+
});
|
|
1027
|
+
if (errors.length || !json) {
|
|
1028
|
+
logError('Error occurs when handling inventory refund', 'warn', JSON.stringify(errors));
|
|
1029
|
+
return null;
|
|
1030
|
+
}
|
|
1031
|
+
// Proceed if the item is available
|
|
1032
|
+
if (!json.available || json.status === 204) {
|
|
1033
|
+
return translate("The item you're looking for is currently unavailable in our inventory. Please check back later or contact support for assistance with availability.");
|
|
1034
|
+
}
|
|
1035
|
+
if (json.available || json.status === 200) {
|
|
1036
|
+
stripeStore.shouldInventoryRefund = true;
|
|
1037
|
+
return null;
|
|
1038
|
+
}
|
|
1039
|
+
return null;
|
|
1040
|
+
}
|
|
1041
|
+
if (typeof onInventoryCheck !== 'function') {
|
|
1042
|
+
return null;
|
|
1043
|
+
}
|
|
1044
|
+
try {
|
|
1045
|
+
const message = await onInventoryCheck({ items: cartStore.items });
|
|
1046
|
+
return message;
|
|
1047
|
+
}
|
|
1048
|
+
catch (err) {
|
|
1049
|
+
const message = err instanceof Error ? err.message : 'Unknown error';
|
|
1050
|
+
void sendErrorLog({
|
|
1051
|
+
endpoint: 'onInventoryCheck',
|
|
1052
|
+
errors: [`cartId: ${window.Zonos.cartId} - ${message}`],
|
|
1053
|
+
metadata: {
|
|
1054
|
+
cartId: window.Zonos.cartId,
|
|
1055
|
+
href: window.location.href,
|
|
1056
|
+
items: cartStore.items,
|
|
1057
|
+
},
|
|
1058
|
+
});
|
|
1059
|
+
throw err;
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
/**
|
|
1063
|
+
* Handle inventory check and returns error message if the callback provided.
|
|
1064
|
+
*/
|
|
1065
|
+
const stripeStoreHandleInventoryRefund = async () => {
|
|
1066
|
+
var _a, _b;
|
|
1067
|
+
const hasReferenceId = !!((_b = (_a = window.Zonos.cartData) === null || _a === void 0 ? void 0 : _a.metadata.find(meta => meta.key === 'referenceId')) === null || _b === void 0 ? void 0 : _b.value);
|
|
1068
|
+
// inventory refund is only available for legacy checkout and store has referenceId in metadata
|
|
1069
|
+
if (!window.Zonos.isLegacyCheckout ||
|
|
1070
|
+
!window.Zonos.cartData ||
|
|
1071
|
+
!hasReferenceId) {
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
// handle inventory check on legacy checkout
|
|
1075
|
+
await handleFetch('/api/zonos-elements/legacy/inventory-refund', {
|
|
1076
|
+
body: {
|
|
1077
|
+
cartData: window.Zonos.cartData,
|
|
1078
|
+
},
|
|
1079
|
+
method: 'POST',
|
|
1080
|
+
});
|
|
1081
|
+
};
|
|
1082
|
+
const stripeStoreRetrievePayment = async ({ clientSecret: _clientSecret, storybookForceStatus, }) => {
|
|
1083
|
+
if (storybookForceStatus) {
|
|
1084
|
+
// return status right away if we are in storybook mode
|
|
1085
|
+
const { isError, messages } = stripeStoreMessageBasedOnStatus(storybookForceStatus);
|
|
1086
|
+
return { error: isError, messages };
|
|
1087
|
+
}
|
|
1088
|
+
const clientSecret = _clientSecret || stripeStore.clientSecret;
|
|
1089
|
+
if (!stripeStore.stripe || !clientSecret) {
|
|
1090
|
+
logError('Failed to retrieve payment intent. Stripe is not initialized');
|
|
1091
|
+
return { error: true, message: [translate('Something went wrong.')] };
|
|
1092
|
+
}
|
|
1093
|
+
const { paymentIntent } = await stripeStore.stripe.retrievePaymentIntent(clientSecret);
|
|
1094
|
+
const status = paymentIntent === null || paymentIntent === void 0 ? void 0 : paymentIntent.status;
|
|
1095
|
+
const { isError, messages } = stripeStoreMessageBasedOnStatus(status);
|
|
1096
|
+
return {
|
|
1097
|
+
error: isError,
|
|
1098
|
+
messages,
|
|
1099
|
+
paymentIntentId: paymentIntent === null || paymentIntent === void 0 ? void 0 : paymentIntent.id,
|
|
1100
|
+
paymentMethod: paymentIntent === null || paymentIntent === void 0 ? void 0 : paymentIntent.payment_method,
|
|
1101
|
+
status,
|
|
1102
|
+
};
|
|
1103
|
+
};
|
|
1104
|
+
const stripeStoreConfirmPayment = async () => {
|
|
1105
|
+
var _a, _b;
|
|
1106
|
+
const stripePaymentReady = !!((_a = stripeStore.stripePaymentEventData) === null || _a === void 0 ? void 0 : _a.complete);
|
|
1107
|
+
const stripeElements = stripeStore.stripeElements;
|
|
1108
|
+
const stripe = stripeStore.stripe;
|
|
1109
|
+
const stripeClientSecret = stripeStore.clientSecret;
|
|
1110
|
+
stripeStore.customErrorMessage = null;
|
|
1111
|
+
if (!((_b = cartStore.selectedLandedCost) === null || _b === void 0 ? void 0 : _b.landedCost.id)) {
|
|
1112
|
+
throw new Error('Attempted to confirm the payment when no landed cost is found in store');
|
|
1113
|
+
}
|
|
1114
|
+
// Check if the checkout session is valid before proceeding
|
|
1115
|
+
const checkoutSessionStatus = await validateCheckoutSession();
|
|
1116
|
+
if (!checkoutSessionStatus.valid) {
|
|
1117
|
+
stripeStore.customErrorMessage = checkoutSessionStatus.errorMessage;
|
|
1118
|
+
throw new Error(checkoutSessionStatus.errorMessage);
|
|
1119
|
+
}
|
|
1120
|
+
const checkoutSessionId = storageStore.checkoutSessionId;
|
|
1121
|
+
if (stripe &&
|
|
1122
|
+
stripeElements &&
|
|
1123
|
+
stripePaymentReady &&
|
|
1124
|
+
stripeClientSecret &&
|
|
1125
|
+
checkoutSessionId) {
|
|
1126
|
+
const buildUrl = new URL(window.location.href);
|
|
1127
|
+
buildUrl.searchParams.set('payment_intent_client_secret', stripeClientSecret);
|
|
1128
|
+
buildUrl.searchParams.set('zonosCheckoutSessionId', checkoutSessionId);
|
|
1129
|
+
void trackConversionEvent({
|
|
1130
|
+
checkoutSessionId,
|
|
1131
|
+
eventName: 'checkout_paymentInfoCompleted',
|
|
1132
|
+
});
|
|
1133
|
+
const { error, paymentIntent } = await stripe.confirmPayment({
|
|
1134
|
+
confirmParams: {
|
|
1135
|
+
return_url: buildUrl.toString(),
|
|
1136
|
+
},
|
|
1137
|
+
elements: stripeElements,
|
|
1138
|
+
redirect: 'if_required',
|
|
1139
|
+
});
|
|
1140
|
+
log('Payment intent confirmed', 'info', { error, paymentIntent });
|
|
1141
|
+
if ((paymentIntent === null || paymentIntent === void 0 ? void 0 : paymentIntent.status) === 'requires_action') {
|
|
1142
|
+
throw new Error(translate('Your selected payment method requires additional verification. Please follow the instructions provided by your payment provider to complete the transaction.'));
|
|
1143
|
+
}
|
|
1144
|
+
if (error) {
|
|
1145
|
+
if (error.type === 'card_error' || error.type === 'validation_error') {
|
|
1146
|
+
throw new Error(error.message);
|
|
1147
|
+
}
|
|
1148
|
+
if (error.type === 'invalid_request_error') {
|
|
1149
|
+
if (error.code === 'payment_intent_unexpected_state') {
|
|
1150
|
+
// PaymentIntent was canceled or expired, or status is `require_capture`.
|
|
1151
|
+
// don't throw error here because we will reset the checkout session last step
|
|
1152
|
+
return;
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
throw new Error('An unexpected error occurred.');
|
|
1156
|
+
}
|
|
1157
|
+
if (paymentIntent.status === 'requires_payment_method') {
|
|
1158
|
+
// Failed to confirm payment, allows user to try another payment method
|
|
1159
|
+
throw new Error(translate('Payment failed. Please try another payment method.'));
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
};
|
|
1163
|
+
const getCheckoutSessionBody = () => {
|
|
1164
|
+
var _a;
|
|
1165
|
+
const total = cartStore.items.reduce((amount, item) => amount + item.amount * item.quantity, 0);
|
|
1166
|
+
const varianceTestInput = storageStore.enabledVariantTestKeys || [];
|
|
1167
|
+
const body = {
|
|
1168
|
+
adjustmentsAmount: cartStore.adjustments.reduce((prev, adj) => prev + adj.amount, 0),
|
|
1169
|
+
cartId: window.Zonos.cartId,
|
|
1170
|
+
currency: ((_a = cartStore.items.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode) || '',
|
|
1171
|
+
customerAuthenticationToken: cartStore.customerAuthenticationToken || undefined,
|
|
1172
|
+
itemsAmount: total,
|
|
1173
|
+
metadata: [
|
|
1174
|
+
{
|
|
1175
|
+
key: 'language',
|
|
1176
|
+
value: localizationStore.selectedLocale,
|
|
1177
|
+
},
|
|
1178
|
+
{
|
|
1179
|
+
key: 'appVersion',
|
|
1180
|
+
value: window.Zonos.version,
|
|
1181
|
+
},
|
|
1182
|
+
{
|
|
1183
|
+
key: 'appVersionNpmIntegration',
|
|
1184
|
+
value: window.Zonos.isNpm ? '1' : '0',
|
|
1185
|
+
},
|
|
1186
|
+
{
|
|
1187
|
+
key: 'legacyCheckoutFacade',
|
|
1188
|
+
value: window.Zonos.isLegacyCheckout ? '1' : '0',
|
|
1189
|
+
},
|
|
1190
|
+
],
|
|
1191
|
+
presentmentCountryCode: localizationStore.selectedCountryCode,
|
|
1192
|
+
skipPaymentIntent: stripeStore.skipPaymentIntent,
|
|
1193
|
+
varianceTestInput,
|
|
1194
|
+
};
|
|
1195
|
+
return body;
|
|
1196
|
+
};
|
|
1197
|
+
const stripeStoreGetPaymentIntent = async () => {
|
|
1198
|
+
var _a;
|
|
1199
|
+
if (!storageStore.checkoutSessionId) {
|
|
1200
|
+
// We want to log the error anytime we fail to create a checkout session
|
|
1201
|
+
void sendErrorLog({
|
|
1202
|
+
endpoint: 'Error creating payment intent',
|
|
1203
|
+
errors: ['No checkout session id found when retrieving payment intent'],
|
|
1204
|
+
metadata: {
|
|
1205
|
+
allLogs,
|
|
1206
|
+
cartId: window.Zonos.cartId,
|
|
1207
|
+
},
|
|
1208
|
+
});
|
|
1209
|
+
cartStoreUpdateToErrorState({
|
|
1210
|
+
messages: [
|
|
1211
|
+
translate("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists"),
|
|
1212
|
+
],
|
|
1213
|
+
title: translate('Error creating Checkout'),
|
|
1214
|
+
});
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/create-payment-intent', {
|
|
1218
|
+
body: {
|
|
1219
|
+
checkoutSessionId: storageStore.checkoutSessionId,
|
|
1220
|
+
},
|
|
1221
|
+
method: 'POST',
|
|
1222
|
+
});
|
|
1223
|
+
const clientSecret = (_a = json === null || json === void 0 ? void 0 : json.checkoutSessionPaymentIntentCreate) === null || _a === void 0 ? void 0 : _a.clientSecret;
|
|
1224
|
+
if (errors.length || !clientSecret) {
|
|
1225
|
+
logError('Error occurs when getting payment intent', JSON.stringify(errors, null, 2));
|
|
1226
|
+
// We want to log the error anytime we fail to create a payment intent
|
|
1227
|
+
void sendErrorLog({
|
|
1228
|
+
endpoint: 'Error creating payment intent',
|
|
1229
|
+
errors: errors.map(error => error.message),
|
|
1230
|
+
metadata: {
|
|
1231
|
+
allLogs,
|
|
1232
|
+
cartId: window.Zonos.cartId,
|
|
1233
|
+
checkoutSessionId: storageStore.checkoutSessionId,
|
|
1234
|
+
clientSecret,
|
|
1235
|
+
},
|
|
1236
|
+
});
|
|
1237
|
+
cartStoreUpdateToErrorState({
|
|
1238
|
+
messages: [
|
|
1239
|
+
translate("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists"),
|
|
1240
|
+
],
|
|
1241
|
+
title: translate('Error creating Checkout'),
|
|
1242
|
+
});
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
// update cart store checkout session with updated from checkout session payment intent creation call so the checkout session and payment intent are in sync
|
|
1246
|
+
cartStoreSetCheckoutSession(json.checkoutSessionPaymentIntentCreate);
|
|
1247
|
+
};
|
|
1248
|
+
/**
|
|
1249
|
+
* Init checkout session
|
|
1250
|
+
* @returns {boolean} whether or not the checkout session is successfully created
|
|
1251
|
+
*/
|
|
1252
|
+
const stripeStoreInitCheckoutSession = async () => {
|
|
1253
|
+
var _a, _b;
|
|
1254
|
+
if (!localizationStore.targetCurrency) {
|
|
1255
|
+
logError(`Failed to create checkout session - missing localizationStore.targetCurrency`);
|
|
1256
|
+
return false;
|
|
1257
|
+
}
|
|
1258
|
+
stripeStore.isFetchingSession = true;
|
|
1259
|
+
const body = getCheckoutSessionBody();
|
|
1260
|
+
log('Checkout session body', 'info', body);
|
|
1261
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/create-checkout-session', {
|
|
1262
|
+
body,
|
|
1263
|
+
method: 'POST',
|
|
1264
|
+
});
|
|
1265
|
+
stripeStore.isFetchingSession = false;
|
|
1266
|
+
if (errors.length || !json) {
|
|
1267
|
+
const messages = (_a = errors.find(error => error.message)) === null || _a === void 0 ? void 0 : _a.message;
|
|
1268
|
+
// check if the error is related to expired cart and thow error so we can show error message accordingly
|
|
1269
|
+
if (messages.some(message => message.message === 'Cart is expired.')) {
|
|
1270
|
+
throw new Error('Cart is expired.');
|
|
1271
|
+
}
|
|
1272
|
+
logError('Error occurred when creating checkout session', JSON.stringify(errors, null, 2));
|
|
1273
|
+
return false;
|
|
1274
|
+
}
|
|
1275
|
+
const result = json.checkoutSessionCreate;
|
|
1276
|
+
// update cart store with updated information
|
|
1277
|
+
cartStoreSetCheckoutSession(result);
|
|
1278
|
+
cartStoreApplySubtotals({
|
|
1279
|
+
method: ((_b = result.landedCost) === null || _b === void 0 ? void 0 : _b.method) || 'DDP',
|
|
1280
|
+
subtotals: result.subtotals,
|
|
1281
|
+
});
|
|
1282
|
+
log('Exchange rate updated for cart items (checkout session create)', 'info', cartStore.exchangeRate);
|
|
1283
|
+
log('done-init-checkout-session');
|
|
1284
|
+
return true;
|
|
1285
|
+
};
|
|
1286
|
+
const stripeStoreUpdateCheckoutSessionBaseCurrency = async () => {
|
|
1287
|
+
const checkoutSessionId = storageStore.checkoutSessionId;
|
|
1288
|
+
// Checkout session id should be available at this point
|
|
1289
|
+
if (!checkoutSessionId) {
|
|
1290
|
+
logError('Failed to update checkout session base currency');
|
|
1291
|
+
return false;
|
|
1292
|
+
}
|
|
1293
|
+
// Only update checkout session currency if setting is enabled
|
|
1294
|
+
if (zonosStore.checkoutSettings.allowedSettlementCurrencies === 'LOCAL') {
|
|
1295
|
+
log('allowedSettlementCurrencies: "LOCAL". Skip updating checkout session base currency');
|
|
1296
|
+
return true;
|
|
1297
|
+
}
|
|
1298
|
+
const { json } = await handleFetch('/api/zonos-elements/update-checkout-session-base-currency', {
|
|
1299
|
+
body: {
|
|
1300
|
+
checkoutSessionId,
|
|
1301
|
+
currencyCode: stripeStore.checkoutSettlementCurrency,
|
|
1302
|
+
},
|
|
1303
|
+
method: 'POST',
|
|
1304
|
+
});
|
|
1305
|
+
const settlementCurrencyCode = json === null || json === void 0 ? void 0 : json.checkoutSessionBaseCurrencyUpdate.subtotals.presentmentCurrencyCode;
|
|
1306
|
+
// S
|
|
1307
|
+
if (!json ||
|
|
1308
|
+
settlementCurrencyCode !== stripeStore.checkoutSettlementCurrency) {
|
|
1309
|
+
logError('Failed to update checkout session base currency');
|
|
1310
|
+
return false;
|
|
1311
|
+
}
|
|
1312
|
+
log(`Updated checkout session to settlement currency "${settlementCurrencyCode}".`);
|
|
1313
|
+
return true;
|
|
1314
|
+
};
|
|
1315
|
+
/**
|
|
1316
|
+
* Update checkout session. Use for updating amount with landed cost id, or update session when cart items change
|
|
1317
|
+
*/
|
|
1318
|
+
const stripeStoreUpdateCheckoutSession = async ({ adjustmentsAmount, cartId, currency, id, itemsAmount, landedCostId, presentmentCountryCode, }) => {
|
|
1319
|
+
const varianceTestInput = storageStore.enabledVariantTestKeys || [];
|
|
1320
|
+
// No need to set loading state here because this function will be called under the hood to update
|
|
1321
|
+
// landed cost id for the section.
|
|
1322
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/update-checkout-session', {
|
|
1323
|
+
body: {
|
|
1324
|
+
adjustmentsAmount,
|
|
1325
|
+
cartId,
|
|
1326
|
+
currency,
|
|
1327
|
+
customerAuthenticationToken: cartStore.customerAuthenticationToken || undefined,
|
|
1328
|
+
id,
|
|
1329
|
+
itemsAmount,
|
|
1330
|
+
landedCostId,
|
|
1331
|
+
metadata: [
|
|
1332
|
+
{
|
|
1333
|
+
key: 'language',
|
|
1334
|
+
value: localizationStore.selectedLocale,
|
|
1335
|
+
},
|
|
1336
|
+
{
|
|
1337
|
+
key: 'appVersion',
|
|
1338
|
+
value: window.Zonos.version,
|
|
1339
|
+
},
|
|
1340
|
+
{
|
|
1341
|
+
key: 'appVersionNpmIntegration',
|
|
1342
|
+
value: window.Zonos.isNpm ? '1' : '0',
|
|
1343
|
+
},
|
|
1344
|
+
{
|
|
1345
|
+
key: 'legacyCheckoutFacade',
|
|
1346
|
+
value: window.Zonos.isLegacyCheckout ? '1' : '0',
|
|
1347
|
+
},
|
|
1348
|
+
],
|
|
1349
|
+
presentmentCountryCode,
|
|
1350
|
+
skipPaymentIntent: stripeStore.skipPaymentIntent,
|
|
1351
|
+
varianceTestInput,
|
|
1352
|
+
},
|
|
1353
|
+
method: 'POST',
|
|
1354
|
+
});
|
|
1355
|
+
if (errors.length || !json) {
|
|
1356
|
+
logError('Error occurs when updating checkout session', JSON.stringify(errors, null, 2));
|
|
1357
|
+
return { errors, json };
|
|
1358
|
+
}
|
|
1359
|
+
return { errors: [], json };
|
|
1360
|
+
};
|
|
1361
|
+
/**
|
|
1362
|
+
* This function builds a translated address object from the current address and the translated address result.
|
|
1363
|
+
* It checks each field in the current address and if it exists in the translated address result, it adds it to the translated address object.
|
|
1364
|
+
* The key of each field in the translated address object is the current address's field value and the value is the corresponding translated address's field value.
|
|
1365
|
+
*
|
|
1366
|
+
* @param {Object} params - The parameters for the function.
|
|
1367
|
+
* @param {Address} params.currentAddress - The current address information.
|
|
1368
|
+
* @param {Address} params.translatedAddressResult - The translated address result.
|
|
1369
|
+
*
|
|
1370
|
+
* @returns {TranslatedAddress} - An object containing the translated address. Each field is an object with the current address's field value as the key and the translated address's field value as the value.
|
|
1371
|
+
*/
|
|
1372
|
+
const buildTranslatedAddress = ({ currentAddress, translatedAddressResult, }) => {
|
|
1373
|
+
const translatedAddress = {};
|
|
1374
|
+
if (!translatedAddressResult) {
|
|
1375
|
+
return translatedAddress;
|
|
1376
|
+
}
|
|
1377
|
+
const { city, line1, line2, name, postal_code, state } = translatedAddressResult;
|
|
1378
|
+
// If we have translated address, add it to the translated address object
|
|
1379
|
+
if (currentAddress.city && city) {
|
|
1380
|
+
translatedAddress.city = {
|
|
1381
|
+
[currentAddress.city]: city,
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
if (currentAddress.line1 && line1) {
|
|
1385
|
+
translatedAddress.line1 = {
|
|
1386
|
+
[currentAddress.line1]: line1,
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
if (currentAddress.line2 && line2) {
|
|
1390
|
+
translatedAddress.line2 = {
|
|
1391
|
+
[currentAddress.line2]: line2,
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
if (currentAddress.postal_code && postal_code) {
|
|
1395
|
+
translatedAddress.postal_code = {
|
|
1396
|
+
[currentAddress.postal_code]: postal_code,
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
if (currentAddress.state && state) {
|
|
1400
|
+
translatedAddress.state = {
|
|
1401
|
+
[currentAddress.state]: state,
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
if (currentAddress.name && name) {
|
|
1405
|
+
translatedAddress.name = {
|
|
1406
|
+
[currentAddress.name]: name,
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
return translatedAddress;
|
|
1410
|
+
};
|
|
1411
|
+
/**
|
|
1412
|
+
* This function translates an address to Latin characters using the Zonos API.
|
|
1413
|
+
* It first builds the request body for the API call. If there's no request body, it resets the translated address in the store and returns.
|
|
1414
|
+
* If the address is not outdated, it returns without making the API call.
|
|
1415
|
+
* It then makes a POST request to the Zonos API to validate and translate the address. If the API call fails, it resets the translated address in the store and returns.
|
|
1416
|
+
* If the API call is successful, it sets the current address and billing address in the store and builds the translated address and billing address from the API response.
|
|
1417
|
+
*
|
|
1418
|
+
* @param {Object} params - The parameters for the function.
|
|
1419
|
+
* @param {ReturnType<typeof containsNonLatinChars> | null} params.addressInvalidCharactersList - The list of address fields that contain invalid characters.
|
|
1420
|
+
* @param {ReturnType<typeof containsNonLatinChars> | null} params.billingAddressInvalidCharactersList - The list of billing address fields that contain invalid characters.
|
|
1421
|
+
*/
|
|
1422
|
+
const stripeStoreTranslateAddressToLatin = async ({ addressInvalidCharactersList, billingAddressInvalidCharactersList, }) => {
|
|
1423
|
+
var _a, _b, _c, _d;
|
|
1424
|
+
const requestBody = buildTranslateRequest({
|
|
1425
|
+
addressInvalidCharactersList,
|
|
1426
|
+
billingAddressInvalidCharactersList,
|
|
1427
|
+
stripeAddressEventData: stripeStore.stripeAddressEventData,
|
|
1428
|
+
stripeBillingAddressEventData: stripeStore.stripeBillingAddressEventData,
|
|
1429
|
+
stripeShippingSameAsBilling: stripeStore.stripeShippingSameAsBilling,
|
|
1430
|
+
});
|
|
1431
|
+
if (!requestBody) {
|
|
1432
|
+
// reset translated address if we don't have any address to translate
|
|
1433
|
+
stripeStore.translatedAddress = {
|
|
1434
|
+
address: {},
|
|
1435
|
+
billingAddress: {},
|
|
1436
|
+
};
|
|
1437
|
+
return;
|
|
1438
|
+
}
|
|
1439
|
+
// only translate address if the address is out of date
|
|
1440
|
+
const isAddressOutdated = checkIsAddressOutdatedForValidation();
|
|
1441
|
+
if (!isAddressOutdated) {
|
|
1442
|
+
return;
|
|
1443
|
+
}
|
|
1444
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/validate-address', {
|
|
1445
|
+
body: requestBody,
|
|
1446
|
+
method: 'POST',
|
|
1447
|
+
});
|
|
1448
|
+
if (errors.length || !json) {
|
|
1449
|
+
logError('Error occurs when translating address to latin', JSON.stringify(errors, null, 2));
|
|
1450
|
+
// reset translated address if we Failed to translate and let user manually fix it
|
|
1451
|
+
stripeStore.translatedAddress = {
|
|
1452
|
+
address: {},
|
|
1453
|
+
billingAddress: {},
|
|
1454
|
+
};
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
// Set current address to the store so we can compare it later to determine if we need to re-translate the address
|
|
1458
|
+
stripeStore.stripeAddressUsedWhenValidatingAddress =
|
|
1459
|
+
stripeStore.stripeAddressEventData;
|
|
1460
|
+
stripeStore.stripeBillingAddressUsedWhenValidatingAddress =
|
|
1461
|
+
stripeStore.stripeBillingAddressEventData;
|
|
1462
|
+
const address = (_a = stripeStore.stripeAddressEventData) === null || _a === void 0 ? void 0 : _a.value.address;
|
|
1463
|
+
const billingAddress = (_b = stripeStore.stripeBillingAddressEventData) === null || _b === void 0 ? void 0 : _b.value.address;
|
|
1464
|
+
// Set the translated address to the store so we can populate it to the address element for user to update
|
|
1465
|
+
stripeStore.translatedAddress = {
|
|
1466
|
+
address: address
|
|
1467
|
+
? buildTranslatedAddress({
|
|
1468
|
+
currentAddress: Object.assign(Object.assign({}, address), { name: (_c = stripeStore.stripeAddressEventData) === null || _c === void 0 ? void 0 : _c.value.name }),
|
|
1469
|
+
translatedAddressResult: json.address || null,
|
|
1470
|
+
})
|
|
1471
|
+
: {},
|
|
1472
|
+
billingAddress: !stripeStore.stripeShippingSameAsBilling
|
|
1473
|
+
? buildTranslatedAddress({
|
|
1474
|
+
currentAddress: Object.assign(Object.assign({}, billingAddress), { name: (_d = stripeStore.stripeBillingAddressEventData) === null || _d === void 0 ? void 0 : _d.value.name }),
|
|
1475
|
+
translatedAddressResult: json.billingAddress || null,
|
|
1476
|
+
})
|
|
1477
|
+
: {},
|
|
1478
|
+
};
|
|
1479
|
+
};
|
|
1480
|
+
stripeStoreOnChange('clientSecret', clientSecret => {
|
|
1481
|
+
// update stripe elements when client secret changes
|
|
1482
|
+
if (clientSecret && stripeStore.stripe) {
|
|
1483
|
+
sessionStorage.setItem('zonos--client-secret', clientSecret);
|
|
1484
|
+
}
|
|
1485
|
+
if (!clientSecret) {
|
|
1486
|
+
sessionStorage.removeItem('zonos--client-secret');
|
|
1487
|
+
}
|
|
1488
|
+
});
|
|
1489
|
+
|
|
1490
|
+
const { reset, state: cartStore } = createStore(() => ({
|
|
1491
|
+
adjustmentTotal: 0,
|
|
1492
|
+
adjustments: [],
|
|
1493
|
+
checkoutSession: null,
|
|
1494
|
+
checkoutSessionTimeoutShow: false,
|
|
1495
|
+
checkoutTimeoutInterval: null,
|
|
1496
|
+
currency: 'USD',
|
|
1497
|
+
customQuotingError: null,
|
|
1498
|
+
customerAuthenticationToken: null,
|
|
1499
|
+
displayBaseCurrency: false,
|
|
1500
|
+
dutiesTaxesFees: null,
|
|
1501
|
+
dutiesTaxesFeesEstimate: null,
|
|
1502
|
+
error: null,
|
|
1503
|
+
exchangeRate: null,
|
|
1504
|
+
externalConfirmationPageURL: null,
|
|
1505
|
+
inventoryCheckErrorMessage: null,
|
|
1506
|
+
isSelectedShippingAboveDeminimis: false,
|
|
1507
|
+
isSelectedShippingGuarantee: false,
|
|
1508
|
+
isStagingMode: getIsStagingMode(),
|
|
1509
|
+
items: [],
|
|
1510
|
+
landedCostData: null,
|
|
1511
|
+
landedCostMethod: 'DDP',
|
|
1512
|
+
partiesData: [],
|
|
1513
|
+
promoCode: sessionStorage.getItem('zonos--promo-code') || '',
|
|
1514
|
+
// When user clicked applied button, save promocode into session storage for later use. So if session has promocode, applied button is clicked
|
|
1515
|
+
promoCodeApplied: !!sessionStorage.getItem('zonos--promo-code'),
|
|
1516
|
+
promoCodeError: false,
|
|
1517
|
+
restrictedItems: [],
|
|
1518
|
+
selectedLandedCost: null,
|
|
1519
|
+
selectedShippingOption: null,
|
|
1520
|
+
selectedShippingOptionExpectedDate: '',
|
|
1521
|
+
selectedShippingOptionTransitTime: '',
|
|
1522
|
+
shipping: 0,
|
|
1523
|
+
shippingData: null,
|
|
1524
|
+
shouldHideDiscountInput: false,
|
|
1525
|
+
step: 'customer-info',
|
|
1526
|
+
subtotal: 0,
|
|
1527
|
+
tabItems: {
|
|
1528
|
+
'customer-info': {
|
|
1529
|
+
index: 1,
|
|
1530
|
+
isDone: false,
|
|
1531
|
+
label: 'Customer',
|
|
1532
|
+
value: 'customer-info',
|
|
1533
|
+
},
|
|
1534
|
+
shipping: {
|
|
1535
|
+
index: 2,
|
|
1536
|
+
isDone: false,
|
|
1537
|
+
label: 'Shipping',
|
|
1538
|
+
value: 'shipping',
|
|
1539
|
+
},
|
|
1540
|
+
// eslint-disable-next-line sort-keys/sort-keys-fix
|
|
1541
|
+
payment: {
|
|
1542
|
+
index: 3,
|
|
1543
|
+
isDone: false,
|
|
1544
|
+
label: 'Payment',
|
|
1545
|
+
value: 'payment',
|
|
1546
|
+
},
|
|
1547
|
+
},
|
|
1548
|
+
total: 0,
|
|
1549
|
+
}));
|
|
1550
|
+
const getTransitUnit = (type) => {
|
|
1551
|
+
switch (type) {
|
|
1552
|
+
case 'DAYS':
|
|
1553
|
+
return translate('days');
|
|
1554
|
+
case 'WEEKS':
|
|
1555
|
+
return translate('weeks');
|
|
1556
|
+
case 'BUSINESS_DAYS':
|
|
1557
|
+
default:
|
|
1558
|
+
return translate('business days');
|
|
1559
|
+
}
|
|
1560
|
+
};
|
|
1561
|
+
/**
|
|
1562
|
+
* Format shipping transit info to be displayed on UI
|
|
1563
|
+
* @returns
|
|
1564
|
+
* - expectedDate: Thursday, Aug 12
|
|
1565
|
+
* - maxTransit: 5
|
|
1566
|
+
* - minTransit: 3
|
|
1567
|
+
*/
|
|
1568
|
+
const cartStoreGetShippingTransitInfo = (item) => {
|
|
1569
|
+
var _a;
|
|
1570
|
+
const transitTime = (_a = item.shippingProfile) === null || _a === void 0 ? void 0 : _a.transitTime;
|
|
1571
|
+
// Don't care about falsy 0 values because this is international shipping and 0 days is not feasible
|
|
1572
|
+
if (!(transitTime === null || transitTime === void 0 ? void 0 : transitTime.min) || !(transitTime === null || transitTime === void 0 ? void 0 : transitTime.max) || !(transitTime === null || transitTime === void 0 ? void 0 : transitTime.type)) {
|
|
1573
|
+
return null;
|
|
1574
|
+
}
|
|
1575
|
+
return {
|
|
1576
|
+
maxTransit: transitTime.max,
|
|
1577
|
+
minTransit: transitTime.min,
|
|
1578
|
+
unit: getTransitUnit(transitTime.type),
|
|
1579
|
+
};
|
|
1580
|
+
};
|
|
1581
|
+
const getMatchItem = ({ item1, item2, }) => {
|
|
1582
|
+
if (!item1 || !item2) {
|
|
1583
|
+
return false;
|
|
1584
|
+
}
|
|
1585
|
+
return ((item2.sku && item1.sku && item1.sku === item2.sku) ||
|
|
1586
|
+
(item2.description &&
|
|
1587
|
+
item1.description &&
|
|
1588
|
+
item1.description === item2.description) ||
|
|
1589
|
+
(item1.name && item2.name && item1.name === item2.name));
|
|
1590
|
+
};
|
|
1591
|
+
/**
|
|
1592
|
+
* Check and set restricted items in cart
|
|
1593
|
+
*/
|
|
1594
|
+
const cartStoreCheckItemRestrictions = (itemsWorkflow) => {
|
|
1595
|
+
log('Checking item restrictions');
|
|
1596
|
+
const mappedRestrictedItems = itemsWorkflow
|
|
1597
|
+
.map(item => {
|
|
1598
|
+
if (!item.restriction) {
|
|
1599
|
+
return null;
|
|
1600
|
+
}
|
|
1601
|
+
const { restriction } = item;
|
|
1602
|
+
const matchedItem = cartStore.items.find(x => getMatchItem({ item1: x, item2: item }));
|
|
1603
|
+
return Object.assign(Object.assign({ matchedItem }, item), { restriction });
|
|
1604
|
+
})
|
|
1605
|
+
.filter(Boolean);
|
|
1606
|
+
cartStore.restrictedItems = mappedRestrictedItems;
|
|
1607
|
+
// remove items that are restricted from cart
|
|
1608
|
+
cartStore.items = cartStore.items.map(item => (Object.assign(Object.assign({}, item), { isRestricted: !!mappedRestrictedItems.find(x => getMatchItem({ item1: x, item2: item })) })));
|
|
1609
|
+
return {
|
|
1610
|
+
cartItems: cartStore.items,
|
|
1611
|
+
restrictedItems: mappedRestrictedItems,
|
|
1612
|
+
};
|
|
1613
|
+
};
|
|
1614
|
+
const cartStoreReset = () => {
|
|
1615
|
+
storageStore.checkoutSessionId = null;
|
|
1616
|
+
// reset cart store
|
|
1617
|
+
reset();
|
|
1618
|
+
};
|
|
1619
|
+
const cartStoreUpdateToErrorState = ({ messages, title, }) => {
|
|
1620
|
+
cartStoreReset();
|
|
1621
|
+
stripeStoreReset();
|
|
1622
|
+
cartStore.step = 'error';
|
|
1623
|
+
cartStore.error = {
|
|
1624
|
+
messages,
|
|
1625
|
+
title,
|
|
1626
|
+
};
|
|
1627
|
+
};
|
|
1628
|
+
const cartStoreApplySubtotals = ({ dutiesTaxesFeesEstimate, method, subtotals, }) => {
|
|
1629
|
+
// update exchange rate so we can use it to display cart items
|
|
1630
|
+
cartStore.exchangeRate = subtotals.exchangeRate;
|
|
1631
|
+
cartStore.adjustmentTotal = subtotals.adjustments;
|
|
1632
|
+
cartStore.dutiesTaxesFees =
|
|
1633
|
+
method === 'DAP' ? null : subtotals.landedCostTotal;
|
|
1634
|
+
cartStore.subtotal = subtotals.items;
|
|
1635
|
+
cartStore.total = subtotals.total;
|
|
1636
|
+
cartStore.currency = subtotals.presentmentCurrencyCode;
|
|
1637
|
+
cartStore.dutiesTaxesFeesEstimate = dutiesTaxesFeesEstimate || null;
|
|
1638
|
+
};
|
|
1639
|
+
/**
|
|
1640
|
+
* Detect if there are any items in cart that are not restricted and have positive amount, exclude negative amount items
|
|
1641
|
+
*/
|
|
1642
|
+
const cartStoreHasOneEligibleItem = () => {
|
|
1643
|
+
// filter all items with positive amount
|
|
1644
|
+
const checkItems = cartStore.items.filter(item => item.amount > 0);
|
|
1645
|
+
// only check restricted status for items with positive amount
|
|
1646
|
+
// if there is no item restricted found => all items are restricted
|
|
1647
|
+
return !!checkItems.find(item => !item.isRestricted);
|
|
1648
|
+
};
|
|
1649
|
+
const cartStoreSetCheckoutSession = (checkoutSession) => {
|
|
1650
|
+
var _a, _b, _c, _d, _e;
|
|
1651
|
+
// update stripe store with updated information
|
|
1652
|
+
stripeStore.clientSecret = checkoutSession.clientSecret;
|
|
1653
|
+
stripeStore.stripeCustomerSessionClientSecret =
|
|
1654
|
+
checkoutSession.customerSessionClientSecret;
|
|
1655
|
+
stripeStore.customerProfile = checkoutSession.customerProfile;
|
|
1656
|
+
cartStore.checkoutSession = checkoutSession;
|
|
1657
|
+
if (!checkoutSession.id) {
|
|
1658
|
+
// Log error to track down the issue
|
|
1659
|
+
void sendErrorLog({
|
|
1660
|
+
endpoint: 'cartStoreSetCheckoutSession',
|
|
1661
|
+
errors: ['Missing checkout session id in checkout session'],
|
|
1662
|
+
metadata: {
|
|
1663
|
+
allLogs,
|
|
1664
|
+
checkoutSession,
|
|
1665
|
+
},
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
// Only update checkout session id if it's not empty
|
|
1669
|
+
if (checkoutSession.id) {
|
|
1670
|
+
storageStore.checkoutSessionId = checkoutSession.id;
|
|
1671
|
+
}
|
|
1672
|
+
// Filter the response to only include test keys that we support and then save it to the session
|
|
1673
|
+
const availableSelectedVariantTestKeys = filterValidTests(checkoutSession.varianceTestResults || []);
|
|
1674
|
+
storageStoreSetEnabledVariantTestKeys(availableSelectedVariantTestKeys);
|
|
1675
|
+
// Check if there is a redirect URL in the metadata to override
|
|
1676
|
+
const externalConfirmationPageURL = ((_c = (_b = (_a = cartStore.checkoutSession) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.find(entry => (entry === null || entry === void 0 ? void 0 : entry.key) === 'externalConfirmationPageURL')) === null || _c === void 0 ? void 0 : _c.value) ||
|
|
1677
|
+
(
|
|
1678
|
+
// Sometimes externalConfirmationPageURL is not in checkoutSession create/update, check if there is a redirect URL in the cart metadata to override
|
|
1679
|
+
(_e = (_d = window.Zonos.cartData) === null || _d === void 0 ? void 0 : _d.metadata.find(entry => (entry === null || entry === void 0 ? void 0 : entry.key) === 'externalConfirmationPageURL')) === null || _e === void 0 ? void 0 : _e.value) ||
|
|
1680
|
+
null;
|
|
1681
|
+
if (externalConfirmationPageURL) {
|
|
1682
|
+
log(`Found externalConfirmationPageURL: ${externalConfirmationPageURL}`);
|
|
1683
|
+
cartStore.externalConfirmationPageURL = externalConfirmationPageURL;
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1686
|
+
const cartStoreReCalculateTotal = async ({ adjustmentsAmount, cartId, currency, dutiesTaxesFeesEstimate, itemsAmount, landedCostId, shouldInitSessionOnFailure, }) => {
|
|
1687
|
+
var _a;
|
|
1688
|
+
if (landedCostId && cartStore.selectedLandedCost) {
|
|
1689
|
+
// update cart total right away if we have landed cost id to avoid order total flickering
|
|
1690
|
+
const subtotals = cartStore.selectedLandedCost.subtotals;
|
|
1691
|
+
cartStoreApplySubtotals({
|
|
1692
|
+
dutiesTaxesFeesEstimate,
|
|
1693
|
+
method: cartStore.landedCostMethod,
|
|
1694
|
+
subtotals,
|
|
1695
|
+
});
|
|
1696
|
+
log('Exchange rate updated for cart items (landed cost subtotal)', 'info', cartStore.exchangeRate);
|
|
1697
|
+
}
|
|
1698
|
+
// update checkout session
|
|
1699
|
+
if (!storageStore.checkoutSessionId) {
|
|
1700
|
+
log('Could not update cart total without checkout session id', 'info');
|
|
1701
|
+
return false;
|
|
1702
|
+
}
|
|
1703
|
+
const { errors, json } = await stripeStoreUpdateCheckoutSession({
|
|
1704
|
+
adjustmentsAmount,
|
|
1705
|
+
cartId,
|
|
1706
|
+
currency,
|
|
1707
|
+
id: storageStore.checkoutSessionId,
|
|
1708
|
+
itemsAmount,
|
|
1709
|
+
landedCostId,
|
|
1710
|
+
presentmentCountryCode: localizationStore.selectedCountryCode,
|
|
1711
|
+
varianceTestInput: storageStore.enabledVariantTestKeys || [],
|
|
1712
|
+
});
|
|
1713
|
+
if (errors.length > 0 || !json) {
|
|
1714
|
+
logError('Error occurs when updating checkout session.');
|
|
1715
|
+
if (shouldInitSessionOnFailure) {
|
|
1716
|
+
log('Initiating checkout session on failure', 'info');
|
|
1717
|
+
const success = await stripeStoreInitCheckoutSession();
|
|
1718
|
+
log(`stripeStoreInitCheckoutSession: ${success}`);
|
|
1719
|
+
if (!success) {
|
|
1720
|
+
cartStoreUpdateToErrorState({
|
|
1721
|
+
messages: [
|
|
1722
|
+
translate("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists"),
|
|
1723
|
+
],
|
|
1724
|
+
title: translate('Error creating Checkout'),
|
|
1725
|
+
});
|
|
1726
|
+
return false;
|
|
1727
|
+
}
|
|
1728
|
+
return true;
|
|
1729
|
+
}
|
|
1730
|
+
return false;
|
|
1731
|
+
}
|
|
1732
|
+
if (!landedCostId) {
|
|
1733
|
+
// This is when we first open the checkout modal and we just want to get info from the old cart session.
|
|
1734
|
+
// use subtotals from checkout session to update cart total
|
|
1735
|
+
cartStoreApplySubtotals({
|
|
1736
|
+
method: ((_a = json.checkoutSessionUpdate.landedCost) === null || _a === void 0 ? void 0 : _a.method) || 'DDP',
|
|
1737
|
+
subtotals: json.checkoutSessionUpdate.subtotals,
|
|
1738
|
+
});
|
|
1739
|
+
log('Exchange rate updated for cart items (checkout session update)', 'info', cartStore.exchangeRate);
|
|
1740
|
+
}
|
|
1741
|
+
cartStoreSetCheckoutSession(json.checkoutSessionUpdate);
|
|
1742
|
+
return true;
|
|
1743
|
+
};
|
|
1744
|
+
const cartStoreUpdateSelectedShippingOption = async (selectedShippingOption, landedCostId) => {
|
|
1745
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
1746
|
+
cartStore.selectedShippingOption = selectedShippingOption;
|
|
1747
|
+
// update shipping transit info
|
|
1748
|
+
const transitData = cartStoreGetShippingTransitInfo(cartStore.selectedShippingOption);
|
|
1749
|
+
if (transitData) {
|
|
1750
|
+
const { maxTransit, minTransit, unit } = transitData;
|
|
1751
|
+
cartStore.selectedShippingOptionTransitTime = `${minTransit}-${maxTransit} ${unit}`;
|
|
1752
|
+
}
|
|
1753
|
+
else {
|
|
1754
|
+
cartStore.selectedShippingOptionTransitTime = '';
|
|
1755
|
+
}
|
|
1756
|
+
const selectedLandedCost = (_a = cartStore.landedCostData) === null || _a === void 0 ? void 0 : _a.find(x => x.landedCostId === landedCostId);
|
|
1757
|
+
// save selected landed cost for later use
|
|
1758
|
+
cartStore.selectedLandedCost = selectedLandedCost || null;
|
|
1759
|
+
if (!selectedLandedCost) {
|
|
1760
|
+
// do nothing if we can't find landed cost for selected shipping option
|
|
1761
|
+
return false;
|
|
1762
|
+
}
|
|
1763
|
+
// If the quote is DAP, then convert manually.
|
|
1764
|
+
const landedCostAmount = ((_b = selectedLandedCost.landedCost.amountSubtotals) === null || _b === void 0 ? void 0 : _b.landedCostTotal) || 0;
|
|
1765
|
+
// Convert using checkout presentment exchange rate
|
|
1766
|
+
const exchangeRate = selectedLandedCost.subtotals.exchangeRate.rate;
|
|
1767
|
+
const dutiesTaxesFeesEstimate = landedCostAmount * exchangeRate;
|
|
1768
|
+
if (dutiesTaxesFeesEstimate) {
|
|
1769
|
+
log(`DAP quote, using estimate: ${dutiesTaxesFeesEstimate}`, 'info');
|
|
1770
|
+
}
|
|
1771
|
+
cartStore.landedCostMethod = selectedLandedCost.landedCost.method || 'DDP';
|
|
1772
|
+
// update shipping value and dutiesTaxFees on selectedShippingOption change
|
|
1773
|
+
cartStore.shipping = selectedLandedCost.subtotals.shipping;
|
|
1774
|
+
// update deminimis status
|
|
1775
|
+
const isGuarantee = ((_c = selectedLandedCost === null || selectedLandedCost === void 0 ? void 0 : selectedLandedCost.landedCost) === null || _c === void 0 ? void 0 : _c.landedCostGuaranteeCode) === 'ZONOS';
|
|
1776
|
+
// one item in deminimis with type of duty and tax has threshold value is "ABOVE"
|
|
1777
|
+
const isAboveDeminimis = !!((_e = (_d = selectedLandedCost === null || selectedLandedCost === void 0 ? void 0 : selectedLandedCost.landedCost) === null || _d === void 0 ? void 0 : _d.deMinimis) === null || _e === void 0 ? void 0 : _e.find(item => ['DUTY', 'TAX'].includes(item.type) && item.threshold === 'ABOVE'));
|
|
1778
|
+
cartStore.isSelectedShippingAboveDeminimis = isAboveDeminimis;
|
|
1779
|
+
cartStore.isSelectedShippingGuarantee = isGuarantee;
|
|
1780
|
+
// update session with selected landed cost
|
|
1781
|
+
const updateCalculateStatus = await cartStoreReCalculateTotal({
|
|
1782
|
+
adjustmentsAmount: cartStore.adjustmentTotal,
|
|
1783
|
+
cartId: window.Zonos.cartId,
|
|
1784
|
+
dutiesTaxesFeesEstimate: dutiesTaxesFeesEstimate,
|
|
1785
|
+
landedCostId: (_f = selectedLandedCost.landedCost) === null || _f === void 0 ? void 0 : _f.id,
|
|
1786
|
+
varianceTestInput: storageStore.enabledVariantTestKeys || [],
|
|
1787
|
+
});
|
|
1788
|
+
// update conditionally render pay in USD button
|
|
1789
|
+
const firstItem = (_g = cartStore.items.find(Boolean)) === null || _g === void 0 ? void 0 : _g.currencyCode;
|
|
1790
|
+
// Stripe address event data should be available at this point
|
|
1791
|
+
const shipToCountry = ((_h = stripeStore.stripeAddressEventData) === null || _h === void 0 ? void 0 : _h.value.address.country) || 'US';
|
|
1792
|
+
// Only show pay in USD button if item's currency is in USD, the setting is enabled and the order presentment currency is not USD, also only in USD settlement ship to country list
|
|
1793
|
+
stripeStore.shouldRenderPayInUsdButton =
|
|
1794
|
+
firstItem === 'USD' &&
|
|
1795
|
+
zonosStore.checkoutSettings.allowedSettlementCurrencies ===
|
|
1796
|
+
'LOCAL_AND_USD' &&
|
|
1797
|
+
((_j = cartStore.checkoutSession) === null || _j === void 0 ? void 0 : _j.subtotals.presentmentCurrencyCode) !== 'USD' &&
|
|
1798
|
+
!!((_l = (_k = zonosStore.genericSettings) === null || _k === void 0 ? void 0 : _k.usdSettlementCountryEnabled) === null || _l === void 0 ? void 0 : _l.includes(shipToCountry));
|
|
1799
|
+
return updateCalculateStatus;
|
|
1800
|
+
};
|
|
1801
|
+
const cartStoreStartCheckoutInterval = ({ isPreview, sessionTimeout, }) => {
|
|
1802
|
+
// do nothing if in preview mode
|
|
1803
|
+
if (isPreview) {
|
|
1804
|
+
return;
|
|
1805
|
+
}
|
|
1806
|
+
const timeoutQuery = new URLSearchParams(window.location.search).get('zonosCheckoutTimeout');
|
|
1807
|
+
const timeout =
|
|
1808
|
+
// timeout query is mainly for testing purpose
|
|
1809
|
+
timeoutQuery && !isNaN(parseInt(timeoutQuery, 10))
|
|
1810
|
+
? parseInt(timeoutQuery, 10)
|
|
1811
|
+
: sessionTimeout;
|
|
1812
|
+
log(`==START CHECKOUT TIMEOUT - ${timeout}==`);
|
|
1813
|
+
cartStore.checkoutTimeoutInterval = setTimeout(() => {
|
|
1814
|
+
cartStore.checkoutSessionTimeoutShow = true;
|
|
1815
|
+
}, timeout);
|
|
1816
|
+
};
|
|
1817
|
+
const cartStoreClearCheckoutInterval = () => {
|
|
1818
|
+
if (cartStore.checkoutTimeoutInterval) {
|
|
1819
|
+
clearTimeout(cartStore.checkoutTimeoutInterval);
|
|
1820
|
+
cartStore.checkoutTimeoutInterval = null;
|
|
1821
|
+
}
|
|
1822
|
+
};
|
|
1823
|
+
const getCartItemToUse = (items) => items.map(item => (Object.assign(Object.assign({}, item), { isRestricted: false })));
|
|
1824
|
+
const cartStoreResetCartItems = () => {
|
|
1825
|
+
// mark all items as not restricted
|
|
1826
|
+
cartStore.items = cartStore.items.map(item => (Object.assign(Object.assign({}, item), { isRestricted: false })));
|
|
1827
|
+
cartStore.restrictedItems = [];
|
|
1828
|
+
};
|
|
1829
|
+
const cartStoreUpdateItems = async ({ adjustments, cartItems, }) => {
|
|
1830
|
+
var _a;
|
|
1831
|
+
// Update adjustments and items
|
|
1832
|
+
cartStore.adjustments = adjustments;
|
|
1833
|
+
cartStore.items = getCartItemToUse(cartItems);
|
|
1834
|
+
const currency = (_a = cartItems.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode;
|
|
1835
|
+
const total = cartItems.reduce((amt, item) => {
|
|
1836
|
+
return amt + item.amount * item.quantity;
|
|
1837
|
+
}, 0);
|
|
1838
|
+
const adjustmentTotal = adjustments.reduce((amt, adjustment) => amt + adjustment.amount, 0);
|
|
1839
|
+
if (!currency || !total) {
|
|
1840
|
+
// do nothing if we can't get currency or total
|
|
1841
|
+
return;
|
|
1842
|
+
}
|
|
1843
|
+
cartStore.currency = currency;
|
|
1844
|
+
// set loading state here because this is the first load checkout session when we already have checkout session id stored
|
|
1845
|
+
stripeStore.isFetchingSession = true;
|
|
1846
|
+
await cartStoreReCalculateTotal({
|
|
1847
|
+
adjustmentsAmount: adjustmentTotal,
|
|
1848
|
+
cartId: window.Zonos.cartId,
|
|
1849
|
+
currency: currency,
|
|
1850
|
+
dutiesTaxesFeesEstimate: 0,
|
|
1851
|
+
itemsAmount: total,
|
|
1852
|
+
// attempt to init session on failure to update checkout session
|
|
1853
|
+
shouldInitSessionOnFailure: true,
|
|
1854
|
+
varianceTestInput: storageStore.enabledVariantTestKeys || [],
|
|
1855
|
+
});
|
|
1856
|
+
stripeStore.isFetchingSession = false;
|
|
1857
|
+
};
|
|
1858
|
+
const cartStoreResetSelectedShippingOption = () => {
|
|
1859
|
+
cartStore.selectedShippingOption = null;
|
|
1860
|
+
cartStore.isSelectedShippingAboveDeminimis = false;
|
|
1861
|
+
cartStore.isSelectedShippingGuarantee = false;
|
|
1862
|
+
cartStore.selectedShippingOptionTransitTime = '';
|
|
1863
|
+
cartStore.dutiesTaxesFees = 0;
|
|
1864
|
+
cartStore.dutiesTaxesFeesEstimate = 0;
|
|
1865
|
+
cartStore.shipping = 0;
|
|
1866
|
+
// reset total to subtotal
|
|
1867
|
+
cartStore.total = cartStore.subtotal;
|
|
1868
|
+
};
|
|
1869
|
+
const cartStorePreviousStep = () => {
|
|
1870
|
+
if (cartStore.step === 'shipping') {
|
|
1871
|
+
cartStore.step = 'customer-info';
|
|
1872
|
+
// set shipping step to done
|
|
1873
|
+
cartStore.tabItems = Object.assign(Object.assign({}, cartStore.tabItems), { 'customer-info': Object.assign(Object.assign({}, cartStore.tabItems.shipping), { isDone: false }) });
|
|
1874
|
+
}
|
|
1875
|
+
else if (cartStore.step === 'payment') {
|
|
1876
|
+
cartStore.step = 'shipping';
|
|
1877
|
+
// set shipping step to done
|
|
1878
|
+
cartStore.tabItems = Object.assign(Object.assign({}, cartStore.tabItems), { shipping: Object.assign(Object.assign({}, cartStore.tabItems.shipping), { isDone: false }) });
|
|
1879
|
+
}
|
|
1880
|
+
else if (cartStore.step === 'finish') {
|
|
1881
|
+
cartStore.step = 'payment';
|
|
1882
|
+
// set shipping step to done
|
|
1883
|
+
cartStore.tabItems = Object.assign(Object.assign({}, cartStore.tabItems), { payment: Object.assign(Object.assign({}, cartStore.tabItems.payment), { isDone: false }) });
|
|
1884
|
+
}
|
|
1885
|
+
};
|
|
1886
|
+
const cartStoreNextStep = () => {
|
|
1887
|
+
if (cartStore.step === 'customer-info') {
|
|
1888
|
+
cartStore.step = 'shipping';
|
|
1889
|
+
// set customer-info step to done
|
|
1890
|
+
cartStore.tabItems = Object.assign(Object.assign({}, cartStore.tabItems), { 'customer-info': Object.assign(Object.assign({}, cartStore.tabItems['customer-info']), { isDone: true }) });
|
|
1891
|
+
}
|
|
1892
|
+
else if (cartStore.step === 'shipping') {
|
|
1893
|
+
cartStore.step = 'payment';
|
|
1894
|
+
// set shipping step to done
|
|
1895
|
+
cartStore.tabItems = Object.assign(Object.assign({}, cartStore.tabItems), { shipping: Object.assign(Object.assign({}, cartStore.tabItems.shipping), { isDone: true }) });
|
|
1896
|
+
}
|
|
1897
|
+
else if (cartStore.step === 'payment') {
|
|
1898
|
+
cartStore.step = 'finish';
|
|
1899
|
+
}
|
|
1900
|
+
};
|
|
1901
|
+
const cartStoreResetTabItems = () => {
|
|
1902
|
+
cartStore.step = 'customer-info';
|
|
1903
|
+
cartStore.tabItems = Object.assign(Object.assign({}, cartStore.tabItems), { 'customer-info': Object.assign(Object.assign({}, cartStore.tabItems['customer-info']), { isDone: false }), payment: Object.assign(Object.assign({}, cartStore.tabItems.payment), { isDone: false }), shipping: Object.assign(Object.assign({}, cartStore.tabItems.shipping), { isDone: false }) });
|
|
1904
|
+
cartStoreResetSelectedShippingOption();
|
|
1905
|
+
};
|
|
1906
|
+
|
|
1907
|
+
export { cartStoreHasOneEligibleItem as A, stripeStoreApplyPromoCode as B, stripeStoreRemovePromoCode as C, stripeStoreResetPromoCode as D, stripeStoreMessageBasedOnStatus as E, stripeStoreTranslateAddressToLatin as F, cartStoreUpdateSelectedShippingOption as G, cartStoreGetShippingTransitInfo as H, sortServiceLevelOptionsByAmount as I, stripeStoreCleanupDomesticShippingSession as a, stripeStoreSaveDomesticShippingSession as b, stripeStoreRetrievePayment as c, stripeStore as d, cartStore as e, cartStoreUpdateItems as f, cartStoreReset as g, cartStoreResetTabItems as h, initStripeElements as i, cartStoreClearCheckoutInterval as j, stripeStoreInitCheckoutSession as k, stripeStoreGetPaymentIntent as l, cartStoreStartCheckoutInterval as m, getCheckoutSessionBody as n, cartStoreUpdateToErrorState as o, cartStoreSetCheckoutSession as p, stripeStorePrefetchLandedCost as q, cartStoreNextStep as r, stripeStoreGetDomesticShippingSession as s, trackConversionEvent as t, stripeStoreUpdateCheckoutSessionBaseCurrency as u, stripeStoreHandleInventoryCheck as v, stripeStoreConfirmPayment as w, stripeStoreHandleInventoryRefund as x, stripeStoreReset as y, validateCheckoutSession as z };
|