@zonos/elements 1.2.3 → 1.2.4-alpha.10
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 +15 -1
- package/dist/cjs/cart-90f7c8c0.js +644 -0
- package/dist/cjs/getBorderRadius-bf4a4276.js +18 -0
- package/dist/cjs/getHasMoreSpaceOnRight-4c94667f.js +10 -0
- package/dist/cjs/{index-9542d2e7.js → index-0dcccc22.js} +154 -42
- package/dist/cjs/index.cjs.js +6 -6
- package/dist/cjs/isColorVariable-41cacd82.js +16 -0
- package/dist/cjs/{isDarkColor-f3446afd.js → isDarkColor-ff6ff183.js} +2 -2
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/localization-9caf3397.js +3667 -0
- package/dist/cjs/submitGtag-b141b45d.js +27 -0
- package/dist/cjs/zonos-address_2.cjs.entry.js +108 -108
- package/dist/cjs/zonos-badge.cjs.entry.js +25 -22
- package/dist/cjs/zonos-banner.cjs.entry.js +65 -53
- package/dist/cjs/zonos-button_2.cjs.entry.js +100 -99
- package/dist/cjs/zonos-card_2.cjs.entry.js +32 -27
- package/dist/cjs/zonos-cart-items_10.cjs.entry.js +464 -419
- package/dist/cjs/zonos-checkout.cjs.entry.js +358 -356
- package/dist/cjs/zonos-component.cjs.entry.js +15 -15
- package/dist/cjs/zonos-controller.cjs.entry.js +232 -194
- package/dist/cjs/zonos-country-flag_4.cjs.entry.js +85 -77
- package/dist/cjs/zonos-elements.cjs.js +3 -3
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +101 -101
- package/dist/cjs/zonos-hello.cjs.entry.js +349 -349
- package/dist/cjs/zonos-icon.cjs.entry.js +22 -20
- package/dist/cjs/zonos-notification.cjs.entry.js +60 -57
- package/dist/cjs/zonos-payment.cjs.entry.js +45 -45
- package/dist/cjs/zonos-shipping-rich-radio.cjs.entry.js +40 -40
- package/dist/cjs/zonos-text.cjs.entry.js +145 -143
- package/dist/cjs/{zonosStore-a430ec5b.js → zonosStore-b43ef5db.js} +102 -97
- package/dist/collection/__mocks__/vercel-app/loadZonos.js +492 -0
- package/dist/collection/__mocks__/vercel-app/localization.js +1 -0
- package/dist/collection/__mocks__/vercel-app/zonos-hello.entry.js +1 -0
- package/dist/collection/__mocks__/zonos-url/loadZonos.js +492 -0
- package/dist/{esm-es5/localization-f3828793.js → collection/__mocks__/zonos-url/localization.js} +1 -1
- package/dist/collection/__mocks__/zonos-url/zonos-hello.entry.js +1 -0
- package/dist/collection/__tests__/build-utils/urlCheckOne.js +59 -0
- package/dist/collection/collection-manifest.json +2 -2
- package/dist/collection/components/checkout/zonos-checkout/zonos-cart-items/zonos-cart-items.css +5 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-cart-items/zonos-cart-items.js +37 -37
- package/dist/collection/components/checkout/zonos-checkout/zonos-cart-subtotal/zonos-cart-subtotal.css +5 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-cart-subtotal/zonos-cart-subtotal.js +44 -44
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.css +5 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js +209 -163
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-payment/zonos-checkout-payment.css +5 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-payment/zonos-checkout-payment.js +149 -149
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.css +5 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +562 -559
- 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 +153 -153
- package/dist/collection/components/checkout/zonos-checkout/zonos-review/zonos-review.css +5 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-review/zonos-review.js +107 -107
- package/dist/collection/components/checkout/zonos-checkout/zonos-shipping/zonos-shipping.css +5 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-shipping/zonos-shipping.js +164 -164
- package/dist/collection/components/common/countries.js +261 -261
- package/dist/collection/components/common/zonos-badge/zonos-badge.css +5 -1
- package/dist/collection/components/common/zonos-badge/zonos-badge.js +189 -186
- package/dist/collection/components/common/zonos-banner/zonos-banner.css +5 -1
- package/dist/collection/components/common/zonos-banner/zonos-banner.js +140 -128
- package/dist/collection/components/common/zonos-button/zonos-button.css +6 -5
- package/dist/collection/components/common/zonos-button/zonos-button.js +407 -406
- package/dist/collection/components/common/zonos-card/zonos-card.css +5 -1
- package/dist/collection/components/common/zonos-card/zonos-card.js +165 -162
- package/dist/collection/components/common/zonos-collapse/zonos-collapse.css +5 -1
- package/dist/collection/components/common/zonos-collapse/zonos-collapse.js +85 -83
- package/dist/collection/components/common/zonos-country-flag/zonos-country-flag.css +5 -1
- package/dist/collection/components/common/zonos-country-flag/zonos-country-flag.js +101 -96
- package/dist/collection/components/common/zonos-country-select/zonos-country-select.css +5 -1
- package/dist/collection/components/common/zonos-country-select/zonos-country-select.js +73 -70
- package/dist/collection/components/common/zonos-custom-message/zonos-custom-message.css +5 -1
- package/dist/collection/components/common/zonos-custom-message/zonos-custom-message.js +62 -59
- package/dist/collection/components/common/zonos-dialog/zonos-dialog.css +5 -1
- package/dist/collection/components/common/zonos-dialog/zonos-dialog.js +373 -371
- package/dist/collection/components/common/zonos-icon/zonos-icon.css +5 -1
- package/dist/collection/components/common/zonos-icon/zonos-icon.js +123 -121
- package/dist/collection/components/common/zonos-logo/zonos-logo.css +5 -1
- package/dist/collection/components/common/zonos-logo/zonos-logo.js +92 -90
- package/dist/collection/components/common/zonos-notification/zonos-notification.css +5 -1
- package/dist/collection/components/common/zonos-notification/zonos-notification.js +129 -125
- package/dist/collection/components/common/zonos-shipping-rich-radio/zonos-shipping-rich-radio.css +5 -1
- package/dist/collection/components/common/zonos-shipping-rich-radio/zonos-shipping-rich-radio.js +168 -168
- package/dist/collection/components/common/zonos-spinner/zonos-spinner.css +5 -1
- package/dist/collection/components/common/zonos-spinner/zonos-spinner.js +71 -71
- package/dist/collection/components/common/zonos-text/zonos-text.css +5 -1
- package/dist/collection/components/common/zonos-text/zonos-text.js +193 -191
- package/dist/collection/components/common/zonos-v-stack/zonos-v-stack.css +5 -1
- package/dist/collection/components/common/zonos-v-stack/zonos-v-stack.js +70 -67
- package/dist/collection/components/component-template/zonos-component/zonos-component.css +5 -1
- package/dist/collection/components/component-template/zonos-component/zonos-component.js +81 -81
- package/dist/collection/components/hello/zonos-hello/zonos-hello.css +5 -2
- package/dist/collection/components/hello/zonos-hello/zonos-hello.js +450 -446
- package/dist/collection/components/hello/zonos-hello-dialog/zonos-hello-dialog-footer/zonos-hello-dialog-footer.css +5 -1
- package/dist/collection/components/hello/zonos-hello-dialog/zonos-hello-dialog-footer/zonos-hello-dialog-footer.js +70 -70
- package/dist/collection/components/hello/zonos-hello-dialog/zonos-hello-dialog.css +5 -1
- package/dist/collection/components/hello/zonos-hello-dialog/zonos-hello-dialog.js +272 -272
- package/dist/collection/components/main/zonos-controller.css +5 -1
- package/dist/collection/components/main/zonos-controller.js +403 -320
- package/dist/collection/components/store/checkout/cart.js +162 -162
- package/dist/collection/components/store/checkout/stripe.js +265 -264
- package/dist/collection/components/store/hello/localization.js +112 -112
- package/dist/collection/components/store/translationStore/strings.arabic.js +147 -147
- package/dist/collection/components/store/translationStore/strings.base.js +147 -147
- package/dist/collection/components/store/translationStore/strings.chinese.js +147 -147
- package/dist/collection/components/store/translationStore/strings.danish.js +147 -147
- package/dist/collection/components/store/translationStore/strings.dutch.js +147 -147
- package/dist/collection/components/store/translationStore/strings.french.js +147 -147
- package/dist/collection/components/store/translationStore/strings.german.js +147 -147
- package/dist/collection/components/store/translationStore/strings.hebrew.js +147 -147
- package/dist/collection/components/store/translationStore/strings.indonesian.js +147 -147
- package/dist/collection/components/store/translationStore/strings.italian.js +147 -147
- package/dist/collection/components/store/translationStore/strings.japanese.js +147 -147
- package/dist/collection/components/store/translationStore/strings.korean.js +147 -147
- package/dist/collection/components/store/translationStore/strings.norwegian.js +147 -147
- package/dist/collection/components/store/translationStore/strings.polish.js +147 -147
- package/dist/collection/components/store/translationStore/strings.portuguese.js +147 -147
- package/dist/collection/components/store/translationStore/strings.russian.js +147 -147
- package/dist/collection/components/store/translationStore/strings.spanish.js +147 -147
- package/dist/collection/components/store/translationStore/strings.swedish.js +147 -147
- package/dist/collection/components/store/translationStore/strings.turkish.js +147 -147
- package/dist/collection/components/store/translationStore/strings.vietnamese.js +147 -147
- package/dist/collection/components/store/translationStore.js +65 -65
- package/dist/collection/components/store/zonosStore.js +98 -94
- package/dist/collection/components/stripe/zonos-address/zonos-address.css +5 -1
- package/dist/collection/components/stripe/zonos-address/zonos-address.js +142 -142
- package/dist/collection/components/stripe/zonos-link-authentication/zonos-link-authentication.css +5 -1
- package/dist/collection/components/stripe/zonos-link-authentication/zonos-link-authentication.js +76 -76
- package/dist/collection/components/stripe/zonos-payment/zonos-payment.css +5 -1
- package/dist/collection/components/stripe/zonos-payment/zonos-payment.js +81 -81
- package/dist/collection/components/utils/addDays.js +5 -5
- package/dist/collection/components/utils/api/calculateLandedCost.js +19 -11
- package/dist/collection/components/utils/api/checkItemRestrictions.js +13 -13
- package/dist/collection/components/utils/api/getCountries.js +11 -11
- package/dist/collection/components/utils/api/getCountryLandedCost.js +11 -11
- package/dist/collection/components/utils/api/getExchangeRate.js +17 -17
- package/dist/collection/components/utils/api/getLocaleMessages.js +9 -9
- package/dist/collection/components/utils/api/getLocalization.js +24 -19
- package/dist/collection/components/utils/api/getShippingZones.js +9 -9
- package/dist/collection/components/utils/api/getZonosSettings.js +11 -0
- package/dist/collection/components/utils/api/prepCalculateLandedCost.js +26 -26
- package/dist/collection/components/utils/api/triggerBuildLandedCost.js +22 -0
- package/dist/collection/components/utils/checkout/initCheckout.js +16 -16
- package/dist/collection/components/utils/checkout/isCheckoutMobile.js +1 -1
- package/dist/collection/components/utils/darkenColor.js +4 -4
- package/dist/collection/components/utils/formatCurrency.js +8 -8
- package/dist/collection/components/utils/formatDate.js +2 -2
- package/dist/collection/components/utils/getBorderRadius.js +5 -5
- package/dist/collection/components/utils/getButtonTheme.js +8 -8
- package/dist/collection/components/utils/getDaysDifference.js +4 -4
- package/dist/collection/components/utils/handleFetch.js +107 -77
- package/dist/collection/components/utils/hello/currencyConversion/currencyConvert.js +9 -9
- package/dist/collection/components/utils/hello/currencyConversion/currencyConvertAndFormat.js +3 -3
- package/dist/collection/components/utils/hello/currencyConversion/currencyDisplay.js +10 -10
- package/dist/collection/components/utils/hello/currencyConversion/currencyFormat.js +29 -29
- package/dist/collection/components/utils/hello/currencyConversion/defaultCurrencyConverter.js +35 -35
- package/dist/collection/components/utils/hello/currencyConversion/getCurrencyCode.js +6 -6
- package/dist/collection/components/utils/hello/currencyConversion/getCurrencyElements.js +13 -13
- package/dist/collection/components/utils/hello/currencyConversion/getInitialElementAmount.js +12 -12
- package/dist/collection/components/utils/hello/currencyConversion/getLanguageCode.js +6 -6
- package/dist/collection/components/utils/hello/detectItemRestrictions.js +23 -23
- package/dist/collection/components/utils/hello/getCurrentHelloLocalePage.js +17 -17
- package/dist/collection/components/utils/hello/getHasMoreSpaceAbove.js +5 -5
- package/dist/collection/components/utils/hello/getHasMoreSpaceOnRight.js +5 -5
- package/dist/collection/components/utils/hello/getProductsOnPage.js +42 -42
- package/dist/collection/components/utils/hello/getZCountryUrlParam.js +5 -0
- package/dist/collection/components/utils/hello/initHello.js +15 -15
- package/dist/collection/components/utils/hello/setZCountryUrlParam.js +9 -0
- package/dist/collection/components/utils/isColorVariable.js +10 -10
- package/dist/collection/components/utils/isDarkColor.js +1 -1
- package/dist/collection/components/utils/isValidSelector.js +8 -8
- package/dist/collection/components/utils/jsonParse.js +10 -10
- package/dist/collection/components/utils/lightenColor.js +4 -4
- package/dist/collection/components/utils/logging/log.js +42 -22
- package/dist/collection/components/utils/logging/logError.js +2 -2
- package/dist/collection/components/utils/mergeConfig.js +3 -3
- package/dist/collection/components/utils/submitGtag.js +9 -9
- package/dist/collection/environment.js +139 -116
- package/dist/collection/scripts/extractZonosQaUrl.js +26 -0
- package/dist/collection/scripts/loadStripe.js +7 -7
- package/dist/collection/scripts/stripe.js +80 -80
- package/dist/collection/scripts/zonos.js +331 -253
- package/dist/collection/styles/stripe/addressRuleStyle.js +14 -14
- package/dist/collection/styles/stripe/defaultVariable.js +14 -14
- package/dist/collection/types/generated/graphql.customer.types.js +1513 -1424
- package/dist/collection/types/generated/graphql.frontend.types.js +452 -378
- package/dist/collection/types/stripe/Apperance.js +56 -56
- package/dist/collection/types/styles/Color.js +18 -18
- package/dist/collection/types/styles/Text.js +97 -97
- package/dist/collection/utils/format.js +1 -1
- package/dist/collection/utils/generateVercelDeployUrl.js +17 -17
- package/dist/components/cart.js +529 -501
- package/dist/components/formatCurrency.js +8 -8
- package/dist/components/getBorderRadius.js +5 -5
- package/dist/components/isColorVariable.js +10 -10
- package/dist/components/isDarkColor.js +1 -1
- package/dist/components/localization.js +3486 -3426
- package/dist/components/submitGtag.js +9 -9
- package/dist/components/zonos-address.d.ts +2 -2
- package/dist/components/zonos-address2.js +90 -90
- package/dist/components/zonos-badge.d.ts +2 -2
- package/dist/components/zonos-badge2.js +52 -43
- package/dist/components/zonos-banner.d.ts +2 -2
- package/dist/components/zonos-banner2.js +88 -76
- package/dist/components/zonos-button.d.ts +2 -2
- package/dist/components/zonos-button2.js +120 -119
- package/dist/components/zonos-card.d.ts +2 -2
- package/dist/components/zonos-card2.js +48 -39
- package/dist/components/zonos-cart-items.d.ts +2 -2
- package/dist/components/zonos-cart-items2.js +43 -43
- package/dist/components/zonos-cart-subtotal.d.ts +2 -2
- package/dist/components/zonos-cart-subtotal2.js +65 -65
- package/dist/components/zonos-checkout-finish.d.ts +2 -2
- package/dist/components/zonos-checkout-finish2.js +146 -103
- package/dist/components/zonos-checkout-payment.d.ts +2 -2
- package/dist/components/zonos-checkout-payment2.js +82 -82
- package/dist/components/zonos-checkout.d.ts +2 -2
- package/dist/components/zonos-checkout.js +500 -498
- package/dist/components/zonos-collapse.d.ts +2 -2
- package/dist/components/zonos-collapse2.js +48 -46
- package/dist/components/zonos-component.d.ts +2 -2
- package/dist/components/zonos-component.js +32 -32
- package/dist/components/zonos-controller.d.ts +2 -2
- package/dist/components/zonos-controller.js +260 -220
- package/dist/components/zonos-country-flag.d.ts +2 -2
- package/dist/components/zonos-country-flag2.js +41 -36
- package/dist/components/zonos-country-select.d.ts +2 -2
- package/dist/components/zonos-country-select2.js +82 -79
- package/dist/components/zonos-custom-message.d.ts +2 -2
- package/dist/components/zonos-custom-message2.js +44 -41
- package/dist/components/zonos-customer-info.d.ts +2 -2
- package/dist/components/zonos-customer-info2.js +82 -82
- package/dist/components/zonos-dialog.d.ts +2 -2
- package/dist/components/zonos-dialog2.js +105 -103
- package/dist/components/zonos-hello-dialog-footer.d.ts +2 -2
- package/dist/components/zonos-hello-dialog-footer2.js +46 -46
- package/dist/components/zonos-hello-dialog.d.ts +2 -2
- package/dist/components/zonos-hello-dialog2.js +182 -182
- package/dist/components/zonos-hello.d.ts +2 -2
- package/dist/components/zonos-hello.js +437 -437
- package/dist/components/zonos-icon.d.ts +2 -2
- package/dist/components/zonos-icon2.js +40 -38
- package/dist/components/zonos-link-authentication.d.ts +2 -2
- package/dist/components/zonos-link-authentication2.js +60 -60
- package/dist/components/zonos-logo.d.ts +2 -2
- package/dist/components/zonos-logo2.js +37 -35
- package/dist/components/zonos-notification.d.ts +2 -2
- package/dist/components/zonos-notification2.js +82 -79
- package/dist/components/zonos-payment.d.ts +2 -2
- package/dist/components/zonos-payment2.js +64 -64
- package/dist/components/zonos-review.d.ts +2 -2
- package/dist/components/zonos-review2.js +72 -72
- package/dist/components/zonos-shipping-rich-radio.d.ts +2 -2
- package/dist/components/zonos-shipping-rich-radio2.js +62 -62
- package/dist/components/zonos-shipping.d.ts +2 -2
- package/dist/components/zonos-shipping2.js +114 -114
- package/dist/components/zonos-spinner.d.ts +2 -2
- package/dist/components/zonos-spinner2.js +31 -31
- package/dist/components/zonos-text.d.ts +2 -2
- package/dist/components/zonos-text2.js +166 -164
- package/dist/components/zonos-v-stack.d.ts +2 -2
- package/dist/components/zonos-v-stack2.js +29 -26
- package/dist/components/zonosStore.js +101 -97
- package/dist/esm/cart-b439be00.js +626 -0
- package/dist/esm/getBorderRadius-178a0a05.js +16 -0
- package/dist/esm/getHasMoreSpaceOnRight-70eb913a.js +8 -0
- package/dist/esm/{index-d1aa9293.js → index-36ff6342.js} +154 -42
- package/dist/esm/index.js +6 -6
- package/dist/esm/isColorVariable-91c33804.js +14 -0
- package/dist/esm/{isDarkColor-6fbb9b14.js → isDarkColor-416d6047.js} +2 -2
- package/dist/esm/loader.js +3 -3
- package/dist/esm/localization-a51ccbc2.js +3652 -0
- package/dist/esm/submitGtag-521826a2.js +24 -0
- package/dist/esm/zonos-address_2.entry.js +108 -108
- package/dist/esm/zonos-badge.entry.js +25 -22
- package/dist/esm/zonos-banner.entry.js +65 -53
- package/dist/esm/zonos-button_2.entry.js +100 -99
- package/dist/esm/zonos-card_2.entry.js +32 -27
- package/dist/esm/zonos-cart-items_10.entry.js +464 -419
- package/dist/esm/zonos-checkout.entry.js +358 -356
- package/dist/esm/zonos-component.entry.js +15 -15
- package/dist/esm/zonos-controller.entry.js +232 -194
- package/dist/esm/zonos-country-flag_4.entry.js +85 -77
- package/dist/esm/zonos-elements.js +4 -4
- package/dist/esm/zonos-hello-dialog.entry.js +101 -101
- package/dist/esm/zonos-hello.entry.js +349 -349
- package/dist/esm/zonos-icon.entry.js +22 -20
- package/dist/esm/zonos-notification.entry.js +60 -57
- package/dist/esm/zonos-payment.entry.js +45 -45
- package/dist/esm/zonos-shipping-rich-radio.entry.js +40 -40
- package/dist/esm/zonos-text.entry.js +145 -143
- package/dist/esm/{zonosStore-05a62104.js → zonosStore-61e74f58.js} +102 -98
- package/dist/esm-es5/cart-b439be00.js +1 -0
- package/dist/esm-es5/getBorderRadius-178a0a05.js +1 -0
- package/dist/esm-es5/getHasMoreSpaceOnRight-70eb913a.js +1 -0
- package/dist/esm-es5/index-36ff6342.js +2 -0
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/{isDarkColor-6fbb9b14.js → isDarkColor-416d6047.js} +1 -1
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/localization-a51ccbc2.js +1 -0
- package/dist/esm-es5/{submitGtag-a901ece5.js → submitGtag-521826a2.js} +1 -1
- package/dist/esm-es5/zonos-address_2.entry.js +1 -1
- package/dist/esm-es5/zonos-badge.entry.js +1 -1
- package/dist/esm-es5/zonos-banner.entry.js +1 -1
- package/dist/esm-es5/zonos-button_2.entry.js +1 -1
- package/dist/esm-es5/zonos-card_2.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_10.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_4.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-icon.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-shipping-rich-radio.entry.js +1 -1
- package/dist/esm-es5/zonos-text.entry.js +1 -1
- package/dist/esm-es5/zonosStore-61e74f58.js +1 -0
- package/dist/scripts/extractZonosQaUrl.js +30 -0
- package/dist/scripts/loadZonos.js +172 -48
- package/dist/scripts/zonos.js +172 -48
- package/dist/types/__tests__/build-utils/urlCheckOne.d.ts +6 -0
- package/dist/types/components/checkout/zonos-checkout/zonos-cart-items/zonos-cart-items.d.ts +2 -2
- package/dist/types/components/checkout/zonos-checkout/zonos-cart-subtotal/zonos-cart-subtotal.d.ts +1 -1
- package/dist/types/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.d.ts +33 -29
- package/dist/types/components/checkout/zonos-checkout/zonos-checkout-payment/zonos-checkout-payment.d.ts +31 -31
- package/dist/types/components/checkout/zonos-checkout/zonos-checkout.d.ts +77 -77
- package/dist/types/components/checkout/zonos-checkout/zonos-customer-info/zonos-customer-info.d.ts +31 -31
- package/dist/types/components/checkout/zonos-checkout/zonos-review/zonos-review.d.ts +14 -14
- package/dist/types/components/checkout/zonos-checkout/zonos-shipping/zonos-shipping.d.ts +29 -29
- package/dist/types/components/common/zonos-badge/zonos-badge.d.ts +35 -35
- package/dist/types/components/common/zonos-banner/zonos-banner.d.ts +21 -21
- package/dist/types/components/common/zonos-button/zonos-button.d.ts +92 -92
- package/dist/types/components/common/zonos-card/zonos-card.d.ts +29 -29
- package/dist/types/components/common/zonos-collapse/zonos-collapse.d.ts +14 -14
- package/dist/types/components/common/zonos-country-flag/zonos-country-flag.d.ts +16 -16
- package/dist/types/components/common/zonos-country-select/zonos-country-select.d.ts +9 -9
- package/dist/types/components/common/zonos-custom-message/zonos-custom-message.d.ts +9 -9
- package/dist/types/components/common/zonos-dialog/zonos-dialog.d.ts +75 -75
- package/dist/types/components/common/zonos-icon/zonos-icon.d.ts +27 -27
- package/dist/types/components/common/zonos-logo/zonos-logo.d.ts +13 -13
- package/dist/types/components/common/zonos-notification/zonos-notification.d.ts +28 -28
- package/dist/types/components/common/zonos-shipping-rich-radio/zonos-shipping-rich-radio.d.ts +35 -35
- package/dist/types/components/common/zonos-spinner/zonos-spinner.d.ts +11 -11
- package/dist/types/components/common/zonos-text/zonos-text.d.ts +30 -30
- package/dist/types/components/common/zonos-v-stack/zonos-v-stack.d.ts +10 -10
- package/dist/types/components/component-template/zonos-component/zonos-component.d.ts +14 -14
- package/dist/types/components/hello/zonos-hello/zonos-hello.d.ts +68 -68
- package/dist/types/components/hello/zonos-hello-dialog/zonos-hello-dialog-footer/zonos-hello-dialog-footer.d.ts +10 -10
- package/dist/types/components/hello/zonos-hello-dialog/zonos-hello-dialog.d.ts +41 -41
- package/dist/types/components/main/zonos-controller.d.ts +47 -38
- package/dist/types/components/store/checkout/cart.d.ts +64 -64
- package/dist/types/components/store/checkout/stripe.d.ts +44 -43
- package/dist/types/components/store/hello/localization.d.ts +15 -15
- package/dist/types/components/store/translationStore/strings.arabic.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.base.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.chinese.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.danish.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.dutch.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.french.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.german.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.hebrew.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.indonesian.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.italian.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.japanese.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.korean.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.norwegian.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.polish.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.portuguese.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.russian.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.spanish.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.swedish.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.turkish.d.ts +147 -147
- package/dist/types/components/store/translationStore/strings.vietnamese.d.ts +147 -147
- package/dist/types/components/store/translationStore.d.ts +2 -2
- package/dist/types/components/store/zonosStore.d.ts +23 -22
- package/dist/types/components/stripe/zonos-address/zonos-address.d.ts +17 -17
- package/dist/types/components/stripe/zonos-link-authentication/zonos-link-authentication.d.ts +9 -9
- package/dist/types/components/stripe/zonos-payment/zonos-payment.d.ts +10 -10
- package/dist/types/components/utils/addDays.d.ts +6 -6
- package/dist/types/components/utils/api/checkItemRestrictions.d.ts +14 -14
- package/dist/types/components/utils/api/getCountryLandedCost.d.ts +6 -6
- package/dist/types/components/utils/api/getExchangeRate.d.ts +17 -17
- package/dist/types/components/utils/api/getLocaleMessages.d.ts +15 -15
- package/dist/types/components/utils/api/getLocalization.d.ts +2 -2
- package/dist/types/components/utils/api/getZonosSettings.d.ts +8 -0
- package/dist/types/components/utils/api/triggerBuildLandedCost.d.ts +5 -0
- package/dist/types/components/utils/changeDeepProperty.d.ts +4 -4
- package/dist/types/components/utils/changeDeepPropertyAtIndex.d.ts +5 -5
- package/dist/types/components/utils/darkenColor.d.ts +2 -2
- package/dist/types/components/utils/formatCurrency.d.ts +3 -3
- package/dist/types/components/utils/formatDate.d.ts +6 -6
- package/dist/types/components/utils/handleFetch.d.ts +7 -7
- package/dist/types/components/utils/hello/detectItemRestrictions.d.ts +10 -10
- package/dist/types/components/utils/hello/getZCountryUrlParam.d.ts +2 -0
- package/dist/types/components/utils/hello/setZCountryUrlParam.d.ts +2 -0
- package/dist/types/components/utils/lightenColor.d.ts +2 -2
- package/dist/types/components/utils/mergeConfig.d.ts +1 -1
- package/dist/types/components/utils/submitGtag.d.ts +3 -3
- package/dist/types/components.d.ts +96 -0
- package/dist/types/environment.d.ts +39 -34
- package/dist/types/scripts/extractZonosQaUrl.d.ts +11 -0
- package/dist/types/scripts/stripe.d.ts +2 -2
- package/dist/types/scripts/zonos.d.ts +51 -40
- package/dist/types/stencil-public-runtime.d.ts +29 -0
- package/dist/types/styles/stripe/addressRuleStyle.d.ts +1 -1
- package/dist/types/styles/stripe/defaultVariable.d.ts +2 -2
- package/dist/types/types/ICountryJson.d.ts +20 -20
- package/dist/types/types/JsonError.d.ts +3 -3
- package/dist/types/types/Translation.d.ts +1 -1
- package/dist/types/types/checkout/CheckoutConfig.d.ts +55 -53
- package/dist/types/types/checkout/api/CalculateLandedCostRequest.d.ts +16 -16
- package/dist/types/types/generated/graphql.customer.types.d.ts +2217 -1970
- package/dist/types/types/generated/graphql.customer.types.ts +310 -7
- package/dist/types/types/generated/graphql.frontend.types.d.ts +649 -450
- package/dist/types/types/generated/graphql.frontend.types.ts +358 -11
- package/dist/types/types/global.d.ts +12 -0
- package/dist/types/types/hello/HelloConfig.d.ts +20 -20
- package/dist/types/types/hello/Product.d.ts +3 -3
- package/dist/types/types/hello/RestrictedItem.d.ts +1 -1
- package/dist/types/types/online-store/OnlineStoreConfig.d.ts +1 -1
- package/dist/types/types/stripe/Apperance.d.ts +3 -3
- package/dist/types/types/styles/Text.d.ts +90 -90
- package/dist/types/types/utils/deep/IDeepKeyof.d.ts +1 -1
- package/dist/types/types/utils/deep/IDeepKeyofAtIndex.d.ts +2 -2
- package/dist/types/utils/generateVercelDeployUrl.d.ts +2 -2
- package/dist/zonos-elements/assets/RemoveIcon.svg +1 -1
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/p-06fb9d1f.system.entry.js +1 -0
- package/dist/zonos-elements/{p-08695f4e.js → p-089ba905.js} +1 -1
- package/dist/zonos-elements/{p-f7875c40.js → p-1685c8df.js} +1 -1
- package/dist/zonos-elements/p-18904b7c.system.js +2 -0
- package/dist/zonos-elements/p-1d4a970b.entry.js +1 -0
- package/dist/zonos-elements/p-23e7c655.system.js +1 -1
- package/dist/zonos-elements/p-24eed2a8.system.js +1 -0
- package/dist/zonos-elements/p-24fbe845.system.js +1 -0
- package/dist/zonos-elements/p-2801d868.entry.js +1 -0
- package/dist/zonos-elements/p-2a307c55.system.entry.js +1 -0
- package/dist/zonos-elements/p-2f43da39.system.entry.js +1 -0
- package/dist/zonos-elements/{p-770c959e.js → p-3c6988d7.js} +1 -1
- package/dist/zonos-elements/p-3cea383b.system.entry.js +1 -0
- package/dist/zonos-elements/p-47390db7.system.entry.js +1 -0
- package/dist/zonos-elements/p-4846796a.js +1 -0
- package/dist/zonos-elements/p-494c77a7.entry.js +1 -0
- package/dist/zonos-elements/p-49f09b91.entry.js +1 -0
- package/dist/zonos-elements/p-4a15c5c7.system.entry.js +1 -0
- package/dist/zonos-elements/p-4bee0bff.system.entry.js +1 -0
- package/dist/zonos-elements/p-4d93275c.entry.js +1 -0
- package/dist/zonos-elements/p-4ed71bd7.entry.js +1 -0
- package/dist/zonos-elements/{p-bf070bf6.js → p-55f49f1e.js} +1 -1
- package/dist/zonos-elements/p-560aa686.system.entry.js +1 -0
- package/dist/zonos-elements/p-639396bb.entry.js +1 -0
- package/dist/zonos-elements/p-67154df2.system.entry.js +1 -0
- package/dist/zonos-elements/p-67aec665.entry.js +1 -0
- package/dist/zonos-elements/p-684ed483.entry.js +1 -0
- package/dist/zonos-elements/p-89c210d6.entry.js +1 -0
- package/dist/zonos-elements/p-8c48b75e.system.js +1 -0
- package/dist/zonos-elements/p-8c5595d9.system.entry.js +1 -0
- package/dist/zonos-elements/p-938803f4.entry.js +1 -0
- package/dist/zonos-elements/p-956efa27.js +2 -0
- package/dist/zonos-elements/{p-3f3fbcea.entry.js → p-a0e36ed3.entry.js} +1 -1
- package/dist/zonos-elements/p-a376a37f.entry.js +1 -0
- package/dist/zonos-elements/p-a504f64f.system.js +1 -0
- package/dist/zonos-elements/p-afe26069.entry.js +1 -0
- package/dist/zonos-elements/p-b4601210.system.entry.js +1 -0
- package/dist/zonos-elements/{p-164fae93.system.js → p-b51de536.system.js} +1 -1
- package/dist/zonos-elements/p-b6148206.entry.js +1 -0
- package/dist/zonos-elements/p-b85be1ab.system.js +1 -0
- package/dist/zonos-elements/p-bc7bf53e.system.js +1 -0
- package/dist/zonos-elements/p-c9348bb0.system.entry.js +1 -0
- package/dist/zonos-elements/p-d2217f09.system.js +1 -0
- package/dist/zonos-elements/p-d856a200.system.entry.js +1 -0
- package/dist/zonos-elements/{p-85ab35c9.system.js → p-da060b1c.system.js} +1 -1
- package/dist/zonos-elements/p-e1f6ab97.entry.js +1 -0
- package/dist/zonos-elements/p-e5ae22a9.system.entry.js +1 -0
- package/dist/zonos-elements/p-e98be2d0.system.entry.js +1 -0
- package/dist/zonos-elements/p-e9b832c5.entry.js +1 -0
- package/dist/zonos-elements/p-edbea8df.system.js +1 -0
- package/dist/zonos-elements/p-f141519c.system.entry.js +1 -0
- package/dist/zonos-elements/p-f367f2fe.system.entry.js +1 -0
- package/dist/zonos-elements/p-ff95f098.js +1 -0
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/dist/zonos-elements/zonos-elements.js +15 -15
- package/package.json +60 -58
- package/dist/cjs/cart-55512e32.js +0 -616
- package/dist/cjs/getBorderRadius-fdd605c6.js +0 -18
- package/dist/cjs/getHasMoreSpaceOnRight-2855491b.js +0 -10
- package/dist/cjs/isColorVariable-c1ed7303.js +0 -16
- package/dist/cjs/localization-d7fe7290.js +0 -3606
- package/dist/cjs/submitGtag-d65003f9.js +0 -27
- package/dist/collection/components/utils/api/getZonosSetting.js +0 -11
- package/dist/collection/components/utils/hello/setZonosCountryUrlParam.js +0 -9
- package/dist/esm/cart-17650017.js +0 -598
- package/dist/esm/getBorderRadius-45764ad7.js +0 -16
- package/dist/esm/getHasMoreSpaceOnRight-feba1ae2.js +0 -8
- package/dist/esm/isColorVariable-4cda28c9.js +0 -14
- package/dist/esm/localization-f3828793.js +0 -3592
- package/dist/esm/submitGtag-a901ece5.js +0 -24
- package/dist/esm-es5/cart-17650017.js +0 -1
- package/dist/esm-es5/getBorderRadius-45764ad7.js +0 -1
- package/dist/esm-es5/getHasMoreSpaceOnRight-feba1ae2.js +0 -1
- package/dist/esm-es5/index-d1aa9293.js +0 -2
- package/dist/esm-es5/zonosStore-05a62104.js +0 -1
- package/dist/types/components/utils/api/getZonosSetting.d.ts +0 -8
- package/dist/types/components/utils/hello/setZonosCountryUrlParam.d.ts +0 -2
- package/dist/zonos-elements/p-0190f7c4.entry.js +0 -1
- package/dist/zonos-elements/p-0e0b46a5.js +0 -1
- package/dist/zonos-elements/p-0ed3bb9f.system.entry.js +0 -1
- package/dist/zonos-elements/p-15b71f0b.system.entry.js +0 -1
- package/dist/zonos-elements/p-224125da.system.entry.js +0 -1
- package/dist/zonos-elements/p-23204b78.system.entry.js +0 -1
- package/dist/zonos-elements/p-28681677.entry.js +0 -1
- package/dist/zonos-elements/p-2b6325ab.entry.js +0 -1
- package/dist/zonos-elements/p-36425562.system.entry.js +0 -1
- package/dist/zonos-elements/p-3a56c240.entry.js +0 -1
- package/dist/zonos-elements/p-43a25dab.entry.js +0 -1
- package/dist/zonos-elements/p-4a5096d2.system.js +0 -1
- package/dist/zonos-elements/p-64fdb7b6.system.js +0 -1
- package/dist/zonos-elements/p-68d06767.system.js +0 -2
- package/dist/zonos-elements/p-6d82986c.system.entry.js +0 -1
- package/dist/zonos-elements/p-6dcd752e.system.js +0 -1
- package/dist/zonos-elements/p-6e7cd3f7.entry.js +0 -1
- package/dist/zonos-elements/p-7bacecf7.entry.js +0 -1
- package/dist/zonos-elements/p-824395fd.system.entry.js +0 -1
- package/dist/zonos-elements/p-8378d94e.js +0 -1
- package/dist/zonos-elements/p-84b00605.system.entry.js +0 -1
- package/dist/zonos-elements/p-8a75b765.system.entry.js +0 -1
- package/dist/zonos-elements/p-8aabbb9b.system.js +0 -1
- package/dist/zonos-elements/p-8b415737.system.entry.js +0 -1
- package/dist/zonos-elements/p-8c867835.system.js +0 -1
- package/dist/zonos-elements/p-9202375f.entry.js +0 -1
- package/dist/zonos-elements/p-9688bb12.entry.js +0 -1
- package/dist/zonos-elements/p-98a6e093.system.entry.js +0 -1
- package/dist/zonos-elements/p-a1fa50fb.entry.js +0 -1
- package/dist/zonos-elements/p-aca66238.system.entry.js +0 -1
- package/dist/zonos-elements/p-b618cf03.entry.js +0 -1
- package/dist/zonos-elements/p-b75ffe64.system.entry.js +0 -1
- package/dist/zonos-elements/p-bc2c42f5.entry.js +0 -1
- package/dist/zonos-elements/p-c8ad044e.system.entry.js +0 -1
- package/dist/zonos-elements/p-cc070c1c.entry.js +0 -1
- package/dist/zonos-elements/p-cc1c785c.system.entry.js +0 -1
- package/dist/zonos-elements/p-cd71e41e.entry.js +0 -1
- package/dist/zonos-elements/p-cf97cc68.system.entry.js +0 -1
- package/dist/zonos-elements/p-d6b8563b.system.entry.js +0 -1
- package/dist/zonos-elements/p-dc8d7000.js +0 -2
- package/dist/zonos-elements/p-e5908de2.entry.js +0 -1
- package/dist/zonos-elements/p-f6add79c.system.js +0 -1
- package/dist/zonos-elements/p-f8491335.system.js +0 -1
- package/dist/zonos-elements/p-f868ed42.entry.js +0 -1
- package/dist/zonos-elements/p-f95ac9ec.system.js +0 -1
- /package/dist/esm-es5/{isColorVariable-4cda28c9.js → isColorVariable-91c33804.js} +0 -0
- /package/dist/zonos-elements/{p-0636859b.js → p-4c414a92.js} +0 -0
- /package/dist/zonos-elements/{p-b6c499d4.js → p-5883217a.js} +0 -0
package/dist/components/cart.js
CHANGED
|
@@ -1,424 +1,452 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z as zonosStore, c as createStore } from './zonosStore.js';
|
|
2
2
|
import { h as handleFetch, l as logError, a as log, b as localizationStore, t as translate } from './localization.js';
|
|
3
3
|
import { i as isDarkColor } from './isDarkColor.js';
|
|
4
4
|
import { g as getBorderRadius } from './getBorderRadius.js';
|
|
5
5
|
|
|
6
6
|
const prepCalculateLandedCost = () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
7
|
+
// maybe we don't need email now for prefetch the landed cost
|
|
8
|
+
const stripeLinkData = stripeStore.stripeLinkEventData;
|
|
9
|
+
const stripeAddressData = stripeStore.stripeAddressEventData;
|
|
10
|
+
if (!stripeAddressData || !stripeAddressData.complete) {
|
|
11
|
+
throw new Error('Missing stripe address data');
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
checkoutSessionId: cartStore.checkoutSessionId || '',
|
|
15
|
+
contact: {
|
|
16
|
+
email: (stripeLinkData === null || stripeLinkData === void 0 ? void 0 : stripeLinkData.value.email) || '',
|
|
17
|
+
// firstName and lastName should be valid now since stripe only mark
|
|
18
|
+
// the address as complete when both fields are filled.
|
|
19
|
+
firstName: stripeAddressData.value.firstName || '',
|
|
20
|
+
lastName: stripeAddressData.value.lastName || '',
|
|
21
|
+
phone: stripeAddressData.value.phone || '',
|
|
22
|
+
},
|
|
23
|
+
items: cartStore.items.map(item => item),
|
|
24
|
+
shippingAddress: {
|
|
25
|
+
addressLine1: stripeAddressData.value.address.line1,
|
|
26
|
+
addressLine2: stripeAddressData.value.address.line2 || '',
|
|
27
|
+
city: stripeAddressData.value.address.city,
|
|
28
|
+
country: stripeAddressData.value.address.country,
|
|
29
|
+
postalCode: stripeAddressData.value.address.postal_code,
|
|
30
|
+
state: stripeAddressData.value.address.state,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const triggerBuildLandedCost = async (buildLandedCost) => {
|
|
36
|
+
var _a;
|
|
37
|
+
const data = prepCalculateLandedCost();
|
|
38
|
+
const landedCost = await buildLandedCost(data.checkoutSessionId, data.contact, data.shippingAddress);
|
|
39
|
+
if (!landedCost) {
|
|
40
|
+
throw new Error('Failed to build landed cost');
|
|
41
|
+
}
|
|
42
|
+
// Validate the landed cost object to make sure the returned value from buildLandedCost has a valid schema
|
|
43
|
+
const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/validate-landed-cost`, {
|
|
44
|
+
body: landedCost,
|
|
45
|
+
headers: {
|
|
46
|
+
'Content-Type': 'application/json',
|
|
47
|
+
},
|
|
48
|
+
method: 'POST',
|
|
49
|
+
});
|
|
50
|
+
if (!json || errors.length) {
|
|
51
|
+
throw new Error(`Invalid landed cost object: ${((_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message) || 'Unknown error'}`);
|
|
52
|
+
}
|
|
53
|
+
return landedCost;
|
|
33
54
|
};
|
|
34
55
|
|
|
35
56
|
const calculateLandedCost = async (abortController) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
// If buildLandedCost callback is supplied, use that instead of our regular request to '/calculate-landed-cost'
|
|
58
|
+
const buildLandedCost = zonosStore.checkoutSettings.buildLandedCost;
|
|
59
|
+
if (buildLandedCost) {
|
|
60
|
+
const json = await triggerBuildLandedCost(buildLandedCost);
|
|
61
|
+
return json;
|
|
62
|
+
}
|
|
63
|
+
// request to get landed cost info
|
|
64
|
+
const url = `${"https://v1.route.js.zonos.com"}/api/zonos-elements/calculate-landed-cost`;
|
|
65
|
+
const { errors, json } = await handleFetch(url, {
|
|
66
|
+
body: prepCalculateLandedCost(),
|
|
67
|
+
method: 'POST',
|
|
68
|
+
signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
|
|
69
|
+
});
|
|
70
|
+
if (errors.length || !json) {
|
|
71
|
+
throw new Error('Failed to calculate landed cost');
|
|
72
|
+
}
|
|
73
|
+
return json;
|
|
47
74
|
};
|
|
48
75
|
|
|
49
76
|
const addressRuleStyle = ({ theme, }) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
77
|
+
switch (theme) {
|
|
78
|
+
default:
|
|
79
|
+
return {
|
|
80
|
+
'.Input': {
|
|
81
|
+
// need to reset everything and the paddingTop to default, otherwise the paddingTop will not be updated.
|
|
82
|
+
padding: '0',
|
|
83
|
+
paddingBottom: '8px',
|
|
84
|
+
paddingLeft: '16px',
|
|
85
|
+
paddingRight: '8px',
|
|
86
|
+
// any value here will be add up to the default paddingTop (20px).
|
|
87
|
+
paddingTop: '6px',
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
64
91
|
};
|
|
65
92
|
|
|
66
93
|
const defaultVariable = ({ borderStyle, theme, }) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
94
|
+
switch (theme) {
|
|
95
|
+
case 'DARK':
|
|
96
|
+
return {
|
|
97
|
+
borderRadius: getBorderRadius(borderStyle),
|
|
98
|
+
colorBackground: '#101117',
|
|
99
|
+
colorBackgroundText: '#C5C6CA',
|
|
100
|
+
colorText: '#C5C6CA',
|
|
101
|
+
colorTextPlaceholder: '#C5C6CA',
|
|
102
|
+
};
|
|
103
|
+
default:
|
|
104
|
+
return {
|
|
105
|
+
borderRadius: getBorderRadius(borderStyle),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
81
108
|
};
|
|
82
109
|
|
|
83
110
|
const { onChange: onChange$1, reset: reset$1, state: stripeStore, } = createStore(() => ({
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
111
|
+
clientSecret: sessionStorage.getItem('zonos--client-secret') || null,
|
|
112
|
+
fetchingLandedCostAbordController: null,
|
|
113
|
+
isFetchingLandedCost: false,
|
|
114
|
+
isFetchingSession: false,
|
|
115
|
+
stripe: null,
|
|
116
|
+
stripeAddressElement: null,
|
|
117
|
+
stripeAddressEventData: null,
|
|
118
|
+
stripeAddressUsedWhenFetchingLC: null,
|
|
119
|
+
stripeBillingAddressElement: null,
|
|
120
|
+
stripeElements: null,
|
|
121
|
+
stripeElementsOptions: null,
|
|
122
|
+
stripeLinkElement: null,
|
|
123
|
+
stripeLinkEventData: null,
|
|
124
|
+
stripeLinkUsedWhenFetchingLC: null,
|
|
125
|
+
stripePaymentElement: null,
|
|
126
|
+
stripePaymentEventData: null,
|
|
99
127
|
}));
|
|
100
128
|
const getStripeOptions = ({ clientSecret, overrideBorderRaidus, overridePrimaryColor, overrideTheme, }) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
129
|
+
const primaryColor = overridePrimaryColor || zonosStore.appearance.colorPrimary;
|
|
130
|
+
const themeBasedColor = primaryColor && isDarkColor(primaryColor) ? 'night' : 'flat';
|
|
131
|
+
// if overrideTheme is provided, use it. Otherwise, use theme based on primary color
|
|
132
|
+
const theme = overrideTheme === 'DARK' ? 'night' : 'flat';
|
|
133
|
+
return {
|
|
134
|
+
appearance: {
|
|
135
|
+
labels: 'floating',
|
|
136
|
+
rules: Object.assign({}, addressRuleStyle({ theme: 'LIGHT' })),
|
|
137
|
+
// get contrast theme color base on primary color
|
|
138
|
+
theme: overrideTheme ? theme : themeBasedColor,
|
|
139
|
+
variables: Object.assign({}, defaultVariable({
|
|
140
|
+
borderStyle: overrideBorderRaidus,
|
|
141
|
+
theme: 'LIGHT',
|
|
142
|
+
})),
|
|
143
|
+
},
|
|
144
|
+
clientSecret,
|
|
145
|
+
locale: localizationStore.selectedLocale,
|
|
146
|
+
};
|
|
119
147
|
};
|
|
120
148
|
const initStripeElements = async (props) => {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
149
|
+
var _a;
|
|
150
|
+
const clientSecret = stripeStore.clientSecret;
|
|
151
|
+
if (!stripeStore.stripe) {
|
|
152
|
+
log('Skip. Stripe is not initialized');
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (clientSecret) {
|
|
156
|
+
const stripeOptions = getStripeOptions({
|
|
157
|
+
clientSecret,
|
|
158
|
+
overrideBorderRaidus: props === null || props === void 0 ? void 0 : props.overrideBorderRaidus,
|
|
159
|
+
overridePrimaryColor: props === null || props === void 0 ? void 0 : props.overridePrimaryColor,
|
|
160
|
+
overrideTheme: props === null || props === void 0 ? void 0 : props.overrideTheme,
|
|
161
|
+
});
|
|
162
|
+
// compare with the previous options to see if we need to update
|
|
163
|
+
const isSameOptions = JSON.stringify(stripeOptions) ===
|
|
164
|
+
JSON.stringify(stripeStore.stripeElementsOptions);
|
|
165
|
+
if (!stripeStore.stripeElements) {
|
|
166
|
+
// init stripe elements if it doesn't exist
|
|
167
|
+
stripeStore.stripeElements = (_a = stripeStore.stripe) === null || _a === void 0 ? void 0 : _a.elements(stripeOptions);
|
|
168
|
+
// save stripe elements options for later comparison
|
|
169
|
+
stripeStore.stripeElementsOptions = stripeOptions;
|
|
170
|
+
log('Stripe elements initialized');
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (!isSameOptions) {
|
|
174
|
+
// update elements with new option if it already exists
|
|
175
|
+
stripeStore.stripeElements.update(stripeOptions);
|
|
176
|
+
// save stripe elements options for later comparison
|
|
177
|
+
stripeStore.stripeElementsOptions = stripeOptions;
|
|
178
|
+
}
|
|
179
|
+
log('Stripe elements initialized');
|
|
180
|
+
}
|
|
153
181
|
};
|
|
154
182
|
const stripeStoreReset = () => {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
183
|
+
// clean clientSecret so that we can start the new one.
|
|
184
|
+
sessionStorage.removeItem('zonos--client-secret');
|
|
185
|
+
// cleanup stripe elements
|
|
186
|
+
reset$1();
|
|
187
|
+
// set stripe back to window.Zonos.stripe
|
|
188
|
+
stripeStore.stripe = window.Zonos.stripe;
|
|
161
189
|
};
|
|
162
190
|
/**
|
|
163
191
|
* Check if the address and email info used when fetching landed cost with the current email and address info are different
|
|
164
192
|
* Purpose is to resend the request if the info used when fetching landed cost is different from the current info
|
|
165
193
|
*/
|
|
166
194
|
const isPrefetchInfoOutdated = () => {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
195
|
+
var _a, _b, _c, _d;
|
|
196
|
+
const hasAbortController = stripeStore.fetchingLandedCostAbordController;
|
|
197
|
+
if (!hasAbortController) {
|
|
198
|
+
// if there is no abort controller, this is a new request
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
const isLinkDataDirty = JSON.stringify((_a = stripeStore.stripeLinkUsedWhenFetchingLC) === null || _a === void 0 ? void 0 : _a.value) !==
|
|
202
|
+
JSON.stringify((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.value);
|
|
203
|
+
const isAddressDataDirty = JSON.stringify((_c = stripeStore.stripeAddressUsedWhenFetchingLC) === null || _c === void 0 ? void 0 : _c.value) !==
|
|
204
|
+
JSON.stringify((_d = stripeStore.stripeAddressEventData) === null || _d === void 0 ? void 0 : _d.value);
|
|
205
|
+
return isLinkDataDirty || isAddressDataDirty;
|
|
178
206
|
};
|
|
179
207
|
const stripeStorePrefetchLandedCost = async () => {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
// only fetch if we are not fetching or we need to refetch
|
|
190
|
-
if (stripeAddressReady &&
|
|
191
|
-
stripeLinkReady &&
|
|
192
|
-
(shouldRefetch || !stripeStore.isFetchingLandedCost)) {
|
|
193
|
-
stripeStore.isFetchingLandedCost = true;
|
|
194
|
-
if (stripeStore.stripeAddressEventData) {
|
|
195
|
-
stripeStore.stripeAddressUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeAddressEventData);
|
|
196
|
-
}
|
|
197
|
-
if (stripeStore.stripeLinkEventData) {
|
|
198
|
-
stripeStore.stripeLinkUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeLinkEventData);
|
|
199
|
-
}
|
|
200
|
-
try {
|
|
201
|
-
const abortController = new AbortController();
|
|
202
|
-
stripeStore.fetchingLandedCostAbordController = abortController;
|
|
203
|
-
const { checkoutSessionWorkflow, shipmentRatingCalculateWorkflow } = await calculateLandedCost(abortController);
|
|
204
|
-
// reset abort controller after we are done
|
|
205
|
-
stripeStore.fetchingLandedCostAbordController = null;
|
|
206
|
-
// update cart store with landed cost info
|
|
207
|
-
cartStore.landedCostData =
|
|
208
|
-
(checkoutSessionWorkflow === null || checkoutSessionWorkflow === void 0 ? void 0 : checkoutSessionWorkflow.filter(Boolean)) || null;
|
|
209
|
-
cartStore.shippingData =
|
|
210
|
-
(shipmentRatingCalculateWorkflow === null || shipmentRatingCalculateWorkflow === void 0 ? void 0 : shipmentRatingCalculateWorkflow.filter(Boolean)) || null;
|
|
211
|
-
// apply new subtotal and total, this is mainly to show items in the presentment currency
|
|
212
|
-
const firstLandedCostData = (_d = cartStore.landedCostData) === null || _d === void 0 ? void 0 : _d.find(Boolean);
|
|
213
|
-
const subtotals = !!firstLandedCostData
|
|
214
|
-
? firstLandedCostData.subtotals
|
|
215
|
-
: null;
|
|
216
|
-
if (subtotals) {
|
|
217
|
-
// prefetch landed cost will not update shipping and taxes since we haven't selected shipping method yet
|
|
218
|
-
cartStoreApplySubtotals({
|
|
219
|
-
exchangeRate: subtotals.exchangeRate,
|
|
220
|
-
items: subtotals.items,
|
|
221
|
-
landedCostTotal: 0,
|
|
222
|
-
presentmentCurrencyCode: subtotals.presentmentCurrencyCode,
|
|
223
|
-
shipping: 0,
|
|
224
|
-
total: subtotals.items,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
208
|
+
var _a, _b, _c, _d;
|
|
209
|
+
const stripeAddressReady = !!((_a = stripeStore.stripeAddressEventData) === null || _a === void 0 ? void 0 : _a.complete);
|
|
210
|
+
const stripeLinkReady = !!((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.complete);
|
|
211
|
+
const shouldRefetch = isPrefetchInfoOutdated();
|
|
212
|
+
if (shouldRefetch) {
|
|
213
|
+
// if the info used when fetching landed cost is different from the current info, abort the previous request
|
|
214
|
+
(_c = stripeStore.fetchingLandedCostAbordController) === null || _c === void 0 ? void 0 : _c.abort();
|
|
215
|
+
stripeStore.fetchingLandedCostAbordController = null;
|
|
227
216
|
}
|
|
228
|
-
|
|
229
|
-
|
|
217
|
+
// only fetch if we are not fetching or we need to refetch
|
|
218
|
+
if (stripeAddressReady &&
|
|
219
|
+
stripeLinkReady &&
|
|
220
|
+
(shouldRefetch || !stripeStore.isFetchingLandedCost)) {
|
|
221
|
+
stripeStore.isFetchingLandedCost = true;
|
|
222
|
+
if (stripeStore.stripeAddressEventData) {
|
|
223
|
+
stripeStore.stripeAddressUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeAddressEventData);
|
|
224
|
+
}
|
|
225
|
+
if (stripeStore.stripeLinkEventData) {
|
|
226
|
+
stripeStore.stripeLinkUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeLinkEventData);
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
const abortController = new AbortController();
|
|
230
|
+
stripeStore.fetchingLandedCostAbordController = abortController;
|
|
231
|
+
const { checkoutSessionWorkflow, shipmentRatingCalculateWorkflow } = await calculateLandedCost(abortController);
|
|
232
|
+
// reset abort controller after we are done
|
|
233
|
+
stripeStore.fetchingLandedCostAbordController = null;
|
|
234
|
+
// update cart store with landed cost info
|
|
235
|
+
cartStore.landedCostData =
|
|
236
|
+
(checkoutSessionWorkflow === null || checkoutSessionWorkflow === void 0 ? void 0 : checkoutSessionWorkflow.filter(Boolean)) || null;
|
|
237
|
+
cartStore.shippingData =
|
|
238
|
+
(shipmentRatingCalculateWorkflow === null || shipmentRatingCalculateWorkflow === void 0 ? void 0 : shipmentRatingCalculateWorkflow.filter(Boolean)) || null;
|
|
239
|
+
// apply new subtotal and total, this is mainly to show items in the presentment currency
|
|
240
|
+
const firstLandedCostData = (_d = cartStore.landedCostData) === null || _d === void 0 ? void 0 : _d.find(Boolean);
|
|
241
|
+
const subtotals = !!firstLandedCostData
|
|
242
|
+
? firstLandedCostData.subtotals
|
|
243
|
+
: null;
|
|
244
|
+
if (subtotals) {
|
|
245
|
+
// prefetch landed cost will not update shipping and taxes since we haven't selected shipping method yet
|
|
246
|
+
cartStoreApplySubtotals({
|
|
247
|
+
exchangeRate: subtotals.exchangeRate,
|
|
248
|
+
items: subtotals.items,
|
|
249
|
+
landedCostTotal: 0,
|
|
250
|
+
presentmentCurrencyCode: subtotals.presentmentCurrencyCode,
|
|
251
|
+
shipping: 0,
|
|
252
|
+
total: subtotals.items,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
catch (err) {
|
|
257
|
+
logError(err);
|
|
258
|
+
}
|
|
259
|
+
stripeStore.isFetchingLandedCost = false;
|
|
230
260
|
}
|
|
231
|
-
stripeStore.isFetchingLandedCost = false;
|
|
232
|
-
}
|
|
233
261
|
};
|
|
234
262
|
const getStripeMessageBasedOnStatus = (status) => {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
263
|
+
let messages = [];
|
|
264
|
+
let isError = true;
|
|
265
|
+
// Inspect the PaymentIntent `status` to indicate the status of the payment
|
|
266
|
+
// to your customer.
|
|
267
|
+
//
|
|
268
|
+
// Some payment methods will [immediately succeed or fail][0] upon
|
|
269
|
+
// confirmation, while others will first enter a `processing` state.
|
|
270
|
+
//
|
|
271
|
+
// [0]: https://stripe.com/docs/payments/payment-methods#payment-notification
|
|
272
|
+
switch (status) {
|
|
273
|
+
case 'succeeded': {
|
|
274
|
+
messages = [
|
|
275
|
+
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.'),
|
|
276
|
+
'',
|
|
277
|
+
'',
|
|
278
|
+
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."),
|
|
279
|
+
];
|
|
280
|
+
isError = false;
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
case 'requires_capture':
|
|
284
|
+
case 'processing': {
|
|
285
|
+
messages = [
|
|
286
|
+
translate("Payment processing. We'll update you when payment is received."),
|
|
287
|
+
];
|
|
288
|
+
isError = false;
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
case 'requires_payment_method': {
|
|
292
|
+
messages = [
|
|
293
|
+
translate('Payment failed. Please try another payment method.'),
|
|
294
|
+
];
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
default: {
|
|
298
|
+
messages = [translate('Something went wrong.')];
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
isError,
|
|
304
|
+
messages,
|
|
305
|
+
};
|
|
278
306
|
};
|
|
279
307
|
const stripeStoreRetrievePayment = async ({ clientSecret: _clientSecret, storybookForceStatus, }) => {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
308
|
+
if (storybookForceStatus) {
|
|
309
|
+
// return status right away if we are in storybook mode
|
|
310
|
+
const { isError, messages } = getStripeMessageBasedOnStatus(storybookForceStatus);
|
|
311
|
+
return { error: isError, messages };
|
|
312
|
+
}
|
|
313
|
+
const clientSecret = _clientSecret || stripeStore.clientSecret;
|
|
314
|
+
if (!stripeStore.stripe || !clientSecret) {
|
|
315
|
+
logError('Failed to retrieve payment intent. Stripe is not initialized');
|
|
316
|
+
return { error: true, message: [translate('Something went wrong.')] };
|
|
317
|
+
}
|
|
318
|
+
const { paymentIntent } = await stripeStore.stripe.retrievePaymentIntent(clientSecret);
|
|
319
|
+
const status = paymentIntent === null || paymentIntent === void 0 ? void 0 : paymentIntent.status;
|
|
320
|
+
const { isError, messages } = getStripeMessageBasedOnStatus(status);
|
|
283
321
|
return { error: isError, messages };
|
|
284
|
-
}
|
|
285
|
-
const clientSecret = _clientSecret || stripeStore.clientSecret;
|
|
286
|
-
if (!stripeStore.stripe || !clientSecret) {
|
|
287
|
-
logError('Failed to retrieve payment intent. Stripe is not initialized');
|
|
288
|
-
return { error: true, message: [translate('Something went wrong.')] };
|
|
289
|
-
}
|
|
290
|
-
const { paymentIntent } = await stripeStore.stripe.retrievePaymentIntent(clientSecret);
|
|
291
|
-
const status = paymentIntent === null || paymentIntent === void 0 ? void 0 : paymentIntent.status;
|
|
292
|
-
const { isError, messages } = getStripeMessageBasedOnStatus(status);
|
|
293
|
-
return { error: isError, messages };
|
|
294
322
|
};
|
|
295
323
|
const stripeStoreConfirmPayment = async () => {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
324
|
+
var _a, _b, _c;
|
|
325
|
+
const stripePaymentReady = !!((_a = stripeStore.stripePaymentEventData) === null || _a === void 0 ? void 0 : _a.complete);
|
|
326
|
+
const stripeElements = stripeStore.stripeElements;
|
|
327
|
+
const stripe = stripeStore.stripe;
|
|
328
|
+
const stripeClientSecret = stripeStore.clientSecret;
|
|
329
|
+
if (stripe && stripeElements && stripePaymentReady && stripeClientSecret) {
|
|
330
|
+
const { error } = await stripe.confirmPayment({
|
|
331
|
+
confirmParams: {
|
|
332
|
+
receipt_email: (_c = (_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.email,
|
|
333
|
+
return_url: window.location.href,
|
|
334
|
+
},
|
|
335
|
+
elements: stripeElements,
|
|
336
|
+
redirect: 'if_required',
|
|
337
|
+
});
|
|
338
|
+
if (error) {
|
|
339
|
+
if (error.type === 'card_error' || error.type === 'validation_error') {
|
|
340
|
+
throw new Error(error.message);
|
|
341
|
+
}
|
|
342
|
+
if (error.type === 'invalid_request_error') {
|
|
343
|
+
if (error.code === 'payment_intent_unexpected_state') {
|
|
344
|
+
// PaymentIntent was canceled or expired, or status is `require_capture`.
|
|
345
|
+
// don't throw error here because we will reset the checkout session last step
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
throw new Error('An unexpected error occurred.');
|
|
319
350
|
}
|
|
320
|
-
}
|
|
321
|
-
throw new Error('An unexpected error occurred.');
|
|
322
351
|
}
|
|
323
|
-
}
|
|
324
352
|
};
|
|
325
353
|
/**
|
|
326
354
|
* Init checkout session
|
|
327
355
|
* @returns {boolean} whether or not the checkout session is successfully created
|
|
328
356
|
*/
|
|
329
357
|
const stripeStoreInitCheckoutSession = async () => {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
+
var _a;
|
|
359
|
+
const total = cartStore.items.reduce((amount, item) => amount + item.amount * item.quantity, 0);
|
|
360
|
+
if (!total || !localizationStore.targetCurrency) {
|
|
361
|
+
logError('Fail to create checkout session - invalid total or currency');
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
stripeStore.isFetchingSession = true;
|
|
365
|
+
const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/create-checkout-session`, {
|
|
366
|
+
body: {
|
|
367
|
+
currency: ((_a = cartStore.items.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode) || '',
|
|
368
|
+
itemsAmount: total,
|
|
369
|
+
presentmentCountryCode: localizationStore.selectedCountryCode || null,
|
|
370
|
+
},
|
|
371
|
+
method: 'POST',
|
|
372
|
+
});
|
|
373
|
+
stripeStore.isFetchingSession = false;
|
|
374
|
+
if (errors.length || !json) {
|
|
375
|
+
logError('Error occurs when creating checkout session', JSON.stringify(errors, null, 2));
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
const result = json.checkoutSessionCreate;
|
|
379
|
+
stripeStore.clientSecret = result.clientSecret;
|
|
380
|
+
// update cart store with updated informations
|
|
381
|
+
cartStore.checkoutSessionId = result.id;
|
|
382
|
+
cartStoreApplySubtotals(Object.assign(Object.assign({}, result.subtotals), { landedCostTotal: 0, shipping: 0, total: result.subtotals.items }));
|
|
383
|
+
log('Exchange rate updated for cart items (checkout session create)', 'info', cartStore.exchangeRate);
|
|
384
|
+
log('done-init-checkout-session');
|
|
385
|
+
return true;
|
|
358
386
|
};
|
|
359
387
|
/**
|
|
360
388
|
* Update checkout session. Use for updating amount with landed cost id, or update session when cart items change
|
|
361
389
|
*/
|
|
362
390
|
const stripeStoreUpdateCheckoutSession = async ({ currency, id, itemsAmount, landedCostId, presentmentCountryCode, }) => {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
391
|
+
// No need to set loading state here because this function will be called under the hood to update
|
|
392
|
+
// landed cost id for the section.
|
|
393
|
+
const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/update-checkout-session`, {
|
|
394
|
+
body: {
|
|
395
|
+
currency,
|
|
396
|
+
id,
|
|
397
|
+
itemsAmount,
|
|
398
|
+
landedCostId,
|
|
399
|
+
presentmentCountryCode,
|
|
400
|
+
},
|
|
401
|
+
method: 'POST',
|
|
402
|
+
});
|
|
403
|
+
if (errors.length || !json) {
|
|
404
|
+
logError('Error occurs when updating checkout session', JSON.stringify(errors, null, 2));
|
|
405
|
+
return { errors, json };
|
|
406
|
+
}
|
|
407
|
+
return { errors: [], json };
|
|
380
408
|
};
|
|
381
409
|
onChange$1('clientSecret', clientSecret => {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
410
|
+
// update stripe elements when client secret changes
|
|
411
|
+
if (clientSecret && stripeStore.stripe) {
|
|
412
|
+
sessionStorage.setItem('zonos--client-secret', clientSecret);
|
|
413
|
+
}
|
|
414
|
+
if (!clientSecret) {
|
|
415
|
+
sessionStorage.removeItem('zonos--client-secret');
|
|
416
|
+
}
|
|
389
417
|
});
|
|
390
418
|
|
|
391
419
|
const formatDate = ({ date, formatOptions = { day: 'numeric', weekday: 'long', year: 'numeric' }, }) => {
|
|
392
|
-
|
|
393
|
-
|
|
420
|
+
// format date to Thursday 3, 2023
|
|
421
|
+
return new Intl.DateTimeFormat('en-US', formatOptions).format(date);
|
|
394
422
|
};
|
|
395
423
|
|
|
396
424
|
const getDaysDifference = (targetDate) => {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
425
|
+
const currentDate = new Date();
|
|
426
|
+
const timeDifference = targetDate.getTime() - currentDate.getTime();
|
|
427
|
+
const daysDifference = Math.floor(timeDifference / (1000 * 60 * 60 * 24)); // Convert milliseconds to days
|
|
428
|
+
return daysDifference;
|
|
401
429
|
};
|
|
402
430
|
|
|
403
431
|
const { onChange, reset, state: cartStore, } = createStore(() => ({
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
432
|
+
checkoutSessionId: sessionStorage.getItem('zonos--checkout-session-id') || null,
|
|
433
|
+
currency: 'USD',
|
|
434
|
+
dutiesTaxFees: 0,
|
|
435
|
+
error: null,
|
|
436
|
+
exchangeRate: null,
|
|
437
|
+
isSelectedShippingAboveDeminimis: false,
|
|
438
|
+
isSelectedShippingGuarantee: false,
|
|
439
|
+
items: [],
|
|
440
|
+
landedCostData: null,
|
|
441
|
+
selectedLandedCost: null,
|
|
442
|
+
selectedShippingOption: null,
|
|
443
|
+
selectedShippingOptionExpectedDate: '',
|
|
444
|
+
selectedShippingOptionTransitTime: '',
|
|
445
|
+
shipping: 0,
|
|
446
|
+
shippingData: null,
|
|
447
|
+
step: 'customer-info',
|
|
448
|
+
subtotal: 0,
|
|
449
|
+
total: 0,
|
|
422
450
|
}));
|
|
423
451
|
/**
|
|
424
452
|
* Format shipping transit info to be displayed on UI
|
|
@@ -428,171 +456,171 @@ const { onChange, reset, state: cartStore, } = createStore(() => ({
|
|
|
428
456
|
* - minTransit: 3
|
|
429
457
|
*/
|
|
430
458
|
const cartStoreGetShippingTransitInfo = (item) => {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
459
|
+
const minTransit = item.minTransitAt
|
|
460
|
+
? getDaysDifference(new Date(item.minTransitAt))
|
|
461
|
+
: '';
|
|
462
|
+
const maxTransit = item.maxTransitAt
|
|
463
|
+
? getDaysDifference(new Date(item.maxTransitAt))
|
|
464
|
+
: '';
|
|
465
|
+
const expectedDate = item.minTransitAt
|
|
466
|
+
? formatDate({
|
|
467
|
+
date: new Date(item.minTransitAt),
|
|
468
|
+
})
|
|
469
|
+
: '';
|
|
470
|
+
return {
|
|
471
|
+
expectedDate,
|
|
472
|
+
maxTransit,
|
|
473
|
+
minTransit,
|
|
474
|
+
};
|
|
447
475
|
};
|
|
448
476
|
const cartStoreReset = () => {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
477
|
+
sessionStorage.removeItem('zonos--checkout-session-id');
|
|
478
|
+
// reset cart store
|
|
479
|
+
reset();
|
|
452
480
|
};
|
|
453
481
|
const cartStoreUpdateToErrorState = ({ messages, title, }) => {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
482
|
+
cartStore.step = 'error';
|
|
483
|
+
cartStore.error = {
|
|
484
|
+
messages,
|
|
485
|
+
title,
|
|
486
|
+
};
|
|
459
487
|
};
|
|
460
488
|
const cartStoreApplySubtotals = (subtotals) => {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
489
|
+
// update exchange rate so we can use it to display cart items
|
|
490
|
+
cartStore.exchangeRate = subtotals.exchangeRate;
|
|
491
|
+
cartStore.dutiesTaxFees = subtotals.landedCostTotal;
|
|
492
|
+
cartStore.subtotal = subtotals.items;
|
|
493
|
+
cartStore.total = subtotals.total;
|
|
494
|
+
cartStore.currency = subtotals.presentmentCurrencyCode;
|
|
467
495
|
};
|
|
468
496
|
const cartStoreReCalculateTotal = async ({ currency, itemsAmount, landedCostId, }) => {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
});
|
|
487
|
-
if (!json) {
|
|
488
|
-
// do nothing if we can't get checkout session
|
|
489
|
-
logError('Error occurs when updating checkout session');
|
|
490
|
-
cartStoreUpdateToErrorState({
|
|
491
|
-
messages: [
|
|
492
|
-
translate("There's been an error updating your checkout session. Please reload and try again or contact support if the error persists"),
|
|
493
|
-
],
|
|
494
|
-
title: translate('Error updating Checkout'),
|
|
497
|
+
if (landedCostId && cartStore.selectedLandedCost) {
|
|
498
|
+
// update cart total right away if we have landed cost id to avoid order total flickering
|
|
499
|
+
const subtotals = cartStore.selectedLandedCost.subtotals;
|
|
500
|
+
cartStoreApplySubtotals(subtotals);
|
|
501
|
+
log('Exchange rate updated for cart items (landed cost subtotal)', 'info', cartStore.exchangeRate);
|
|
502
|
+
}
|
|
503
|
+
// update checkout session
|
|
504
|
+
if (!cartStore.checkoutSessionId) {
|
|
505
|
+
logError('Could not update cart total without checkout session id');
|
|
506
|
+
return false;
|
|
507
|
+
}
|
|
508
|
+
const { json } = await stripeStoreUpdateCheckoutSession({
|
|
509
|
+
currency,
|
|
510
|
+
id: cartStore.checkoutSessionId,
|
|
511
|
+
itemsAmount,
|
|
512
|
+
landedCostId,
|
|
513
|
+
presentmentCountryCode: localizationStore.selectedCountryCode,
|
|
495
514
|
});
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
515
|
+
if (!json) {
|
|
516
|
+
// do nothing if we can't get checkout session
|
|
517
|
+
logError('Error occurs when updating checkout session');
|
|
518
|
+
cartStoreUpdateToErrorState({
|
|
519
|
+
messages: [
|
|
520
|
+
translate("There's been an error updating your checkout session. Please reload and try again or contact support if the error persists"),
|
|
521
|
+
],
|
|
522
|
+
title: translate('Error updating Checkout'),
|
|
523
|
+
});
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
if (!landedCostId) {
|
|
527
|
+
// This is when first open the checkout modal and we just want to get info from the old cart session.
|
|
528
|
+
// use subtotals from checkout session to update cart total
|
|
529
|
+
cartStoreApplySubtotals(json.checkoutSessionUpdate.subtotals);
|
|
530
|
+
log('Exchange rate updated for cart items (checkout session update)', 'info', cartStore.exchangeRate);
|
|
531
|
+
}
|
|
532
|
+
return true;
|
|
505
533
|
};
|
|
506
534
|
const cartStoreUpdateSelectedShippingOption = async (selectedShippingOption) => {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
535
|
+
var _a, _b, _c, _d, _e;
|
|
536
|
+
cartStore.selectedShippingOption = selectedShippingOption;
|
|
537
|
+
// update shipping transit info
|
|
538
|
+
const { expectedDate, maxTransit, minTransit } = cartStoreGetShippingTransitInfo(cartStore.selectedShippingOption);
|
|
539
|
+
cartStore.selectedShippingOptionExpectedDate = expectedDate;
|
|
540
|
+
cartStore.selectedShippingOptionTransitTime =
|
|
541
|
+
minTransit && maxTransit
|
|
542
|
+
? `${minTransit}-${maxTransit}`
|
|
543
|
+
: `${minTransit || maxTransit}`;
|
|
544
|
+
const selectedLandedCost = (_a = cartStore.landedCostData) === null || _a === void 0 ? void 0 : _a.find(checkoutSessionPresentment => {
|
|
545
|
+
var _a, _b, _c;
|
|
546
|
+
return ((_b = (_a = checkoutSessionPresentment.landedCost) === null || _a === void 0 ? void 0 : _a.shipmentRating) === null || _b === void 0 ? void 0 : _b.id) ===
|
|
547
|
+
((_c = cartStore.selectedShippingOption) === null || _c === void 0 ? void 0 : _c.id);
|
|
548
|
+
});
|
|
549
|
+
// save selected landed cost for later use
|
|
550
|
+
cartStore.selectedLandedCost = selectedLandedCost || null;
|
|
551
|
+
if (!selectedLandedCost) {
|
|
552
|
+
// do nothing if we can't find landed cost for selected shipping option
|
|
553
|
+
return false;
|
|
554
|
+
}
|
|
555
|
+
// update shipping value and dutiesTaxFees on selectedShippingOption change
|
|
556
|
+
cartStore.shipping = selectedLandedCost.subtotals.shipping;
|
|
557
|
+
// update deminimis status
|
|
558
|
+
const isGuarantee = ((_b = selectedLandedCost === null || selectedLandedCost === void 0 ? void 0 : selectedLandedCost.landedCost) === null || _b === void 0 ? void 0 : _b.landedCostGuaranteeCode) === 'ZONOS';
|
|
559
|
+
// one item in deminimis with type of duty and tax has threshold value is "ABOVE"
|
|
560
|
+
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'));
|
|
561
|
+
cartStore.isSelectedShippingAboveDeminimis = isAboveDeminimis;
|
|
562
|
+
cartStore.isSelectedShippingGuarantee = isGuarantee;
|
|
563
|
+
// update session with selected landed cost
|
|
564
|
+
const updateCalulateStatus = await cartStoreReCalculateTotal({
|
|
565
|
+
landedCostId: (_e = selectedLandedCost.landedCost) === null || _e === void 0 ? void 0 : _e.id,
|
|
566
|
+
});
|
|
567
|
+
return updateCalulateStatus;
|
|
540
568
|
};
|
|
541
569
|
onChange('checkoutSessionId', () => {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
570
|
+
if (!cartStore.checkoutSessionId) {
|
|
571
|
+
sessionStorage.removeItem('zonos--checkout-session-id');
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
sessionStorage.setItem('zonos--checkout-session-id', cartStore.checkoutSessionId);
|
|
547
575
|
});
|
|
548
576
|
const cartStoreUpdateItems = async (items) => {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
577
|
+
var _a;
|
|
578
|
+
cartStore.items = items;
|
|
579
|
+
const currency = (_a = items.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode;
|
|
580
|
+
const total = items.reduce((amt, item) => {
|
|
581
|
+
return amt + item.amount * item.quantity;
|
|
582
|
+
}, 0);
|
|
583
|
+
if (!currency || !total) {
|
|
584
|
+
// do nothing if we can't get currency or total
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
cartStore.currency = currency;
|
|
588
|
+
// set loading state here because this is first load checkout session when we already have checkout session id stored
|
|
589
|
+
stripeStore.isFetchingSession = true;
|
|
590
|
+
await cartStoreReCalculateTotal({
|
|
591
|
+
currency: currency,
|
|
592
|
+
itemsAmount: total,
|
|
593
|
+
});
|
|
594
|
+
stripeStore.isFetchingSession = false;
|
|
567
595
|
};
|
|
568
596
|
const cartStoreResetSelectedShippingOption = () => {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
597
|
+
cartStore.selectedShippingOption = null;
|
|
598
|
+
cartStore.isSelectedShippingAboveDeminimis = false;
|
|
599
|
+
cartStore.isSelectedShippingGuarantee = false;
|
|
600
|
+
cartStore.selectedShippingOptionExpectedDate = '';
|
|
601
|
+
cartStore.selectedShippingOptionTransitTime = '';
|
|
602
|
+
cartStore.shipping = 0;
|
|
575
603
|
};
|
|
576
604
|
const cartStoreNextStep = () => {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
605
|
+
if (cartStore.step === 'customer-info') {
|
|
606
|
+
cartStore.step = 'shipping';
|
|
607
|
+
}
|
|
608
|
+
else if (cartStore.step === 'shipping') {
|
|
609
|
+
cartStore.step = 'payment';
|
|
610
|
+
}
|
|
611
|
+
else if (cartStore.step === 'payment') {
|
|
612
|
+
cartStore.step = 'finish';
|
|
613
|
+
}
|
|
586
614
|
};
|
|
587
615
|
const cartStorePreviousStep = () => {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
616
|
+
if (cartStore.step === 'payment') {
|
|
617
|
+
cartStore.step = 'shipping';
|
|
618
|
+
}
|
|
619
|
+
else if (cartStore.step === 'shipping') {
|
|
620
|
+
cartStore.step = 'customer-info';
|
|
621
|
+
// reset selected shipping option
|
|
622
|
+
cartStoreResetSelectedShippingOption();
|
|
623
|
+
}
|
|
596
624
|
};
|
|
597
625
|
|
|
598
626
|
export { cartStoreApplySubtotals as a, cartStoreGetShippingTransitInfo as b, cartStore as c, cartStoreNextStep as d, cartStorePreviousStep as e, cartStoreReCalculateTotal as f, cartStoreReset as g, cartStoreUpdateItems as h, cartStoreUpdateSelectedShippingOption as i, cartStoreUpdateToErrorState as j, stripeStorePrefetchLandedCost as k, initStripeElements as l, stripeStoreInitCheckoutSession as m, stripeStoreConfirmPayment as n, stripeStoreReset as o, stripeStoreRetrievePayment as p, stripeStore as s };
|