@zonos/elements 1.3.6 → 1.3.7-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{localization-2c9f5765.js → cart-89d9fff4.js} +863 -89
- package/dist/cjs/formatStringWithLinks-52341fc7.js +17 -0
- package/dist/cjs/{getBorderRadius-b252096d.js → getBorderRadius-d8f18958.js} +1 -1
- package/dist/cjs/{isDarkColor-168002d6.js → isDarkColor-57860b44.js} +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/submitGtag-24740560.js +55 -0
- package/dist/cjs/zonos-address_4.cjs.entry.js +36 -18
- package/dist/cjs/zonos-badge_2.cjs.entry.js +6 -6
- package/dist/cjs/zonos-banner.cjs.entry.js +1 -1
- package/dist/cjs/zonos-button_3.cjs.entry.js +8 -8
- package/dist/cjs/zonos-card_2.cjs.entry.js +10 -8
- package/dist/cjs/zonos-cart-items_9.cjs.entry.js +66 -56
- package/dist/cjs/zonos-checkout.cjs.entry.js +170 -34
- package/dist/cjs/zonos-component.cjs.entry.js +1 -1
- package/dist/cjs/zonos-controller.cjs.entry.js +51 -32
- package/dist/cjs/zonos-country-flag.cjs.entry.js +5 -3
- package/dist/cjs/zonos-country-select_3.cjs.entry.js +21 -12
- package/dist/cjs/zonos-elements.cjs.js +1 -1
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +23 -19
- package/dist/cjs/zonos-hello.cjs.entry.js +51 -34
- package/dist/cjs/zonos-link.cjs.entry.js +24 -0
- package/dist/cjs/zonos-logo.cjs.entry.js +3 -3
- package/dist/cjs/zonos-notification.cjs.entry.js +1 -1
- package/dist/cjs/zonos-payment.cjs.entry.js +5 -6
- package/dist/cjs/zonos-select-dialog-header_2.cjs.entry.js +5 -5
- package/dist/cjs/zonos-shipping-rich-radio.cjs.entry.js +3 -3
- package/dist/cjs/zonos-text.cjs.entry.js +1 -1
- package/dist/cjs/{zonosStore-5d94dabb.js → zonosStore-138c5555.js} +9 -7
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/checkout/zonos-checkout/zonos-cart-subtotal/zonos-cart-subtotal.js +1 -6
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js +27 -13
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-payment/zonos-checkout-payment.css +3 -0
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +39 -18
- package/dist/collection/components/checkout/zonos-checkout/zonos-customer-info/zonos-customer-info.css +5 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-customer-info/zonos-customer-info.js +2 -0
- package/dist/collection/components/checkout/zonos-checkout/zonos-review/zonos-review.js +1 -6
- package/dist/collection/components/checkout/zonos-checkout/zonos-shipping/zonos-shipping.css +3 -0
- package/dist/collection/components/checkout/zonos-checkout/zonos-shipping/zonos-shipping.js +5 -0
- package/dist/collection/components/common/component-template/zonos-link/zonos-link.css +54 -0
- package/dist/collection/components/common/component-template/zonos-link/zonos-link.js +97 -0
- package/dist/collection/components/common/zonos-badge/zonos-badge.js +3 -3
- package/dist/collection/components/common/zonos-button/zonos-button.css +2 -0
- package/dist/collection/components/common/zonos-button/zonos-button.js +4 -4
- package/dist/collection/components/common/zonos-card/zonos-card.js +2 -2
- package/dist/collection/components/common/zonos-checkbox/zonos-checkbox.js +3 -3
- package/dist/collection/components/common/zonos-collapse/zonos-collapse.js +26 -6
- package/dist/collection/components/common/zonos-country-select/zonos-country-select.js +8 -2
- package/dist/collection/components/common/zonos-custom-message/zonos-custom-message.js +4 -2
- package/dist/collection/components/common/zonos-dialog/zonos-dialog.js +3 -3
- package/dist/collection/components/common/zonos-language-select/zonos-language-select.js +2 -2
- 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-shipping-rich-radio/zonos-shipping-rich-radio.js +1 -1
- 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/zonos-hello.js +50 -11
- 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 +5 -3
- package/dist/collection/components/main/zonos-controller.js +1 -1
- package/dist/collection/components/store/checkout/cart.js +2 -2
- package/dist/collection/components/store/checkout/stripe.js +29 -4
- package/dist/collection/components/store/hello/localization.js +34 -7
- package/dist/collection/components/store/zonosStore.js +9 -7
- package/dist/collection/components/stripe/zonos-address/zonos-address.js +1 -1
- 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/components/utils/api/trackConversionEvent.js +22 -0
- package/dist/collection/components/utils/checkout/isShippableCountry.js +15 -0
- package/dist/collection/components/utils/checkout/watchBigcommerceDomesticCheckout.js +111 -0
- package/dist/collection/components/utils/formatStringWithLinks.js +13 -0
- package/dist/collection/components/utils/handleFetch.js +1 -1
- package/dist/collection/components/utils/hello/currencyConversion/defaultCurrencyConverter.js +25 -28
- package/dist/collection/components/utils/hello/currencyConversion/getCurrencyElements.js +2 -1
- package/dist/collection/components/utils/hello/currencyConversion/getInitialElementAmount.js +8 -6
- package/dist/collection/components/utils/hello/initHello.js +23 -3
- package/dist/collection/components/utils/logging/log.js +20 -9
- package/dist/collection/components/utils/logging/logError.js +2 -1
- package/dist/collection/components/utils/logging/sendErrorLog.js +12 -0
- package/dist/collection/scripts/checkIfLoadVersionDomain.js +35 -0
- package/dist/collection/scripts/zonosBase.js +21 -31
- package/dist/collection/styles/stripe/addressRuleStyle.js +4 -0
- package/dist/collection/types/generated/graphql.customer.types.js +7 -4
- package/dist/collection/types/generated/graphql.frontend.types.js +3 -0
- package/dist/components/stripe.js +4097 -7
- package/dist/components/submitGtag.js +1 -1
- package/dist/components/trackConversionEvent.js +24 -0
- package/dist/components/zonos-address2.js +2 -3
- package/dist/components/zonos-badge2.js +3 -3
- package/dist/components/zonos-button2.js +5 -5
- package/dist/components/zonos-card2.js +2 -2
- package/dist/components/zonos-cart-subtotal2.js +2 -8
- package/dist/components/zonos-checkbox2.js +3 -3
- package/dist/components/zonos-checkout-finish2.js +44 -16
- package/dist/components/zonos-checkout-footer2.js +1 -1
- package/dist/components/zonos-checkout-payment2.js +2 -3
- package/dist/components/zonos-checkout.js +157 -19
- package/dist/components/zonos-collapse2.js +26 -6
- package/dist/components/zonos-component.js +1 -1
- package/dist/components/zonos-controller.js +25 -6
- package/dist/components/zonos-country-flag2.js +1 -1
- package/dist/components/zonos-country-select2.js +9 -3
- package/dist/components/zonos-custom-message2.js +18 -3
- package/dist/components/zonos-customer-info2.js +4 -3
- package/dist/components/zonos-dialog2.js +3 -3
- package/dist/components/zonos-hello-dialog-footer2.js +3 -3
- package/dist/components/zonos-hello-dialog2.js +6 -5
- package/dist/components/zonos-hello.js +23 -7
- package/dist/components/zonos-language-select2.js +3 -3
- package/dist/components/zonos-link-authentication2.js +1 -1
- package/dist/components/zonos-link.d.ts +11 -0
- package/dist/components/zonos-link.js +43 -0
- package/dist/components/zonos-logo.js +2 -2
- package/dist/components/zonos-payment2.js +1 -1
- package/dist/components/zonos-review2.js +2 -8
- package/dist/components/zonos-select-dialog-header2.js +2 -2
- package/dist/components/zonos-shipping-rich-radio2.js +1 -1
- package/dist/components/zonos-shipping2.js +7 -3
- package/dist/components/zonos-tooltip2.js +2 -2
- package/dist/components/zonos-v-stack2.js +2 -2
- package/dist/components/zonosStore.js +9 -7
- package/dist/esm/{localization-d8f6453b.js → cart-1bbb7662.js} +846 -90
- package/dist/esm/formatStringWithLinks-9e819405.js +15 -0
- package/dist/esm/{getBorderRadius-e9736f7e.js → getBorderRadius-19787feb.js} +1 -1
- package/dist/esm/{isDarkColor-e982fa09.js → isDarkColor-2344e7a5.js} +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/submitGtag-d3d11f1a.js +51 -0
- package/dist/esm/zonos-address_4.entry.js +33 -15
- package/dist/esm/zonos-badge_2.entry.js +6 -6
- package/dist/esm/zonos-banner.entry.js +1 -1
- package/dist/esm/zonos-button_3.entry.js +8 -8
- package/dist/esm/zonos-card_2.entry.js +8 -6
- package/dist/esm/zonos-cart-items_9.entry.js +47 -37
- package/dist/esm/zonos-checkout.entry.js +158 -22
- package/dist/esm/zonos-component.entry.js +1 -1
- package/dist/esm/zonos-controller.entry.js +28 -9
- package/dist/esm/zonos-country-flag.entry.js +4 -2
- package/dist/esm/zonos-country-select_3.entry.js +19 -10
- package/dist/esm/zonos-elements.js +1 -1
- package/dist/esm/zonos-hello-dialog.entry.js +9 -5
- package/dist/esm/zonos-hello.entry.js +24 -7
- package/dist/esm/zonos-link.entry.js +20 -0
- package/dist/esm/zonos-logo.entry.js +3 -3
- package/dist/esm/zonos-notification.entry.js +1 -1
- package/dist/esm/zonos-payment.entry.js +5 -6
- package/dist/esm/zonos-select-dialog-header_2.entry.js +5 -5
- package/dist/esm/zonos-shipping-rich-radio.entry.js +3 -3
- package/dist/esm/zonos-text.entry.js +1 -1
- package/dist/esm/{zonosStore-e6c7be3a.js → zonosStore-00bce01b.js} +9 -7
- package/dist/esm-es5/cart-1bbb7662.js +1 -0
- package/dist/esm-es5/formatStringWithLinks-9e819405.js +1 -0
- package/dist/esm-es5/{getBorderRadius-e9736f7e.js → getBorderRadius-19787feb.js} +1 -1
- package/dist/esm-es5/{isDarkColor-e982fa09.js → isDarkColor-2344e7a5.js} +1 -1
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/submitGtag-d3d11f1a.js +1 -0
- package/dist/esm-es5/zonos-address_4.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_9.entry.js +1 -1
- 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-link.entry.js +1 -0
- 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-e6c7be3a.js → zonosStore-00bce01b.js} +1 -1
- package/dist/scripts/checkIfLoadVersionDomain.js +1 -0
- package/dist/scripts/loadStripe.js +1 -1
- package/dist/scripts/loadZonos.js +1 -1
- package/dist/scripts/stripe.js +1 -1
- package/dist/scripts/zonos.js +1 -1
- package/dist/scripts/zonosBase.js +1 -1
- package/dist/types/components/checkout/zonos-checkout/zonos-checkout.d.ts +1 -1
- package/dist/types/components/common/component-template/zonos-link/zonos-link.d.ts +19 -0
- package/dist/types/components/common/zonos-collapse/zonos-collapse.d.ts +1 -0
- package/dist/types/components/common/zonos-country-select/zonos-country-select.d.ts +2 -0
- package/dist/types/components/hello/zonos-hello/zonos-hello.d.ts +9 -3
- package/dist/types/components/store/checkout/cart.d.ts +6 -3
- package/dist/types/components/store/checkout/stripe.d.ts +26 -1
- package/dist/types/components/store/hello/localization.d.ts +1 -1
- package/dist/types/components/store/zonosStore.d.ts +2 -1
- package/dist/types/components/utils/api/getLocaleMessages.d.ts +1 -1
- package/dist/types/components/utils/api/trackConversionEvent.d.ts +3 -0
- package/dist/types/components/utils/checkout/isShippableCountry.d.ts +1 -0
- package/dist/types/components/utils/checkout/watchBigcommerceDomesticCheckout.d.ts +20 -0
- package/dist/types/components/utils/formatStringWithLinks.d.ts +1 -0
- package/dist/types/components/utils/hello/currencyConversion/getCurrencyElements.d.ts +1 -1
- package/dist/types/components/utils/hello/currencyConversion/getLanguageCode.d.ts +1 -1
- package/dist/types/components/utils/logging/log.d.ts +1 -1
- package/dist/types/components/utils/logging/sendErrorLog.d.ts +7 -0
- package/dist/types/components.d.ts +53 -3
- package/dist/types/scripts/checkIfLoadVersionDomain.d.ts +13 -0
- package/dist/types/scripts/zonosBase.d.ts +2 -0
- package/dist/types/types/ICountryJson.d.ts +2 -1
- package/dist/types/types/checkout/CheckoutConfig.d.ts +1 -1
- package/dist/types/types/generated/graphql.customer.types.d.ts +23 -53
- package/dist/types/types/generated/graphql.customer.types.ts +42 -62
- package/dist/types/types/generated/graphql.frontend.types.d.ts +9 -1
- package/dist/types/types/generated/graphql.frontend.types.ts +19 -1
- package/dist/zonos-elements/p-0318632a.entry.js +1 -0
- package/dist/zonos-elements/p-066c5893.system.js +1 -1
- package/dist/zonos-elements/p-07966463.entry.js +1 -0
- package/dist/zonos-elements/p-0c0aa552.js +1 -0
- package/dist/zonos-elements/p-127b480c.entry.js +1 -0
- package/dist/zonos-elements/p-135ab559.system.entry.js +1 -0
- package/dist/zonos-elements/{p-b81a0577.system.entry.js → p-143dc0d9.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-32bca9c8.system.entry.js → p-14d27ce1.system.entry.js} +1 -1
- package/dist/zonos-elements/p-15a80c4a.entry.js +1 -0
- package/dist/zonos-elements/p-17e87be1.entry.js +1 -0
- package/dist/zonos-elements/{p-0c7480a5.entry.js → p-1e0dd491.entry.js} +1 -1
- package/dist/zonos-elements/{p-a33745e9.entry.js → p-279d1c5f.entry.js} +1 -1
- package/dist/zonos-elements/p-2d6557ee.system.js +1 -0
- package/dist/zonos-elements/p-314be538.system.entry.js +1 -0
- package/dist/zonos-elements/{p-dd7729fd.system.entry.js → p-328b7f6f.system.entry.js} +1 -1
- package/dist/zonos-elements/p-354603b3.system.entry.js +1 -0
- package/dist/zonos-elements/{p-50287643.system.js → p-49f6a985.system.js} +1 -1
- package/dist/zonos-elements/p-57b65321.system.entry.js +1 -0
- package/dist/zonos-elements/p-58c1ddef.system.js +1 -0
- package/dist/zonos-elements/{p-06652d87.system.entry.js → p-58e2f6a1.system.entry.js} +1 -1
- package/dist/zonos-elements/p-5ee03db0.system.entry.js +1 -0
- package/dist/zonos-elements/{p-5a113c3d.system.entry.js → p-61e5cf29.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-49a764e9.system.entry.js → p-799d8a17.system.entry.js} +1 -1
- package/dist/zonos-elements/p-7a32526c.entry.js +1 -0
- package/dist/zonos-elements/p-7b87b82f.js +1 -0
- package/dist/zonos-elements/{p-9cbbf261.system.entry.js → p-7c45ce37.system.entry.js} +1 -1
- package/dist/zonos-elements/p-84f4f00f.entry.js +1 -0
- package/dist/zonos-elements/{p-e8a9bc56.entry.js → p-857cfe35.entry.js} +1 -1
- package/dist/zonos-elements/p-87e9c42f.entry.js +1 -0
- package/dist/zonos-elements/{p-e99d79d9.system.js → p-91797d4e.system.js} +1 -1
- package/dist/zonos-elements/{p-17550a10.js → p-95e0fc06.js} +1 -1
- package/dist/zonos-elements/{p-7a6144b1.entry.js → p-a3cc0f84.entry.js} +1 -1
- package/dist/zonos-elements/p-a5f12396.entry.js +1 -0
- package/dist/zonos-elements/p-a87561b8.js +1 -0
- package/dist/zonos-elements/{p-ba43275e.entry.js → p-ac0a7b8f.entry.js} +1 -1
- package/dist/zonos-elements/p-ae82a9ae.js +1 -0
- package/dist/zonos-elements/p-b0462325.system.entry.js +1 -0
- package/dist/zonos-elements/p-b2c0ec71.system.entry.js +1 -0
- package/dist/zonos-elements/{p-fcc4f140.system.js → p-b4725505.system.js} +1 -1
- package/dist/zonos-elements/p-bef54fb1.entry.js +1 -0
- package/dist/zonos-elements/p-c0d431f6.system.entry.js +1 -0
- package/dist/zonos-elements/p-d054788b.system.js +1 -0
- package/dist/zonos-elements/p-d407c93a.system.entry.js +1 -0
- package/dist/zonos-elements/p-e55dd932.js +1 -0
- package/dist/zonos-elements/p-ec37439e.entry.js +1 -0
- package/dist/zonos-elements/p-edace42b.entry.js +1 -0
- package/dist/zonos-elements/p-f478c814.system.entry.js +1 -0
- package/dist/zonos-elements/{p-7dd8e8ba.system.entry.js → p-f6eaef7b.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-bd6a2095.entry.js → p-f7c36fcc.entry.js} +1 -1
- package/dist/zonos-elements/p-f862b97f.system.entry.js +1 -0
- package/dist/zonos-elements/p-fd642725.entry.js +1 -0
- package/dist/zonos-elements/p-fdb72530.system.entry.js +1 -0
- package/dist/zonos-elements/{p-a4de3fb2.entry.js → p-ff64ddc5.entry.js} +1 -1
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/cart-b8bbf22d.js +0 -698
- package/dist/cjs/submitGtag-792fe45d.js +0 -21
- package/dist/collection/scripts/extractZonosQaUrl.js +0 -26
- package/dist/components/localization.js +0 -4016
- package/dist/esm/cart-bc3bb22e.js +0 -682
- package/dist/esm/submitGtag-bebe2cb0.js +0 -19
- package/dist/esm-es5/cart-bc3bb22e.js +0 -1
- package/dist/esm-es5/localization-d8f6453b.js +0 -1
- package/dist/esm-es5/submitGtag-bebe2cb0.js +0 -1
- package/dist/types/scripts/extractZonosQaUrl.d.ts +0 -11
- package/dist/zonos-elements/p-00d63df1.system.entry.js +0 -1
- package/dist/zonos-elements/p-04f63cea.entry.js +0 -1
- package/dist/zonos-elements/p-16b74c31.system.js +0 -1
- package/dist/zonos-elements/p-1d16a6fb.js +0 -1
- package/dist/zonos-elements/p-1ea68e3b.entry.js +0 -1
- package/dist/zonos-elements/p-1ed530cc.entry.js +0 -1
- package/dist/zonos-elements/p-289c8b1a.system.entry.js +0 -1
- package/dist/zonos-elements/p-2a00c270.system.entry.js +0 -1
- package/dist/zonos-elements/p-37f53a79.entry.js +0 -1
- package/dist/zonos-elements/p-394cf1cf.js +0 -1
- package/dist/zonos-elements/p-3ef27745.js +0 -1
- package/dist/zonos-elements/p-458fd100.system.entry.js +0 -1
- package/dist/zonos-elements/p-47fac33f.js +0 -1
- package/dist/zonos-elements/p-4fafb2a5.system.entry.js +0 -1
- package/dist/zonos-elements/p-4fb71a93.js +0 -1
- package/dist/zonos-elements/p-5276c61b.system.entry.js +0 -1
- package/dist/zonos-elements/p-6308b347.entry.js +0 -1
- package/dist/zonos-elements/p-63d1b1fe.entry.js +0 -1
- package/dist/zonos-elements/p-7347ee7c.system.entry.js +0 -1
- package/dist/zonos-elements/p-8c26a080.system.js +0 -1
- package/dist/zonos-elements/p-96aabe02.entry.js +0 -1
- package/dist/zonos-elements/p-a682fd38.system.entry.js +0 -1
- package/dist/zonos-elements/p-ba1a111a.system.entry.js +0 -1
- package/dist/zonos-elements/p-c4321084.system.entry.js +0 -1
- package/dist/zonos-elements/p-cdf114a2.entry.js +0 -1
- package/dist/zonos-elements/p-d5ae3cbb.system.entry.js +0 -1
- package/dist/zonos-elements/p-d5d7c8f5.entry.js +0 -1
- package/dist/zonos-elements/p-de339fb6.entry.js +0 -1
- package/dist/zonos-elements/p-ec25f180.entry.js +0 -1
- package/dist/zonos-elements/p-f49dfd06.system.js +0 -1
- package/dist/zonos-elements/p-f6f5f644.entry.js +0 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const zonosStore = require('./zonosStore-
|
|
3
|
+
const zonosStore = require('./zonosStore-138c5555.js');
|
|
4
|
+
const isDarkColor = require('./isDarkColor-57860b44.js');
|
|
5
|
+
const getBorderRadius = require('./getBorderRadius-d8f18958.js');
|
|
4
6
|
|
|
5
7
|
const stringsArabic = {
|
|
6
8
|
'Above de minimis threshold for': {
|
|
@@ -3546,7 +3548,7 @@ const handleFetch = async (url, _opts) => {
|
|
|
3546
3548
|
const modifiedUrl = new URL(url);
|
|
3547
3549
|
modifiedUrl.searchParams.set('zToken', encodeString(window.location.hostname));
|
|
3548
3550
|
// headers content type
|
|
3549
|
-
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 }, opts.headers);
|
|
3551
|
+
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);
|
|
3550
3552
|
const options = Object.assign(Object.assign({}, opts), { body: method === 'GET' ? undefined : body, headers,
|
|
3551
3553
|
method });
|
|
3552
3554
|
return handleRequest(modifiedUrl.toString(), options);
|
|
@@ -3567,9 +3569,65 @@ const getCountries = async () => {
|
|
|
3567
3569
|
}
|
|
3568
3570
|
};
|
|
3569
3571
|
|
|
3572
|
+
const log = (message, type, ...additionalInfo) => {
|
|
3573
|
+
var _a, _b;
|
|
3574
|
+
const isDebug = !((_a = window.Zonos) === null || _a === void 0 ? void 0 : _a.debug) ||
|
|
3575
|
+
!window.location.search.match(/\?.*(&*)zonosDebug=1/);
|
|
3576
|
+
// if debug is false, do not log
|
|
3577
|
+
if (!isDebug) {
|
|
3578
|
+
// log errors to the console if the type is error
|
|
3579
|
+
if (type === 'error') {
|
|
3580
|
+
// eslint-disable-next-line no-console
|
|
3581
|
+
console.error(message, ...additionalInfo);
|
|
3582
|
+
}
|
|
3583
|
+
return;
|
|
3584
|
+
}
|
|
3585
|
+
let loggingIframe = document.querySelector('iframe#zonos---debug-logging-iframe');
|
|
3586
|
+
if (!loggingIframe) {
|
|
3587
|
+
// add a hidden iframe
|
|
3588
|
+
loggingIframe = document.createElement('iframe');
|
|
3589
|
+
loggingIframe.id = 'zonos---debug-logging-iframe';
|
|
3590
|
+
loggingIframe.style.display = 'none';
|
|
3591
|
+
loggingIframe.style.opacity = '0';
|
|
3592
|
+
loggingIframe.style.position = 'absolute';
|
|
3593
|
+
loggingIframe.style.top = '-9999px';
|
|
3594
|
+
loggingIframe.style.left = '-9999px';
|
|
3595
|
+
loggingIframe.style.width = '1px';
|
|
3596
|
+
loggingIframe.style.height = '1px';
|
|
3597
|
+
loggingIframe.style.border = 'none';
|
|
3598
|
+
loggingIframe.style.overflow = 'hidden';
|
|
3599
|
+
loggingIframe.style.visibility = 'hidden';
|
|
3600
|
+
document.body.appendChild(loggingIframe);
|
|
3601
|
+
}
|
|
3602
|
+
// use the logging iframe's console to log just in case the console is disabled (overriden) by the site owner
|
|
3603
|
+
const zConsole = ((_b = loggingIframe.contentWindow) === null || _b === void 0 ? void 0 : _b.window.console) || window.console;
|
|
3604
|
+
switch (type) {
|
|
3605
|
+
case 'warn':
|
|
3606
|
+
// eslint-disable-next-line no-console
|
|
3607
|
+
zConsole.warn(message, ...additionalInfo);
|
|
3608
|
+
break;
|
|
3609
|
+
case 'info':
|
|
3610
|
+
// eslint-disable-next-line no-console
|
|
3611
|
+
zConsole.info(message, ...additionalInfo);
|
|
3612
|
+
break;
|
|
3613
|
+
case 'error':
|
|
3614
|
+
// eslint-disable-next-line no-console
|
|
3615
|
+
zConsole.error(message, ...additionalInfo);
|
|
3616
|
+
break;
|
|
3617
|
+
default:
|
|
3618
|
+
// eslint-disable-next-line no-console
|
|
3619
|
+
zConsole.groupCollapsed(message, ...additionalInfo);
|
|
3620
|
+
// eslint-disable-next-line no-console
|
|
3621
|
+
zConsole.trace();
|
|
3622
|
+
// eslint-disable-next-line no-console
|
|
3623
|
+
zConsole.groupEnd();
|
|
3624
|
+
break;
|
|
3625
|
+
}
|
|
3626
|
+
};
|
|
3627
|
+
|
|
3570
3628
|
const logError = (message, ...rest) => {
|
|
3571
3629
|
// eslint-disable-next-line no-console
|
|
3572
|
-
|
|
3630
|
+
log(message, 'error', ...rest);
|
|
3573
3631
|
};
|
|
3574
3632
|
|
|
3575
3633
|
const getCountryLandedCost = async (countryCode) => {
|
|
@@ -3731,51 +3789,6 @@ const isValidSelector = (selector) => {
|
|
|
3731
3789
|
return true;
|
|
3732
3790
|
};
|
|
3733
3791
|
|
|
3734
|
-
const log = (message, type, ...additionalInfo) => {
|
|
3735
|
-
var _a;
|
|
3736
|
-
// if type is error and debug is false, do not log
|
|
3737
|
-
if (!window.Zonos.debug) {
|
|
3738
|
-
return;
|
|
3739
|
-
}
|
|
3740
|
-
let loggingIframe = document.querySelector('iframe#zonos---debug-logging-iframe');
|
|
3741
|
-
if (!loggingIframe) {
|
|
3742
|
-
// add a hidden iframe
|
|
3743
|
-
loggingIframe = document.createElement('iframe');
|
|
3744
|
-
loggingIframe.id = 'zonos---debug-logging-iframe';
|
|
3745
|
-
loggingIframe.style.display = 'none';
|
|
3746
|
-
loggingIframe.style.opacity = '0';
|
|
3747
|
-
loggingIframe.style.position = 'absolute';
|
|
3748
|
-
loggingIframe.style.top = '-9999px';
|
|
3749
|
-
loggingIframe.style.left = '-9999px';
|
|
3750
|
-
loggingIframe.style.width = '1px';
|
|
3751
|
-
loggingIframe.style.height = '1px';
|
|
3752
|
-
loggingIframe.style.border = 'none';
|
|
3753
|
-
loggingIframe.style.overflow = 'hidden';
|
|
3754
|
-
loggingIframe.style.visibility = 'hidden';
|
|
3755
|
-
document.body.appendChild(loggingIframe);
|
|
3756
|
-
}
|
|
3757
|
-
// use the logging iframe's console to log just in case the console is disabled (overriden) by the site owner
|
|
3758
|
-
const console = ((_a = loggingIframe.contentWindow) === null || _a === void 0 ? void 0 : _a.window.console) || window.console;
|
|
3759
|
-
switch (type) {
|
|
3760
|
-
case 'warn':
|
|
3761
|
-
// eslint-disable-next-line no-console
|
|
3762
|
-
console.warn(message, ...additionalInfo);
|
|
3763
|
-
break;
|
|
3764
|
-
case 'info':
|
|
3765
|
-
// eslint-disable-next-line no-console
|
|
3766
|
-
console.info(message, ...additionalInfo);
|
|
3767
|
-
break;
|
|
3768
|
-
default:
|
|
3769
|
-
// eslint-disable-next-line no-console
|
|
3770
|
-
console.groupCollapsed(message, ...additionalInfo);
|
|
3771
|
-
// eslint-disable-next-line no-console
|
|
3772
|
-
console.trace();
|
|
3773
|
-
// eslint-disable-next-line no-console
|
|
3774
|
-
console.groupEnd();
|
|
3775
|
-
break;
|
|
3776
|
-
}
|
|
3777
|
-
};
|
|
3778
|
-
|
|
3779
3792
|
const getCurrencyElements = (selector) => {
|
|
3780
3793
|
const currencySelector = selector || '.money';
|
|
3781
3794
|
if (!isValidSelector(currencySelector)) {
|
|
@@ -3789,18 +3802,21 @@ const getCurrencyElements = (selector) => {
|
|
|
3789
3802
|
log(`No currency elements found with selector "${currencySelector}"`, 'warn');
|
|
3790
3803
|
return null;
|
|
3791
3804
|
}
|
|
3792
|
-
return
|
|
3805
|
+
// return array of currency elements instead of a NodeList
|
|
3806
|
+
return Array.from(currencyElements);
|
|
3793
3807
|
};
|
|
3794
3808
|
|
|
3795
3809
|
const getInitialElementAmount = (element) => {
|
|
3796
3810
|
var _a;
|
|
3797
3811
|
const domesticValue = element.getAttribute('data-domestic');
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3812
|
+
const intlValue = element.getAttribute('data-zintl');
|
|
3813
|
+
// Only keep numbers, decimal, and hyphens
|
|
3814
|
+
const cleanedText = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.replace(/[^\d.-]/g, '');
|
|
3815
|
+
if (!cleanedText) {
|
|
3816
|
+
return null;
|
|
3817
|
+
}
|
|
3818
|
+
// If the element has no data-domestic attribute, or the text content is different from the data-zintl attribute, set the data-domestic attribute
|
|
3819
|
+
if (!domesticValue || element.textContent !== intlValue) {
|
|
3804
3820
|
// Store the original value on the element once, and international on every new conversion
|
|
3805
3821
|
element.setAttribute('data-domestic', cleanedText);
|
|
3806
3822
|
return parseFloat(cleanedText);
|
|
@@ -3808,9 +3824,32 @@ const getInitialElementAmount = (element) => {
|
|
|
3808
3824
|
return parseFloat(domesticValue);
|
|
3809
3825
|
};
|
|
3810
3826
|
|
|
3827
|
+
const convertCurrency = (element) => {
|
|
3828
|
+
var _a;
|
|
3829
|
+
const amount = getInitialElementAmount(element);
|
|
3830
|
+
if (!amount || isNaN(amount)) {
|
|
3831
|
+
return;
|
|
3832
|
+
}
|
|
3833
|
+
const currentIntlValue = element.getAttribute('data-zintl');
|
|
3834
|
+
const currentCountryValue = element.getAttribute('data-zcountry-code');
|
|
3835
|
+
// do nothing if the target currency is the same
|
|
3836
|
+
const isExchangeRateReady = localizationStore.targetCurrency ===
|
|
3837
|
+
((_a = localizationStore.exchangeRate) === null || _a === void 0 ? void 0 : _a.targetFormat.currencyCode);
|
|
3838
|
+
// if the current value on the element is different from the current intl value, update the data-zintl attribute
|
|
3839
|
+
if (isExchangeRateReady &&
|
|
3840
|
+
(element.textContent !== currentIntlValue ||
|
|
3841
|
+
currentCountryValue !== localizationStore.selectedCountryCode)) {
|
|
3842
|
+
const observedFormattedValue = currencyConvertAndFormat(amount);
|
|
3843
|
+
element.textContent = observedFormattedValue;
|
|
3844
|
+
// save the new value to the data-zintl attribute
|
|
3845
|
+
element.setAttribute('data-zintl', observedFormattedValue);
|
|
3846
|
+
element.setAttribute('data-zcountry-code', localizationStore.selectedCountryCode || '');
|
|
3847
|
+
}
|
|
3848
|
+
};
|
|
3811
3849
|
const defaultCurrencyConverter = () => {
|
|
3812
3850
|
const { currencyElementSelector } = zonosStore.zonosStore.helloSettings;
|
|
3813
3851
|
const currencyElements = getCurrencyElements(currencyElementSelector);
|
|
3852
|
+
// do nothing if none of the currency elements are found
|
|
3814
3853
|
if (!(currencyElements === null || currencyElements === void 0 ? void 0 : currencyElements.length)) {
|
|
3815
3854
|
return;
|
|
3816
3855
|
}
|
|
@@ -3819,33 +3858,8 @@ const defaultCurrencyConverter = () => {
|
|
|
3819
3858
|
return;
|
|
3820
3859
|
}
|
|
3821
3860
|
currencyElements.forEach((element) => {
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
return;
|
|
3825
|
-
}
|
|
3826
|
-
element.setAttribute('data-zintl', currencyConvert(amount).toString());
|
|
3827
|
-
// Check if an observer is already attached to the element
|
|
3828
|
-
let observer = element._mutationObserver;
|
|
3829
|
-
if (!observer) {
|
|
3830
|
-
observer = new MutationObserver(() => {
|
|
3831
|
-
const observedFormattedValue = currencyConvertAndFormat(amount);
|
|
3832
|
-
element.textContent = observedFormattedValue;
|
|
3833
|
-
});
|
|
3834
|
-
observer.observe(element, {
|
|
3835
|
-
characterData: true,
|
|
3836
|
-
childList: true,
|
|
3837
|
-
});
|
|
3838
|
-
element._mutationObserver = observer;
|
|
3839
|
-
}
|
|
3840
|
-
// Temporarily disconnect the observer to prevent an infinite loop
|
|
3841
|
-
observer.disconnect();
|
|
3842
|
-
const formattedValue = currencyConvertAndFormat(amount);
|
|
3843
|
-
element.textContent = formattedValue;
|
|
3844
|
-
// Reconnect the observer after the update is complete
|
|
3845
|
-
observer.observe(element, {
|
|
3846
|
-
characterData: true,
|
|
3847
|
-
childList: true,
|
|
3848
|
-
});
|
|
3861
|
+
// convert the currency and save the formatted value to the data-zintl attribute
|
|
3862
|
+
convertCurrency(element);
|
|
3849
3863
|
});
|
|
3850
3864
|
};
|
|
3851
3865
|
|
|
@@ -3927,11 +3941,9 @@ const getNewLocalization = async () => {
|
|
|
3927
3941
|
!selectedCountryCode) {
|
|
3928
3942
|
return;
|
|
3929
3943
|
}
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
startExchangeRateTimeout({ isGuaranteed, maxAge });
|
|
3934
|
-
}
|
|
3944
|
+
const isGuaranteed = zonosStore.zonosStore.checkoutSettings.visibilityStatus === 'ENABLED';
|
|
3945
|
+
const { maxAge } = await triggerGetExchangeRate(isGuaranteed);
|
|
3946
|
+
startExchangeRateTimeout({ isGuaranteed, maxAge });
|
|
3935
3947
|
localizationStore.countryLandedCost = await getCountryLandedCost(localizationStore.selectedCountryCode);
|
|
3936
3948
|
};
|
|
3937
3949
|
const getCustomMessages = async () => {
|
|
@@ -3958,7 +3970,8 @@ const getOverrideLocale = () => {
|
|
|
3958
3970
|
const zonosLocale = currentUrl.searchParams.get('zonosLocale');
|
|
3959
3971
|
return zonosLocale;
|
|
3960
3972
|
};
|
|
3961
|
-
const localizationStoreUpdateSelectedCountryCode =
|
|
3973
|
+
const localizationStoreUpdateSelectedCountryCode = (newSelectedCountryCode) => {
|
|
3974
|
+
var _a;
|
|
3962
3975
|
log('update selected country code');
|
|
3963
3976
|
localizationStore.selectedCountryCode = newSelectedCountryCode;
|
|
3964
3977
|
const { selectedCountryCode, shippingZoneCountries } = localizationStore;
|
|
@@ -3982,6 +3995,8 @@ const localizationStoreUpdateSelectedCountryCode = async (newSelectedCountryCode
|
|
|
3982
3995
|
window.sessionStorage.setItem('zonos--country', selectedCountryCode);
|
|
3983
3996
|
// Update the URL query param with the new country code
|
|
3984
3997
|
setZCountryUrlParam(selectedCountryCode);
|
|
3998
|
+
(_a = document
|
|
3999
|
+
.querySelector('zonos-hello')) === null || _a === void 0 ? void 0 : _a.setAttribute('z-country', selectedCountryCode);
|
|
3985
4000
|
};
|
|
3986
4001
|
const initLocalizationStore = async () => {
|
|
3987
4002
|
// all countries from countries.json, shipping zone and localization
|
|
@@ -3989,7 +4004,7 @@ const initLocalizationStore = async () => {
|
|
|
3989
4004
|
// Filter countries to only include countries in the shipping zone
|
|
3990
4005
|
const filteredCountries = shippingZoneCountries === null || shippingZoneCountries === void 0 ? void 0 : shippingZoneCountries.reduce((acc, countryCode) => {
|
|
3991
4006
|
const countryInfo = allCountries === null || allCountries === void 0 ? void 0 : allCountries[countryCode];
|
|
3992
|
-
return countryInfo
|
|
4007
|
+
return countryInfo && countryInfo.active
|
|
3993
4008
|
? Object.assign(Object.assign({}, acc), { [countryCode]: countryInfo }) : acc;
|
|
3994
4009
|
}, {});
|
|
3995
4010
|
localizationStore.shippingZoneCountries = filteredCountries || null;
|
|
@@ -4010,11 +4025,760 @@ const initLocalizationStore = async () => {
|
|
|
4010
4025
|
localizationStore.localizationLoaded = true;
|
|
4011
4026
|
void getCustomMessages();
|
|
4012
4027
|
};
|
|
4028
|
+
const updateCheckoutSessionLanguage = async () => {
|
|
4029
|
+
if (!cartStore.checkoutSessionId) {
|
|
4030
|
+
return null;
|
|
4031
|
+
}
|
|
4032
|
+
const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/update-checkout-session-metadata`, {
|
|
4033
|
+
body: {
|
|
4034
|
+
id: cartStore.checkoutSessionId,
|
|
4035
|
+
metadata: [
|
|
4036
|
+
{
|
|
4037
|
+
key: 'language',
|
|
4038
|
+
value: localizationStore.selectedLocale,
|
|
4039
|
+
},
|
|
4040
|
+
],
|
|
4041
|
+
},
|
|
4042
|
+
method: 'POST',
|
|
4043
|
+
});
|
|
4044
|
+
if (errors.length || !json) {
|
|
4045
|
+
logError('Error occurs when updating checkout session', JSON.stringify(errors, null, 2));
|
|
4046
|
+
return { errors, json };
|
|
4047
|
+
}
|
|
4048
|
+
return { errors: [], json };
|
|
4049
|
+
};
|
|
4013
4050
|
const localizationStoreUpdateSelectedLocale = (newSelectedLocale) => {
|
|
4014
4051
|
localizationStore.selectedLocale = newSelectedLocale;
|
|
4015
4052
|
translationStoreUpdateLanguage(newSelectedLocale);
|
|
4053
|
+
void updateCheckoutSessionLanguage();
|
|
4054
|
+
};
|
|
4055
|
+
|
|
4056
|
+
const prepCalculateLandedCost = () => {
|
|
4057
|
+
// maybe we don't need email now for prefetch the landed cost
|
|
4058
|
+
const stripeLinkData = stripeStore.stripeLinkEventData;
|
|
4059
|
+
const stripeAddressData = stripeStore.stripeAddressEventData;
|
|
4060
|
+
const stripeBillingAddressData = stripeStore.stripeShippingSameAsBilling
|
|
4061
|
+
? stripeStore.stripeAddressEventData
|
|
4062
|
+
: stripeStore.stripeBillingAddressEventData;
|
|
4063
|
+
if (!(stripeAddressData === null || stripeAddressData === void 0 ? void 0 : stripeAddressData.complete) || !(stripeBillingAddressData === null || stripeBillingAddressData === void 0 ? void 0 : stripeBillingAddressData.complete)) {
|
|
4064
|
+
throw new Error('Missing stripe address data');
|
|
4065
|
+
}
|
|
4066
|
+
return {
|
|
4067
|
+
billingAddress: {
|
|
4068
|
+
addressLine1: stripeBillingAddressData.value.address.line1,
|
|
4069
|
+
addressLine2: stripeBillingAddressData.value.address.line2 || '',
|
|
4070
|
+
city: stripeBillingAddressData.value.address.city,
|
|
4071
|
+
country: stripeBillingAddressData.value.address.country,
|
|
4072
|
+
postalCode: stripeBillingAddressData.value.address.postal_code,
|
|
4073
|
+
state: stripeBillingAddressData.value.address.state,
|
|
4074
|
+
},
|
|
4075
|
+
billingContact: {
|
|
4076
|
+
// firstName and lastName should be valid now since stripe only mark
|
|
4077
|
+
// the address as complete when both fields are filled.
|
|
4078
|
+
firstName: stripeBillingAddressData.value.firstName || '',
|
|
4079
|
+
lastName: stripeBillingAddressData.value.lastName || '',
|
|
4080
|
+
phone: stripeBillingAddressData.value.phone || '',
|
|
4081
|
+
},
|
|
4082
|
+
checkoutSessionId: cartStore.checkoutSessionId || '',
|
|
4083
|
+
contact: {
|
|
4084
|
+
email: (stripeLinkData === null || stripeLinkData === void 0 ? void 0 : stripeLinkData.value.email) || '',
|
|
4085
|
+
// firstName and lastName should be valid now since stripe only mark
|
|
4086
|
+
// the address as complete when both fields are filled.
|
|
4087
|
+
firstName: stripeAddressData.value.firstName || '',
|
|
4088
|
+
lastName: stripeAddressData.value.lastName || '',
|
|
4089
|
+
phone: stripeAddressData.value.phone || '',
|
|
4090
|
+
},
|
|
4091
|
+
items: cartStore.items.map(item => item),
|
|
4092
|
+
shippingAddress: {
|
|
4093
|
+
addressLine1: stripeAddressData.value.address.line1,
|
|
4094
|
+
addressLine2: stripeAddressData.value.address.line2 || '',
|
|
4095
|
+
city: stripeAddressData.value.address.city,
|
|
4096
|
+
country: stripeAddressData.value.address.country,
|
|
4097
|
+
postalCode: stripeAddressData.value.address.postal_code,
|
|
4098
|
+
state: stripeAddressData.value.address.state,
|
|
4099
|
+
},
|
|
4100
|
+
};
|
|
4101
|
+
};
|
|
4102
|
+
|
|
4103
|
+
const triggerBuildLandedCost = async (buildLandedCost) => {
|
|
4104
|
+
var _a, _b, _c, _d;
|
|
4105
|
+
const data = prepCalculateLandedCost();
|
|
4106
|
+
const landedCost = await buildLandedCost({
|
|
4107
|
+
billingAddress: data.billingAddress,
|
|
4108
|
+
billingContact: data.billingContact,
|
|
4109
|
+
checkoutSessionId: data.checkoutSessionId,
|
|
4110
|
+
contact: data.contact,
|
|
4111
|
+
shippingAddress: data.shippingAddress,
|
|
4112
|
+
});
|
|
4113
|
+
if (!landedCost || ((_a = landedCost.errors) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
4114
|
+
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'}`);
|
|
4115
|
+
}
|
|
4116
|
+
// Validate the landed cost object to make sure the returned value from buildLandedCost has a valid schema
|
|
4117
|
+
const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/validate-landed-cost`, {
|
|
4118
|
+
body: landedCost,
|
|
4119
|
+
headers: {
|
|
4120
|
+
'Content-Type': 'application/json',
|
|
4121
|
+
},
|
|
4122
|
+
method: 'POST',
|
|
4123
|
+
});
|
|
4124
|
+
if (!json || errors.length) {
|
|
4125
|
+
throw new Error(`Invalid landed cost object: ${((_d = errors.find(Boolean)) === null || _d === void 0 ? void 0 : _d.message) || 'Unknown error'}`);
|
|
4126
|
+
}
|
|
4127
|
+
return landedCost;
|
|
4128
|
+
};
|
|
4129
|
+
|
|
4130
|
+
const calculateLandedCost = async (abortController) => {
|
|
4131
|
+
var _a;
|
|
4132
|
+
// If buildLandedCost callback is supplied, use that instead of our regular request to '/calculate-landed-cost'
|
|
4133
|
+
const buildLandedCost = zonosStore.zonosStore.checkoutSettings.buildLandedCost;
|
|
4134
|
+
if (buildLandedCost) {
|
|
4135
|
+
const json = await triggerBuildLandedCost(buildLandedCost);
|
|
4136
|
+
return json;
|
|
4137
|
+
}
|
|
4138
|
+
// request to get landed cost info
|
|
4139
|
+
const url = `${"https://v1.route.js.zonos.com"}/api/zonos-elements/calculate-landed-cost`;
|
|
4140
|
+
const { errors, json } = await handleFetch(url, {
|
|
4141
|
+
body: prepCalculateLandedCost(),
|
|
4142
|
+
method: 'POST',
|
|
4143
|
+
signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
|
|
4144
|
+
});
|
|
4145
|
+
if (errors.length || !json) {
|
|
4146
|
+
const isAbortedRequest = ((_a = errors[0]) === null || _a === void 0 ? void 0 : _a.message) === 'The user aborted a request.';
|
|
4147
|
+
const errorMessage = isAbortedRequest
|
|
4148
|
+
? 'The landed cost calculation request was aborted to initiate a new one.'
|
|
4149
|
+
: 'Failed to calculate landed cost';
|
|
4150
|
+
throw new Error(errorMessage);
|
|
4151
|
+
}
|
|
4152
|
+
return json;
|
|
4153
|
+
};
|
|
4154
|
+
|
|
4155
|
+
const jsonParse = (_data) => {
|
|
4156
|
+
if (typeof _data === 'string') {
|
|
4157
|
+
try {
|
|
4158
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
4159
|
+
const json = JSON.parse(_data);
|
|
4160
|
+
return json;
|
|
4161
|
+
}
|
|
4162
|
+
catch (_error) {
|
|
4163
|
+
return null;
|
|
4164
|
+
}
|
|
4165
|
+
}
|
|
4166
|
+
return null;
|
|
4167
|
+
};
|
|
4168
|
+
|
|
4169
|
+
const addressRuleStyle = ({ theme, }) => {
|
|
4170
|
+
switch (theme) {
|
|
4171
|
+
default:
|
|
4172
|
+
return {
|
|
4173
|
+
'.Input': {
|
|
4174
|
+
boxShadow: 'none',
|
|
4175
|
+
// need to reset everything and the paddingTop to default, otherwise the paddingTop will not be updated.
|
|
4176
|
+
padding: '0',
|
|
4177
|
+
paddingBottom: '8px',
|
|
4178
|
+
paddingLeft: '16px',
|
|
4179
|
+
paddingRight: '8px',
|
|
4180
|
+
// any value here will be add up to the default paddingTop (20px).
|
|
4181
|
+
paddingTop: '6px',
|
|
4182
|
+
},
|
|
4183
|
+
'.Input:focus': {
|
|
4184
|
+
boxShadow: 'none',
|
|
4185
|
+
},
|
|
4186
|
+
};
|
|
4187
|
+
}
|
|
4188
|
+
};
|
|
4189
|
+
|
|
4190
|
+
const defaultVariable = ({ borderStyle, theme, }) => {
|
|
4191
|
+
switch (theme) {
|
|
4192
|
+
case 'DARK':
|
|
4193
|
+
return {
|
|
4194
|
+
borderRadius: getBorderRadius.getBorderRadius(borderStyle),
|
|
4195
|
+
colorBackground: '#101117',
|
|
4196
|
+
colorBackgroundText: '#C5C6CA',
|
|
4197
|
+
colorText: '#C5C6CA',
|
|
4198
|
+
colorTextPlaceholder: '#C5C6CA',
|
|
4199
|
+
};
|
|
4200
|
+
default:
|
|
4201
|
+
return {
|
|
4202
|
+
borderRadius: getBorderRadius.getBorderRadius(borderStyle),
|
|
4203
|
+
};
|
|
4204
|
+
}
|
|
4205
|
+
};
|
|
4206
|
+
|
|
4207
|
+
const { onChange: onChange$1, reset: reset$1, state: stripeStore, } = zonosStore.createStore(() => ({
|
|
4208
|
+
clientSecret: sessionStorage.getItem('zonos--client-secret') || null,
|
|
4209
|
+
fetchingLandedCostAbordController: null,
|
|
4210
|
+
isFetchingLandedCost: false,
|
|
4211
|
+
isFetchingSession: false,
|
|
4212
|
+
stripe: null,
|
|
4213
|
+
stripeAddressElement: null,
|
|
4214
|
+
stripeAddressEventData: null,
|
|
4215
|
+
stripeAddressUsedWhenFetchingLC: null,
|
|
4216
|
+
stripeBillingAddressElement: null,
|
|
4217
|
+
stripeBillingAddressEventData: null,
|
|
4218
|
+
stripeBillingAddressUsedWhenFetchingLC: null,
|
|
4219
|
+
stripeElements: null,
|
|
4220
|
+
stripeElementsForBillingAddress: null,
|
|
4221
|
+
stripeElementsOptions: null,
|
|
4222
|
+
stripeLinkElement: null,
|
|
4223
|
+
stripeLinkEventData: null,
|
|
4224
|
+
stripeLinkUsedWhenFetchingLC: null,
|
|
4225
|
+
stripePaymentElement: null,
|
|
4226
|
+
stripePaymentEventData: null,
|
|
4227
|
+
stripeShippingSameAsBilling: true,
|
|
4228
|
+
}));
|
|
4229
|
+
const getStripeOptions = ({ clientSecret, overrideBorderRaidus, overridePrimaryColor, overrideSecondaryColor, overrideTheme, }) => {
|
|
4230
|
+
const primaryColor = overridePrimaryColor || zonosStore.zonosStore.appearance.colorPrimary;
|
|
4231
|
+
const secondaryColor = overrideSecondaryColor || zonosStore.zonosStore.appearance.colorSecondary;
|
|
4232
|
+
const themeBasedColor = primaryColor && isDarkColor.isDarkColor(primaryColor) ? 'night' : 'flat';
|
|
4233
|
+
// if overrideTheme is provided, use it. Otherwise, use theme based on primary color
|
|
4234
|
+
const theme = overrideTheme === 'DARK' ? 'night' : 'flat';
|
|
4235
|
+
return {
|
|
4236
|
+
appearance: {
|
|
4237
|
+
labels: 'floating',
|
|
4238
|
+
rules: Object.assign({}, addressRuleStyle({ theme: 'LIGHT' })),
|
|
4239
|
+
// get contrast theme color base on primary color
|
|
4240
|
+
theme: overrideTheme ? theme : themeBasedColor,
|
|
4241
|
+
variables: Object.assign(Object.assign({}, defaultVariable({
|
|
4242
|
+
borderStyle: overrideBorderRaidus,
|
|
4243
|
+
theme: 'LIGHT',
|
|
4244
|
+
})), {
|
|
4245
|
+
// use the button background color for input glow color
|
|
4246
|
+
colorPrimary: secondaryColor }),
|
|
4247
|
+
},
|
|
4248
|
+
clientSecret,
|
|
4249
|
+
locale: localizationStore.selectedLocale,
|
|
4250
|
+
};
|
|
4251
|
+
};
|
|
4252
|
+
const stripeStoreCleanupDomesticShippingSession = () => {
|
|
4253
|
+
window.sessionStorage.removeItem('zonos--bigcommerce-domestic-checkout-shipping');
|
|
4254
|
+
};
|
|
4255
|
+
// Save shipping address to session storage
|
|
4256
|
+
const stripeStoreSaveDomesticShippingSession = (props) => {
|
|
4257
|
+
window.sessionStorage.setItem('zonos--bigcommerce-domestic-checkout-shipping', JSON.stringify(props));
|
|
4258
|
+
};
|
|
4259
|
+
const stripeStoreGetDomesticShippingSession = () => {
|
|
4260
|
+
const session = window.sessionStorage.getItem('zonos--bigcommerce-domestic-checkout-shipping');
|
|
4261
|
+
return jsonParse(session);
|
|
4262
|
+
};
|
|
4263
|
+
const initStripeElements = async (props) => {
|
|
4264
|
+
var _a, _b;
|
|
4265
|
+
const clientSecret = stripeStore.clientSecret;
|
|
4266
|
+
if (!stripeStore.stripe) {
|
|
4267
|
+
log('Skip. Stripe is not initialized');
|
|
4268
|
+
return;
|
|
4269
|
+
}
|
|
4270
|
+
if (clientSecret) {
|
|
4271
|
+
const stripeOptions = getStripeOptions({
|
|
4272
|
+
clientSecret,
|
|
4273
|
+
overrideBorderRaidus: props === null || props === void 0 ? void 0 : props.overrideBorderRaidus,
|
|
4274
|
+
overridePrimaryColor: props === null || props === void 0 ? void 0 : props.overridePrimaryColor,
|
|
4275
|
+
overrideSecondaryColor: props === null || props === void 0 ? void 0 : props.overrideSecondaryColor,
|
|
4276
|
+
overrideTheme: props === null || props === void 0 ? void 0 : props.overrideTheme,
|
|
4277
|
+
});
|
|
4278
|
+
// compare with the previous options to see if we need to update
|
|
4279
|
+
const isSameOptions = JSON.stringify(stripeOptions) ===
|
|
4280
|
+
JSON.stringify(stripeStore.stripeElementsOptions);
|
|
4281
|
+
if (!stripeStore.stripeElements ||
|
|
4282
|
+
!stripeStore.stripeElementsForBillingAddress) {
|
|
4283
|
+
// init stripe elements if it doesn't exist
|
|
4284
|
+
stripeStore.stripeElements = (_a = stripeStore.stripe) === null || _a === void 0 ? void 0 : _a.elements(stripeOptions);
|
|
4285
|
+
// save stripe elements options for later comparison
|
|
4286
|
+
stripeStore.stripeElementsOptions = stripeOptions;
|
|
4287
|
+
log('Stripe elements initialized');
|
|
4288
|
+
// init stripe elements for billing address
|
|
4289
|
+
stripeStore.stripeElementsForBillingAddress =
|
|
4290
|
+
(_b = stripeStore.stripe) === null || _b === void 0 ? void 0 : _b.elements(stripeOptions);
|
|
4291
|
+
log('Stripe elements for billing address initialized');
|
|
4292
|
+
return;
|
|
4293
|
+
}
|
|
4294
|
+
if (!isSameOptions) {
|
|
4295
|
+
// update elements with new option if it already exists
|
|
4296
|
+
stripeStore.stripeElements.update(stripeOptions);
|
|
4297
|
+
// update elements for stripe billing address
|
|
4298
|
+
stripeStore.stripeElementsForBillingAddress.update(stripeOptions);
|
|
4299
|
+
// save stripe elements options for later comparison
|
|
4300
|
+
stripeStore.stripeElementsOptions = stripeOptions;
|
|
4301
|
+
}
|
|
4302
|
+
log('Stripe elements initialized');
|
|
4303
|
+
}
|
|
4304
|
+
};
|
|
4305
|
+
const stripeStoreReset = () => {
|
|
4306
|
+
// clean clientSecret so that we can start the new one.
|
|
4307
|
+
sessionStorage.removeItem('zonos--client-secret');
|
|
4308
|
+
// cleanup stripe elements
|
|
4309
|
+
reset$1();
|
|
4310
|
+
// set stripe back to window.Zonos.stripe
|
|
4311
|
+
stripeStore.stripe = window.Zonos.stripe;
|
|
4312
|
+
};
|
|
4313
|
+
/**
|
|
4314
|
+
* Check if the address and email info used when fetching landed cost with the current email and address info are different
|
|
4315
|
+
* Purpose is to resend the request if the info used when fetching landed cost is different from the current info
|
|
4316
|
+
*/
|
|
4317
|
+
const isPrefetchInfoOutdated = () => {
|
|
4318
|
+
var _a, _b, _c, _d, _e, _f;
|
|
4319
|
+
const hasAbortController = stripeStore.fetchingLandedCostAbordController;
|
|
4320
|
+
if (!hasAbortController) {
|
|
4321
|
+
// if there is no abort controller, this is a new request
|
|
4322
|
+
return false;
|
|
4323
|
+
}
|
|
4324
|
+
const isLinkDataDirty = JSON.stringify((_a = stripeStore.stripeLinkUsedWhenFetchingLC) === null || _a === void 0 ? void 0 : _a.value) !==
|
|
4325
|
+
JSON.stringify((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.value);
|
|
4326
|
+
const isAddressDataDirty = JSON.stringify((_c = stripeStore.stripeAddressUsedWhenFetchingLC) === null || _c === void 0 ? void 0 : _c.value) !==
|
|
4327
|
+
JSON.stringify((_d = stripeStore.stripeAddressEventData) === null || _d === void 0 ? void 0 : _d.value);
|
|
4328
|
+
const isBillingAddressDataDirty = !stripeStore.stripeShippingSameAsBilling &&
|
|
4329
|
+
JSON.stringify((_e = stripeStore.stripeBillingAddressEventData) === null || _e === void 0 ? void 0 : _e.value) !==
|
|
4330
|
+
JSON.stringify((_f = stripeStore.stripeBillingAddressUsedWhenFetchingLC) === null || _f === void 0 ? void 0 : _f.value);
|
|
4331
|
+
return isLinkDataDirty || isAddressDataDirty || isBillingAddressDataDirty;
|
|
4332
|
+
};
|
|
4333
|
+
const stripeStorePrefetchLandedCost = async () => {
|
|
4334
|
+
var _a, _b, _c, _d, _e, _f;
|
|
4335
|
+
const stripeAddressReady = !!((_a = stripeStore.stripeAddressEventData) === null || _a === void 0 ? void 0 : _a.complete);
|
|
4336
|
+
const stripeLinkReady = !!((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.complete);
|
|
4337
|
+
const stripeBillingAddressReady = stripeStore.stripeShippingSameAsBilling
|
|
4338
|
+
? !!((_c = stripeStore.stripeLinkEventData) === null || _c === void 0 ? void 0 : _c.complete)
|
|
4339
|
+
: !!((_d = stripeStore.stripeBillingAddressEventData) === null || _d === void 0 ? void 0 : _d.complete);
|
|
4340
|
+
const shouldRefetch = isPrefetchInfoOutdated();
|
|
4341
|
+
if (shouldRefetch) {
|
|
4342
|
+
// if the info used when fetching landed cost is different from the current info, abort the previous request
|
|
4343
|
+
(_e = stripeStore.fetchingLandedCostAbordController) === null || _e === void 0 ? void 0 : _e.abort();
|
|
4344
|
+
stripeStore.fetchingLandedCostAbordController = null;
|
|
4345
|
+
}
|
|
4346
|
+
// only fetch if we are not fetching or we need to refetch
|
|
4347
|
+
if (stripeAddressReady &&
|
|
4348
|
+
stripeLinkReady &&
|
|
4349
|
+
stripeBillingAddressReady &&
|
|
4350
|
+
(shouldRefetch || !stripeStore.isFetchingLandedCost)) {
|
|
4351
|
+
stripeStore.isFetchingLandedCost = true;
|
|
4352
|
+
if (stripeStore.stripeAddressEventData) {
|
|
4353
|
+
stripeStore.stripeAddressUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeAddressEventData);
|
|
4354
|
+
}
|
|
4355
|
+
if (stripeStore.stripeBillingAddressEventData) {
|
|
4356
|
+
stripeStore.stripeBillingAddressUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeBillingAddressEventData);
|
|
4357
|
+
}
|
|
4358
|
+
if (stripeStore.stripeLinkEventData) {
|
|
4359
|
+
stripeStore.stripeLinkUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeLinkEventData);
|
|
4360
|
+
}
|
|
4361
|
+
try {
|
|
4362
|
+
const abortController = new AbortController();
|
|
4363
|
+
stripeStore.fetchingLandedCostAbordController = abortController;
|
|
4364
|
+
const { checkoutSessionWorkflow, landedCostCalculateWorkflow, shipmentRatingCalculateWorkflow, } = await calculateLandedCost(abortController);
|
|
4365
|
+
// reset abort controller after we are done
|
|
4366
|
+
stripeStore.fetchingLandedCostAbordController = null;
|
|
4367
|
+
// update cart store with landed cost info
|
|
4368
|
+
cartStore.landedCostData =
|
|
4369
|
+
(checkoutSessionWorkflow === null || checkoutSessionWorkflow === void 0 ? void 0 : checkoutSessionWorkflow.map(checkoutSession => {
|
|
4370
|
+
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); });
|
|
4371
|
+
if (!foundLandedCost) {
|
|
4372
|
+
return null;
|
|
4373
|
+
}
|
|
4374
|
+
return Object.assign(Object.assign({}, checkoutSession), { landedCost: foundLandedCost });
|
|
4375
|
+
}).filter(Boolean)) || null;
|
|
4376
|
+
cartStore.shippingData =
|
|
4377
|
+
(shipmentRatingCalculateWorkflow === null || shipmentRatingCalculateWorkflow === void 0 ? void 0 : shipmentRatingCalculateWorkflow.filter(Boolean)) || null;
|
|
4378
|
+
// apply new subtotal and total, this is mainly to show items in the presentment currency
|
|
4379
|
+
const firstLandedCostData = (_f = cartStore.landedCostData) === null || _f === void 0 ? void 0 : _f.find(Boolean);
|
|
4380
|
+
const subtotals = !!firstLandedCostData
|
|
4381
|
+
? firstLandedCostData.subtotals
|
|
4382
|
+
: null;
|
|
4383
|
+
if (subtotals) {
|
|
4384
|
+
// prefetch landed cost will not update shipping and taxes since we haven't selected shipping method yet
|
|
4385
|
+
cartStoreApplySubtotals({
|
|
4386
|
+
exchangeRate: subtotals.exchangeRate,
|
|
4387
|
+
items: subtotals.items,
|
|
4388
|
+
landedCostTotal: 0,
|
|
4389
|
+
presentmentCurrencyCode: subtotals.presentmentCurrencyCode,
|
|
4390
|
+
shipping: 0,
|
|
4391
|
+
total: subtotals.items,
|
|
4392
|
+
});
|
|
4393
|
+
}
|
|
4394
|
+
}
|
|
4395
|
+
catch (err) {
|
|
4396
|
+
logError(err);
|
|
4397
|
+
}
|
|
4398
|
+
stripeStore.isFetchingLandedCost = false;
|
|
4399
|
+
}
|
|
4400
|
+
};
|
|
4401
|
+
const getStripeMessageBasedOnStatus = (status) => {
|
|
4402
|
+
let messages = [];
|
|
4403
|
+
let isError = true;
|
|
4404
|
+
// Inspect the PaymentIntent `status` to indicate the status of the payment
|
|
4405
|
+
// to your customer.
|
|
4406
|
+
//
|
|
4407
|
+
// Some payment methods will [immediately succeed or fail][0] upon
|
|
4408
|
+
// confirmation, while others will first enter a `processing` state.
|
|
4409
|
+
//
|
|
4410
|
+
// [0]: https://stripe.com/docs/payments/payment-methods#payment-notification
|
|
4411
|
+
switch (status) {
|
|
4412
|
+
case 'succeeded': {
|
|
4413
|
+
messages = [
|
|
4414
|
+
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.'),
|
|
4415
|
+
'',
|
|
4416
|
+
'',
|
|
4417
|
+
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."),
|
|
4418
|
+
];
|
|
4419
|
+
isError = false;
|
|
4420
|
+
break;
|
|
4421
|
+
}
|
|
4422
|
+
case 'requires_capture':
|
|
4423
|
+
case 'processing': {
|
|
4424
|
+
messages = [
|
|
4425
|
+
translate("Payment processing. We'll update you when payment is received."),
|
|
4426
|
+
];
|
|
4427
|
+
isError = false;
|
|
4428
|
+
break;
|
|
4429
|
+
}
|
|
4430
|
+
case 'requires_payment_method': {
|
|
4431
|
+
messages = [
|
|
4432
|
+
translate('Payment failed. Please try another payment method.'),
|
|
4433
|
+
];
|
|
4434
|
+
break;
|
|
4435
|
+
}
|
|
4436
|
+
default: {
|
|
4437
|
+
messages = [translate('Something went wrong.')];
|
|
4438
|
+
break;
|
|
4439
|
+
}
|
|
4440
|
+
}
|
|
4441
|
+
return {
|
|
4442
|
+
isError,
|
|
4443
|
+
messages,
|
|
4444
|
+
};
|
|
4445
|
+
};
|
|
4446
|
+
const stripeStoreRetrievePayment = async ({ clientSecret: _clientSecret, storybookForceStatus, }) => {
|
|
4447
|
+
if (storybookForceStatus) {
|
|
4448
|
+
// return status right away if we are in storybook mode
|
|
4449
|
+
const { isError, messages } = getStripeMessageBasedOnStatus(storybookForceStatus);
|
|
4450
|
+
return { error: isError, messages };
|
|
4451
|
+
}
|
|
4452
|
+
const clientSecret = _clientSecret || stripeStore.clientSecret;
|
|
4453
|
+
if (!stripeStore.stripe || !clientSecret) {
|
|
4454
|
+
logError('Failed to retrieve payment intent. Stripe is not initialized');
|
|
4455
|
+
return { error: true, message: [translate('Something went wrong.')] };
|
|
4456
|
+
}
|
|
4457
|
+
const { paymentIntent } = await stripeStore.stripe.retrievePaymentIntent(clientSecret);
|
|
4458
|
+
const status = paymentIntent === null || paymentIntent === void 0 ? void 0 : paymentIntent.status;
|
|
4459
|
+
const { isError, messages } = getStripeMessageBasedOnStatus(status);
|
|
4460
|
+
return {
|
|
4461
|
+
error: isError,
|
|
4462
|
+
messages,
|
|
4463
|
+
paymentMethod: paymentIntent === null || paymentIntent === void 0 ? void 0 : paymentIntent.payment_method,
|
|
4464
|
+
};
|
|
4465
|
+
};
|
|
4466
|
+
const stripeStoreConfirmPayment = async () => {
|
|
4467
|
+
var _a, _b, _c;
|
|
4468
|
+
const stripePaymentReady = !!((_a = stripeStore.stripePaymentEventData) === null || _a === void 0 ? void 0 : _a.complete);
|
|
4469
|
+
const stripeElements = stripeStore.stripeElements;
|
|
4470
|
+
const stripe = stripeStore.stripe;
|
|
4471
|
+
const stripeClientSecret = stripeStore.clientSecret;
|
|
4472
|
+
if (stripe && stripeElements && stripePaymentReady && stripeClientSecret) {
|
|
4473
|
+
const { error } = await stripe.confirmPayment({
|
|
4474
|
+
confirmParams: {
|
|
4475
|
+
receipt_email: (_c = (_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.email,
|
|
4476
|
+
return_url: window.location.href,
|
|
4477
|
+
},
|
|
4478
|
+
elements: stripeElements,
|
|
4479
|
+
redirect: 'if_required',
|
|
4480
|
+
});
|
|
4481
|
+
if (error) {
|
|
4482
|
+
if (error.type === 'card_error' || error.type === 'validation_error') {
|
|
4483
|
+
throw new Error(error.message);
|
|
4484
|
+
}
|
|
4485
|
+
if (error.type === 'invalid_request_error') {
|
|
4486
|
+
if (error.code === 'payment_intent_unexpected_state') {
|
|
4487
|
+
// PaymentIntent was canceled or expired, or status is `require_capture`.
|
|
4488
|
+
// don't throw error here because we will reset the checkout session last step
|
|
4489
|
+
return;
|
|
4490
|
+
}
|
|
4491
|
+
}
|
|
4492
|
+
throw new Error('An unexpected error occurred.');
|
|
4493
|
+
}
|
|
4494
|
+
}
|
|
4495
|
+
};
|
|
4496
|
+
/**
|
|
4497
|
+
* Init checkout session
|
|
4498
|
+
* @returns {boolean} whether or not the checkout session is successfully created
|
|
4499
|
+
*/
|
|
4500
|
+
const stripeStoreInitCheckoutSession = async () => {
|
|
4501
|
+
var _a;
|
|
4502
|
+
const total = cartStore.items.reduce((amount, item) => amount + item.amount * item.quantity, 0);
|
|
4503
|
+
if (!total || !localizationStore.targetCurrency) {
|
|
4504
|
+
logError('Fail to create checkout session - invalid total or currency');
|
|
4505
|
+
return false;
|
|
4506
|
+
}
|
|
4507
|
+
stripeStore.isFetchingSession = true;
|
|
4508
|
+
const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/create-checkout-session`, {
|
|
4509
|
+
body: {
|
|
4510
|
+
currency: ((_a = cartStore.items.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode) || '',
|
|
4511
|
+
itemsAmount: total,
|
|
4512
|
+
metadata: [
|
|
4513
|
+
{ key: 'language', value: localizationStore.selectedLocale },
|
|
4514
|
+
],
|
|
4515
|
+
presentmentCountryCode: localizationStore.selectedCountryCode || null,
|
|
4516
|
+
},
|
|
4517
|
+
method: 'POST',
|
|
4518
|
+
});
|
|
4519
|
+
stripeStore.isFetchingSession = false;
|
|
4520
|
+
if (errors.length || !json) {
|
|
4521
|
+
logError('Error occurs when creating checkout session', JSON.stringify(errors, null, 2));
|
|
4522
|
+
return false;
|
|
4523
|
+
}
|
|
4524
|
+
const result = json.checkoutSessionCreate;
|
|
4525
|
+
stripeStore.clientSecret = result.clientSecret;
|
|
4526
|
+
// update cart store with updated informations
|
|
4527
|
+
cartStore.checkoutSessionId = result.id;
|
|
4528
|
+
cartStoreApplySubtotals(Object.assign(Object.assign({}, result.subtotals), { landedCostTotal: 0, shipping: 0, total: result.subtotals.items }));
|
|
4529
|
+
log('Exchange rate updated for cart items (checkout session create)', 'info', cartStore.exchangeRate);
|
|
4530
|
+
log('done-init-checkout-session');
|
|
4531
|
+
return true;
|
|
4532
|
+
};
|
|
4533
|
+
/**
|
|
4534
|
+
* Update checkout session. Use for updating amount with landed cost id, or update session when cart items change
|
|
4535
|
+
*/
|
|
4536
|
+
const stripeStoreUpdateCheckoutSession = async ({ currency, id, itemsAmount, landedCostId, presentmentCountryCode, }) => {
|
|
4537
|
+
// No need to set loading state here because this function will be called under the hood to update
|
|
4538
|
+
// landed cost id for the section.
|
|
4539
|
+
const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/update-checkout-session`, {
|
|
4540
|
+
body: {
|
|
4541
|
+
currency,
|
|
4542
|
+
id,
|
|
4543
|
+
itemsAmount,
|
|
4544
|
+
landedCostId,
|
|
4545
|
+
presentmentCountryCode,
|
|
4546
|
+
},
|
|
4547
|
+
method: 'POST',
|
|
4548
|
+
});
|
|
4549
|
+
if (errors.length || !json) {
|
|
4550
|
+
logError('Error occurs when updating checkout session', JSON.stringify(errors, null, 2));
|
|
4551
|
+
return { errors, json };
|
|
4552
|
+
}
|
|
4553
|
+
return { errors: [], json };
|
|
4554
|
+
};
|
|
4555
|
+
onChange$1('clientSecret', clientSecret => {
|
|
4556
|
+
// update stripe elements when client secret changes
|
|
4557
|
+
if (clientSecret && stripeStore.stripe) {
|
|
4558
|
+
sessionStorage.setItem('zonos--client-secret', clientSecret);
|
|
4559
|
+
}
|
|
4560
|
+
if (!clientSecret) {
|
|
4561
|
+
sessionStorage.removeItem('zonos--client-secret');
|
|
4562
|
+
}
|
|
4563
|
+
});
|
|
4564
|
+
|
|
4565
|
+
const formatDate = ({ date, formatOptions = { day: 'numeric', weekday: 'long', year: 'numeric' }, }) => {
|
|
4566
|
+
// format date to Thursday 3, 2023
|
|
4567
|
+
return new Intl.DateTimeFormat('en-US', formatOptions).format(date);
|
|
4568
|
+
};
|
|
4569
|
+
|
|
4570
|
+
const getDaysDifference = (targetDate) => {
|
|
4571
|
+
const currentDate = new Date();
|
|
4572
|
+
const timeDifference = targetDate.getTime() - currentDate.getTime();
|
|
4573
|
+
const daysDifference = Math.floor(timeDifference / (1000 * 60 * 60 * 24)); // Convert milliseconds to days
|
|
4574
|
+
return daysDifference;
|
|
4575
|
+
};
|
|
4576
|
+
|
|
4577
|
+
const { onChange, reset, state: cartStore, } = zonosStore.createStore(() => ({
|
|
4578
|
+
checkoutSessionId: sessionStorage.getItem('zonos--checkout-session-id') || null,
|
|
4579
|
+
currency: 'USD',
|
|
4580
|
+
dutiesTaxFees: 0,
|
|
4581
|
+
error: null,
|
|
4582
|
+
exchangeRate: null,
|
|
4583
|
+
isSelectedShippingAboveDeminimis: false,
|
|
4584
|
+
isSelectedShippingGuarantee: false,
|
|
4585
|
+
items: [],
|
|
4586
|
+
landedCostData: null,
|
|
4587
|
+
selectedLandedCost: null,
|
|
4588
|
+
selectedShippingOption: null,
|
|
4589
|
+
selectedShippingOptionExpectedDate: '',
|
|
4590
|
+
selectedShippingOptionTransitTime: '',
|
|
4591
|
+
shipping: 0,
|
|
4592
|
+
shippingData: null,
|
|
4593
|
+
step: 'customer-info',
|
|
4594
|
+
subtotal: 0,
|
|
4595
|
+
total: 0,
|
|
4596
|
+
}));
|
|
4597
|
+
/**
|
|
4598
|
+
* Format shipping transit info to be displayed on UI
|
|
4599
|
+
* @returns
|
|
4600
|
+
* - expectedDate: Thursday, Aug 12
|
|
4601
|
+
* - maxTransit: 5
|
|
4602
|
+
* - minTransit: 3
|
|
4603
|
+
*/
|
|
4604
|
+
const cartStoreGetShippingTransitInfo = (item) => {
|
|
4605
|
+
const minTransit = item.minTransitAt
|
|
4606
|
+
? getDaysDifference(new Date(item.minTransitAt))
|
|
4607
|
+
: '';
|
|
4608
|
+
const maxTransit = item.maxTransitAt
|
|
4609
|
+
? getDaysDifference(new Date(item.maxTransitAt))
|
|
4610
|
+
: '';
|
|
4611
|
+
const expectedDate = item.minTransitAt
|
|
4612
|
+
? formatDate({
|
|
4613
|
+
date: new Date(item.minTransitAt),
|
|
4614
|
+
})
|
|
4615
|
+
: '';
|
|
4616
|
+
return {
|
|
4617
|
+
expectedDate,
|
|
4618
|
+
maxTransit,
|
|
4619
|
+
minTransit,
|
|
4620
|
+
};
|
|
4621
|
+
};
|
|
4622
|
+
const cartStoreReset = () => {
|
|
4623
|
+
sessionStorage.removeItem('zonos--checkout-session-id');
|
|
4624
|
+
// reset cart store
|
|
4625
|
+
reset();
|
|
4626
|
+
};
|
|
4627
|
+
const cartStoreUpdateToErrorState = ({ messages, title, }) => {
|
|
4628
|
+
cartStoreReset();
|
|
4629
|
+
stripeStoreReset();
|
|
4630
|
+
cartStore.step = 'error';
|
|
4631
|
+
cartStore.error = {
|
|
4632
|
+
messages,
|
|
4633
|
+
title,
|
|
4634
|
+
};
|
|
4635
|
+
};
|
|
4636
|
+
const cartStoreApplySubtotals = (subtotals) => {
|
|
4637
|
+
// update exchange rate so we can use it to display cart items
|
|
4638
|
+
cartStore.exchangeRate = subtotals.exchangeRate;
|
|
4639
|
+
cartStore.dutiesTaxFees = subtotals.landedCostTotal;
|
|
4640
|
+
cartStore.subtotal = subtotals.items;
|
|
4641
|
+
cartStore.total = subtotals.total;
|
|
4642
|
+
cartStore.currency = subtotals.presentmentCurrencyCode;
|
|
4643
|
+
};
|
|
4644
|
+
const cartStoreReCalculateTotal = async ({ currency, itemsAmount, landedCostId, }) => {
|
|
4645
|
+
if (landedCostId && cartStore.selectedLandedCost) {
|
|
4646
|
+
// update cart total right away if we have landed cost id to avoid order total flickering
|
|
4647
|
+
const subtotals = cartStore.selectedLandedCost.subtotals;
|
|
4648
|
+
cartStoreApplySubtotals(subtotals);
|
|
4649
|
+
log('Exchange rate updated for cart items (landed cost subtotal)', 'info', cartStore.exchangeRate);
|
|
4650
|
+
}
|
|
4651
|
+
// update checkout session
|
|
4652
|
+
if (!cartStore.checkoutSessionId) {
|
|
4653
|
+
logError('Could not update cart total without checkout session id');
|
|
4654
|
+
return false;
|
|
4655
|
+
}
|
|
4656
|
+
const { errors, json } = await stripeStoreUpdateCheckoutSession({
|
|
4657
|
+
currency,
|
|
4658
|
+
id: cartStore.checkoutSessionId,
|
|
4659
|
+
itemsAmount,
|
|
4660
|
+
landedCostId,
|
|
4661
|
+
presentmentCountryCode: localizationStore.selectedCountryCode,
|
|
4662
|
+
});
|
|
4663
|
+
if (errors.length > 0 || !json) {
|
|
4664
|
+
// do nothing if we can't get checkout session
|
|
4665
|
+
logError('Error occurs when updating checkout session');
|
|
4666
|
+
cartStoreUpdateToErrorState({
|
|
4667
|
+
messages: [
|
|
4668
|
+
translate("There's been an error updating your checkout session. Please reload and try again or contact support if the error persists"),
|
|
4669
|
+
],
|
|
4670
|
+
title: translate('Error updating Checkout'),
|
|
4671
|
+
});
|
|
4672
|
+
return false;
|
|
4673
|
+
}
|
|
4674
|
+
if (!landedCostId) {
|
|
4675
|
+
// This is when first open the checkout modal and we just want to get info from the old cart session.
|
|
4676
|
+
// use subtotals from checkout session to update cart total
|
|
4677
|
+
cartStoreApplySubtotals(json.checkoutSessionUpdate.subtotals);
|
|
4678
|
+
log('Exchange rate updated for cart items (checkout session update)', 'info', cartStore.exchangeRate);
|
|
4679
|
+
}
|
|
4680
|
+
return true;
|
|
4681
|
+
};
|
|
4682
|
+
const cartStoreUpdateSelectedShippingOption = async (selectedShippingOption) => {
|
|
4683
|
+
var _a, _b, _c, _d, _e;
|
|
4684
|
+
cartStore.selectedShippingOption = selectedShippingOption;
|
|
4685
|
+
// update shipping transit info
|
|
4686
|
+
const { expectedDate, maxTransit, minTransit } = cartStoreGetShippingTransitInfo(cartStore.selectedShippingOption);
|
|
4687
|
+
cartStore.selectedShippingOptionExpectedDate = expectedDate;
|
|
4688
|
+
cartStore.selectedShippingOptionTransitTime =
|
|
4689
|
+
minTransit && maxTransit
|
|
4690
|
+
? `${minTransit}-${maxTransit}`
|
|
4691
|
+
: `${minTransit || maxTransit}`;
|
|
4692
|
+
const selectedLandedCost = (_a = cartStore.landedCostData) === null || _a === void 0 ? void 0 : _a.find(checkoutSessionPresentment => {
|
|
4693
|
+
var _a, _b, _c;
|
|
4694
|
+
return ((_b = (_a = checkoutSessionPresentment.landedCost) === null || _a === void 0 ? void 0 : _a.shipmentRating) === null || _b === void 0 ? void 0 : _b.id) ===
|
|
4695
|
+
((_c = cartStore.selectedShippingOption) === null || _c === void 0 ? void 0 : _c.id);
|
|
4696
|
+
});
|
|
4697
|
+
// save selected landed cost for later use
|
|
4698
|
+
cartStore.selectedLandedCost = selectedLandedCost || null;
|
|
4699
|
+
if (!selectedLandedCost) {
|
|
4700
|
+
// do nothing if we can't find landed cost for selected shipping option
|
|
4701
|
+
return false;
|
|
4702
|
+
}
|
|
4703
|
+
// update shipping value and dutiesTaxFees on selectedShippingOption change
|
|
4704
|
+
cartStore.shipping = selectedLandedCost.subtotals.shipping;
|
|
4705
|
+
// update deminimis status
|
|
4706
|
+
const isGuarantee = ((_b = selectedLandedCost === null || selectedLandedCost === void 0 ? void 0 : selectedLandedCost.landedCost) === null || _b === void 0 ? void 0 : _b.landedCostGuaranteeCode) === 'ZONOS';
|
|
4707
|
+
// one item in deminimis with type of duty and tax has threshold value is "ABOVE"
|
|
4708
|
+
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'));
|
|
4709
|
+
cartStore.isSelectedShippingAboveDeminimis = isAboveDeminimis;
|
|
4710
|
+
cartStore.isSelectedShippingGuarantee = isGuarantee;
|
|
4711
|
+
// update session with selected landed cost
|
|
4712
|
+
const updateCalulateStatus = await cartStoreReCalculateTotal({
|
|
4713
|
+
landedCostId: (_e = selectedLandedCost.landedCost) === null || _e === void 0 ? void 0 : _e.id,
|
|
4714
|
+
});
|
|
4715
|
+
return updateCalulateStatus;
|
|
4716
|
+
};
|
|
4717
|
+
onChange('checkoutSessionId', () => {
|
|
4718
|
+
if (!cartStore.checkoutSessionId) {
|
|
4719
|
+
sessionStorage.removeItem('zonos--checkout-session-id');
|
|
4720
|
+
return;
|
|
4721
|
+
}
|
|
4722
|
+
sessionStorage.setItem('zonos--checkout-session-id', cartStore.checkoutSessionId);
|
|
4723
|
+
});
|
|
4724
|
+
const cartStoreUpdateItems = async (items) => {
|
|
4725
|
+
var _a;
|
|
4726
|
+
cartStore.items = items;
|
|
4727
|
+
const currency = (_a = items.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode;
|
|
4728
|
+
const total = items.reduce((amt, item) => {
|
|
4729
|
+
return amt + item.amount * item.quantity;
|
|
4730
|
+
}, 0);
|
|
4731
|
+
if (!currency || !total) {
|
|
4732
|
+
// do nothing if we can't get currency or total
|
|
4733
|
+
return;
|
|
4734
|
+
}
|
|
4735
|
+
cartStore.currency = currency;
|
|
4736
|
+
// set loading state here because this is first load checkout session when we already have checkout session id stored
|
|
4737
|
+
stripeStore.isFetchingSession = true;
|
|
4738
|
+
await cartStoreReCalculateTotal({
|
|
4739
|
+
currency: currency,
|
|
4740
|
+
itemsAmount: total,
|
|
4741
|
+
});
|
|
4742
|
+
stripeStore.isFetchingSession = false;
|
|
4743
|
+
};
|
|
4744
|
+
const cartStoreResetSelectedShippingOption = () => {
|
|
4745
|
+
cartStore.selectedShippingOption = null;
|
|
4746
|
+
cartStore.isSelectedShippingAboveDeminimis = false;
|
|
4747
|
+
cartStore.isSelectedShippingGuarantee = false;
|
|
4748
|
+
cartStore.selectedShippingOptionExpectedDate = '';
|
|
4749
|
+
cartStore.selectedShippingOptionTransitTime = '';
|
|
4750
|
+
cartStore.shipping = 0;
|
|
4751
|
+
};
|
|
4752
|
+
const cartStoreNextStep = () => {
|
|
4753
|
+
if (cartStore.step === 'customer-info') {
|
|
4754
|
+
cartStore.step = 'shipping';
|
|
4755
|
+
}
|
|
4756
|
+
else if (cartStore.step === 'shipping') {
|
|
4757
|
+
cartStore.step = 'payment';
|
|
4758
|
+
}
|
|
4759
|
+
else if (cartStore.step === 'payment') {
|
|
4760
|
+
cartStore.step = 'finish';
|
|
4761
|
+
}
|
|
4762
|
+
};
|
|
4763
|
+
const cartStorePreviousStep = () => {
|
|
4764
|
+
if (cartStore.step === 'payment') {
|
|
4765
|
+
cartStore.step = 'shipping';
|
|
4766
|
+
}
|
|
4767
|
+
else if (cartStore.step === 'shipping') {
|
|
4768
|
+
cartStore.step = 'customer-info';
|
|
4769
|
+
// reset selected shipping option
|
|
4770
|
+
cartStoreResetSelectedShippingOption();
|
|
4771
|
+
}
|
|
4016
4772
|
};
|
|
4017
4773
|
|
|
4774
|
+
exports.cartStore = cartStore;
|
|
4775
|
+
exports.cartStoreGetShippingTransitInfo = cartStoreGetShippingTransitInfo;
|
|
4776
|
+
exports.cartStoreNextStep = cartStoreNextStep;
|
|
4777
|
+
exports.cartStorePreviousStep = cartStorePreviousStep;
|
|
4778
|
+
exports.cartStoreReset = cartStoreReset;
|
|
4779
|
+
exports.cartStoreUpdateItems = cartStoreUpdateItems;
|
|
4780
|
+
exports.cartStoreUpdateSelectedShippingOption = cartStoreUpdateSelectedShippingOption;
|
|
4781
|
+
exports.cartStoreUpdateToErrorState = cartStoreUpdateToErrorState;
|
|
4018
4782
|
exports.currencyConvert = currencyConvert;
|
|
4019
4783
|
exports.currencyConvertAndFormat = currencyConvertAndFormat;
|
|
4020
4784
|
exports.currencyDisplay = currencyDisplay;
|
|
@@ -4022,6 +4786,7 @@ exports.currencyFormat = currencyFormat;
|
|
|
4022
4786
|
exports.getZCountryUrlParam = getZCountryUrlParam;
|
|
4023
4787
|
exports.handleFetch = handleFetch;
|
|
4024
4788
|
exports.initLocalizationStore = initLocalizationStore;
|
|
4789
|
+
exports.initStripeElements = initStripeElements;
|
|
4025
4790
|
exports.isValidSelector = isValidSelector;
|
|
4026
4791
|
exports.localizationStore = localizationStore;
|
|
4027
4792
|
exports.localizationStoreUpdateSelectedCountryCode = localizationStoreUpdateSelectedCountryCode;
|
|
@@ -4029,4 +4794,13 @@ exports.localizationStoreUpdateSelectedLocale = localizationStoreUpdateSelectedL
|
|
|
4029
4794
|
exports.log = log;
|
|
4030
4795
|
exports.logError = logError;
|
|
4031
4796
|
exports.setZCountryUrlParam = setZCountryUrlParam;
|
|
4797
|
+
exports.stripeStore = stripeStore;
|
|
4798
|
+
exports.stripeStoreCleanupDomesticShippingSession = stripeStoreCleanupDomesticShippingSession;
|
|
4799
|
+
exports.stripeStoreConfirmPayment = stripeStoreConfirmPayment;
|
|
4800
|
+
exports.stripeStoreGetDomesticShippingSession = stripeStoreGetDomesticShippingSession;
|
|
4801
|
+
exports.stripeStoreInitCheckoutSession = stripeStoreInitCheckoutSession;
|
|
4802
|
+
exports.stripeStorePrefetchLandedCost = stripeStorePrefetchLandedCost;
|
|
4803
|
+
exports.stripeStoreReset = stripeStoreReset;
|
|
4804
|
+
exports.stripeStoreRetrievePayment = stripeStoreRetrievePayment;
|
|
4805
|
+
exports.stripeStoreSaveDomesticShippingSession = stripeStoreSaveDomesticShippingSession;
|
|
4032
4806
|
exports.translate = translate;
|