@zonos/elements 1.3.18-alpha.1 → 1.3.18-alpha.3
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/README.md +341 -96
- package/dist/cjs/{cart-95209ae8.js → cart-5468dfd1.js} +284 -89
- package/dist/cjs/{getBorderRadius-44b3eca1.js → getBorderRadius-bcb309a8.js} +1 -1
- package/dist/cjs/{index-654a6001.js → index-b071017b.js} +4 -1
- package/dist/cjs/index.cjs.js +624 -0
- package/dist/cjs/{isDarkColor-01f45d3f.js → isDarkColor-b0393089.js} +1 -1
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/logError-4e2f2020.js +58 -0
- package/dist/cjs/{submitGtag-9d60f3bb.js → submitGtag-127a220f.js} +4 -3
- package/dist/cjs/zonos-address_8.cjs.entry.js +30 -18
- package/dist/cjs/zonos-badge_2.cjs.entry.js +7 -7
- package/dist/cjs/zonos-banner.cjs.entry.js +2 -2
- package/dist/cjs/zonos-button_3.cjs.entry.js +22 -11
- package/dist/cjs/zonos-card_2.cjs.entry.js +11 -10
- package/dist/cjs/{zonos-cart-items_10.cjs.entry.js → zonos-cart-items_11.cjs.entry.js} +118 -11
- package/dist/cjs/zonos-checkout.cjs.entry.js +47 -20
- package/dist/cjs/zonos-component.cjs.entry.js +2 -2
- package/dist/cjs/zonos-controller.cjs.entry.js +29 -24
- package/dist/cjs/zonos-country-flag.cjs.entry.js +6 -5
- package/dist/cjs/zonos-country-select_3.cjs.entry.js +12 -11
- package/dist/cjs/zonos-elements.cjs.js +2 -2
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +9 -8
- package/dist/cjs/zonos-hello.cjs.entry.js +14 -13
- package/dist/cjs/zonos-input.cjs.entry.js +7 -7
- package/dist/cjs/zonos-link.cjs.entry.js +2 -2
- package/dist/cjs/zonos-logo.cjs.entry.js +4 -4
- package/dist/cjs/zonos-notification.cjs.entry.js +2 -2
- package/dist/cjs/zonos-payment.cjs.entry.js +8 -7
- package/dist/cjs/zonos-select-dialog-header_2.cjs.entry.js +6 -6
- package/dist/cjs/zonos-shipping-rich-radio.cjs.entry.js +3 -3
- package/dist/cjs/zonos-text.cjs.entry.js +2 -2
- package/dist/cjs/{zonosStore-d8bb0bda.js → zonosStore-7c6205ca.js} +2 -1
- package/dist/collection/__mocks__/zonos-url/index.js +1 -0
- package/dist/collection/__tests__/build-utils/urlCheckOne.js +1 -1
- package/dist/collection/collection-manifest.json +2 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js +4 -9
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +45 -8
- package/dist/collection/components/checkout/zonos-checkout/zonos-customer-info/zonos-customer-info.js +3 -3
- package/dist/collection/components/common/zonos-badge/zonos-badge.js +3 -3
- package/dist/collection/components/common/zonos-button/zonos-button.css +12 -0
- package/dist/collection/components/common/zonos-button/zonos-button.js +43 -8
- package/dist/collection/components/common/zonos-card/zonos-card.js +3 -3
- package/dist/collection/components/common/zonos-checkbox/zonos-checkbox.js +3 -3
- package/dist/collection/components/common/zonos-checkout-progress-tabs/zonos-checkout-progress-tabs.js +3 -3
- package/dist/collection/components/common/zonos-collapse/zonos-collapse.js +2 -2
- package/dist/collection/components/common/zonos-confirm-dialog/assets/ExclamationMarkDuotoneIcon.svg +4 -0
- package/dist/collection/components/common/zonos-confirm-dialog/assets/HelpDuotoneIcon.svg +4 -0
- package/dist/collection/components/common/zonos-confirm-dialog/assets/WarningDuotoneIcon.svg +4 -0
- package/dist/collection/components/common/zonos-confirm-dialog/zonos-confirm-dialog.css +125 -0
- package/dist/collection/components/common/zonos-confirm-dialog/zonos-confirm-dialog.js +322 -0
- package/dist/collection/components/common/zonos-country-select/zonos-country-select.js +2 -2
- package/dist/collection/components/common/zonos-custom-message/zonos-custom-message.js +2 -2
- package/dist/collection/components/common/zonos-dialog/zonos-dialog.css +1 -4
- package/dist/collection/components/common/zonos-dialog/zonos-dialog.js +38 -4
- package/dist/collection/components/common/zonos-input/zonos-input.js +4 -4
- package/dist/collection/components/common/zonos-language-select/zonos-language-select.js +2 -2
- package/dist/collection/components/common/{component-template/zonos-link → zonos-link}/zonos-link.js +1 -1
- package/dist/collection/components/common/zonos-logo/zonos-logo.js +2 -2
- package/dist/collection/components/common/zonos-select-dialog-header/zonos-select-dialog-header.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/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 +3 -3
- package/dist/collection/components/main/zonos-controller.js +12 -8
- package/dist/collection/components/store/hello/localization.js +12 -2
- package/dist/collection/components/store/translationStore/strings.arabic.js +12 -0
- package/dist/collection/components/store/translationStore/strings.base.js +12 -0
- package/dist/collection/components/store/translationStore/strings.chinese.js +12 -0
- package/dist/collection/components/store/translationStore/strings.danish.js +12 -0
- package/dist/collection/components/store/translationStore/strings.dutch.js +12 -0
- package/dist/collection/components/store/translationStore/strings.french.js +12 -0
- package/dist/collection/components/store/translationStore/strings.german.js +12 -0
- package/dist/collection/components/store/translationStore/strings.hebrew.js +12 -0
- package/dist/collection/components/store/translationStore/strings.indonesian.js +12 -0
- package/dist/collection/components/store/translationStore/strings.italian.js +12 -0
- package/dist/collection/components/store/translationStore/strings.japanese.js +12 -0
- package/dist/collection/components/store/translationStore/strings.korean.js +12 -0
- package/dist/collection/components/store/translationStore/strings.norwegian.js +12 -0
- package/dist/collection/components/store/translationStore/strings.polish.js +12 -0
- package/dist/collection/components/store/translationStore/strings.portuguese.js +12 -0
- package/dist/collection/components/store/translationStore/strings.russian.js +12 -0
- package/dist/collection/components/store/translationStore/strings.spanish.js +12 -0
- package/dist/collection/components/store/translationStore/strings.swedish.js +12 -0
- package/dist/collection/components/store/translationStore/strings.turkish.js +12 -0
- package/dist/collection/components/store/translationStore/strings.vietnamese.js +12 -0
- package/dist/collection/components/store/zonosStore.js +1 -0
- package/dist/collection/components/stripe/zonos-address/zonos-address.js +3 -3
- package/dist/collection/components/stripe/zonos-link-authentication/zonos-link-authentication.js +1 -1
- package/dist/collection/components/stripe/zonos-payment/zonos-payment.js +1 -1
- package/dist/collection/environment.js +0 -2
- package/dist/collection/index.js +1 -0
- package/dist/collection/scripts/_extractZonosQaUrl.js +26 -0
- package/dist/collection/scripts/_getZonosQaUrl.js +40 -0
- package/dist/collection/scripts/{loadStripe.js → _loadStripe.js} +1 -1
- package/dist/collection/scripts/{zonosBase.js → _zonosBase.js} +31 -7
- package/dist/collection/scripts/index.js +2 -0
- package/dist/collection/types/generated/graphql.customer.types.js +1 -0
- package/dist/collection/types/generated/graphql.frontend.types.js +1 -0
- package/dist/esm/{cart-6448e883.js → cart-63d120e1.js} +257 -60
- package/dist/{components/getBorderRadius.js → esm/getBorderRadius-d244b4b1.js} +1 -1
- package/dist/esm/{index-e063389c.js → index-3b46f3c3.js} +4 -1
- package/dist/esm/index.js +621 -0
- package/dist/{components/isDarkColor.js → esm/isDarkColor-39a36e82.js} +1 -1
- package/dist/esm/loader.js +3 -3
- package/dist/esm/logError-c456c092.js +55 -0
- package/dist/esm/{submitGtag-b7d369cd.js → submitGtag-35bb3945.js} +3 -2
- package/dist/esm/zonos-address_8.entry.js +28 -16
- package/dist/esm/zonos-badge_2.entry.js +7 -7
- package/dist/esm/zonos-banner.entry.js +2 -2
- package/dist/esm/zonos-button_3.entry.js +22 -11
- package/dist/esm/zonos-card_2.entry.js +11 -10
- package/dist/esm/{zonos-cart-items_10.entry.js → zonos-cart-items_11.entry.js} +118 -12
- package/dist/esm/zonos-checkout.entry.js +35 -8
- package/dist/esm/zonos-component.entry.js +2 -2
- package/dist/esm/zonos-controller.entry.js +12 -7
- package/dist/esm/zonos-country-flag.entry.js +6 -5
- package/dist/esm/zonos-country-select_3.entry.js +12 -11
- package/dist/esm/zonos-elements.js +3 -3
- package/dist/esm/zonos-hello-dialog.entry.js +9 -8
- package/dist/esm/zonos-hello.entry.js +6 -5
- package/dist/esm/zonos-input.entry.js +7 -7
- package/dist/esm/zonos-link.entry.js +2 -2
- package/dist/esm/zonos-logo.entry.js +4 -4
- package/dist/esm/zonos-notification.entry.js +2 -2
- package/dist/esm/zonos-payment.entry.js +7 -6
- package/dist/esm/zonos-select-dialog-header_2.entry.js +6 -6
- package/dist/esm/zonos-shipping-rich-radio.entry.js +3 -3
- package/dist/esm/zonos-text.entry.js +2 -2
- package/dist/esm/{zonosStore-33ff08ff.js → zonosStore-32e33a45.js} +2 -1
- package/dist/esm-es5/cart-63d120e1.js +1 -0
- package/dist/esm-es5/{getBorderRadius-567f1786.js → getBorderRadius-d244b4b1.js} +1 -1
- package/dist/esm-es5/{index-e063389c.js → index-3b46f3c3.js} +1 -1
- package/dist/esm-es5/index.js +1 -0
- package/dist/esm-es5/{isDarkColor-7f62035a.js → isDarkColor-39a36e82.js} +1 -1
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/logError-c456c092.js +1 -0
- package/dist/esm-es5/submitGtag-35bb3945.js +1 -0
- package/dist/esm-es5/zonos-address_8.entry.js +1 -1
- package/dist/esm-es5/zonos-badge_2.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_2.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_11.entry.js +1 -0
- package/dist/esm-es5/zonos-checkout.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_3.entry.js +1 -1
- package/dist/esm-es5/zonos-elements.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-link.entry.js +1 -1
- package/dist/esm-es5/zonos-logo.entry.js +1 -1
- package/dist/esm-es5/zonos-notification.entry.js +1 -1
- package/dist/esm-es5/zonos-payment.entry.js +1 -1
- package/dist/esm-es5/zonos-select-dialog-header_2.entry.js +1 -1
- package/dist/esm-es5/zonos-shipping-rich-radio.entry.js +1 -1
- package/dist/esm-es5/zonos-text.entry.js +1 -1
- package/dist/esm-es5/{zonosStore-33ff08ff.js → zonosStore-32e33a45.js} +1 -1
- package/dist/scripts/index.d.ts +3908 -0
- package/dist/scripts/index.js +1 -0
- package/dist/scripts/loadZonos.d.ts +3954 -0
- package/dist/scripts/loadZonos.js +1 -1
- package/dist/scripts/zonos.js +1 -1
- package/dist/types/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.d.ts +5 -7
- package/dist/types/components/checkout/zonos-checkout/zonos-checkout.d.ts +13 -3
- package/dist/types/components/checkout/zonos-checkout/zonos-customer-info/zonos-customer-info.d.ts +2 -2
- package/dist/types/components/common/zonos-button/zonos-button.d.ts +7 -1
- package/dist/types/components/common/zonos-confirm-dialog/zonos-confirm-dialog.d.ts +60 -0
- package/dist/types/components/common/zonos-dialog/zonos-dialog.d.ts +6 -1
- package/dist/types/components/main/zonos-controller.d.ts +1 -1
- package/dist/types/components/store/checkout/stripe.d.ts +1 -1
- package/dist/types/components/store/translationStore/strings.arabic.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.base.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.chinese.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.danish.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.dutch.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.french.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.german.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.hebrew.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.indonesian.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.italian.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.japanese.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.korean.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.norwegian.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.polish.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.portuguese.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.russian.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.spanish.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.swedish.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.turkish.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.vietnamese.d.ts +12 -0
- package/dist/types/components/store/translationStore.d.ts +1 -1
- package/dist/types/components/store/zonosStore.d.ts +5 -1
- package/dist/types/components/stripe/zonos-address/zonos-address.d.ts +2 -2
- package/dist/types/components/utils/styles.d.ts +1 -0
- package/dist/types/components.d.ts +164 -19
- package/dist/types/index.d.ts +1 -0
- package/dist/types/scripts/_extractZonosQaUrl.d.ts +11 -0
- package/dist/types/scripts/_getZonosQaUrl.d.ts +4 -0
- package/dist/types/scripts/{loadStripe.d.ts → _loadStripe.d.ts} +1 -1
- package/dist/types/scripts/{zonosBase.d.ts → _zonosBase.d.ts} +51 -3
- package/dist/types/scripts/index.d.ts +2 -0
- package/dist/types/types/checkout/CheckoutConfig.d.ts +12 -0
- package/dist/types/types/checkout/api/CalculateLandedCostRequest.d.ts +9 -0
- package/dist/types/types/generated/graphql.customer.types.d.ts +1 -0
- package/dist/types/types/generated/graphql.customer.types.ts +3 -0
- package/dist/types/types/generated/graphql.frontend.types.d.ts +1 -0
- package/dist/types/types/generated/graphql.frontend.types.ts +1 -0
- package/dist/types/types/global.d.ts +1 -1
- package/dist/zonos-elements/assets/ExclamationMarkDuotoneIcon.svg +4 -0
- package/dist/zonos-elements/assets/HelpDuotoneIcon.svg +4 -0
- package/dist/zonos-elements/assets/WarningDuotoneIcon.svg +4 -0
- package/dist/zonos-elements/index.esm.js +1 -0
- package/dist/zonos-elements/p-023c764c.system.entry.js +1 -0
- package/dist/zonos-elements/p-06b6ce37.system.entry.js +1 -0
- package/dist/zonos-elements/p-07c53d83.entry.js +1 -0
- package/dist/zonos-elements/{p-fe246229.system.entry.js → p-0d0f9694.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-fd49d864.entry.js → p-0d5b5bcc.entry.js} +1 -1
- package/dist/zonos-elements/{p-771fbeb3.system.js → p-1b9442f6.system.js} +1 -1
- package/dist/zonos-elements/p-200b661c.entry.js +1 -0
- package/dist/zonos-elements/{p-835c8928.entry.js → p-281b8bdf.entry.js} +1 -1
- package/dist/zonos-elements/{p-a889c1bc.entry.js → p-2af19b63.entry.js} +1 -1
- package/dist/zonos-elements/{p-582d8b27.entry.js → p-2ced091f.entry.js} +1 -1
- package/dist/zonos-elements/{p-909a331c.js → p-2f759d82.js} +1 -1
- package/dist/zonos-elements/p-3b66df06.system.entry.js +1 -0
- package/dist/zonos-elements/{p-d7acc81c.entry.js → p-3ba8838a.entry.js} +1 -1
- package/dist/zonos-elements/p-428c034a.entry.js +1 -0
- package/dist/zonos-elements/p-43b2d28d.system.entry.js +1 -0
- package/dist/zonos-elements/p-47a42a30.js +1 -0
- package/dist/zonos-elements/{p-9ec93319.entry.js → p-498a0e18.entry.js} +1 -1
- package/dist/zonos-elements/{p-f71489e5.system.entry.js → p-4f72bfee.system.entry.js} +1 -1
- package/dist/zonos-elements/p-4fc1459c.entry.js +1 -0
- package/dist/zonos-elements/p-4fca8fd5.system.entry.js +1 -0
- package/dist/zonos-elements/{p-79f3c4f5.system.js → p-58e730b6.system.js} +1 -1
- package/dist/zonos-elements/{p-83fecb2a.entry.js → p-58fc8ec1.entry.js} +1 -1
- package/dist/zonos-elements/{p-e7b4b756.entry.js → p-597b75f3.entry.js} +1 -1
- package/dist/zonos-elements/{p-87badea9.system.js → p-62ecfbcc.system.js} +1 -1
- package/dist/zonos-elements/p-63db40b9.system.js +1 -0
- package/dist/zonos-elements/p-693b9985.js +1 -0
- package/dist/zonos-elements/{p-ff403840.entry.js → p-6cb9812b.entry.js} +1 -1
- package/dist/zonos-elements/p-6df1fc3a.system.entry.js +1 -0
- package/dist/zonos-elements/{p-bf32179a.system.entry.js → p-6eda6199.system.entry.js} +1 -1
- package/dist/zonos-elements/p-6f6f160d.entry.js +1 -0
- package/dist/zonos-elements/p-7c78e340.entry.js +1 -0
- package/dist/zonos-elements/{p-305f27c7.entry.js → p-80442f16.entry.js} +1 -1
- package/dist/zonos-elements/p-808fa731.js +1 -0
- package/dist/zonos-elements/p-80f174b9.system.js +1 -0
- package/dist/zonos-elements/{p-679877b1.system.entry.js → p-8171d013.system.entry.js} +1 -1
- package/dist/zonos-elements/p-85f3d13f.system.js +1 -0
- package/dist/zonos-elements/p-8aeb0629.entry.js +1 -0
- package/dist/zonos-elements/{p-83cc2936.js → p-8c0b4a61.js} +1 -1
- package/dist/zonos-elements/{p-4dca5484.system.entry.js → p-8cd6633a.system.entry.js} +1 -1
- package/dist/zonos-elements/p-9288fd21.system.entry.js +1 -0
- package/dist/zonos-elements/p-98ad4ab3.system.entry.js +1 -0
- package/dist/zonos-elements/{p-ad088d46.system.entry.js → p-9e8d38f7.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-e108e5ed.system.entry.js → p-a47382ae.system.entry.js} +1 -1
- package/dist/zonos-elements/p-b1567fa3.system.entry.js +1 -0
- package/dist/zonos-elements/p-b81562f5.entry.js +1 -0
- package/dist/zonos-elements/{p-3638e2ed.entry.js → p-bd9b2165.entry.js} +1 -1
- package/dist/zonos-elements/p-bdfa3705.system.entry.js +1 -0
- package/dist/zonos-elements/{p-13ddaf31.js → p-ce347974.js} +1 -1
- package/dist/zonos-elements/p-cfae51c1.system.js +1 -0
- package/dist/zonos-elements/p-d6eb260c.entry.js +1 -0
- package/dist/zonos-elements/{p-17e265c3.system.entry.js → p-d7a939df.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-163ff5b5.system.js → p-d99232c5.system.js} +1 -1
- package/dist/zonos-elements/p-dc40a60c.entry.js +1 -0
- package/dist/zonos-elements/{p-36a461a6.system.entry.js → p-dda78e8e.system.entry.js} +1 -1
- package/dist/zonos-elements/p-de405d7e.system.entry.js +1 -0
- package/dist/zonos-elements/p-e0bf9666.system.js +1 -0
- package/dist/zonos-elements/p-eaa335e1.js +1 -0
- package/dist/zonos-elements/{p-b98bdbcc.system.entry.js → p-ed3524ae.system.entry.js} +1 -1
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/dist/zonos-elements/zonos-elements.js +1 -1
- package/package.json +5 -3
- package/dist/components/ILanguage.js +0 -24
- package/dist/components/classes.js +0 -12
- package/dist/components/containsNonLatinChars.js +0 -21
- package/dist/components/formatCurrency.js +0 -11
- package/dist/components/index.d.ts +0 -33
- package/dist/components/index.js +0 -1
- package/dist/components/isCheckoutMobile.js +0 -6
- package/dist/components/isColorVariable.js +0 -14
- package/dist/components/stripe.js +0 -1681
- package/dist/components/submitGtag.js +0 -19
- package/dist/components/trackConversionEvent.js +0 -37
- package/dist/components/translationStore.js +0 -5371
- package/dist/components/zonos-address-display.d.ts +0 -11
- package/dist/components/zonos-address-display.js +0 -6
- package/dist/components/zonos-address-display2.js +0 -64
- package/dist/components/zonos-address-form.d.ts +0 -11
- package/dist/components/zonos-address-form.js +0 -6
- package/dist/components/zonos-address-form2.js +0 -84
- package/dist/components/zonos-address-update-dialog.d.ts +0 -11
- package/dist/components/zonos-address-update-dialog.js +0 -6
- package/dist/components/zonos-address-update-dialog2.js +0 -264
- package/dist/components/zonos-address.d.ts +0 -11
- package/dist/components/zonos-address.js +0 -6
- package/dist/components/zonos-address2.js +0 -176
- package/dist/components/zonos-badge.d.ts +0 -11
- package/dist/components/zonos-badge.js +0 -6
- package/dist/components/zonos-badge2.js +0 -61
- package/dist/components/zonos-banner.d.ts +0 -11
- package/dist/components/zonos-banner.js +0 -6
- package/dist/components/zonos-banner2.js +0 -95
- package/dist/components/zonos-button.d.ts +0 -11
- package/dist/components/zonos-button.js +0 -6
- package/dist/components/zonos-button2.js +0 -174
- package/dist/components/zonos-card.d.ts +0 -11
- package/dist/components/zonos-card.js +0 -6
- package/dist/components/zonos-card2.js +0 -57
- package/dist/components/zonos-cart-items.d.ts +0 -11
- package/dist/components/zonos-cart-items.js +0 -6
- package/dist/components/zonos-cart-items2.js +0 -57
- package/dist/components/zonos-cart-restricted-items.d.ts +0 -11
- package/dist/components/zonos-cart-restricted-items.js +0 -6
- package/dist/components/zonos-cart-restricted-items2.js +0 -135
- package/dist/components/zonos-cart-subtotal.d.ts +0 -11
- package/dist/components/zonos-cart-subtotal.js +0 -6
- package/dist/components/zonos-cart-subtotal2.js +0 -91
- package/dist/components/zonos-checkbox.d.ts +0 -11
- package/dist/components/zonos-checkbox.js +0 -6
- package/dist/components/zonos-checkbox2.js +0 -96
- package/dist/components/zonos-checkout-finish.d.ts +0 -11
- package/dist/components/zonos-checkout-finish.js +0 -6
- package/dist/components/zonos-checkout-finish2.js +0 -246
- package/dist/components/zonos-checkout-footer.d.ts +0 -11
- package/dist/components/zonos-checkout-footer.js +0 -6
- package/dist/components/zonos-checkout-footer2.js +0 -125
- package/dist/components/zonos-checkout-payment.d.ts +0 -11
- package/dist/components/zonos-checkout-payment.js +0 -6
- package/dist/components/zonos-checkout-payment2.js +0 -104
- package/dist/components/zonos-checkout-progress-tabs.d.ts +0 -11
- package/dist/components/zonos-checkout-progress-tabs.js +0 -6
- package/dist/components/zonos-checkout-progress-tabs2.js +0 -138
- package/dist/components/zonos-checkout.d.ts +0 -11
- package/dist/components/zonos-checkout.js +0 -1018
- package/dist/components/zonos-collapse.d.ts +0 -11
- package/dist/components/zonos-collapse.js +0 -6
- package/dist/components/zonos-collapse2.js +0 -78
- package/dist/components/zonos-component.d.ts +0 -11
- package/dist/components/zonos-component.js +0 -48
- package/dist/components/zonos-controller.d.ts +0 -11
- package/dist/components/zonos-controller.js +0 -309
- package/dist/components/zonos-country-flag.d.ts +0 -11
- package/dist/components/zonos-country-flag.js +0 -6
- package/dist/components/zonos-country-flag2.js +0 -54
- package/dist/components/zonos-country-select.d.ts +0 -11
- package/dist/components/zonos-country-select.js +0 -6
- package/dist/components/zonos-country-select2.js +0 -1891
- package/dist/components/zonos-custom-message.d.ts +0 -11
- package/dist/components/zonos-custom-message.js +0 -6
- package/dist/components/zonos-custom-message2.js +0 -72
- package/dist/components/zonos-customer-info.d.ts +0 -11
- package/dist/components/zonos-customer-info.js +0 -6
- package/dist/components/zonos-customer-info2.js +0 -316
- package/dist/components/zonos-dialog.d.ts +0 -11
- package/dist/components/zonos-dialog.js +0 -6
- package/dist/components/zonos-dialog2.js +0 -124
- package/dist/components/zonos-hello-dialog-footer.d.ts +0 -11
- package/dist/components/zonos-hello-dialog-footer.js +0 -6
- package/dist/components/zonos-hello-dialog-footer2.js +0 -83
- package/dist/components/zonos-hello-dialog.d.ts +0 -11
- package/dist/components/zonos-hello-dialog.js +0 -6
- package/dist/components/zonos-hello-dialog2.js +0 -305
- package/dist/components/zonos-hello.d.ts +0 -11
- package/dist/components/zonos-hello.js +0 -879
- package/dist/components/zonos-icon.d.ts +0 -11
- package/dist/components/zonos-icon.js +0 -6
- package/dist/components/zonos-icon2.js +0 -55
- package/dist/components/zonos-input.d.ts +0 -11
- package/dist/components/zonos-input.js +0 -6
- package/dist/components/zonos-input2.js +0 -78
- package/dist/components/zonos-language-select.d.ts +0 -11
- package/dist/components/zonos-language-select.js +0 -6
- package/dist/components/zonos-language-select2.js +0 -88
- package/dist/components/zonos-link-authentication.d.ts +0 -11
- package/dist/components/zonos-link-authentication.js +0 -6
- package/dist/components/zonos-link-authentication2.js +0 -80
- package/dist/components/zonos-link.d.ts +0 -11
- package/dist/components/zonos-link.js +0 -43
- package/dist/components/zonos-logo.d.ts +0 -11
- package/dist/components/zonos-logo.js +0 -49
- package/dist/components/zonos-notification.d.ts +0 -11
- package/dist/components/zonos-notification.js +0 -6
- package/dist/components/zonos-notification2.js +0 -92
- package/dist/components/zonos-payment.d.ts +0 -11
- package/dist/components/zonos-payment.js +0 -6
- package/dist/components/zonos-payment2.js +0 -77
- package/dist/components/zonos-review.d.ts +0 -11
- package/dist/components/zonos-review.js +0 -6
- package/dist/components/zonos-review2.js +0 -89
- package/dist/components/zonos-select-dialog-header.d.ts +0 -11
- package/dist/components/zonos-select-dialog-header.js +0 -6
- package/dist/components/zonos-select-dialog-header2.js +0 -71
- package/dist/components/zonos-shipping-rich-radio.d.ts +0 -11
- package/dist/components/zonos-shipping-rich-radio.js +0 -6
- package/dist/components/zonos-shipping-rich-radio2.js +0 -88
- package/dist/components/zonos-shipping.d.ts +0 -11
- package/dist/components/zonos-shipping.js +0 -6
- package/dist/components/zonos-shipping2.js +0 -159
- package/dist/components/zonos-spinner.d.ts +0 -11
- package/dist/components/zonos-spinner.js +0 -6
- package/dist/components/zonos-spinner2.js +0 -43
- package/dist/components/zonos-text.d.ts +0 -11
- package/dist/components/zonos-text.js +0 -6
- package/dist/components/zonos-text2.js +0 -182
- package/dist/components/zonos-tooltip.d.ts +0 -11
- package/dist/components/zonos-tooltip.js +0 -6
- package/dist/components/zonos-tooltip2.js +0 -48
- package/dist/components/zonos-v-stack.d.ts +0 -11
- package/dist/components/zonos-v-stack.js +0 -6
- package/dist/components/zonos-v-stack2.js +0 -38
- package/dist/components/zonosStore.js +0 -2880
- package/dist/esm/getBorderRadius-567f1786.js +0 -18
- package/dist/esm/isDarkColor-7f62035a.js +0 -1199
- package/dist/esm-es5/cart-6448e883.js +0 -1
- package/dist/esm-es5/submitGtag-b7d369cd.js +0 -1
- package/dist/esm-es5/zonos-cart-items_10.entry.js +0 -1
- package/dist/scripts/checkIfLoadVersionDomain.js +0 -1
- package/dist/scripts/extractZonosQaUrl.js +0 -1
- package/dist/scripts/getTempCartById.js +0 -1
- package/dist/scripts/loadStripe.js +0 -1
- package/dist/scripts/stripe.js +0 -1
- package/dist/scripts/zonosBase.js +0 -1
- package/dist/zonos-elements/p-0759a84d.system.entry.js +0 -1
- package/dist/zonos-elements/p-0ee61fba.system.entry.js +0 -1
- package/dist/zonos-elements/p-154aaf95.system.js +0 -1
- package/dist/zonos-elements/p-2fc561ac.system.entry.js +0 -1
- package/dist/zonos-elements/p-345503b7.entry.js +0 -1
- package/dist/zonos-elements/p-3be2e469.entry.js +0 -1
- package/dist/zonos-elements/p-47c75f81.system.entry.js +0 -1
- package/dist/zonos-elements/p-50ea2036.system.js +0 -1
- package/dist/zonos-elements/p-54004793.system.entry.js +0 -1
- package/dist/zonos-elements/p-58f8cee7.system.entry.js +0 -1
- package/dist/zonos-elements/p-61100d2e.system.entry.js +0 -1
- package/dist/zonos-elements/p-6ea746b9.entry.js +0 -1
- package/dist/zonos-elements/p-70c35519.system.entry.js +0 -1
- package/dist/zonos-elements/p-7b19cd96.entry.js +0 -1
- package/dist/zonos-elements/p-7cc730b0.js +0 -1
- package/dist/zonos-elements/p-7f48fafe.entry.js +0 -1
- package/dist/zonos-elements/p-9c575a18.system.entry.js +0 -1
- package/dist/zonos-elements/p-aaf1e517.system.js +0 -1
- package/dist/zonos-elements/p-aff5f4ca.js +0 -1
- package/dist/zonos-elements/p-beca252d.entry.js +0 -1
- package/dist/zonos-elements/p-c1f4bb4a.entry.js +0 -1
- package/dist/zonos-elements/p-c64eefdd.system.entry.js +0 -1
- package/dist/zonos-elements/p-ca621143.entry.js +0 -1
- package/dist/zonos-elements/p-dbee6587.entry.js +0 -1
- package/dist/zonos-elements/p-e0706108.system.entry.js +0 -1
- package/dist/zonos-elements/p-e3335228.entry.js +0 -1
- package/dist/zonos-elements/p-ef9cbb66.system.js +0 -1
- package/dist/zonos-elements/p-f1962041.js +0 -1
- /package/dist/collection/components/common/{component-template/zonos-link → zonos-link}/zonos-link.css +0 -0
- /package/dist/collection/scripts/{checkIfLoadVersionDomain.js → _checkIfLoadVersionDomain.js} +0 -0
- /package/dist/collection/scripts/{stripe.js → _stripe.js} +0 -0
- /package/dist/types/components/common/{component-template/zonos-link → zonos-link}/zonos-link.d.ts +0 -0
- /package/dist/types/scripts/{checkIfLoadVersionDomain.d.ts → _checkIfLoadVersionDomain.d.ts} +0 -0
- /package/dist/types/scripts/{stripe.d.ts → _stripe.d.ts} +0 -0
|
@@ -1,1681 +0,0 @@
|
|
|
1
|
-
import { z as zonosStore, c as createStore } from './zonosStore.js';
|
|
2
|
-
import { t as translationStoreUpdateLanguage, a as translate } from './translationStore.js';
|
|
3
|
-
import { i as isDarkColor } from './isDarkColor.js';
|
|
4
|
-
import { g as getBorderRadius } from './getBorderRadius.js';
|
|
5
|
-
|
|
6
|
-
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
7
|
-
var t = {};
|
|
8
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
9
|
-
t[p] = s[p];
|
|
10
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
11
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
12
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
13
|
-
t[p[i]] = s[p[i]];
|
|
14
|
-
}
|
|
15
|
-
return t;
|
|
16
|
-
};
|
|
17
|
-
const getResponseBody = async ({ response, shouldLog = true, shouldThrow = false, }) => {
|
|
18
|
-
try {
|
|
19
|
-
const json = await response.json();
|
|
20
|
-
return json;
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
if (shouldThrow) {
|
|
24
|
-
throw e;
|
|
25
|
-
}
|
|
26
|
-
if (shouldLog) {
|
|
27
|
-
// eslint-disable-next-line
|
|
28
|
-
console.error(e);
|
|
29
|
-
}
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
const handleRequest = async (url, options) => {
|
|
34
|
-
let response;
|
|
35
|
-
try {
|
|
36
|
-
response = await fetch(url, options);
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
if (e instanceof Error) {
|
|
40
|
-
return {
|
|
41
|
-
errors: [{ message: e.message, type: 'unknown' }],
|
|
42
|
-
json: null,
|
|
43
|
-
response: null,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
const message = 'Fail to fetch';
|
|
47
|
-
return {
|
|
48
|
-
errors: [{ message, type: 'unknown' }],
|
|
49
|
-
json: null,
|
|
50
|
-
response: null,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
const zonosMode = response.headers.get('Zonos-Mode');
|
|
54
|
-
const usingZonosPreview = window.Zonos.zonosQaUrl;
|
|
55
|
-
// We only want to alert once if the user is in preview mode and it's also using production environment
|
|
56
|
-
if (!window.Zonos.modeAlerted && zonosMode && usingZonosPreview) {
|
|
57
|
-
if (zonosMode === 'production') {
|
|
58
|
-
alert(`Please be aware that you are currently operating in the production environment. Any interactions with the customer store, including payments, will be processed as real transactions!`);
|
|
59
|
-
}
|
|
60
|
-
if (zonosMode === 'test') {
|
|
61
|
-
alert(`For testing payments, you can utilize the test payment information provided at this link: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements#web-test-the-integration`);
|
|
62
|
-
}
|
|
63
|
-
window.Zonos.modeAlerted = true;
|
|
64
|
-
}
|
|
65
|
-
if (response.ok) {
|
|
66
|
-
const data = await getResponseBody({ response });
|
|
67
|
-
return {
|
|
68
|
-
errors: [],
|
|
69
|
-
json: data,
|
|
70
|
-
response,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
const status = response.status.toString();
|
|
74
|
-
try {
|
|
75
|
-
const data = await getResponseBody({
|
|
76
|
-
response,
|
|
77
|
-
shouldThrow: true,
|
|
78
|
-
});
|
|
79
|
-
const message = JSON.stringify(data);
|
|
80
|
-
return {
|
|
81
|
-
errors: [{ message: `${status}: ${message}`, type: status }],
|
|
82
|
-
json: null,
|
|
83
|
-
response,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
const message = 'Unknown error';
|
|
88
|
-
return {
|
|
89
|
-
errors: [{ message: `${status}: ${message}`, type: status }],
|
|
90
|
-
json: null,
|
|
91
|
-
response: null,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
function encodeString(text) {
|
|
96
|
-
try {
|
|
97
|
-
// encode the string, remove the "=" at the end of the encoded string
|
|
98
|
-
const encodedString = btoa(text).replace(/=/g, '');
|
|
99
|
-
return encodedString;
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
// return the reverse string if the encoding failed
|
|
103
|
-
return text
|
|
104
|
-
.replace(/[^A-Za-z0-9]/g, '')
|
|
105
|
-
.split('')
|
|
106
|
-
.reverse()
|
|
107
|
-
.join('');
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const handleFetch = async (url, _opts) => {
|
|
111
|
-
const opts = __rest(_opts || {}, []);
|
|
112
|
-
const body = opts.body ? JSON.stringify(opts.body) : undefined;
|
|
113
|
-
const method = opts.method || 'GET';
|
|
114
|
-
// adding random encoded token to the url so that the request will be cached differently for each store
|
|
115
|
-
const modifiedUrl = new URL(url);
|
|
116
|
-
modifiedUrl.searchParams.set('zToken', encodeString(window.location.hostname));
|
|
117
|
-
// headers content type
|
|
118
|
-
const headers = Object.assign({ 'Content-Type': 'application/json', 'Zonos-Is-BigCommerce': window.Zonos.isBigCommerce.toString(), 'Zonos-Referer': window.location.hostname, 'Zonos-Version': window.Zonos.version, credentialtoken: window.Zonos.zonosApiKey || 'Empty credential token from zonos-elements' }, opts.headers);
|
|
119
|
-
const options = Object.assign(Object.assign({}, opts), { body: method === 'GET' ? undefined : body, headers,
|
|
120
|
-
method });
|
|
121
|
-
return handleRequest(modifiedUrl.toString(), options);
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const getCountries = async () => {
|
|
125
|
-
try {
|
|
126
|
-
const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/get-countries`, {
|
|
127
|
-
method: 'GET',
|
|
128
|
-
});
|
|
129
|
-
if (errors.length || !json) {
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
return json;
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const log = (message, type, ...additionalInfo) => {
|
|
140
|
-
var _a, _b;
|
|
141
|
-
const isDebug = !!((_a = window.Zonos) === null || _a === void 0 ? void 0 : _a.debug) ||
|
|
142
|
-
!!window.location.search.match(/\?.*(&*)zonosDebug=1/);
|
|
143
|
-
// if debug is false, do not log
|
|
144
|
-
if (!isDebug) {
|
|
145
|
-
// log errors to the console if the type is error
|
|
146
|
-
if (type === 'error') {
|
|
147
|
-
// eslint-disable-next-line no-console
|
|
148
|
-
console.error(message, ...additionalInfo);
|
|
149
|
-
}
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
let loggingIframe = document.querySelector('iframe#zonos---debug-logging-iframe');
|
|
153
|
-
if (!loggingIframe) {
|
|
154
|
-
// add a hidden iframe
|
|
155
|
-
loggingIframe = document.createElement('iframe');
|
|
156
|
-
loggingIframe.id = 'zonos---debug-logging-iframe';
|
|
157
|
-
loggingIframe.style.display = 'none';
|
|
158
|
-
loggingIframe.style.opacity = '0';
|
|
159
|
-
loggingIframe.style.position = 'absolute';
|
|
160
|
-
loggingIframe.style.top = '-9999px';
|
|
161
|
-
loggingIframe.style.left = '-9999px';
|
|
162
|
-
loggingIframe.style.width = '1px';
|
|
163
|
-
loggingIframe.style.height = '1px';
|
|
164
|
-
loggingIframe.style.border = 'none';
|
|
165
|
-
loggingIframe.style.overflow = 'hidden';
|
|
166
|
-
loggingIframe.style.visibility = 'hidden';
|
|
167
|
-
document.body.appendChild(loggingIframe);
|
|
168
|
-
}
|
|
169
|
-
// use the logging iframe's console to log just in case the console is disabled (overriden) by the site owner
|
|
170
|
-
const zConsole = ((_b = loggingIframe.contentWindow) === null || _b === void 0 ? void 0 : _b.window.console) || window.console;
|
|
171
|
-
switch (type) {
|
|
172
|
-
case 'warn':
|
|
173
|
-
zConsole.warn(message, ...additionalInfo);
|
|
174
|
-
break;
|
|
175
|
-
case 'info':
|
|
176
|
-
zConsole.info(message, ...additionalInfo);
|
|
177
|
-
break;
|
|
178
|
-
case 'error':
|
|
179
|
-
zConsole.error(message, ...additionalInfo);
|
|
180
|
-
break;
|
|
181
|
-
default:
|
|
182
|
-
zConsole.groupCollapsed(message, ...additionalInfo);
|
|
183
|
-
zConsole.trace();
|
|
184
|
-
zConsole.groupEnd();
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
const logError = (message, ...rest) => {
|
|
190
|
-
log(message, 'error', ...rest);
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const getCountryLandedCost = async (countryCode) => {
|
|
194
|
-
var _a;
|
|
195
|
-
if (!countryCode) {
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
const url = `${"https://v1.route.js.zonos.com"}/api/zonos-elements/country-landed-cost/${countryCode}`;
|
|
199
|
-
const { errors, json } = await handleFetch(url);
|
|
200
|
-
if (errors.length || !json) {
|
|
201
|
-
logError(`Error fetching country landed cost: ${(_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
return json || null;
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
const getExchangeRate = async ({ country, isGuaranteed, sourceCurrency, targetCurrency, }) => {
|
|
208
|
-
var _a;
|
|
209
|
-
// If source currency matches target currency (US -> US) and is not a guaranteed rate, return null
|
|
210
|
-
if (sourceCurrency === targetCurrency && !isGuaranteed) {
|
|
211
|
-
return { exchangeRate: null, maxAge: null };
|
|
212
|
-
}
|
|
213
|
-
const url = `${"https://v1.route.js.zonos.com"}/api/zonos-elements/exchange-rates?sourceCurrency=${sourceCurrency}&targetCurrency=${targetCurrency}&isGuaranteed=${isGuaranteed}&country=${country}`;
|
|
214
|
-
const { errors, json } = await handleFetch(url);
|
|
215
|
-
if (errors.length || !json) {
|
|
216
|
-
logError(`Error fetching country landed cost: ${(_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
217
|
-
return { exchangeRate: null, maxAge: null };
|
|
218
|
-
}
|
|
219
|
-
const { maxAge, rate, targetFormat } = json.exchangeRateCreate;
|
|
220
|
-
if (rate) {
|
|
221
|
-
sessionStorage.setItem(country + '_rate', JSON.stringify(rate));
|
|
222
|
-
const exchangeRate = { rate, targetFormat };
|
|
223
|
-
return { exchangeRate, maxAge };
|
|
224
|
-
}
|
|
225
|
-
return { exchangeRate: null, maxAge: null };
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
const getLocaleMessages = async ({ countryCode, localeTo, storeId, }) => {
|
|
229
|
-
var _a;
|
|
230
|
-
const url = `${"https://v1.route.js.zonos.com"}/api/zonos-elements/locale-messages?countryCode=${countryCode}&storeId=${storeId}&localeTo=${localeTo}`;
|
|
231
|
-
const { errors, json } = await handleFetch(url);
|
|
232
|
-
if (errors.length || !json) {
|
|
233
|
-
logError('Error fetching exchange rate', (_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message);
|
|
234
|
-
return [];
|
|
235
|
-
}
|
|
236
|
-
return json.locale_countryCodesPage;
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
const getZCountryUrlParam = (urlParams) => {
|
|
240
|
-
const urlSearchParams = new URLSearchParams(urlParams || window.location.search);
|
|
241
|
-
const zCountry = urlSearchParams.get('zCountry');
|
|
242
|
-
return zCountry;
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
const getLocalization = async () => {
|
|
246
|
-
try {
|
|
247
|
-
const currentUrl = new URL(window.location.href);
|
|
248
|
-
// load and use country from session storage when zCountry query param is not present
|
|
249
|
-
const countryLoadedSession = window.sessionStorage.getItem('zonos--country');
|
|
250
|
-
const zCountry = getZCountryUrlParam(currentUrl.searchParams) || countryLoadedSession;
|
|
251
|
-
const localizationUrl = new URL(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/localization`);
|
|
252
|
-
if (zCountry) {
|
|
253
|
-
localizationUrl.searchParams.set('zCountry', zCountry);
|
|
254
|
-
}
|
|
255
|
-
const fetchUrl = localizationUrl.href;
|
|
256
|
-
const { errors, json } = await handleFetch(fetchUrl, {
|
|
257
|
-
method: 'GET',
|
|
258
|
-
});
|
|
259
|
-
if (errors.length || !json) {
|
|
260
|
-
return { country: null, locale: null };
|
|
261
|
-
}
|
|
262
|
-
return {
|
|
263
|
-
country: json.country,
|
|
264
|
-
locale: json.locale,
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
catch (error) {
|
|
268
|
-
return { country: null, locale: null };
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
const getShippingZones = async () => {
|
|
273
|
-
var _a, _b;
|
|
274
|
-
const url = `${"https://v1.route.js.zonos.com"}/api/zonos-elements/shipping-zones`;
|
|
275
|
-
const { errors, json } = await handleFetch(url);
|
|
276
|
-
if (errors.length || !json) {
|
|
277
|
-
logError(`Error fetching shipping zones: ${(_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
278
|
-
return null;
|
|
279
|
-
}
|
|
280
|
-
const shippingZones = (_b = json === null || json === void 0 ? void 0 : json.shippingZones) === null || _b === void 0 ? void 0 : _b.flatMap(zone => zone === null || zone === void 0 ? void 0 : zone.countryCodes).filter(Boolean);
|
|
281
|
-
return shippingZones || null;
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
const currencyConvert = (value) => {
|
|
285
|
-
// TODO(potentially): Bring over the code for vanity checks
|
|
286
|
-
const { exchangeRate } = localizationStore;
|
|
287
|
-
if (!exchangeRate || !value || isNaN(value)) {
|
|
288
|
-
return value;
|
|
289
|
-
}
|
|
290
|
-
const minimumFractionDigits = (exchangeRate === null || exchangeRate === void 0 ? void 0 : exchangeRate.targetFormat.scale) || 2;
|
|
291
|
-
const convertedValue = value * exchangeRate.rate;
|
|
292
|
-
const fixedValue = convertedValue.toFixed(minimumFractionDigits);
|
|
293
|
-
return Number(fixedValue);
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
const currencyFormat = (value) => {
|
|
297
|
-
if (!value || isNaN(value)) {
|
|
298
|
-
return '';
|
|
299
|
-
}
|
|
300
|
-
const { exchangeRate } = localizationStore;
|
|
301
|
-
const { targetFormat } = exchangeRate || {};
|
|
302
|
-
if (!targetFormat) {
|
|
303
|
-
return value.toString();
|
|
304
|
-
}
|
|
305
|
-
const minimumFractionDigits = (exchangeRate === null || exchangeRate === void 0 ? void 0 : exchangeRate.targetFormat.scale) || 2;
|
|
306
|
-
// browsers can autoformat the currency based on the users language setting
|
|
307
|
-
// unless the browser is Internet Explorer, because Internet Explorer is stupid
|
|
308
|
-
const isIE = window.navigator.userAgent.indexOf('MSIE ') !== -1;
|
|
309
|
-
const numberFormatExists = typeof Intl === 'object' && Intl && typeof Intl.NumberFormat === 'function';
|
|
310
|
-
if (!isIE && numberFormatExists) {
|
|
311
|
-
return new Intl.NumberFormat(window.navigator.language, {
|
|
312
|
-
currency: targetFormat.currencyCode,
|
|
313
|
-
minimumFractionDigits: minimumFractionDigits,
|
|
314
|
-
style: 'currency',
|
|
315
|
-
}).format(value);
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
let formattedNumber = Number(value)
|
|
319
|
-
.toFixed(minimumFractionDigits)
|
|
320
|
-
.replace('.', '|dec|')
|
|
321
|
-
.replace(',', targetFormat.thousandsDelimiter || '')
|
|
322
|
-
.replace('|dec|', targetFormat.decimalDelimiter || '');
|
|
323
|
-
const result = `${targetFormat.symbol}${formattedNumber}${targetFormat.currencyCode !== 'USD' ? ` ${targetFormat.currencyCode}` : ''}`;
|
|
324
|
-
return result;
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
const currencyConvertAndFormat = (value) => {
|
|
329
|
-
const convertedValue = currencyConvert(value);
|
|
330
|
-
const formattedValue = currencyFormat(convertedValue);
|
|
331
|
-
return formattedValue;
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Check if selector user pass is valid
|
|
336
|
-
* @example
|
|
337
|
-
* isValidSelector('div') // true
|
|
338
|
-
* isValidSelector('div + >>> span') // false
|
|
339
|
-
*/
|
|
340
|
-
const isValidSelector = (selector) => {
|
|
341
|
-
try {
|
|
342
|
-
// this will error out if the selector is invalid in the DOM
|
|
343
|
-
document.createDocumentFragment().querySelector(selector);
|
|
344
|
-
}
|
|
345
|
-
catch (e) {
|
|
346
|
-
return false;
|
|
347
|
-
}
|
|
348
|
-
return true;
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
const getCurrencyElements = (selector) => {
|
|
352
|
-
const currencySelector = selector || '.money';
|
|
353
|
-
if (!isValidSelector(currencySelector)) {
|
|
354
|
-
logError(`Currency element selector "${currencySelector}" is not valid.`);
|
|
355
|
-
return null;
|
|
356
|
-
}
|
|
357
|
-
const currencyElements = document.querySelectorAll(currencySelector);
|
|
358
|
-
if (!currencyElements.length) {
|
|
359
|
-
log(`No currency elements found with selector "${currencySelector}"`, 'warn');
|
|
360
|
-
return null;
|
|
361
|
-
}
|
|
362
|
-
// return array of currency elements instead of a NodeList
|
|
363
|
-
return Array.from(currencyElements);
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
const getInitialElementAmount = (element) => {
|
|
367
|
-
var _a;
|
|
368
|
-
const domesticValue = element.getAttribute('data-domestic');
|
|
369
|
-
const intlValue = element.getAttribute('data-zintl');
|
|
370
|
-
// Only keep numbers, decimal, and hyphens
|
|
371
|
-
const cleanedText = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.replace(/[^\d.-]/g, '');
|
|
372
|
-
if (!cleanedText) {
|
|
373
|
-
return null;
|
|
374
|
-
}
|
|
375
|
-
// If the element has no data-domestic attribute, or the text content is different from the data-zintl attribute, set the data-domestic attribute
|
|
376
|
-
if (!domesticValue || (element.textContent !== intlValue && intlValue)) {
|
|
377
|
-
// Store the original value on the element once, and international on every new conversion
|
|
378
|
-
element.setAttribute('data-domestic', cleanedText);
|
|
379
|
-
return parseFloat(cleanedText);
|
|
380
|
-
}
|
|
381
|
-
return parseFloat(domesticValue);
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
const convertCurrency = (element) => {
|
|
385
|
-
var _a;
|
|
386
|
-
const amount = getInitialElementAmount(element);
|
|
387
|
-
if (!amount || isNaN(amount)) {
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
const currentIntlValue = element.getAttribute('data-zintl');
|
|
391
|
-
const currentCountryValue = element.getAttribute('data-zcountry-code');
|
|
392
|
-
// do nothing if the target currency is the same
|
|
393
|
-
const isExchangeRateReady = localizationStore.targetCurrency ===
|
|
394
|
-
((_a = localizationStore.exchangeRate) === null || _a === void 0 ? void 0 : _a.targetFormat.currencyCode);
|
|
395
|
-
// if the current value on the element is different from the current intl value, update the data-zintl attribute
|
|
396
|
-
if (isExchangeRateReady &&
|
|
397
|
-
(element.textContent !== currentIntlValue ||
|
|
398
|
-
currentCountryValue !== localizationStore.selectedCountryCode)) {
|
|
399
|
-
const observedFormattedValue = currencyConvertAndFormat(amount);
|
|
400
|
-
element.textContent = observedFormattedValue;
|
|
401
|
-
// save the new value to the data-zintl attribute
|
|
402
|
-
element.setAttribute('data-zintl', observedFormattedValue);
|
|
403
|
-
element.setAttribute('data-zcountry-code', localizationStore.selectedCountryCode || '');
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
const defaultCurrencyConverter = () => {
|
|
407
|
-
const { currencyElementSelector } = zonosStore.helloSettings;
|
|
408
|
-
const currencyElements = getCurrencyElements(currencyElementSelector);
|
|
409
|
-
// do nothing if none of the currency elements are found
|
|
410
|
-
if (!(currencyElements === null || currencyElements === void 0 ? void 0 : currencyElements.length)) {
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
if (!localizationStore.exchangeRate) {
|
|
414
|
-
logError('Could not display currency. Exchange rate and format data is not available.');
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
currencyElements.forEach((element) => {
|
|
418
|
-
// convert the currency and save the formatted value to the data-zintl attribute
|
|
419
|
-
convertCurrency(element);
|
|
420
|
-
});
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
const currencyDisplay = () => {
|
|
424
|
-
if (zonosStore.helloSettings.currencyBehavior === 'DISABLED') {
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
const { currencyElementSelector } = zonosStore.helloSettings;
|
|
428
|
-
if (zonosStore.currencyConverter) {
|
|
429
|
-
zonosStore.currencyConverter({
|
|
430
|
-
convert: currencyConvert,
|
|
431
|
-
convertAndFormat: currencyConvertAndFormat,
|
|
432
|
-
format: currencyFormat,
|
|
433
|
-
selector: currencyElementSelector,
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
else {
|
|
437
|
-
defaultCurrencyConverter();
|
|
438
|
-
}
|
|
439
|
-
};
|
|
440
|
-
|
|
441
|
-
const getCurrencyCode = (code) => {
|
|
442
|
-
var _a;
|
|
443
|
-
const countryInShippingZone = (_a = localizationStore.shippingZoneCountries) === null || _a === void 0 ? void 0 : _a[code];
|
|
444
|
-
if (countryInShippingZone) {
|
|
445
|
-
return countryInShippingZone.currencyCode;
|
|
446
|
-
}
|
|
447
|
-
return null;
|
|
448
|
-
};
|
|
449
|
-
|
|
450
|
-
const setZCountryUrlParam = (selectedCountryCode) => {
|
|
451
|
-
if (!selectedCountryCode) {
|
|
452
|
-
return;
|
|
453
|
-
}
|
|
454
|
-
const urlSearchParams = new URLSearchParams(window.location.search);
|
|
455
|
-
urlSearchParams.set('zCountry', selectedCountryCode);
|
|
456
|
-
const newUrl = `${window.location.pathname}?${urlSearchParams.toString()}`;
|
|
457
|
-
window.history.replaceState({}, '', newUrl);
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
const { onChange: localizationStoreOnUpdate, state: localizationStore } = createStore({
|
|
461
|
-
countryLandedCost: null,
|
|
462
|
-
customMessages: [],
|
|
463
|
-
exchangeRate: null,
|
|
464
|
-
isShippableCountry: false,
|
|
465
|
-
localizationLoaded: false,
|
|
466
|
-
selectedCountryCode: null,
|
|
467
|
-
selectedLocale: 'en',
|
|
468
|
-
shippingZoneCountries: null,
|
|
469
|
-
targetCurrency: 'USD',
|
|
470
|
-
});
|
|
471
|
-
const triggerGetExchangeRate = async (isGuaranteed) => {
|
|
472
|
-
const { exchangeRate, maxAge } = await getExchangeRate({
|
|
473
|
-
country: localizationStore.selectedCountryCode,
|
|
474
|
-
isGuaranteed,
|
|
475
|
-
sourceCurrency: zonosStore.sourceCurrency,
|
|
476
|
-
targetCurrency: localizationStore.targetCurrency,
|
|
477
|
-
});
|
|
478
|
-
if (exchangeRate) {
|
|
479
|
-
localizationStore.exchangeRate = exchangeRate;
|
|
480
|
-
currencyDisplay();
|
|
481
|
-
}
|
|
482
|
-
return { maxAge };
|
|
483
|
-
};
|
|
484
|
-
// This recursive function is for users who step away from their computer and come back needing a new exchange rate
|
|
485
|
-
const startExchangeRateTimeout = ({ isGuaranteed, maxAge, }) => {
|
|
486
|
-
if (localizationStore.exchangeRateTimeout) {
|
|
487
|
-
clearTimeout(localizationStore.exchangeRateTimeout);
|
|
488
|
-
}
|
|
489
|
-
// maxAge comes in seconds, convert to milliseconds
|
|
490
|
-
const defaultMaxAge = 5 * 60;
|
|
491
|
-
const maxAgeToUse = maxAge || defaultMaxAge;
|
|
492
|
-
// Recursively set timeouts to get new exchange rates when the current one expires
|
|
493
|
-
localizationStore.exchangeRateTimeout = setTimeout(async () => {
|
|
494
|
-
const { maxAge: newMaxAge } = await triggerGetExchangeRate(isGuaranteed);
|
|
495
|
-
startExchangeRateTimeout({ isGuaranteed, maxAge: newMaxAge });
|
|
496
|
-
}, maxAgeToUse * 1000);
|
|
497
|
-
};
|
|
498
|
-
const getNewLocalization = async () => {
|
|
499
|
-
log('get new localization store');
|
|
500
|
-
const { isShippableCountry, selectedCountryCode } = localizationStore;
|
|
501
|
-
if (zonosStore.helloSettings.currencyBehavior === 'DISABLED' ||
|
|
502
|
-
!isShippableCountry ||
|
|
503
|
-
!selectedCountryCode) {
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
const isGuaranteed = zonosStore.checkoutSettings.visibilityStatus === 'ENABLED';
|
|
507
|
-
const { maxAge } = await triggerGetExchangeRate(isGuaranteed);
|
|
508
|
-
startExchangeRateTimeout({ isGuaranteed, maxAge });
|
|
509
|
-
localizationStore.countryLandedCost = await getCountryLandedCost(localizationStore.selectedCountryCode);
|
|
510
|
-
};
|
|
511
|
-
const getCustomMessages = async () => {
|
|
512
|
-
if (!localizationStore.selectedCountryCode || !zonosStore.storeId) {
|
|
513
|
-
return;
|
|
514
|
-
}
|
|
515
|
-
const localeMessages = await getLocaleMessages({
|
|
516
|
-
countryCode: localizationStore.selectedCountryCode,
|
|
517
|
-
localeTo: localizationStore.selectedLocale,
|
|
518
|
-
storeId: zonosStore.storeId,
|
|
519
|
-
});
|
|
520
|
-
const allMessages = localeMessages.flatMap(x => {
|
|
521
|
-
var _a;
|
|
522
|
-
return {
|
|
523
|
-
countryCode: localizationStore.selectedCountryCode,
|
|
524
|
-
message: (_a = x.countryCodesPageMessageLinks.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message.textTo,
|
|
525
|
-
pageName: x.pageName,
|
|
526
|
-
};
|
|
527
|
-
});
|
|
528
|
-
localizationStore.customMessages = allMessages;
|
|
529
|
-
};
|
|
530
|
-
const getOverrideLocale = () => {
|
|
531
|
-
const currentUrl = new URL(window.location.href);
|
|
532
|
-
const zonosLocale = currentUrl.searchParams.get('zonosLocale');
|
|
533
|
-
return zonosLocale;
|
|
534
|
-
};
|
|
535
|
-
const localizationStoreUpdateSelectedCountryCode = (newSelectedCountryCode) => {
|
|
536
|
-
var _a;
|
|
537
|
-
log('update selected country code');
|
|
538
|
-
localizationStore.selectedCountryCode = newSelectedCountryCode;
|
|
539
|
-
const { selectedCountryCode, shippingZoneCountries } = localizationStore;
|
|
540
|
-
const isShippableCountry = shippingZoneCountries &&
|
|
541
|
-
selectedCountryCode &&
|
|
542
|
-
!!shippingZoneCountries[selectedCountryCode];
|
|
543
|
-
// update shippable country
|
|
544
|
-
localizationStore.isShippableCountry = !!isShippableCountry;
|
|
545
|
-
log(`Is shippable country: ${localizationStore.isShippableCountry}`);
|
|
546
|
-
if (!selectedCountryCode) {
|
|
547
|
-
return;
|
|
548
|
-
}
|
|
549
|
-
const currencyCode = getCurrencyCode(selectedCountryCode);
|
|
550
|
-
if (!currencyCode) {
|
|
551
|
-
return;
|
|
552
|
-
}
|
|
553
|
-
localizationStore.targetCurrency = currencyCode;
|
|
554
|
-
void getNewLocalization();
|
|
555
|
-
void getCustomMessages();
|
|
556
|
-
// Save the country code to session storage for later use
|
|
557
|
-
window.sessionStorage.setItem('zonos--country', selectedCountryCode);
|
|
558
|
-
// Update the URL query param with the new country code
|
|
559
|
-
setZCountryUrlParam(selectedCountryCode);
|
|
560
|
-
(_a = document
|
|
561
|
-
.querySelector('zonos-hello')) === null || _a === void 0 ? void 0 : _a.setAttribute('z-country', selectedCountryCode);
|
|
562
|
-
};
|
|
563
|
-
const initLocalizationStore = async () => {
|
|
564
|
-
// all countries from countries.json, shipping zone and localization
|
|
565
|
-
const [allCountries, shippingZoneCountries, localization] = await Promise.all([getCountries(), getShippingZones(), getLocalization()]);
|
|
566
|
-
// Filter countries to only include countries in the shipping zone
|
|
567
|
-
const filteredCountries = shippingZoneCountries === null || shippingZoneCountries === void 0 ? void 0 : shippingZoneCountries.reduce((acc, countryCode) => {
|
|
568
|
-
const countryInfo = allCountries === null || allCountries === void 0 ? void 0 : allCountries[countryCode];
|
|
569
|
-
return countryInfo && countryInfo.active
|
|
570
|
-
? Object.assign(Object.assign({}, acc), { [countryCode]: countryInfo }) : acc;
|
|
571
|
-
}, {});
|
|
572
|
-
localizationStore.shippingZoneCountries = filteredCountries || null;
|
|
573
|
-
const { country, locale } = localization;
|
|
574
|
-
// update selected country code in store
|
|
575
|
-
void localizationStoreUpdateSelectedCountryCode(country);
|
|
576
|
-
// use locale from params if it exists, otherwise use locale from localization
|
|
577
|
-
const overrideLocale = getOverrideLocale();
|
|
578
|
-
localizationStore.selectedLocale = overrideLocale || locale || 'en';
|
|
579
|
-
translationStoreUpdateLanguage(localizationStore.selectedLocale);
|
|
580
|
-
const devSites = ['dev.storybook.elements', 'dev.elements', 'dev.dashboard'];
|
|
581
|
-
// If the country code is not set, set it to the US for development (vercel can't get geo country in dev)
|
|
582
|
-
if (!localizationStore.selectedCountryCode &&
|
|
583
|
-
devSites.some(site => window.location.origin.includes(site))) {
|
|
584
|
-
// update selected country code in store
|
|
585
|
-
void localizationStoreUpdateSelectedCountryCode('US');
|
|
586
|
-
}
|
|
587
|
-
localizationStore.localizationLoaded = true;
|
|
588
|
-
void getCustomMessages();
|
|
589
|
-
};
|
|
590
|
-
const updateCheckoutSessionLanguage = async () => {
|
|
591
|
-
if (!cartStore.checkoutSessionId) {
|
|
592
|
-
return null;
|
|
593
|
-
}
|
|
594
|
-
const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/update-checkout-session-metadata`, {
|
|
595
|
-
body: {
|
|
596
|
-
id: cartStore.checkoutSessionId,
|
|
597
|
-
metadata: [
|
|
598
|
-
{
|
|
599
|
-
key: 'language',
|
|
600
|
-
value: localizationStore.selectedLocale,
|
|
601
|
-
},
|
|
602
|
-
],
|
|
603
|
-
},
|
|
604
|
-
method: 'POST',
|
|
605
|
-
});
|
|
606
|
-
if (errors.length || !json) {
|
|
607
|
-
logError('Error occurs when updating checkout session', JSON.stringify(errors, null, 2));
|
|
608
|
-
return { errors, json };
|
|
609
|
-
}
|
|
610
|
-
return { errors: [], json };
|
|
611
|
-
};
|
|
612
|
-
const localizationStoreUpdateSelectedLocale = (newSelectedLocale) => {
|
|
613
|
-
localizationStore.selectedLocale = newSelectedLocale;
|
|
614
|
-
translationStoreUpdateLanguage(newSelectedLocale);
|
|
615
|
-
void updateCheckoutSessionLanguage();
|
|
616
|
-
};
|
|
617
|
-
|
|
618
|
-
const formatDate = ({ date,
|
|
619
|
-
// eslint-disable-next-line sort-keys/sort-keys-fix
|
|
620
|
-
formatOptions = {
|
|
621
|
-
dateStyle: 'full',
|
|
622
|
-
}, }) => {
|
|
623
|
-
// format date to 'Wednesday, May 15, 2024'
|
|
624
|
-
return new Intl.DateTimeFormat('en-US', formatOptions).format(date);
|
|
625
|
-
};
|
|
626
|
-
|
|
627
|
-
const getDaysDifference = (targetDate) => {
|
|
628
|
-
const currentDate = new Date();
|
|
629
|
-
const timeDifference = targetDate.getTime() - currentDate.getTime();
|
|
630
|
-
const daysDifference = Math.floor(timeDifference / (1000 * 60 * 60 * 24)); // Convert milliseconds to days
|
|
631
|
-
return daysDifference;
|
|
632
|
-
};
|
|
633
|
-
|
|
634
|
-
const { onChange: onChange$1, reset: reset$1, state: cartStore, } = createStore(() => ({
|
|
635
|
-
checkoutSessionId: sessionStorage.getItem('zonos--checkout-session-id') || null,
|
|
636
|
-
currency: 'USD',
|
|
637
|
-
doneSteps: [],
|
|
638
|
-
dutiesTaxFees: 0,
|
|
639
|
-
error: null,
|
|
640
|
-
exchangeRate: null,
|
|
641
|
-
isSelectedShippingAboveDeminimis: false,
|
|
642
|
-
isSelectedShippingGuarantee: false,
|
|
643
|
-
items: [],
|
|
644
|
-
landedCostData: null,
|
|
645
|
-
restrictedItems: [],
|
|
646
|
-
selectedLandedCost: null,
|
|
647
|
-
selectedShippingOption: null,
|
|
648
|
-
selectedShippingOptionExpectedDate: '',
|
|
649
|
-
selectedShippingOptionTransitTime: '',
|
|
650
|
-
shipping: 0,
|
|
651
|
-
shippingData: null,
|
|
652
|
-
step: 'customer-info',
|
|
653
|
-
subtotal: 0,
|
|
654
|
-
tabItems: {
|
|
655
|
-
'customer-info': {
|
|
656
|
-
index: 1,
|
|
657
|
-
isDone: false,
|
|
658
|
-
label: 'Customer',
|
|
659
|
-
value: 'customer-info',
|
|
660
|
-
},
|
|
661
|
-
shipping: {
|
|
662
|
-
index: 2,
|
|
663
|
-
isDone: false,
|
|
664
|
-
label: 'Delivery',
|
|
665
|
-
value: 'shipping',
|
|
666
|
-
},
|
|
667
|
-
// eslint-disable-next-line sort-keys/sort-keys-fix
|
|
668
|
-
payment: {
|
|
669
|
-
index: 3,
|
|
670
|
-
isDone: false,
|
|
671
|
-
label: 'Payment',
|
|
672
|
-
value: 'payment',
|
|
673
|
-
},
|
|
674
|
-
},
|
|
675
|
-
total: 0,
|
|
676
|
-
}));
|
|
677
|
-
/**
|
|
678
|
-
* Format shipping transit info to be displayed on UI
|
|
679
|
-
* @returns
|
|
680
|
-
* - expectedDate: Thursday, Aug 12
|
|
681
|
-
* - maxTransit: 5
|
|
682
|
-
* - minTransit: 3
|
|
683
|
-
*/
|
|
684
|
-
const cartStoreGetShippingTransitInfo = (item) => {
|
|
685
|
-
const minTransit = item.minTransitAt
|
|
686
|
-
? getDaysDifference(new Date(item.minTransitAt))
|
|
687
|
-
: '';
|
|
688
|
-
const maxTransit = item.maxTransitAt
|
|
689
|
-
? getDaysDifference(new Date(item.maxTransitAt))
|
|
690
|
-
: '';
|
|
691
|
-
const expectedDate = item.minTransitAt
|
|
692
|
-
? formatDate({
|
|
693
|
-
date: new Date(item.minTransitAt),
|
|
694
|
-
})
|
|
695
|
-
: '';
|
|
696
|
-
return {
|
|
697
|
-
expectedDate,
|
|
698
|
-
maxTransit,
|
|
699
|
-
minTransit,
|
|
700
|
-
};
|
|
701
|
-
};
|
|
702
|
-
const getMatchItem = ({ item1, item2, }) => {
|
|
703
|
-
if (!item1 || !item2) {
|
|
704
|
-
return false;
|
|
705
|
-
}
|
|
706
|
-
return ((item2.sku && item1.sku && item1.sku === item2.sku) ||
|
|
707
|
-
(item2.description &&
|
|
708
|
-
item1.description &&
|
|
709
|
-
item1.description === item2.description) ||
|
|
710
|
-
(item1.name && item2.name && item1.name === item2.name));
|
|
711
|
-
};
|
|
712
|
-
/**
|
|
713
|
-
* Check and set restricted items in cart
|
|
714
|
-
*/
|
|
715
|
-
const cartStoreCheckItemRestrictions = (itemsWorkflow) => {
|
|
716
|
-
log('Checking item restrictions');
|
|
717
|
-
const mappedRestrictedItems = itemsWorkflow
|
|
718
|
-
.map(item => {
|
|
719
|
-
if (!item.restriction) {
|
|
720
|
-
return null;
|
|
721
|
-
}
|
|
722
|
-
const { restriction } = item;
|
|
723
|
-
const matchedItem = cartStore.items.find(x => getMatchItem({ item1: x, item2: item }));
|
|
724
|
-
return Object.assign(Object.assign({ matchedItem }, item), { restriction });
|
|
725
|
-
})
|
|
726
|
-
.filter(Boolean);
|
|
727
|
-
cartStore.restrictedItems = mappedRestrictedItems;
|
|
728
|
-
// remove items that are restricted from cart
|
|
729
|
-
cartStore.items = cartStore.items.map(item => (Object.assign(Object.assign({}, item), { isRestricted: !!mappedRestrictedItems.find(x => getMatchItem({ item1: x, item2: item })) })));
|
|
730
|
-
return {
|
|
731
|
-
cartItems: cartStore.items,
|
|
732
|
-
restrictedItems: mappedRestrictedItems,
|
|
733
|
-
};
|
|
734
|
-
};
|
|
735
|
-
const cartStoreReset = () => {
|
|
736
|
-
sessionStorage.removeItem('zonos--checkout-session-id');
|
|
737
|
-
// reset cart store
|
|
738
|
-
reset$1();
|
|
739
|
-
};
|
|
740
|
-
const cartStoreUpdateToErrorState = ({ messages, title, }) => {
|
|
741
|
-
cartStoreReset();
|
|
742
|
-
stripeStoreReset();
|
|
743
|
-
cartStore.step = 'error';
|
|
744
|
-
cartStore.error = {
|
|
745
|
-
messages,
|
|
746
|
-
title,
|
|
747
|
-
};
|
|
748
|
-
};
|
|
749
|
-
const cartStoreApplySubtotals = (subtotals) => {
|
|
750
|
-
// update exchange rate so we can use it to display cart items
|
|
751
|
-
cartStore.exchangeRate = subtotals.exchangeRate;
|
|
752
|
-
cartStore.dutiesTaxFees = subtotals.landedCostTotal;
|
|
753
|
-
cartStore.subtotal = subtotals.items;
|
|
754
|
-
cartStore.total = subtotals.total;
|
|
755
|
-
cartStore.currency = subtotals.presentmentCurrencyCode;
|
|
756
|
-
};
|
|
757
|
-
/**
|
|
758
|
-
* Detect if there are any items in cart that are not restricted and have positive amount, exclude negative amount items
|
|
759
|
-
*/
|
|
760
|
-
const cartStoreHasOneEligibleItem = () => {
|
|
761
|
-
// filter all items with positive amount
|
|
762
|
-
const checkItems = cartStore.items.filter(item => item.amount > 0);
|
|
763
|
-
// only check restricted status for items with positive amount
|
|
764
|
-
// if there is no item restricted found => all items are restricted
|
|
765
|
-
return !!checkItems.find(item => !item.isRestricted);
|
|
766
|
-
};
|
|
767
|
-
const cartStoreReCalculateTotal = async ({ currency, itemsAmount, landedCostId, }) => {
|
|
768
|
-
if (landedCostId && cartStore.selectedLandedCost) {
|
|
769
|
-
// update cart total right away if we have landed cost id to avoid order total flickering
|
|
770
|
-
const subtotals = cartStore.selectedLandedCost.subtotals;
|
|
771
|
-
cartStoreApplySubtotals(subtotals);
|
|
772
|
-
log('Exchange rate updated for cart items (landed cost subtotal)', 'info', cartStore.exchangeRate);
|
|
773
|
-
}
|
|
774
|
-
// update checkout session
|
|
775
|
-
if (!cartStore.checkoutSessionId) {
|
|
776
|
-
logError('Could not update cart total without checkout session id');
|
|
777
|
-
return false;
|
|
778
|
-
}
|
|
779
|
-
const { errors, json } = await stripeStoreUpdateCheckoutSession({
|
|
780
|
-
currency,
|
|
781
|
-
id: cartStore.checkoutSessionId,
|
|
782
|
-
itemsAmount,
|
|
783
|
-
landedCostId,
|
|
784
|
-
presentmentCountryCode: localizationStore.selectedCountryCode,
|
|
785
|
-
});
|
|
786
|
-
if (errors.length > 0 || !json) {
|
|
787
|
-
// do nothing if we can't get checkout session
|
|
788
|
-
logError('Error occurs when updating checkout session');
|
|
789
|
-
cartStoreUpdateToErrorState({
|
|
790
|
-
messages: [
|
|
791
|
-
translate("There's been an error updating your checkout session. Please reload and try again or contact support if the error persists"),
|
|
792
|
-
],
|
|
793
|
-
title: translate('Error updating Checkout'),
|
|
794
|
-
});
|
|
795
|
-
return false;
|
|
796
|
-
}
|
|
797
|
-
if (!landedCostId) {
|
|
798
|
-
// This is when first open the checkout modal and we just want to get info from the old cart session.
|
|
799
|
-
// use subtotals from checkout session to update cart total
|
|
800
|
-
cartStoreApplySubtotals(json.checkoutSessionUpdate.subtotals);
|
|
801
|
-
log('Exchange rate updated for cart items (checkout session update)', 'info', cartStore.exchangeRate);
|
|
802
|
-
}
|
|
803
|
-
return true;
|
|
804
|
-
};
|
|
805
|
-
const cartStoreUpdateSelectedShippingOption = async (selectedShippingOption) => {
|
|
806
|
-
var _a, _b, _c, _d, _e;
|
|
807
|
-
cartStore.selectedShippingOption = selectedShippingOption;
|
|
808
|
-
// update shipping transit info
|
|
809
|
-
const { expectedDate, maxTransit, minTransit } = cartStoreGetShippingTransitInfo(cartStore.selectedShippingOption);
|
|
810
|
-
cartStore.selectedShippingOptionExpectedDate = expectedDate;
|
|
811
|
-
cartStore.selectedShippingOptionTransitTime =
|
|
812
|
-
minTransit && maxTransit
|
|
813
|
-
? `${minTransit}-${maxTransit}`
|
|
814
|
-
: `${minTransit || maxTransit}`;
|
|
815
|
-
const selectedLandedCost = (_a = cartStore.landedCostData) === null || _a === void 0 ? void 0 : _a.find(checkoutSessionPresentment => {
|
|
816
|
-
var _a, _b, _c;
|
|
817
|
-
return ((_b = (_a = checkoutSessionPresentment.landedCost) === null || _a === void 0 ? void 0 : _a.shipmentRating) === null || _b === void 0 ? void 0 : _b.id) ===
|
|
818
|
-
((_c = cartStore.selectedShippingOption) === null || _c === void 0 ? void 0 : _c.id);
|
|
819
|
-
});
|
|
820
|
-
// save selected landed cost for later use
|
|
821
|
-
cartStore.selectedLandedCost = selectedLandedCost || null;
|
|
822
|
-
if (!selectedLandedCost) {
|
|
823
|
-
// do nothing if we can't find landed cost for selected shipping option
|
|
824
|
-
return false;
|
|
825
|
-
}
|
|
826
|
-
// update shipping value and dutiesTaxFees on selectedShippingOption change
|
|
827
|
-
cartStore.shipping = selectedLandedCost.subtotals.shipping;
|
|
828
|
-
// update deminimis status
|
|
829
|
-
const isGuarantee = ((_b = selectedLandedCost === null || selectedLandedCost === void 0 ? void 0 : selectedLandedCost.landedCost) === null || _b === void 0 ? void 0 : _b.landedCostGuaranteeCode) === 'ZONOS';
|
|
830
|
-
// one item in deminimis with type of duty and tax has threshold value is "ABOVE"
|
|
831
|
-
const isAboveDeminimis = !!((_d = (_c = selectedLandedCost === null || selectedLandedCost === void 0 ? void 0 : selectedLandedCost.landedCost) === null || _c === void 0 ? void 0 : _c.deMinimis) === null || _d === void 0 ? void 0 : _d.find(item => ['DUTY', 'TAX'].includes(item.type) && item.threshold === 'ABOVE'));
|
|
832
|
-
cartStore.isSelectedShippingAboveDeminimis = isAboveDeminimis;
|
|
833
|
-
cartStore.isSelectedShippingGuarantee = isGuarantee;
|
|
834
|
-
// update session with selected landed cost
|
|
835
|
-
const updateCalulateStatus = await cartStoreReCalculateTotal({
|
|
836
|
-
landedCostId: (_e = selectedLandedCost.landedCost) === null || _e === void 0 ? void 0 : _e.id,
|
|
837
|
-
});
|
|
838
|
-
return updateCalulateStatus;
|
|
839
|
-
};
|
|
840
|
-
onChange$1('checkoutSessionId', () => {
|
|
841
|
-
if (!cartStore.checkoutSessionId) {
|
|
842
|
-
sessionStorage.removeItem('zonos--checkout-session-id');
|
|
843
|
-
return;
|
|
844
|
-
}
|
|
845
|
-
sessionStorage.setItem('zonos--checkout-session-id', cartStore.checkoutSessionId);
|
|
846
|
-
});
|
|
847
|
-
const getCartItemToUse = (items) => items.map(item => (Object.assign(Object.assign({}, item), { isRestricted: false })));
|
|
848
|
-
const cartStoreResetCartItems = () => {
|
|
849
|
-
// mark all items as not restricted
|
|
850
|
-
cartStore.items = cartStore.items.map(item => (Object.assign(Object.assign({}, item), { isRestricted: false })));
|
|
851
|
-
cartStore.restrictedItems = [];
|
|
852
|
-
};
|
|
853
|
-
const cartStoreUpdateItems = async (cartItems) => {
|
|
854
|
-
var _a;
|
|
855
|
-
cartStore.items = getCartItemToUse(cartItems);
|
|
856
|
-
const currency = (_a = cartItems.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode;
|
|
857
|
-
const total = cartItems.reduce((amt, item) => {
|
|
858
|
-
return amt + item.amount * item.quantity;
|
|
859
|
-
}, 0);
|
|
860
|
-
if (!currency || !total) {
|
|
861
|
-
// do nothing if we can't get currency or total
|
|
862
|
-
return;
|
|
863
|
-
}
|
|
864
|
-
cartStore.currency = currency;
|
|
865
|
-
// set loading state here because this is first load checkout session when we already have checkout session id stored
|
|
866
|
-
stripeStore.isFetchingSession = true;
|
|
867
|
-
await cartStoreReCalculateTotal({
|
|
868
|
-
currency: currency,
|
|
869
|
-
itemsAmount: total,
|
|
870
|
-
});
|
|
871
|
-
stripeStore.isFetchingSession = false;
|
|
872
|
-
};
|
|
873
|
-
const cartStoreResetSelectedShippingOption = () => {
|
|
874
|
-
cartStore.selectedShippingOption = null;
|
|
875
|
-
cartStore.isSelectedShippingAboveDeminimis = false;
|
|
876
|
-
cartStore.isSelectedShippingGuarantee = false;
|
|
877
|
-
cartStore.selectedShippingOptionExpectedDate = '';
|
|
878
|
-
cartStore.selectedShippingOptionTransitTime = '';
|
|
879
|
-
cartStore.dutiesTaxFees = 0;
|
|
880
|
-
cartStore.shipping = 0;
|
|
881
|
-
// reset total to subtotal
|
|
882
|
-
cartStore.total = cartStore.subtotal;
|
|
883
|
-
};
|
|
884
|
-
const cartStoreNextStep = () => {
|
|
885
|
-
if (cartStore.step === 'customer-info') {
|
|
886
|
-
cartStore.step = 'shipping';
|
|
887
|
-
// set customer-info step to done
|
|
888
|
-
cartStore.tabItems = Object.assign(Object.assign({}, cartStore.tabItems), { 'customer-info': Object.assign(Object.assign({}, cartStore.tabItems['customer-info']), { isDone: true }) });
|
|
889
|
-
}
|
|
890
|
-
else if (cartStore.step === 'shipping') {
|
|
891
|
-
cartStore.step = 'payment';
|
|
892
|
-
// set shipping step to done
|
|
893
|
-
cartStore.tabItems = Object.assign(Object.assign({}, cartStore.tabItems), { shipping: Object.assign(Object.assign({}, cartStore.tabItems.shipping), { isDone: true }) });
|
|
894
|
-
}
|
|
895
|
-
else if (cartStore.step === 'payment') {
|
|
896
|
-
cartStore.step = 'finish';
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
const cartStoreResetTabItems = () => {
|
|
900
|
-
cartStore.step = 'customer-info';
|
|
901
|
-
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 }) });
|
|
902
|
-
cartStoreResetSelectedShippingOption();
|
|
903
|
-
};
|
|
904
|
-
|
|
905
|
-
const prepCalculateLandedCost = () => {
|
|
906
|
-
// maybe we don't need email now for prefetch the landed cost
|
|
907
|
-
const stripeLinkData = stripeStore.stripeLinkEventData;
|
|
908
|
-
const stripeAddressData = stripeStore.stripeAddressEventData;
|
|
909
|
-
const stripeBillingAddressData = stripeStore.stripeShippingSameAsBilling
|
|
910
|
-
? stripeStore.stripeAddressEventData
|
|
911
|
-
: stripeStore.stripeBillingAddressEventData;
|
|
912
|
-
if (!(stripeAddressData === null || stripeAddressData === void 0 ? void 0 : stripeAddressData.complete) || !(stripeBillingAddressData === null || stripeBillingAddressData === void 0 ? void 0 : stripeBillingAddressData.complete)) {
|
|
913
|
-
throw new Error('Missing stripe address data');
|
|
914
|
-
}
|
|
915
|
-
return {
|
|
916
|
-
billingAddress: {
|
|
917
|
-
addressLine1: stripeBillingAddressData.value.address.line1,
|
|
918
|
-
addressLine2: stripeBillingAddressData.value.address.line2 || '',
|
|
919
|
-
city: stripeBillingAddressData.value.address.city,
|
|
920
|
-
country: stripeBillingAddressData.value.address.country,
|
|
921
|
-
postalCode: stripeBillingAddressData.value.address.postal_code,
|
|
922
|
-
state: stripeBillingAddressData.value.address.state,
|
|
923
|
-
},
|
|
924
|
-
billingContact: {
|
|
925
|
-
// firstName and lastName should be valid now since stripe only mark
|
|
926
|
-
// the address as complete when both fields are filled.
|
|
927
|
-
firstName: stripeBillingAddressData.value.firstName || '',
|
|
928
|
-
lastName: stripeBillingAddressData.value.lastName || '',
|
|
929
|
-
phone: stripeBillingAddressData.value.phone || '',
|
|
930
|
-
},
|
|
931
|
-
checkoutSessionId: cartStore.checkoutSessionId || '',
|
|
932
|
-
contact: {
|
|
933
|
-
email: (stripeLinkData === null || stripeLinkData === void 0 ? void 0 : stripeLinkData.value.email) || '',
|
|
934
|
-
// firstName and lastName should be valid now since stripe only mark
|
|
935
|
-
// the address as complete when both fields are filled.
|
|
936
|
-
firstName: stripeAddressData.value.firstName || '',
|
|
937
|
-
lastName: stripeAddressData.value.lastName || '',
|
|
938
|
-
phone: stripeAddressData.value.phone || '',
|
|
939
|
-
},
|
|
940
|
-
items: cartStore.items,
|
|
941
|
-
shippingAddress: {
|
|
942
|
-
addressLine1: stripeAddressData.value.address.line1,
|
|
943
|
-
addressLine2: stripeAddressData.value.address.line2 || '',
|
|
944
|
-
city: stripeAddressData.value.address.city,
|
|
945
|
-
country: stripeAddressData.value.address.country,
|
|
946
|
-
postalCode: stripeAddressData.value.address.postal_code,
|
|
947
|
-
state: stripeAddressData.value.address.state,
|
|
948
|
-
},
|
|
949
|
-
};
|
|
950
|
-
};
|
|
951
|
-
|
|
952
|
-
const triggerBuildLandedCost = async (buildLandedCost) => {
|
|
953
|
-
var _a, _b, _c, _d;
|
|
954
|
-
const data = prepCalculateLandedCost();
|
|
955
|
-
const landedCost = await buildLandedCost({
|
|
956
|
-
billingAddress: data.billingAddress,
|
|
957
|
-
billingContact: data.billingContact,
|
|
958
|
-
checkoutSessionId: data.checkoutSessionId,
|
|
959
|
-
contact: data.contact,
|
|
960
|
-
shippingAddress: data.shippingAddress,
|
|
961
|
-
zonosApiRoute: "https://v1.route.js.zonos.com",
|
|
962
|
-
});
|
|
963
|
-
if (!landedCost || ((_a = landedCost.errors) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
964
|
-
throw new Error(`Failed to build landed cost: ${((_c = (_b = landedCost === null || landedCost === void 0 ? void 0 : landedCost.errors) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.message) || 'Unknown error'}`);
|
|
965
|
-
}
|
|
966
|
-
// Validate the landed cost object to make sure the returned value from buildLandedCost has a valid schema
|
|
967
|
-
const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/validate-landed-cost`, {
|
|
968
|
-
body: landedCost,
|
|
969
|
-
headers: {
|
|
970
|
-
'Content-Type': 'application/json',
|
|
971
|
-
},
|
|
972
|
-
method: 'POST',
|
|
973
|
-
});
|
|
974
|
-
if (!json || errors.length) {
|
|
975
|
-
throw new Error(`Invalid landed cost object: ${((_d = errors.find(Boolean)) === null || _d === void 0 ? void 0 : _d.message) || 'Unknown error'}`);
|
|
976
|
-
}
|
|
977
|
-
return landedCost;
|
|
978
|
-
};
|
|
979
|
-
|
|
980
|
-
const calculateLandedCost = async (abortController) => {
|
|
981
|
-
var _a;
|
|
982
|
-
// If buildLandedCost callback is supplied, use that instead of our regular request to '/calculate-landed-cost'
|
|
983
|
-
const buildLandedCost = zonosStore.checkoutSettings.buildLandedCost;
|
|
984
|
-
if (buildLandedCost) {
|
|
985
|
-
const json = await triggerBuildLandedCost(buildLandedCost);
|
|
986
|
-
return json;
|
|
987
|
-
}
|
|
988
|
-
// request to get landed cost info
|
|
989
|
-
const url = `${"https://v1.route.js.zonos.com"}/api/zonos-elements/calculate-landed-cost`;
|
|
990
|
-
const { errors, json } = await handleFetch(url, {
|
|
991
|
-
body: prepCalculateLandedCost(),
|
|
992
|
-
method: 'POST',
|
|
993
|
-
signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
|
|
994
|
-
});
|
|
995
|
-
if (errors.length || !json) {
|
|
996
|
-
const isAbortedRequest = ((_a = errors[0]) === null || _a === void 0 ? void 0 : _a.message) === 'The user aborted a request.';
|
|
997
|
-
const errorMessage = isAbortedRequest
|
|
998
|
-
? 'The landed cost calculation request was aborted to initiate a new one.'
|
|
999
|
-
: 'Failed to calculate landed cost';
|
|
1000
|
-
throw new Error(errorMessage);
|
|
1001
|
-
}
|
|
1002
|
-
return json;
|
|
1003
|
-
};
|
|
1004
|
-
|
|
1005
|
-
/**
|
|
1006
|
-
* This function generates an object that contains the fields of an address that have invalid characters.
|
|
1007
|
-
*
|
|
1008
|
-
* @param {Object} params - The parameters for the function.
|
|
1009
|
-
* @param {Address | null} params.address - The address to check for invalid characters.
|
|
1010
|
-
* @param {ReturnType<typeof containsNonLatinChars> | null} params.invalidAdddressList - The list of address fields that contain invalid characters.
|
|
1011
|
-
*
|
|
1012
|
-
* @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.
|
|
1013
|
-
*/
|
|
1014
|
-
const getExcludeAddressFieldsObject = ({ address, invalidAdddressList, }) => {
|
|
1015
|
-
if (!address) {
|
|
1016
|
-
return;
|
|
1017
|
-
}
|
|
1018
|
-
// if there are no invalid characters, return an empty object
|
|
1019
|
-
if (!invalidAdddressList) {
|
|
1020
|
-
return;
|
|
1021
|
-
}
|
|
1022
|
-
const excludeFields = {};
|
|
1023
|
-
if (invalidAdddressList.city) {
|
|
1024
|
-
excludeFields.city = address.city;
|
|
1025
|
-
}
|
|
1026
|
-
if (invalidAdddressList.line1) {
|
|
1027
|
-
excludeFields.line1 = address.line1;
|
|
1028
|
-
}
|
|
1029
|
-
if (invalidAdddressList.line2) {
|
|
1030
|
-
excludeFields.line2 = address.line2;
|
|
1031
|
-
}
|
|
1032
|
-
if (invalidAdddressList.postal_code) {
|
|
1033
|
-
excludeFields.postal_code = address.postal_code;
|
|
1034
|
-
}
|
|
1035
|
-
if (invalidAdddressList.state) {
|
|
1036
|
-
excludeFields.state = address.state;
|
|
1037
|
-
}
|
|
1038
|
-
if (invalidAdddressList.name) {
|
|
1039
|
-
excludeFields.name = address.name;
|
|
1040
|
-
}
|
|
1041
|
-
// return null if there are no fields to exclude
|
|
1042
|
-
return Object.keys(excludeFields).length ? excludeFields : undefined;
|
|
1043
|
-
};
|
|
1044
|
-
/**
|
|
1045
|
-
* 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.
|
|
1046
|
-
* 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.
|
|
1047
|
-
* If the conditions are not met, it returns null.
|
|
1048
|
-
*
|
|
1049
|
-
* @param {Object} params - The parameters for the function.
|
|
1050
|
-
* @param {ReturnType<typeof containsNonLatinChars> | null} params.addressInvalidCharactersList - The list of address fields that contain invalid characters.
|
|
1051
|
-
* @param {ReturnType<typeof containsNonLatinChars> | null} params.billingAddressInvalidCharactersList - The list of billing address fields that contain invalid characters.
|
|
1052
|
-
* @param {StripeAddressEventData} params.stripeAddressEventData - The Stripe event data for the address.
|
|
1053
|
-
* @param {StripeAddressEventData} params.stripeBillingAddressEventData - The Stripe event data for the billing address.
|
|
1054
|
-
* @param {boolean} params.stripeShippingSameAsBilling - A flag indicating whether the shipping address is the same as the billing address.
|
|
1055
|
-
*
|
|
1056
|
-
* @returns {ValidateAddressRequestBody | 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.
|
|
1057
|
-
*/
|
|
1058
|
-
const buildTranslateRequestBody = ({ addressInvalidCharactersList, billingAddressInvalidCharactersList, stripeAddressEventData, stripeBillingAddressEventData, stripeShippingSameAsBilling, }) => {
|
|
1059
|
-
var _a, _b, _c, _d;
|
|
1060
|
-
const isStripeAddressReady = !!(stripeAddressEventData === null || stripeAddressEventData === void 0 ? void 0 : stripeAddressEventData.complete);
|
|
1061
|
-
const isStripeBillingAddressReady = stripeShippingSameAsBilling
|
|
1062
|
-
? isStripeAddressReady
|
|
1063
|
-
: !!(stripeBillingAddressEventData === null || stripeBillingAddressEventData === void 0 ? void 0 : stripeBillingAddressEventData.complete);
|
|
1064
|
-
// only translate if both address and billing address are ready
|
|
1065
|
-
if (!isStripeAddressReady || !isStripeBillingAddressReady) {
|
|
1066
|
-
return null;
|
|
1067
|
-
}
|
|
1068
|
-
// only translate if there are invalid characters
|
|
1069
|
-
if (!addressInvalidCharactersList && !billingAddressInvalidCharactersList) {
|
|
1070
|
-
return null;
|
|
1071
|
-
}
|
|
1072
|
-
const stripeAddressValue = stripeAddressEventData.value;
|
|
1073
|
-
const stripeBillingAddressValue = (stripeBillingAddressEventData === null || stripeBillingAddressEventData === void 0 ? void 0 : stripeBillingAddressEventData.value) || null;
|
|
1074
|
-
// Returns undefined if the name is Latin so it won't be included in the request body
|
|
1075
|
-
const firstName = stripeAddressValue.firstName || ((_a = stripeAddressValue.name) === null || _a === void 0 ? void 0 : _a.split(' ')[0]);
|
|
1076
|
-
const lastName = stripeAddressValue.lastName || ((_b = stripeAddressValue.name) === null || _b === void 0 ? void 0 : _b.split(' ')[1]);
|
|
1077
|
-
const name = `${firstName} ${lastName}`;
|
|
1078
|
-
const billingFirstName = stripeAddressValue.firstName ||
|
|
1079
|
-
((_c = stripeBillingAddressValue === null || stripeBillingAddressValue === void 0 ? void 0 : stripeBillingAddressValue.name) === null || _c === void 0 ? void 0 : _c.split(' ')[0]);
|
|
1080
|
-
const billingLastName = stripeAddressValue.lastName ||
|
|
1081
|
-
((_d = stripeBillingAddressValue === null || stripeBillingAddressValue === void 0 ? void 0 : stripeBillingAddressValue.name) === null || _d === void 0 ? void 0 : _d.split(' ')[1]);
|
|
1082
|
-
const billingName = billingFirstName && billingLastName
|
|
1083
|
-
? `${billingFirstName} ${billingLastName}`
|
|
1084
|
-
: '';
|
|
1085
|
-
const address = stripeAddressValue.address;
|
|
1086
|
-
const billingAddress = stripeBillingAddressValue === null || stripeBillingAddressValue === void 0 ? void 0 : stripeBillingAddressValue.address;
|
|
1087
|
-
return {
|
|
1088
|
-
address: getExcludeAddressFieldsObject({
|
|
1089
|
-
address: Object.assign(Object.assign({}, address), { name }),
|
|
1090
|
-
invalidAdddressList: addressInvalidCharactersList,
|
|
1091
|
-
}),
|
|
1092
|
-
// only include billing address if it's different from the shipping address
|
|
1093
|
-
billingAddress: !stripeShippingSameAsBilling
|
|
1094
|
-
? getExcludeAddressFieldsObject({
|
|
1095
|
-
address: billingAddress
|
|
1096
|
-
? Object.assign(Object.assign({}, billingAddress), { name: billingName }) : null,
|
|
1097
|
-
invalidAdddressList: billingAddressInvalidCharactersList,
|
|
1098
|
-
})
|
|
1099
|
-
: undefined,
|
|
1100
|
-
destinationCountry: address.country,
|
|
1101
|
-
};
|
|
1102
|
-
};
|
|
1103
|
-
|
|
1104
|
-
const jsonParse = (_data) => {
|
|
1105
|
-
if (typeof _data === 'string') {
|
|
1106
|
-
try {
|
|
1107
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
1108
|
-
const json = JSON.parse(_data);
|
|
1109
|
-
return json;
|
|
1110
|
-
}
|
|
1111
|
-
catch (_error) {
|
|
1112
|
-
return null;
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
return null;
|
|
1116
|
-
};
|
|
1117
|
-
|
|
1118
|
-
const addressRuleStyle = ({ theme, }) => {
|
|
1119
|
-
const defaultStyle = {
|
|
1120
|
-
'.Action': {
|
|
1121
|
-
color: 'var(--colorText)',
|
|
1122
|
-
},
|
|
1123
|
-
'.Input': {
|
|
1124
|
-
boxShadow: 'none',
|
|
1125
|
-
// need to reset everything and the paddingTop to default, otherwise the paddingTop will not be updated.
|
|
1126
|
-
padding: '0',
|
|
1127
|
-
paddingBottom: '8px',
|
|
1128
|
-
paddingLeft: '16px',
|
|
1129
|
-
paddingRight: '8px',
|
|
1130
|
-
// any value here will be add up to the default paddingTop (20px).
|
|
1131
|
-
paddingTop: '6px',
|
|
1132
|
-
},
|
|
1133
|
-
'.PickerItem--highlight': {
|
|
1134
|
-
boxShadow: '0 0 0 2px var(--colorBackground)',
|
|
1135
|
-
},
|
|
1136
|
-
'.PickerItem--highlight:hover': {
|
|
1137
|
-
backgroundColor: 'var(--colorBackground)',
|
|
1138
|
-
boxShadow: 'none',
|
|
1139
|
-
},
|
|
1140
|
-
'.PickerItem--new': {
|
|
1141
|
-
color: 'var(--colorText)',
|
|
1142
|
-
},
|
|
1143
|
-
};
|
|
1144
|
-
switch (theme) {
|
|
1145
|
-
case 'DARK': {
|
|
1146
|
-
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' }) });
|
|
1147
|
-
}
|
|
1148
|
-
default:
|
|
1149
|
-
return defaultStyle;
|
|
1150
|
-
}
|
|
1151
|
-
};
|
|
1152
|
-
|
|
1153
|
-
const defaultVariable = ({ borderStyle, theme, }) => {
|
|
1154
|
-
switch (theme) {
|
|
1155
|
-
case 'DARK':
|
|
1156
|
-
return {
|
|
1157
|
-
borderRadius: getBorderRadius({ overrideBorderStyle: borderStyle }),
|
|
1158
|
-
colorBackground: '#101117',
|
|
1159
|
-
colorBackgroundText: '#C5C6CA',
|
|
1160
|
-
colorText: '#C5C6CA',
|
|
1161
|
-
colorTextPlaceholder: '#C5C6CA',
|
|
1162
|
-
};
|
|
1163
|
-
default:
|
|
1164
|
-
return {
|
|
1165
|
-
borderRadius: getBorderRadius({ overrideBorderStyle: borderStyle }),
|
|
1166
|
-
};
|
|
1167
|
-
}
|
|
1168
|
-
};
|
|
1169
|
-
|
|
1170
|
-
const { onChange, reset, state: stripeStore, } = createStore(() => ({
|
|
1171
|
-
clientSecret: sessionStorage.getItem('zonos--client-secret') || null,
|
|
1172
|
-
fetchingLandedCostAbordController: null,
|
|
1173
|
-
isFetchingLandedCost: false,
|
|
1174
|
-
isFetchingSession: false,
|
|
1175
|
-
stripe: null,
|
|
1176
|
-
stripeAddressElement: null,
|
|
1177
|
-
stripeAddressEventData: null,
|
|
1178
|
-
stripeAddressUsedWhenFetchingLC: null,
|
|
1179
|
-
stripeAddressUsedWhenValidatingAddress: null,
|
|
1180
|
-
stripeBillingAddressElement: null,
|
|
1181
|
-
stripeBillingAddressEventData: null,
|
|
1182
|
-
stripeBillingAddressUsedWhenFetchingLC: null,
|
|
1183
|
-
stripeBillingAddressUsedWhenValidatingAddress: null,
|
|
1184
|
-
stripeElements: null,
|
|
1185
|
-
stripeElementsForBillingAddress: null,
|
|
1186
|
-
stripeElementsOptions: null,
|
|
1187
|
-
stripeLinkElement: null,
|
|
1188
|
-
stripeLinkEventData: null,
|
|
1189
|
-
stripeLinkUsedWhenFetchingLC: null,
|
|
1190
|
-
stripePaymentElement: null,
|
|
1191
|
-
stripePaymentEventData: null,
|
|
1192
|
-
stripeShippingSameAsBilling: true,
|
|
1193
|
-
translatedAddress: {
|
|
1194
|
-
address: {},
|
|
1195
|
-
billingAddress: {},
|
|
1196
|
-
firstName: {},
|
|
1197
|
-
lastName: {},
|
|
1198
|
-
name: {},
|
|
1199
|
-
},
|
|
1200
|
-
}));
|
|
1201
|
-
const getStripeOptions = ({ clientSecret, overrideBorderRaidus, overridePrimaryColor, overrideSecondaryColor, overrideTheme, }) => {
|
|
1202
|
-
const primaryColor = overridePrimaryColor || zonosStore.appearance.colorPrimary;
|
|
1203
|
-
const secondaryColor = overrideSecondaryColor || zonosStore.appearance.colorSecondary;
|
|
1204
|
-
const themeBasedColor = primaryColor && isDarkColor(primaryColor) ? 'night' : 'flat';
|
|
1205
|
-
// if overrideTheme is provided, use it. Otherwise, use theme based on primary color
|
|
1206
|
-
const theme = overrideTheme === 'DARK' ? 'night' : 'flat';
|
|
1207
|
-
return {
|
|
1208
|
-
appearance: {
|
|
1209
|
-
labels: 'floating',
|
|
1210
|
-
rules: Object.assign({}, addressRuleStyle({ theme: overrideTheme || 'LIGHT' })),
|
|
1211
|
-
// get contrast theme color base on primary color
|
|
1212
|
-
theme: overrideTheme ? theme : themeBasedColor,
|
|
1213
|
-
variables: Object.assign(Object.assign({}, defaultVariable({
|
|
1214
|
-
borderStyle: overrideBorderRaidus,
|
|
1215
|
-
theme: 'LIGHT',
|
|
1216
|
-
})), {
|
|
1217
|
-
// use the button background color for input glow color
|
|
1218
|
-
colorPrimary: secondaryColor }),
|
|
1219
|
-
},
|
|
1220
|
-
clientSecret,
|
|
1221
|
-
locale: localizationStore.selectedLocale,
|
|
1222
|
-
};
|
|
1223
|
-
};
|
|
1224
|
-
const stripeStoreCleanupDomesticShippingSession = () => {
|
|
1225
|
-
window.sessionStorage.removeItem('zonos--bigcommerce-domestic-checkout-shipping');
|
|
1226
|
-
};
|
|
1227
|
-
// Save shipping address to session storage
|
|
1228
|
-
const stripeStoreSaveDomesticShippingSession = (props) => {
|
|
1229
|
-
window.sessionStorage.setItem('zonos--bigcommerce-domestic-checkout-shipping', JSON.stringify(props));
|
|
1230
|
-
};
|
|
1231
|
-
const stripeStoreGetDomesticShippingSession = () => {
|
|
1232
|
-
const session = window.sessionStorage.getItem('zonos--bigcommerce-domestic-checkout-shipping');
|
|
1233
|
-
return jsonParse(session);
|
|
1234
|
-
};
|
|
1235
|
-
const initStripeElements = async (props) => {
|
|
1236
|
-
var _a, _b;
|
|
1237
|
-
const clientSecret = stripeStore.clientSecret;
|
|
1238
|
-
if (!stripeStore.stripe) {
|
|
1239
|
-
log('Skip. Stripe is not initialized');
|
|
1240
|
-
return;
|
|
1241
|
-
}
|
|
1242
|
-
if (clientSecret) {
|
|
1243
|
-
const stripeOptions = getStripeOptions({
|
|
1244
|
-
clientSecret,
|
|
1245
|
-
overrideBorderRaidus: props === null || props === void 0 ? void 0 : props.overrideBorderRaidus,
|
|
1246
|
-
overridePrimaryColor: props === null || props === void 0 ? void 0 : props.overridePrimaryColor,
|
|
1247
|
-
overrideSecondaryColor: props === null || props === void 0 ? void 0 : props.overrideSecondaryColor,
|
|
1248
|
-
overrideTheme: props === null || props === void 0 ? void 0 : props.overrideTheme,
|
|
1249
|
-
});
|
|
1250
|
-
// compare with the previous options to see if we need to update
|
|
1251
|
-
const isSameOptions = JSON.stringify(stripeOptions) ===
|
|
1252
|
-
JSON.stringify(stripeStore.stripeElementsOptions);
|
|
1253
|
-
if (!stripeStore.stripeElements ||
|
|
1254
|
-
!stripeStore.stripeElementsForBillingAddress) {
|
|
1255
|
-
// init stripe elements if it doesn't exist
|
|
1256
|
-
stripeStore.stripeElements = (_a = stripeStore.stripe) === null || _a === void 0 ? void 0 : _a.elements(stripeOptions);
|
|
1257
|
-
// save stripe elements options for later comparison
|
|
1258
|
-
stripeStore.stripeElementsOptions = stripeOptions;
|
|
1259
|
-
log('Stripe elements initialized');
|
|
1260
|
-
// init stripe elements for billing address
|
|
1261
|
-
stripeStore.stripeElementsForBillingAddress =
|
|
1262
|
-
(_b = stripeStore.stripe) === null || _b === void 0 ? void 0 : _b.elements(stripeOptions);
|
|
1263
|
-
log('Stripe elements for billing address initialized');
|
|
1264
|
-
return;
|
|
1265
|
-
}
|
|
1266
|
-
if (!isSameOptions) {
|
|
1267
|
-
// update elements with new option if it already exists
|
|
1268
|
-
stripeStore.stripeElements.update(stripeOptions);
|
|
1269
|
-
// update elements for stripe billing address
|
|
1270
|
-
stripeStore.stripeElementsForBillingAddress.update(stripeOptions);
|
|
1271
|
-
// save stripe elements options for later comparison
|
|
1272
|
-
stripeStore.stripeElementsOptions = stripeOptions;
|
|
1273
|
-
}
|
|
1274
|
-
log('Stripe elements initialized');
|
|
1275
|
-
}
|
|
1276
|
-
};
|
|
1277
|
-
const stripeStoreReset = () => {
|
|
1278
|
-
// clean clientSecret so that we can start the new one.
|
|
1279
|
-
sessionStorage.removeItem('zonos--client-secret');
|
|
1280
|
-
// cleanup stripe elements
|
|
1281
|
-
reset();
|
|
1282
|
-
// set stripe back to window.Zonos.stripe
|
|
1283
|
-
stripeStore.stripe = window.Zonos.stripe;
|
|
1284
|
-
};
|
|
1285
|
-
const checkIsAddressOutdatedForValidation = () => {
|
|
1286
|
-
var _a, _b, _c, _d;
|
|
1287
|
-
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);
|
|
1288
|
-
const isBillingAddressDataDirty = !stripeStore.stripeShippingSameAsBilling &&
|
|
1289
|
-
JSON.stringify((_c = stripeStore.stripeBillingAddressEventData) === null || _c === void 0 ? void 0 : _c.value) !==
|
|
1290
|
-
JSON.stringify((_d = stripeStore.stripeBillingAddressUsedWhenValidatingAddress) === null || _d === void 0 ? void 0 : _d.value);
|
|
1291
|
-
return isAddressDataDirty || isBillingAddressDataDirty;
|
|
1292
|
-
};
|
|
1293
|
-
const checkIsAddressOutdatedForLCPrefetch = () => {
|
|
1294
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1295
|
-
const isLinkDataDirty = JSON.stringify((_a = stripeStore.stripeLinkUsedWhenFetchingLC) === null || _a === void 0 ? void 0 : _a.value) !==
|
|
1296
|
-
JSON.stringify((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.value);
|
|
1297
|
-
const isAddressDataDirty = JSON.stringify((_c = stripeStore.stripeAddressUsedWhenFetchingLC) === null || _c === void 0 ? void 0 : _c.value) !==
|
|
1298
|
-
JSON.stringify((_d = stripeStore.stripeAddressEventData) === null || _d === void 0 ? void 0 : _d.value);
|
|
1299
|
-
const isBillingAddressDataDirty = !stripeStore.stripeShippingSameAsBilling &&
|
|
1300
|
-
JSON.stringify((_e = stripeStore.stripeBillingAddressEventData) === null || _e === void 0 ? void 0 : _e.value) !==
|
|
1301
|
-
JSON.stringify((_f = stripeStore.stripeBillingAddressUsedWhenFetchingLC) === null || _f === void 0 ? void 0 : _f.value);
|
|
1302
|
-
return isLinkDataDirty || isAddressDataDirty || isBillingAddressDataDirty;
|
|
1303
|
-
};
|
|
1304
|
-
/**
|
|
1305
|
-
* Check if the address and email info used when fetching landed cost with the current email and address info are different
|
|
1306
|
-
* Purpose is to resend the request if the info used when fetching landed cost is different from the current info
|
|
1307
|
-
*/
|
|
1308
|
-
const isPrefetchInfoOutdated = () => {
|
|
1309
|
-
var _a;
|
|
1310
|
-
// Mark the landed cost is outdated since the item total amount has changed (items total didn't match with the cart subtotal)
|
|
1311
|
-
const isTotalAmountChanged = cartStore.landedCostData &&
|
|
1312
|
-
((_a = cartStore.landedCostData.find(Boolean)) === null || _a === void 0 ? void 0 : _a.subtotals.items) !==
|
|
1313
|
-
cartStore.subtotal;
|
|
1314
|
-
const isAddressOutdated = checkIsAddressOutdatedForLCPrefetch();
|
|
1315
|
-
return (
|
|
1316
|
-
// if landed cost data is not available, we need to fetch it
|
|
1317
|
-
!cartStore.landedCostData || isAddressOutdated || isTotalAmountChanged);
|
|
1318
|
-
};
|
|
1319
|
-
const stripeStorePrefetchLandedCost = async () => {
|
|
1320
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1321
|
-
const stripeAddressReady = !!((_a = stripeStore.stripeAddressEventData) === null || _a === void 0 ? void 0 : _a.complete);
|
|
1322
|
-
const stripeLinkReady = !!((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.complete);
|
|
1323
|
-
const stripeBillingAddressReady = stripeStore.stripeShippingSameAsBilling
|
|
1324
|
-
? !!((_c = stripeStore.stripeLinkEventData) === null || _c === void 0 ? void 0 : _c.complete)
|
|
1325
|
-
: !!((_d = stripeStore.stripeBillingAddressEventData) === null || _d === void 0 ? void 0 : _d.complete);
|
|
1326
|
-
const shouldRefetch = isPrefetchInfoOutdated();
|
|
1327
|
-
if (shouldRefetch) {
|
|
1328
|
-
// if the info used when fetching landed cost is different from the current info, abort the previous request
|
|
1329
|
-
(_e = stripeStore.fetchingLandedCostAbordController) === null || _e === void 0 ? void 0 : _e.abort();
|
|
1330
|
-
stripeStore.fetchingLandedCostAbordController = null;
|
|
1331
|
-
}
|
|
1332
|
-
// only fetch if we are not fetching or we need to refetch
|
|
1333
|
-
if (stripeAddressReady &&
|
|
1334
|
-
stripeLinkReady &&
|
|
1335
|
-
stripeBillingAddressReady &&
|
|
1336
|
-
shouldRefetch) {
|
|
1337
|
-
stripeStore.isFetchingLandedCost = true;
|
|
1338
|
-
if (stripeStore.stripeAddressEventData) {
|
|
1339
|
-
stripeStore.stripeAddressUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeAddressEventData);
|
|
1340
|
-
}
|
|
1341
|
-
if (stripeStore.stripeBillingAddressEventData) {
|
|
1342
|
-
stripeStore.stripeBillingAddressUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeBillingAddressEventData);
|
|
1343
|
-
}
|
|
1344
|
-
if (stripeStore.stripeLinkEventData) {
|
|
1345
|
-
stripeStore.stripeLinkUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeLinkEventData);
|
|
1346
|
-
}
|
|
1347
|
-
try {
|
|
1348
|
-
const abortController = new AbortController();
|
|
1349
|
-
stripeStore.fetchingLandedCostAbordController = abortController;
|
|
1350
|
-
// Reset cart items to non-restricted state and restricted item list
|
|
1351
|
-
cartStoreResetCartItems();
|
|
1352
|
-
const { checkoutSessionWorkflow, itemCreateWorkflow, landedCostCalculateWorkflow, shipmentRatingCalculateWorkflow, } = await calculateLandedCost(abortController);
|
|
1353
|
-
// reset abort controller after we are done
|
|
1354
|
-
stripeStore.fetchingLandedCostAbordController = null;
|
|
1355
|
-
// update cart store with landed cost info
|
|
1356
|
-
cartStore.landedCostData =
|
|
1357
|
-
(checkoutSessionWorkflow === null || checkoutSessionWorkflow === void 0 ? void 0 : checkoutSessionWorkflow.map(checkoutSession => {
|
|
1358
|
-
const foundLandedCost = landedCostCalculateWorkflow === null || landedCostCalculateWorkflow === void 0 ? void 0 : landedCostCalculateWorkflow.find(item => { var _a; return (item === null || item === void 0 ? void 0 : item.id) === ((_a = checkoutSession.landedCost) === null || _a === void 0 ? void 0 : _a.id); });
|
|
1359
|
-
if (!foundLandedCost) {
|
|
1360
|
-
return null;
|
|
1361
|
-
}
|
|
1362
|
-
return Object.assign(Object.assign({}, checkoutSession), { landedCost: foundLandedCost });
|
|
1363
|
-
}).filter(Boolean)) || [];
|
|
1364
|
-
cartStore.shippingData =
|
|
1365
|
-
(shipmentRatingCalculateWorkflow === null || shipmentRatingCalculateWorkflow === void 0 ? void 0 : shipmentRatingCalculateWorkflow.filter(Boolean)) || [];
|
|
1366
|
-
// apply new subtotal and total, this is mainly to show items in the presentment currency
|
|
1367
|
-
const firstLandedCostData = (_f = cartStore.landedCostData) === null || _f === void 0 ? void 0 : _f.find(Boolean);
|
|
1368
|
-
const subtotals = !!firstLandedCostData
|
|
1369
|
-
? firstLandedCostData.subtotals
|
|
1370
|
-
: null;
|
|
1371
|
-
// check and update cart items with restrictions
|
|
1372
|
-
cartStoreCheckItemRestrictions(itemCreateWorkflow);
|
|
1373
|
-
if (subtotals) {
|
|
1374
|
-
// prefetch landed cost will not update shipping and taxes since we haven't selected shipping method yet
|
|
1375
|
-
cartStoreApplySubtotals({
|
|
1376
|
-
exchangeRate: subtotals.exchangeRate,
|
|
1377
|
-
items: subtotals.items,
|
|
1378
|
-
landedCostTotal: 0,
|
|
1379
|
-
presentmentCurrencyCode: subtotals.presentmentCurrencyCode,
|
|
1380
|
-
shipping: 0,
|
|
1381
|
-
total: subtotals.items,
|
|
1382
|
-
});
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
catch (err) {
|
|
1386
|
-
// default to empty array if we fail to fetch landed cost, so we can show the error message
|
|
1387
|
-
cartStore.landedCostData = [];
|
|
1388
|
-
cartStore.shippingData = [];
|
|
1389
|
-
logError(err);
|
|
1390
|
-
}
|
|
1391
|
-
stripeStore.isFetchingLandedCost = false;
|
|
1392
|
-
}
|
|
1393
|
-
};
|
|
1394
|
-
const getStripeMessageBasedOnStatus = (status) => {
|
|
1395
|
-
let messages = [];
|
|
1396
|
-
let isError = true;
|
|
1397
|
-
// Inspect the PaymentIntent `status` to indicate the status of the payment
|
|
1398
|
-
// to your customer.
|
|
1399
|
-
//
|
|
1400
|
-
// Some payment methods will [immediately succeed or fail][0] upon
|
|
1401
|
-
// confirmation, while others will first enter a `processing` state.
|
|
1402
|
-
//
|
|
1403
|
-
// [0]: https://stripe.com/docs/payments/payment-methods#payment-notification
|
|
1404
|
-
switch (status) {
|
|
1405
|
-
case 'succeeded': {
|
|
1406
|
-
messages = [
|
|
1407
|
-
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.'),
|
|
1408
|
-
'',
|
|
1409
|
-
'',
|
|
1410
|
-
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."),
|
|
1411
|
-
];
|
|
1412
|
-
isError = false;
|
|
1413
|
-
break;
|
|
1414
|
-
}
|
|
1415
|
-
case 'requires_capture':
|
|
1416
|
-
case 'processing': {
|
|
1417
|
-
messages = [
|
|
1418
|
-
translate("Payment processing. We'll update you when payment is received."),
|
|
1419
|
-
];
|
|
1420
|
-
isError = false;
|
|
1421
|
-
break;
|
|
1422
|
-
}
|
|
1423
|
-
case 'requires_payment_method': {
|
|
1424
|
-
messages = [
|
|
1425
|
-
translate('Payment failed. Please try another payment method.'),
|
|
1426
|
-
];
|
|
1427
|
-
break;
|
|
1428
|
-
}
|
|
1429
|
-
default: {
|
|
1430
|
-
messages = [translate('Something went wrong.')];
|
|
1431
|
-
break;
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
return {
|
|
1435
|
-
isError,
|
|
1436
|
-
messages,
|
|
1437
|
-
};
|
|
1438
|
-
};
|
|
1439
|
-
const stripeStoreRetrievePayment = async ({ clientSecret: _clientSecret, storybookForceStatus, }) => {
|
|
1440
|
-
if (storybookForceStatus) {
|
|
1441
|
-
// return status right away if we are in storybook mode
|
|
1442
|
-
const { isError, messages } = getStripeMessageBasedOnStatus(storybookForceStatus);
|
|
1443
|
-
return { error: isError, messages };
|
|
1444
|
-
}
|
|
1445
|
-
const clientSecret = _clientSecret || stripeStore.clientSecret;
|
|
1446
|
-
if (!stripeStore.stripe || !clientSecret) {
|
|
1447
|
-
logError('Failed to retrieve payment intent. Stripe is not initialized');
|
|
1448
|
-
return { error: true, message: [translate('Something went wrong.')] };
|
|
1449
|
-
}
|
|
1450
|
-
const { paymentIntent } = await stripeStore.stripe.retrievePaymentIntent(clientSecret);
|
|
1451
|
-
const status = paymentIntent === null || paymentIntent === void 0 ? void 0 : paymentIntent.status;
|
|
1452
|
-
const { isError, messages } = getStripeMessageBasedOnStatus(status);
|
|
1453
|
-
return {
|
|
1454
|
-
error: isError,
|
|
1455
|
-
messages,
|
|
1456
|
-
paymentMethod: paymentIntent === null || paymentIntent === void 0 ? void 0 : paymentIntent.payment_method,
|
|
1457
|
-
};
|
|
1458
|
-
};
|
|
1459
|
-
const stripeStoreConfirmPayment = async () => {
|
|
1460
|
-
var _a, _b, _c, _d;
|
|
1461
|
-
const stripePaymentReady = !!((_a = stripeStore.stripePaymentEventData) === null || _a === void 0 ? void 0 : _a.complete);
|
|
1462
|
-
const stripeElements = stripeStore.stripeElements;
|
|
1463
|
-
const stripe = stripeStore.stripe;
|
|
1464
|
-
const stripeClientSecret = stripeStore.clientSecret;
|
|
1465
|
-
if (!((_b = cartStore.selectedLandedCost) === null || _b === void 0 ? void 0 : _b.landedCost.id)) {
|
|
1466
|
-
throw new Error('Attemped to confirm the payment when no landed cost is found in store');
|
|
1467
|
-
}
|
|
1468
|
-
if (stripe && stripeElements && stripePaymentReady && stripeClientSecret) {
|
|
1469
|
-
const { error } = await stripe.confirmPayment({
|
|
1470
|
-
confirmParams: {
|
|
1471
|
-
receipt_email: (_d = (_c = stripeStore.stripeLinkEventData) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.email,
|
|
1472
|
-
return_url: window.location.href,
|
|
1473
|
-
},
|
|
1474
|
-
elements: stripeElements,
|
|
1475
|
-
redirect: 'if_required',
|
|
1476
|
-
});
|
|
1477
|
-
if (error) {
|
|
1478
|
-
if (error.type === 'card_error' || error.type === 'validation_error') {
|
|
1479
|
-
throw new Error(error.message);
|
|
1480
|
-
}
|
|
1481
|
-
if (error.type === 'invalid_request_error') {
|
|
1482
|
-
if (error.code === 'payment_intent_unexpected_state') {
|
|
1483
|
-
// PaymentIntent was canceled or expired, or status is `require_capture`.
|
|
1484
|
-
// don't throw error here because we will reset the checkout session last step
|
|
1485
|
-
return;
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
throw new Error('An unexpected error occurred.');
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
};
|
|
1492
|
-
/**
|
|
1493
|
-
* Init checkout session
|
|
1494
|
-
* @returns {boolean} whether or not the checkout session is successfully created
|
|
1495
|
-
*/
|
|
1496
|
-
const stripeStoreInitCheckoutSession = async () => {
|
|
1497
|
-
var _a;
|
|
1498
|
-
const total = cartStore.items.reduce((amount, item) => amount + item.amount * item.quantity, 0);
|
|
1499
|
-
if (!total || !localizationStore.targetCurrency) {
|
|
1500
|
-
logError('Fail to create checkout session - invalid total or currency');
|
|
1501
|
-
return false;
|
|
1502
|
-
}
|
|
1503
|
-
stripeStore.isFetchingSession = true;
|
|
1504
|
-
const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/create-checkout-session`, {
|
|
1505
|
-
body: {
|
|
1506
|
-
currency: ((_a = cartStore.items.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode) || '',
|
|
1507
|
-
itemsAmount: total,
|
|
1508
|
-
metadata: [
|
|
1509
|
-
{ key: 'language', value: localizationStore.selectedLocale },
|
|
1510
|
-
],
|
|
1511
|
-
presentmentCountryCode: localizationStore.selectedCountryCode || null,
|
|
1512
|
-
},
|
|
1513
|
-
method: 'POST',
|
|
1514
|
-
});
|
|
1515
|
-
stripeStore.isFetchingSession = false;
|
|
1516
|
-
if (errors.length || !json) {
|
|
1517
|
-
logError('Error occurs when creating checkout session', JSON.stringify(errors, null, 2));
|
|
1518
|
-
return false;
|
|
1519
|
-
}
|
|
1520
|
-
const result = json.checkoutSessionCreate;
|
|
1521
|
-
stripeStore.clientSecret = result.clientSecret;
|
|
1522
|
-
// update cart store with updated informations
|
|
1523
|
-
cartStore.checkoutSessionId = result.id;
|
|
1524
|
-
cartStoreApplySubtotals(Object.assign(Object.assign({}, result.subtotals), { landedCostTotal: 0, shipping: 0, total: result.subtotals.items }));
|
|
1525
|
-
log('Exchange rate updated for cart items (checkout session create)', 'info', cartStore.exchangeRate);
|
|
1526
|
-
log('done-init-checkout-session');
|
|
1527
|
-
return true;
|
|
1528
|
-
};
|
|
1529
|
-
/**
|
|
1530
|
-
* Update checkout session. Use for updating amount with landed cost id, or update session when cart items change
|
|
1531
|
-
*/
|
|
1532
|
-
const stripeStoreUpdateCheckoutSession = async ({ currency, id, itemsAmount, landedCostId, presentmentCountryCode, }) => {
|
|
1533
|
-
// No need to set loading state here because this function will be called under the hood to update
|
|
1534
|
-
// landed cost id for the section.
|
|
1535
|
-
const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/update-checkout-session`, {
|
|
1536
|
-
body: {
|
|
1537
|
-
currency,
|
|
1538
|
-
id,
|
|
1539
|
-
itemsAmount,
|
|
1540
|
-
landedCostId,
|
|
1541
|
-
presentmentCountryCode,
|
|
1542
|
-
},
|
|
1543
|
-
method: 'POST',
|
|
1544
|
-
});
|
|
1545
|
-
if (errors.length || !json) {
|
|
1546
|
-
logError('Error occurs when updating checkout session', JSON.stringify(errors, null, 2));
|
|
1547
|
-
return { errors, json };
|
|
1548
|
-
}
|
|
1549
|
-
return { errors: [], json };
|
|
1550
|
-
};
|
|
1551
|
-
/**
|
|
1552
|
-
* This function builds a translated address object from the current address and the translated address result.
|
|
1553
|
-
* 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.
|
|
1554
|
-
* 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.
|
|
1555
|
-
*
|
|
1556
|
-
* @param {Object} params - The parameters for the function.
|
|
1557
|
-
* @param {Address} params.currentAddress - The current address information.
|
|
1558
|
-
* @param {Address} params.translatedAddressResult - The translated address result.
|
|
1559
|
-
*
|
|
1560
|
-
* @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.
|
|
1561
|
-
*/
|
|
1562
|
-
const buildTranslatedAddress = ({ currentAddress, translatedAddressResult, }) => {
|
|
1563
|
-
const translatedAddress = {};
|
|
1564
|
-
if (!translatedAddressResult) {
|
|
1565
|
-
return translatedAddress;
|
|
1566
|
-
}
|
|
1567
|
-
const { city, line1, line2, name, postal_code, state } = translatedAddressResult;
|
|
1568
|
-
// If we have translated address, add it to the translated address object
|
|
1569
|
-
if (currentAddress.city && city) {
|
|
1570
|
-
translatedAddress.city = {
|
|
1571
|
-
[currentAddress.city]: city,
|
|
1572
|
-
};
|
|
1573
|
-
}
|
|
1574
|
-
if (currentAddress.line1 && line1) {
|
|
1575
|
-
translatedAddress.line1 = {
|
|
1576
|
-
[currentAddress.line1]: line1,
|
|
1577
|
-
};
|
|
1578
|
-
}
|
|
1579
|
-
if (currentAddress.line2 && line2) {
|
|
1580
|
-
translatedAddress.line2 = {
|
|
1581
|
-
[currentAddress.line2]: line2,
|
|
1582
|
-
};
|
|
1583
|
-
}
|
|
1584
|
-
if (currentAddress.postal_code && postal_code) {
|
|
1585
|
-
translatedAddress.postal_code = {
|
|
1586
|
-
[currentAddress.postal_code]: postal_code,
|
|
1587
|
-
};
|
|
1588
|
-
}
|
|
1589
|
-
if (currentAddress.state && state) {
|
|
1590
|
-
translatedAddress.state = {
|
|
1591
|
-
[currentAddress.state]: state,
|
|
1592
|
-
};
|
|
1593
|
-
}
|
|
1594
|
-
if (currentAddress.name && name) {
|
|
1595
|
-
translatedAddress.name = {
|
|
1596
|
-
[currentAddress.name]: name,
|
|
1597
|
-
};
|
|
1598
|
-
}
|
|
1599
|
-
return translatedAddress;
|
|
1600
|
-
};
|
|
1601
|
-
/**
|
|
1602
|
-
* This function translates an address to Latin characters using the Zonos API.
|
|
1603
|
-
* 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.
|
|
1604
|
-
* If the address is not outdated, it returns without making the API call.
|
|
1605
|
-
* 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.
|
|
1606
|
-
* 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.
|
|
1607
|
-
*
|
|
1608
|
-
* @param {Object} params - The parameters for the function.
|
|
1609
|
-
* @param {ReturnType<typeof containsNonLatinChars> | null} params.addressInvalidCharactersList - The list of address fields that contain invalid characters.
|
|
1610
|
-
* @param {ReturnType<typeof containsNonLatinChars> | null} params.billingAddressInvalidCharactersList - The list of billing address fields that contain invalid characters.
|
|
1611
|
-
*/
|
|
1612
|
-
const stripeStoreTranslateAddressToLatin = async ({ addressInvalidCharactersList, billingAddressInvalidCharactersList, }) => {
|
|
1613
|
-
var _a, _b, _c, _d;
|
|
1614
|
-
const requestBody = buildTranslateRequestBody({
|
|
1615
|
-
addressInvalidCharactersList,
|
|
1616
|
-
billingAddressInvalidCharactersList,
|
|
1617
|
-
stripeAddressEventData: stripeStore.stripeAddressEventData,
|
|
1618
|
-
stripeBillingAddressEventData: stripeStore.stripeBillingAddressEventData,
|
|
1619
|
-
stripeShippingSameAsBilling: stripeStore.stripeShippingSameAsBilling,
|
|
1620
|
-
});
|
|
1621
|
-
if (!requestBody) {
|
|
1622
|
-
// reset translated address if we don't have any address to translate
|
|
1623
|
-
stripeStore.translatedAddress = {
|
|
1624
|
-
address: {},
|
|
1625
|
-
billingAddress: {},
|
|
1626
|
-
};
|
|
1627
|
-
return;
|
|
1628
|
-
}
|
|
1629
|
-
// only translate address if the address is out of date
|
|
1630
|
-
const isAddressOutdated = checkIsAddressOutdatedForValidation();
|
|
1631
|
-
if (!isAddressOutdated) {
|
|
1632
|
-
return;
|
|
1633
|
-
}
|
|
1634
|
-
const routeUrl = "https://v1.route.js.zonos.com";
|
|
1635
|
-
const { errors, json } = await handleFetch(`${routeUrl}/api/zonos-elements/validate-address`, {
|
|
1636
|
-
body: requestBody,
|
|
1637
|
-
method: 'POST',
|
|
1638
|
-
});
|
|
1639
|
-
if (errors.length || !json) {
|
|
1640
|
-
logError('Error occurs when translating address to latin', JSON.stringify(errors, null, 2));
|
|
1641
|
-
// reset translated address if we fail to translate and let user manually fix it
|
|
1642
|
-
stripeStore.translatedAddress = {
|
|
1643
|
-
address: {},
|
|
1644
|
-
billingAddress: {},
|
|
1645
|
-
};
|
|
1646
|
-
return;
|
|
1647
|
-
}
|
|
1648
|
-
// Set current address to the store so we can compare it later to determine if we need to re-translate the address
|
|
1649
|
-
stripeStore.stripeAddressUsedWhenValidatingAddress =
|
|
1650
|
-
stripeStore.stripeAddressEventData;
|
|
1651
|
-
stripeStore.stripeBillingAddressUsedWhenValidatingAddress =
|
|
1652
|
-
stripeStore.stripeBillingAddressEventData;
|
|
1653
|
-
const address = (_a = stripeStore.stripeAddressEventData) === null || _a === void 0 ? void 0 : _a.value.address;
|
|
1654
|
-
const billingAddress = (_b = stripeStore.stripeBillingAddressEventData) === null || _b === void 0 ? void 0 : _b.value.address;
|
|
1655
|
-
// Set the translated address to the store so we can populate it to the address element for user to update
|
|
1656
|
-
stripeStore.translatedAddress = {
|
|
1657
|
-
address: address
|
|
1658
|
-
? buildTranslatedAddress({
|
|
1659
|
-
currentAddress: Object.assign(Object.assign({}, address), { name: (_c = stripeStore.stripeAddressEventData) === null || _c === void 0 ? void 0 : _c.value.name }),
|
|
1660
|
-
translatedAddressResult: json.address || null,
|
|
1661
|
-
})
|
|
1662
|
-
: {},
|
|
1663
|
-
billingAddress: !stripeStore.stripeShippingSameAsBilling
|
|
1664
|
-
? buildTranslatedAddress({
|
|
1665
|
-
currentAddress: Object.assign(Object.assign({}, billingAddress), { name: (_d = stripeStore.stripeBillingAddressEventData) === null || _d === void 0 ? void 0 : _d.value.name }) || {},
|
|
1666
|
-
translatedAddressResult: json.billingAddress || null,
|
|
1667
|
-
})
|
|
1668
|
-
: {},
|
|
1669
|
-
};
|
|
1670
|
-
};
|
|
1671
|
-
onChange('clientSecret', clientSecret => {
|
|
1672
|
-
// update stripe elements when client secret changes
|
|
1673
|
-
if (clientSecret && stripeStore.stripe) {
|
|
1674
|
-
sessionStorage.setItem('zonos--client-secret', clientSecret);
|
|
1675
|
-
}
|
|
1676
|
-
if (!clientSecret) {
|
|
1677
|
-
sessionStorage.removeItem('zonos--client-secret');
|
|
1678
|
-
}
|
|
1679
|
-
});
|
|
1680
|
-
|
|
1681
|
-
export { cartStoreGetShippingTransitInfo as A, isValidSelector as B, initLocalizationStore as C, getZCountryUrlParam as D, setZCountryUrlParam as E, currencyDisplay as F, currencyConvertAndFormat as G, currencyConvert as H, currencyFormat as I, localizationStore as a, cartStoreHasOneEligibleItem as b, cartStore as c, log as d, stripeStoreGetDomesticShippingSession as e, localizationStoreUpdateSelectedCountryCode as f, stripeStoreCleanupDomesticShippingSession as g, stripeStoreSaveDomesticShippingSession as h, initStripeElements as i, cartStoreUpdateItems as j, cartStoreReset as k, logError as l, cartStoreResetTabItems as m, stripeStoreInitCheckoutSession as n, cartStoreUpdateToErrorState as o, stripeStorePrefetchLandedCost as p, cartStoreNextStep as q, stripeStoreConfirmPayment as r, stripeStore as s, stripeStoreReset as t, localizationStoreOnUpdate as u, handleFetch as v, stripeStoreRetrievePayment as w, stripeStoreTranslateAddressToLatin as x, localizationStoreUpdateSelectedLocale as y, cartStoreUpdateSelectedShippingOption as z };
|