@zonos/elements 1.3.208 → 1.3.210
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/{cart-47c17ebf.js → cart-313bd2ff.js} +288 -40
- package/dist/cjs/{debounce-0b9c0f8a.js → debounce-465a4328.js} +1 -1
- package/dist/cjs/{getBorderRadius-c424eb05.js → getBorderRadius-1b5e33cf.js} +1 -1
- package/dist/cjs/{handleFetch-969d05d8.js → handleFetch-05227713.js} +2 -6
- package/dist/cjs/index.cjs.js +8 -8
- package/dist/cjs/{isDarkColor-35e8daec.js → isDarkColor-428965f4.js} +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{localization-e9089be5.js → localization-9b43376c.js} +2 -2
- package/dist/cjs/{paypal-3a803d21.js → paypal-67c96668.js} +5 -5
- package/dist/cjs/{updateCheckoutSessionAttributes-d0332530.js → updateCheckoutSessionAttributes-a31bb681.js} +2 -2
- package/dist/cjs/zonos-address_11.cjs.entry.js +104 -84
- package/dist/cjs/zonos-badge.cjs.entry.js +1 -1
- package/dist/cjs/zonos-banner.cjs.entry.js +1 -1
- package/dist/cjs/zonos-button_3.cjs.entry.js +3 -3
- package/dist/cjs/zonos-card.cjs.entry.js +2 -2
- package/dist/cjs/zonos-cart-items_14.cjs.entry.js +91 -41
- package/dist/cjs/zonos-checkout.cjs.entry.js +45 -21
- package/dist/cjs/zonos-collapse.cjs.entry.js +1 -1
- package/dist/cjs/zonos-controller.cjs.entry.js +6 -6
- package/dist/cjs/zonos-country-flag.cjs.entry.js +3 -3
- package/dist/cjs/zonos-country-select_4.cjs.entry.js +13 -9
- package/dist/cjs/zonos-elements.cjs.js +1 -1
- package/dist/cjs/zonos-empty-state-payment_4.cjs.entry.js +7 -7
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +3 -3
- package/dist/cjs/zonos-hello.cjs.entry.js +4 -4
- package/dist/cjs/zonos-input.cjs.entry.js +2 -2
- package/dist/cjs/zonos-language-select_2.cjs.entry.js +3 -3
- package/dist/cjs/zonos-logo.cjs.entry.js +1 -1
- package/dist/cjs/zonos-shipping-rich-radio.cjs.entry.js +2 -2
- package/dist/cjs/zonos-stripe-input.cjs.entry.js +3 -3
- package/dist/cjs/zonos-text.cjs.entry.js +1 -1
- package/dist/cjs/zonos-toggle.cjs.entry.js +1 -1
- package/dist/cjs/zonos-v-stack.cjs.entry.js +1 -1
- package/dist/cjs/{zonosStore-7c1e1bc1.js → zonosStore-f8ee56aa.js} +1 -0
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +36 -12
- package/dist/collection/components/checkout/zonos-checkout/zonos-customer-info/zonos-customer-info.js +63 -25
- package/dist/collection/components/checkout/zonos-checkout/zonos-shipping/zonos-shipping.js +33 -11
- package/dist/collection/components/common/zonos-checkout-progress-tabs/zonos-checkout-progress-tabs.js +2 -2
- package/dist/collection/components/common/zonos-country-select/zonos-country-select.js +9 -5
- package/dist/collection/components/store/checkout/cart.js +9 -2
- package/dist/collection/components/store/checkout/stripe.js +269 -31
- package/dist/collection/components/stripe/zonos-address/zonos-address.css +2 -1
- package/dist/collection/components/stripe/zonos-address/zonos-address.js +24 -3
- package/dist/collection/components/stripe/zonos-custom-address/zonos-custom-address.css +2 -1
- package/dist/collection/components/stripe/zonos-custom-address/zonos-custom-address.js +7 -5
- package/dist/collection/components/utils/api/cartCalculateLandedCost.js +3 -2
- package/dist/collection/components/utils/api/prepCalculateLandedCost.js +2 -2
- package/dist/collection/components/utils/handleFetch.js +2 -1
- package/dist/collection/components/utils/logging/log.js +0 -5
- package/dist/collection/types/checkout/api/CreateParty.js +1 -0
- package/dist/collection/types/generated/graphql.internal.types.js +3 -0
- package/dist/collection/types/index.js +1 -0
- package/dist/esm/{cart-5b417c0d.js → cart-e0703306.js} +287 -41
- package/dist/esm/{debounce-7ebfa15b.js → debounce-0e42da22.js} +1 -1
- package/dist/esm/{getBorderRadius-174305ff.js → getBorderRadius-71b3b8ab.js} +1 -1
- package/dist/esm/{handleFetch-621e45bc.js → handleFetch-7dd4622b.js} +2 -6
- package/dist/esm/index.js +8 -8
- package/dist/esm/{isDarkColor-915b06b8.js → isDarkColor-3a9d6108.js} +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{localization-669a1714.js → localization-e17c211b.js} +2 -2
- package/dist/esm/{paypal-3a0cf86b.js → paypal-dbaf76fd.js} +6 -6
- package/dist/esm/{updateCheckoutSessionAttributes-183ca6c1.js → updateCheckoutSessionAttributes-5097e715.js} +2 -2
- package/dist/esm/zonos-address_11.entry.js +104 -84
- package/dist/esm/zonos-badge.entry.js +1 -1
- package/dist/esm/zonos-banner.entry.js +1 -1
- package/dist/esm/zonos-button_3.entry.js +3 -3
- package/dist/esm/zonos-card.entry.js +2 -2
- package/dist/esm/zonos-cart-items_14.entry.js +91 -41
- package/dist/esm/zonos-checkout.entry.js +45 -21
- package/dist/esm/zonos-collapse.entry.js +1 -1
- package/dist/esm/zonos-controller.entry.js +6 -6
- package/dist/esm/zonos-country-flag.entry.js +3 -3
- package/dist/esm/zonos-country-select_4.entry.js +13 -9
- package/dist/esm/zonos-elements.js +1 -1
- package/dist/esm/zonos-empty-state-payment_4.entry.js +7 -7
- package/dist/esm/zonos-hello-dialog.entry.js +3 -3
- package/dist/esm/zonos-hello.entry.js +4 -4
- package/dist/esm/zonos-input.entry.js +2 -2
- package/dist/esm/zonos-language-select_2.entry.js +3 -3
- package/dist/esm/zonos-logo.entry.js +1 -1
- package/dist/esm/zonos-shipping-rich-radio.entry.js +2 -2
- package/dist/esm/zonos-stripe-input.entry.js +3 -3
- package/dist/esm/zonos-text.entry.js +1 -1
- package/dist/esm/zonos-toggle.entry.js +1 -1
- package/dist/esm/zonos-v-stack.entry.js +1 -1
- package/dist/esm/{zonosStore-504a7030.js → zonosStore-00975763.js} +1 -1
- package/dist/esm-es5/cart-e0703306.js +1 -0
- package/dist/esm-es5/{debounce-7ebfa15b.js → debounce-0e42da22.js} +1 -1
- package/dist/esm-es5/{getBorderRadius-174305ff.js → getBorderRadius-71b3b8ab.js} +1 -1
- package/dist/esm-es5/handleFetch-7dd4622b.js +1 -0
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/{isDarkColor-915b06b8.js → isDarkColor-3a9d6108.js} +1 -1
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/{localization-669a1714.js → localization-e17c211b.js} +1 -1
- package/dist/esm-es5/{paypal-3a0cf86b.js → paypal-dbaf76fd.js} +2 -2
- package/dist/esm-es5/{updateCheckoutSessionAttributes-183ca6c1.js → updateCheckoutSessionAttributes-5097e715.js} +1 -1
- package/dist/esm-es5/zonos-address_11.entry.js +1 -1
- package/dist/esm-es5/zonos-badge.entry.js +1 -1
- package/dist/esm-es5/zonos-banner.entry.js +1 -1
- package/dist/esm-es5/zonos-button_3.entry.js +1 -1
- package/dist/esm-es5/zonos-card.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_14.entry.js +1 -1
- package/dist/esm-es5/zonos-checkout.entry.js +1 -1
- package/dist/esm-es5/zonos-collapse.entry.js +1 -1
- package/dist/esm-es5/zonos-controller.entry.js +1 -1
- package/dist/esm-es5/zonos-country-flag.entry.js +1 -1
- package/dist/esm-es5/zonos-country-select_4.entry.js +1 -1
- package/dist/esm-es5/zonos-elements.js +1 -1
- package/dist/esm-es5/zonos-empty-state-payment_4.entry.js +1 -1
- package/dist/esm-es5/zonos-hello-dialog.entry.js +1 -1
- package/dist/esm-es5/zonos-hello.entry.js +1 -1
- package/dist/esm-es5/zonos-input.entry.js +1 -1
- package/dist/esm-es5/zonos-language-select_2.entry.js +1 -1
- package/dist/esm-es5/zonos-logo.entry.js +1 -1
- package/dist/esm-es5/zonos-shipping-rich-radio.entry.js +1 -1
- package/dist/esm-es5/zonos-stripe-input.entry.js +1 -1
- package/dist/esm-es5/zonos-text.entry.js +1 -1
- package/dist/esm-es5/zonos-toggle.entry.js +1 -1
- package/dist/esm-es5/zonos-v-stack.entry.js +1 -1
- package/dist/esm-es5/{zonosStore-504a7030.js → zonosStore-00975763.js} +1 -1
- package/dist/scripts/index.d.ts +8 -0
- package/dist/scripts/index.js +1 -1
- package/dist/scripts/loadZonos.js +1 -1
- package/dist/scripts/zonos.js +1 -1
- package/dist/types/components/checkout/zonos-checkout/zonos-customer-info/zonos-customer-info.d.ts +8 -4
- package/dist/types/components/checkout/zonos-checkout/zonos-shipping/zonos-shipping.d.ts +3 -0
- package/dist/types/components/common/zonos-country-select/zonos-country-select.d.ts +1 -0
- package/dist/types/components/store/checkout/cart.d.ts +6 -2
- package/dist/types/components/store/checkout/stripe.d.ts +33 -6
- package/dist/types/components/stripe/zonos-address/zonos-address.d.ts +6 -0
- package/dist/types/types/checkout/api/CheckoutSession.d.ts +2 -0
- package/dist/types/types/checkout/api/CreateParty.d.ts +34 -0
- package/dist/types/types/generated/graphql.internal.types.d.ts +21 -5
- package/dist/types/types/generated/graphql.internal.types.ts +26 -3
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/utils/ZonosSettings.d.ts +6 -0
- package/dist/zonos-elements/assets/RemoveIcon.svg +1 -1
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/p-03c060d3.entry.js +1 -0
- package/dist/zonos-elements/{p-c5455a34.system.js → p-0751b878.system.js} +1 -1
- package/dist/zonos-elements/{p-0731fbba.entry.js → p-0ca1d6dd.entry.js} +1 -1
- package/dist/zonos-elements/{p-e1c2b8f8.entry.js → p-144b5006.entry.js} +1 -1
- package/dist/zonos-elements/{p-d5bdbbb3.system.js → p-19182dc7.system.js} +1 -1
- package/dist/zonos-elements/{p-066afca1.system.entry.js → p-1dc78af3.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-5f2a2ca7.js → p-207bd04a.js} +1 -1
- package/dist/zonos-elements/p-20839c46.js +1 -0
- package/dist/zonos-elements/p-20b702a7.system.entry.js +1 -0
- package/dist/zonos-elements/{p-63ca1242.system.entry.js → p-2122d2cc.system.entry.js} +1 -1
- package/dist/zonos-elements/p-23142862.entry.js +1 -0
- package/dist/zonos-elements/{p-a09bdd20.system.entry.js → p-239695e8.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-6b406abd.entry.js → p-23fe7661.entry.js} +1 -1
- package/dist/zonos-elements/p-2652198d.js +1 -0
- package/dist/zonos-elements/{p-4451a598.system.js → p-3633a952.system.js} +1 -1
- package/dist/zonos-elements/{p-6be43ba8.entry.js → p-36b686b6.entry.js} +1 -1
- package/dist/zonos-elements/p-37058486.system.entry.js +1 -0
- package/dist/zonos-elements/{p-081fa4a8.entry.js → p-3934b38a.entry.js} +1 -1
- package/dist/zonos-elements/p-3ee44728.system.js +1 -1
- package/dist/zonos-elements/{p-cd376c7a.system.entry.js → p-45a2f9b1.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-0d908c15.system.js → p-4a1b4a2d.system.js} +1 -1
- package/dist/zonos-elements/p-4c70fd75.entry.js +1 -0
- package/dist/zonos-elements/{p-07905246.entry.js → p-4d62f3de.entry.js} +1 -1
- package/dist/zonos-elements/{p-bb850bb7.entry.js → p-4dbaa2c2.entry.js} +1 -1
- package/dist/zonos-elements/{p-c607d026.entry.js → p-5956a9e0.entry.js} +1 -1
- package/dist/zonos-elements/{p-b7a5b367.js → p-5b3b58ef.js} +2 -2
- package/dist/zonos-elements/{p-d096d7f2.entry.js → p-5b7686f8.entry.js} +1 -1
- package/dist/zonos-elements/{p-67f807bc.entry.js → p-63a4dac5.entry.js} +1 -1
- package/dist/zonos-elements/{p-7f568108.system.js → p-68650f1e.system.js} +2 -2
- package/dist/zonos-elements/{p-51d596a0.system.entry.js → p-695bf400.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-d35d17f3.js → p-6aa728f2.js} +1 -1
- package/dist/zonos-elements/{p-4bf54953.js → p-71c6bdc3.js} +1 -1
- package/dist/zonos-elements/{p-39039ab7.system.entry.js → p-7211cb9f.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-0f368368.system.js → p-738a49c0.system.js} +1 -1
- package/dist/zonos-elements/{p-ef594c0c.entry.js → p-73ff25d8.entry.js} +1 -1
- package/dist/zonos-elements/{p-7e346632.system.entry.js → p-74276b82.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-d1a31577.entry.js → p-77e22be4.entry.js} +1 -1
- package/dist/zonos-elements/{p-a3a8ba10.entry.js → p-78dd1c53.entry.js} +1 -1
- package/dist/zonos-elements/{p-0fb14108.entry.js → p-7b02b1f6.entry.js} +1 -1
- package/dist/zonos-elements/p-7ec1fecb.system.js +1 -0
- package/dist/zonos-elements/{p-3d6f6367.system.entry.js → p-7f9bbbb3.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-a4d995a2.system.js → p-8d0e116f.system.js} +1 -1
- package/dist/zonos-elements/{p-a63bac79.system.entry.js → p-8f41d864.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-1f706fc9.system.entry.js → p-964e2587.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-1530f958.system.entry.js → p-97831744.system.entry.js} +1 -1
- package/dist/zonos-elements/p-992f0b96.js +1 -0
- package/dist/zonos-elements/{p-160da12a.system.entry.js → p-9d95c896.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-5d909d3d.entry.js → p-a1137930.entry.js} +1 -1
- package/dist/zonos-elements/{p-4f04b499.entry.js → p-a24870af.entry.js} +1 -1
- package/dist/zonos-elements/p-a411ce2a.system.js +1 -0
- package/dist/zonos-elements/{p-5c772fab.system.entry.js → p-a4686344.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-a158b406.js → p-a6f77d44.js} +1 -1
- package/dist/zonos-elements/{p-fc3a6495.entry.js → p-a8f421ac.entry.js} +1 -1
- package/dist/zonos-elements/{p-da304b78.entry.js → p-aa40d402.entry.js} +1 -1
- package/dist/zonos-elements/{p-6c991320.entry.js → p-ad1e1dbc.entry.js} +1 -1
- package/dist/zonos-elements/{p-ab6efb03.system.entry.js → p-baa88176.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-02463cc1.system.entry.js → p-bf364990.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-963fa567.system.entry.js → p-bf9cb85f.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-803e59d2.system.entry.js → p-c345b306.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-ea30d92d.system.entry.js → p-cf999a15.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-a958c4f0.system.entry.js → p-d1697144.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-b3fa7f19.js → p-d6a53ea6.js} +1 -1
- package/dist/zonos-elements/{p-39428328.system.js → p-eb77c0bf.system.js} +1 -1
- package/dist/zonos-elements/{p-f49834d4.system.entry.js → p-ef1ccec6.system.entry.js} +1 -1
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +1 -1
- package/dist/esm-es5/cart-5b417c0d.js +0 -1
- package/dist/esm-es5/handleFetch-621e45bc.js +0 -1
- package/dist/zonos-elements/p-0794c530.entry.js +0 -1
- package/dist/zonos-elements/p-0fc02cde.js +0 -1
- package/dist/zonos-elements/p-1b3e92ea.system.entry.js +0 -1
- package/dist/zonos-elements/p-1b75aa35.system.js +0 -1
- package/dist/zonos-elements/p-2d4e0280.entry.js +0 -1
- package/dist/zonos-elements/p-40a2a649.js +0 -1
- package/dist/zonos-elements/p-5539386e.system.entry.js +0 -1
- package/dist/zonos-elements/p-91553cf0.system.js +0 -1
- package/dist/zonos-elements/p-c740353c.js +0 -1
- package/dist/zonos-elements/p-f1f3a846.entry.js +0 -1
|
@@ -9,7 +9,8 @@ import { allLogs, log } from "../../utils/logging/log";
|
|
|
9
9
|
import { logError } from "../../utils/logging/logError";
|
|
10
10
|
import { sendErrorLog } from "../../utils/logging/sendErrorLog";
|
|
11
11
|
import { filterValidTests } from "../../utils/varianceTest/filterValidTests";
|
|
12
|
-
const { reset, state: cartStore } = createStore(() => ({
|
|
12
|
+
const { onChange: cartStoreOnChange, reset, state: cartStore, } = createStore(() => ({
|
|
13
|
+
addressFormRenderType: 'stripe',
|
|
13
14
|
adjustmentTotal: 0,
|
|
14
15
|
adjustments: [],
|
|
15
16
|
checkoutSession: null,
|
|
@@ -224,12 +225,14 @@ const cartStoreReCalculateTotal = async ({ adjustmentsAmount, cartId, currency,
|
|
|
224
225
|
}
|
|
225
226
|
const { errors, json } = await stripeStoreUpdateCheckoutSession({
|
|
226
227
|
adjustmentsAmount,
|
|
228
|
+
billToPartyId: stripeStore.partyBillingId,
|
|
227
229
|
cartId,
|
|
228
230
|
currency,
|
|
229
231
|
id: storageStore.checkoutSessionId,
|
|
230
232
|
itemsAmount,
|
|
231
233
|
landedCostId,
|
|
232
234
|
presentmentCountryCode: localizationStore.selectedCountryCode,
|
|
235
|
+
shipToPartyId: stripeStore.partyShippingId,
|
|
233
236
|
varianceTestInput: storageStore.enabledVariantTestKeys || [],
|
|
234
237
|
});
|
|
235
238
|
if (errors.length > 0 || !json) {
|
|
@@ -313,9 +316,11 @@ const cartStoreUpdateSelectedShippingOption = async (selectedShippingOption, lan
|
|
|
313
316
|
// update session with selected landed cost
|
|
314
317
|
const updateCalculateStatus = await cartStoreReCalculateTotal({
|
|
315
318
|
adjustmentsAmount: cartStore.adjustmentTotal,
|
|
319
|
+
billToPartyId: stripeStore.partyBillingId,
|
|
316
320
|
cartId: window.Zonos.cartId,
|
|
317
321
|
dutiesTaxesFeesEstimate: dutiesTaxesFeesEstimate,
|
|
318
322
|
landedCostId: (_f = selectedLandedCost.landedCost) === null || _f === void 0 ? void 0 : _f.id,
|
|
323
|
+
shipToPartyId: stripeStore.partyShippingId,
|
|
319
324
|
varianceTestInput: storageStore.enabledVariantTestKeys || [],
|
|
320
325
|
});
|
|
321
326
|
// update conditionally render pay in USD button
|
|
@@ -378,10 +383,12 @@ const cartStoreUpdateItems = async ({ adjustments, cartItems, }) => {
|
|
|
378
383
|
stripeStore.isFetchingSession = true;
|
|
379
384
|
await cartStoreReCalculateTotal({
|
|
380
385
|
adjustmentsAmount: adjustmentTotal,
|
|
386
|
+
billToPartyId: stripeStore.partyBillingId,
|
|
381
387
|
cartId: window.Zonos.cartId,
|
|
382
388
|
currency: currency,
|
|
383
389
|
dutiesTaxesFeesEstimate: 0,
|
|
384
390
|
itemsAmount: total,
|
|
391
|
+
shipToPartyId: stripeStore.partyShippingId,
|
|
385
392
|
// attempt to init session on failure to update checkout session
|
|
386
393
|
shouldInitSessionOnFailure: true,
|
|
387
394
|
varianceTestInput: storageStore.enabledVariantTestKeys || [],
|
|
@@ -436,4 +443,4 @@ const cartStoreResetTabItems = () => {
|
|
|
436
443
|
cartStore.tabItems = Object.assign(Object.assign({}, cartStore.tabItems), { 'customer-info': Object.assign(Object.assign({}, cartStore.tabItems['customer-info']), { isDone: false }), payment: Object.assign(Object.assign({}, cartStore.tabItems.payment), { isDone: false }), shipping: Object.assign(Object.assign({}, cartStore.tabItems.shipping), { isDone: false }) });
|
|
437
444
|
cartStoreResetSelectedShippingOption();
|
|
438
445
|
};
|
|
439
|
-
export { cartStore, cartStoreApplySubtotals, cartStoreCheckItemRestrictions, cartStoreClearCheckoutInterval, cartStoreGetMethod, cartStoreGetShippingTransitInfo, cartStoreHasOneEligibleItem, cartStoreNextStep, cartStorePreviousStep, cartStoreReset, cartStoreResetCartItems, cartStoreResetTabItems, cartStoreSetCheckoutSession, cartStoreStartCheckoutInterval, cartStoreUpdateItems, cartStoreUpdateSelectedShippingOption, cartStoreUpdateToErrorState, };
|
|
446
|
+
export { cartStore, cartStoreApplySubtotals, cartStoreCheckItemRestrictions, cartStoreClearCheckoutInterval, cartStoreGetMethod, cartStoreGetShippingTransitInfo, cartStoreHasOneEligibleItem, cartStoreNextStep, cartStoreOnChange, cartStorePreviousStep, cartStoreReset, cartStoreResetCartItems, cartStoreResetTabItems, cartStoreSetCheckoutSession, cartStoreStartCheckoutInterval, cartStoreUpdateItems, cartStoreUpdateSelectedShippingOption, cartStoreUpdateToErrorState, };
|
|
@@ -21,6 +21,7 @@ const { onChange: stripeStoreOnChange, reset, state: stripeStore, } = createStor
|
|
|
21
21
|
checkoutSettlementCurrency: 'USD',
|
|
22
22
|
clientSecret: sessionStorage.getItem('zonos--client-secret') || '',
|
|
23
23
|
companyName: '',
|
|
24
|
+
companyNameUsedWhenAsyncAddressUpdate: '',
|
|
24
25
|
customAddressErrors: {
|
|
25
26
|
city: '',
|
|
26
27
|
firstName: '',
|
|
@@ -47,6 +48,8 @@ const { onChange: stripeStoreOnChange, reset, state: stripeStore, } = createStor
|
|
|
47
48
|
hasPaymentError: false,
|
|
48
49
|
isFetchingLandedCost: false,
|
|
49
50
|
isFetchingSession: false,
|
|
51
|
+
partyBillingId: null,
|
|
52
|
+
partyShippingId: null,
|
|
50
53
|
shouldInventoryRefund: false,
|
|
51
54
|
shouldRenderPayInUsdButton: false,
|
|
52
55
|
/**
|
|
@@ -59,10 +62,12 @@ const { onChange: stripeStoreOnChange, reset, state: stripeStore, } = createStor
|
|
|
59
62
|
stripe: null,
|
|
60
63
|
stripeAddressElement: null,
|
|
61
64
|
stripeAddressEventData: null,
|
|
65
|
+
stripeAddressUsedWhenAsyncAddressUpdate: null,
|
|
62
66
|
stripeAddressUsedWhenFetchingLC: null,
|
|
63
67
|
stripeAddressUsedWhenValidatingAddress: null,
|
|
64
68
|
stripeBillingAddressElement: null,
|
|
65
69
|
stripeBillingAddressEventData: null,
|
|
70
|
+
stripeBillingAddressUsedWhenAsyncAddressUpdate: null,
|
|
66
71
|
stripeBillingAddressUsedWhenFetchingLC: null,
|
|
67
72
|
stripeBillingAddressUsedWhenValidatingAddress: null,
|
|
68
73
|
stripeCustomerSessionClientSecret: null,
|
|
@@ -76,7 +81,7 @@ const { onChange: stripeStoreOnChange, reset, state: stripeStore, } = createStor
|
|
|
76
81
|
stripePaymentEventData: null,
|
|
77
82
|
stripeShippingSameAsBilling: true,
|
|
78
83
|
taxId: '',
|
|
79
|
-
|
|
84
|
+
taxIdUsedWhenAsyncAddressUpdate: '',
|
|
80
85
|
translatedAddress: {
|
|
81
86
|
address: {},
|
|
82
87
|
billingAddress: {},
|
|
@@ -182,15 +187,178 @@ const checkIsAddressOutdatedForValidation = () => {
|
|
|
182
187
|
JSON.stringify((_d = stripeStore.stripeBillingAddressUsedWhenValidatingAddress) === null || _d === void 0 ? void 0 : _d.value);
|
|
183
188
|
return isAddressDataDirty || isBillingAddressDataDirty;
|
|
184
189
|
};
|
|
185
|
-
const
|
|
190
|
+
const checkIsAddressOutdatedForAsyncAddressUpdate = () => {
|
|
186
191
|
var _a, _b, _c, _d, _e, _f;
|
|
187
192
|
const isLinkDataDirty = JSON.stringify((_a = stripeStore.stripeLinkUsedWhenFetchingLC) === null || _a === void 0 ? void 0 : _a.value) !==
|
|
188
193
|
JSON.stringify((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.value);
|
|
189
|
-
const isAddressDataDirty = JSON.stringify((_c = stripeStore.
|
|
190
|
-
|
|
194
|
+
const isAddressDataDirty = JSON.stringify((_c = stripeStore.stripeAddressUsedWhenAsyncAddressUpdate) === null || _c === void 0 ? void 0 : _c.value) !== JSON.stringify((_d = stripeStore.stripeAddressEventData) === null || _d === void 0 ? void 0 : _d.value);
|
|
195
|
+
const isBillingAddressDataDirty = !stripeStore.stripeShippingSameAsBilling &&
|
|
196
|
+
JSON.stringify((_e = stripeStore.stripeBillingAddressUsedWhenAsyncAddressUpdate) === null || _e === void 0 ? void 0 : _e.value) !== JSON.stringify((_f = stripeStore.stripeBillingAddressEventData) === null || _f === void 0 ? void 0 : _f.value);
|
|
197
|
+
const isTaxIdDirty = stripeStore.taxIdUsedWhenAsyncAddressUpdate !== stripeStore.taxId;
|
|
198
|
+
const isCompanyNameDirty = stripeStore.companyNameUsedWhenAsyncAddressUpdate !==
|
|
199
|
+
stripeStore.companyName;
|
|
200
|
+
return (isLinkDataDirty ||
|
|
201
|
+
isAddressDataDirty ||
|
|
202
|
+
isBillingAddressDataDirty ||
|
|
203
|
+
isTaxIdDirty ||
|
|
204
|
+
isCompanyNameDirty);
|
|
205
|
+
};
|
|
206
|
+
const buildAddressForPartyCreate = ({ address, firstName, lastName, name, phone, }) => {
|
|
207
|
+
const _firstName = (name === null || name === void 0 ? void 0 : name.split(' ')[0]) || firstName || '';
|
|
208
|
+
const _lastName = (name === null || name === void 0 ? void 0 : name.split(' ')[1]) || lastName || '';
|
|
209
|
+
if (!_firstName || !_lastName) {
|
|
210
|
+
void sendErrorLog({
|
|
211
|
+
endpoint: 'PARTY_CREATE_NO_NAME_FOUND',
|
|
212
|
+
errors: ['No name found'],
|
|
213
|
+
metadata: {
|
|
214
|
+
allLogs,
|
|
215
|
+
cartId: window.Zonos.cartId,
|
|
216
|
+
checkoutSessionId: storageStore.checkoutSessionId,
|
|
217
|
+
firstName,
|
|
218
|
+
lastName,
|
|
219
|
+
name,
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
if (!phone) {
|
|
224
|
+
void sendErrorLog({
|
|
225
|
+
endpoint: 'PARTY_CREATE_NO_PHONE_FOUND',
|
|
226
|
+
errors: ['No phone found'],
|
|
227
|
+
metadata: {
|
|
228
|
+
allLogs,
|
|
229
|
+
cartId: window.Zonos.cartId,
|
|
230
|
+
checkoutSessionId: storageStore.checkoutSessionId,
|
|
231
|
+
phone,
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
city: address.city,
|
|
237
|
+
country: address.country,
|
|
238
|
+
firstName: _firstName,
|
|
239
|
+
lastName: _lastName,
|
|
240
|
+
line1: address.line1,
|
|
241
|
+
line2: address.line2,
|
|
242
|
+
phone: phone || '',
|
|
243
|
+
postal_code: address.postal_code,
|
|
244
|
+
state: address.state,
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
const stripeStoreAsyncAddressUpdate = async () => {
|
|
248
|
+
var _a, _b, _c, _d;
|
|
249
|
+
if (!((_a = stripeStore.stripeAddressEventData) === null || _a === void 0 ? void 0 : _a.complete) ||
|
|
250
|
+
(!stripeStore.stripeShippingSameAsBilling &&
|
|
251
|
+
!((_b = stripeStore.stripeBillingAddressEventData) === null || _b === void 0 ? void 0 : _b.complete)) ||
|
|
252
|
+
!stripeStore.stripeBillingAddressEventData) {
|
|
253
|
+
return {
|
|
254
|
+
partiesCreated: false,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
// If there is no landed cost data, no need to create parties
|
|
258
|
+
if (!cartStore.landedCostData) {
|
|
259
|
+
return {
|
|
260
|
+
partiesCreated: false,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
const firstLandedCostRootId = (_c = cartStore.landedCostData.find(Boolean)) === null || _c === void 0 ? void 0 : _c.landedCost.rootId;
|
|
264
|
+
if (!firstLandedCostRootId) {
|
|
265
|
+
// do nothing if we don't have selected landed cost
|
|
266
|
+
void sendErrorLog({
|
|
267
|
+
endpoint: 'PF_NO_SELECTED_LANDED_COST',
|
|
268
|
+
errors: ['No selected landed cost'],
|
|
269
|
+
metadata: {
|
|
270
|
+
allLogs,
|
|
271
|
+
cartId: window.Zonos.cartId,
|
|
272
|
+
checkoutSessionId: storageStore.checkoutSessionId,
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
return {
|
|
276
|
+
partiesCreated: false,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
const isAddressOutdated = checkIsAddressOutdatedForAsyncAddressUpdate();
|
|
280
|
+
if (!isAddressOutdated) {
|
|
281
|
+
return {
|
|
282
|
+
partiesCreated: false,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
const address = buildAddressForPartyCreate({
|
|
286
|
+
address: stripeStore.stripeAddressEventData.value.address,
|
|
287
|
+
firstName: stripeStore.stripeAddressEventData.value.firstName,
|
|
288
|
+
lastName: stripeStore.stripeAddressEventData.value.lastName,
|
|
289
|
+
name: stripeStore.stripeAddressEventData.value.name,
|
|
290
|
+
phone: stripeStore.stripeAddressEventData.value.phone,
|
|
291
|
+
});
|
|
292
|
+
const billingAddress = stripeStore.stripeShippingSameAsBilling
|
|
293
|
+
? address
|
|
294
|
+
: buildAddressForPartyCreate({
|
|
295
|
+
address: stripeStore.stripeBillingAddressEventData.value.address,
|
|
296
|
+
firstName: stripeStore.stripeBillingAddressEventData.value.firstName,
|
|
297
|
+
lastName: stripeStore.stripeBillingAddressEventData.value.lastName,
|
|
298
|
+
name: stripeStore.stripeBillingAddressEventData.value.name,
|
|
299
|
+
phone: stripeStore.stripeBillingAddressEventData.value.phone,
|
|
300
|
+
});
|
|
301
|
+
const isE2ETest = new URLSearchParams(window.location.search).get('zonosE2ETest') === '1';
|
|
302
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/create-parties', {
|
|
303
|
+
body: {
|
|
304
|
+
address,
|
|
305
|
+
billingAddress,
|
|
306
|
+
companyName: stripeStore.companyName,
|
|
307
|
+
email: ((_d = stripeStore.stripeLinkEventData) === null || _d === void 0 ? void 0 : _d.value.email) || '',
|
|
308
|
+
isTest: isE2ETest,
|
|
309
|
+
rootId: firstLandedCostRootId,
|
|
310
|
+
taxId: stripeStore.taxId,
|
|
311
|
+
},
|
|
312
|
+
method: 'POST',
|
|
313
|
+
});
|
|
314
|
+
if (errors.length || !json) {
|
|
315
|
+
logError('Error occurs when creating parties', JSON.stringify(errors, null, 2));
|
|
316
|
+
void sendErrorLog({
|
|
317
|
+
endpoint: 'PF_PARTY_CREATE_FAILED',
|
|
318
|
+
errors: ['Failed to create parties'],
|
|
319
|
+
metadata: {
|
|
320
|
+
allLogs,
|
|
321
|
+
cartId: window.Zonos.cartId,
|
|
322
|
+
checkoutSessionId: storageStore.checkoutSessionId,
|
|
323
|
+
errors,
|
|
324
|
+
json,
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
return {
|
|
328
|
+
partiesCreated: false,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
stripeStore.companyNameUsedWhenAsyncAddressUpdate = stripeStore.companyName;
|
|
332
|
+
stripeStore.stripeAddressUsedWhenAsyncAddressUpdate =
|
|
333
|
+
stripeStore.stripeAddressEventData;
|
|
334
|
+
stripeStore.stripeBillingAddressUsedWhenAsyncAddressUpdate =
|
|
335
|
+
stripeStore.stripeBillingAddressEventData;
|
|
336
|
+
stripeStore.taxIdUsedWhenAsyncAddressUpdate = stripeStore.taxId;
|
|
337
|
+
stripeStore.partyBillingId = json.billToPartyId;
|
|
338
|
+
stripeStore.partyShippingId = json.shipToPartyId;
|
|
339
|
+
return {
|
|
340
|
+
partiesCreated: true,
|
|
341
|
+
};
|
|
342
|
+
};
|
|
343
|
+
/**
|
|
344
|
+
* Extract only the necessary address info for landed cost prefetch
|
|
345
|
+
*/
|
|
346
|
+
const buildAddressForLCPrefetch = (address) => {
|
|
347
|
+
return {
|
|
348
|
+
countryCode: address.address.country,
|
|
349
|
+
postalCode: address.address.postal_code,
|
|
350
|
+
state: address.address.state,
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
const checkIsAddressOutdatedForLCPrefetch = () => {
|
|
354
|
+
var _a, _b;
|
|
355
|
+
const isLinkDataDirty = JSON.stringify((_a = stripeStore.stripeLinkUsedWhenFetchingLC) === null || _a === void 0 ? void 0 : _a.value) !==
|
|
356
|
+
JSON.stringify((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.value);
|
|
357
|
+
const isAddressDataDirty = stripeStore.stripeAddressEventData &&
|
|
358
|
+
JSON.stringify(buildAddressForLCPrefetch(stripeStore.stripeAddressEventData.value)) !== JSON.stringify(stripeStore.stripeAddressUsedWhenFetchingLC);
|
|
191
359
|
const isBillingAddressDataDirty = !stripeStore.stripeShippingSameAsBilling &&
|
|
192
|
-
|
|
193
|
-
|
|
360
|
+
stripeStore.stripeBillingAddressEventData &&
|
|
361
|
+
JSON.stringify(buildAddressForLCPrefetch(stripeStore.stripeBillingAddressEventData.value)) !== JSON.stringify(stripeStore.stripeBillingAddressUsedWhenFetchingLC);
|
|
194
362
|
return isLinkDataDirty || isAddressDataDirty || isBillingAddressDataDirty;
|
|
195
363
|
};
|
|
196
364
|
/**
|
|
@@ -204,14 +372,67 @@ const isPrefetchInfoOutdated = () => {
|
|
|
204
372
|
((_a = cartStore.landedCostData.find(Boolean)) === null || _a === void 0 ? void 0 : _a.subtotals.items) !==
|
|
205
373
|
cartStore.subtotal;
|
|
206
374
|
const isAddressOutdated = checkIsAddressOutdatedForLCPrefetch();
|
|
207
|
-
|
|
208
|
-
|
|
375
|
+
log('isPrefetchInfoOutdated', 'info', {
|
|
376
|
+
isAddressOutdated,
|
|
377
|
+
});
|
|
209
378
|
return (
|
|
210
379
|
// if landed cost data is not available, we need to fetch it
|
|
211
|
-
!cartStore.landedCostData ||
|
|
380
|
+
(!cartStore.landedCostData && !stripeStore.isFetchingLandedCost) ||
|
|
212
381
|
isAddressOutdated ||
|
|
213
|
-
isTotalAmountChanged
|
|
214
|
-
|
|
382
|
+
isTotalAmountChanged);
|
|
383
|
+
};
|
|
384
|
+
const getCountryField = (country) => {
|
|
385
|
+
var _a, _b;
|
|
386
|
+
const countryFieldLabels = (_a = zonosStore.genericSettings) === null || _a === void 0 ? void 0 : _a.countryFields;
|
|
387
|
+
const stripeCountryFieldLabels = (_b = zonosStore.genericSettings) === null || _b === void 0 ? void 0 : _b.stripeCountryFieldLabels;
|
|
388
|
+
const stripeFoundCountryField = stripeCountryFieldLabels && country in stripeCountryFieldLabels
|
|
389
|
+
? stripeCountryFieldLabels[country]
|
|
390
|
+
: null;
|
|
391
|
+
const zonosFoundCountryField = countryFieldLabels && country in countryFieldLabels
|
|
392
|
+
? countryFieldLabels[country]
|
|
393
|
+
: null;
|
|
394
|
+
/**
|
|
395
|
+
* If the address form is using Stripe component, use Stripe country field label if there is one, if not just use one from our countryFieldLabel data
|
|
396
|
+
* stripeCountryFieldLabels is the list we collect from Stripe, and extract only country that state/zip is required and different from what we have in our countryFieldLabel data
|
|
397
|
+
**/
|
|
398
|
+
if (cartStore.addressFormRenderType === 'stripe') {
|
|
399
|
+
return stripeFoundCountryField || zonosFoundCountryField;
|
|
400
|
+
}
|
|
401
|
+
return zonosFoundCountryField;
|
|
402
|
+
};
|
|
403
|
+
const isAddressReadyToRequestLandedCost = () => {
|
|
404
|
+
var _a, _b, _c, _d;
|
|
405
|
+
const linkReady = !!((_a = stripeStore.stripeLinkEventData) === null || _a === void 0 ? void 0 : _a.complete);
|
|
406
|
+
const shippingAddressReady = !!((_b = stripeStore.stripeAddressEventData) === null || _b === void 0 ? void 0 : _b.complete);
|
|
407
|
+
const billingAddressReady = stripeStore.stripeShippingSameAsBilling
|
|
408
|
+
? shippingAddressReady
|
|
409
|
+
: !!((_c = stripeStore.stripeBillingAddressEventData) === null || _c === void 0 ? void 0 : _c.complete);
|
|
410
|
+
const shipToCountry = ((_d = stripeStore.stripeAddressEventData) === null || _d === void 0 ? void 0 : _d.value.address.country) || 'US';
|
|
411
|
+
const countryField = getCountryField(shipToCountry);
|
|
412
|
+
if (shippingAddressReady && billingAddressReady && linkReady) {
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
// Only send landed cost request if the address is complete when we can't get the country field
|
|
416
|
+
if (!countryField || !stripeStore.stripeAddressEventData) {
|
|
417
|
+
return shippingAddressReady && billingAddressReady && linkReady;
|
|
418
|
+
}
|
|
419
|
+
const isValidLine1 = stripeStore.stripeAddressEventData.value.address.line1.length > 0;
|
|
420
|
+
const isValidName = stripeStore.stripeAddressEventData.value.firstName &&
|
|
421
|
+
stripeStore.stripeAddressEventData.value.lastName;
|
|
422
|
+
const isStateValid = !countryField.stateRequired ||
|
|
423
|
+
(countryField.stateRequired &&
|
|
424
|
+
stripeStore.stripeAddressEventData.value.address.state.length > 0);
|
|
425
|
+
const isPostalCodeValid = !countryField.zipRequired ||
|
|
426
|
+
(countryField.zipRequired &&
|
|
427
|
+
stripeStore.stripeAddressEventData.value.address.postal_code.length >= 3);
|
|
428
|
+
const hasPhoneNumber = stripeStore.stripeAddressEventData.value.phone &&
|
|
429
|
+
stripeStore.stripeAddressEventData.value.phone.length > 0;
|
|
430
|
+
return (linkReady &&
|
|
431
|
+
isValidName &&
|
|
432
|
+
isValidLine1 &&
|
|
433
|
+
isStateValid &&
|
|
434
|
+
isPostalCodeValid &&
|
|
435
|
+
hasPhoneNumber);
|
|
215
436
|
};
|
|
216
437
|
const stripeCalculateLandedCost = async () => {
|
|
217
438
|
var _a;
|
|
@@ -260,26 +481,27 @@ const stripeCalculateLandedCost = async () => {
|
|
|
260
481
|
}
|
|
261
482
|
};
|
|
262
483
|
const stripeStorePrefetchLandedCost = async (params) => {
|
|
263
|
-
var _a, _b, _c, _d
|
|
484
|
+
var _a, _b, _c, _d;
|
|
264
485
|
const retries = (params === null || params === void 0 ? void 0 : params.retries) || 0;
|
|
265
486
|
const applyingPromocode = !!(params === null || params === void 0 ? void 0 : params.applyingPromocode);
|
|
266
|
-
const stripeAddressReady = !!((_a = stripeStore.stripeAddressEventData) === null || _a === void 0 ? void 0 : _a.complete);
|
|
267
|
-
const stripeLinkReady = !!((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.complete);
|
|
268
|
-
const stripeBillingAddressReady = stripeStore.stripeShippingSameAsBilling
|
|
269
|
-
? !!((_c = stripeStore.stripeLinkEventData) === null || _c === void 0 ? void 0 : _c.complete)
|
|
270
|
-
: !!((_d = stripeStore.stripeBillingAddressEventData) === null || _d === void 0 ? void 0 : _d.complete);
|
|
271
487
|
const shouldRefetch = isPrefetchInfoOutdated();
|
|
488
|
+
const isRequestReadyToPrefetch = isAddressReadyToRequestLandedCost();
|
|
489
|
+
// Should not do anything if the address is not ready to request landed cost
|
|
490
|
+
if (!isRequestReadyToPrefetch) {
|
|
491
|
+
return {
|
|
492
|
+
isRequestNotReady: true,
|
|
493
|
+
};
|
|
494
|
+
}
|
|
272
495
|
if (shouldRefetch) {
|
|
273
496
|
// if the info used when fetching landed cost is different from the current info, abort the previous request
|
|
274
|
-
(
|
|
497
|
+
(_a = stripeStore.fetchingLandedCostAbortController) === null || _a === void 0 ? void 0 : _a.abort();
|
|
275
498
|
stripeStore.fetchingLandedCostAbortController = null;
|
|
276
499
|
}
|
|
277
500
|
// Do not fetch if we are not ready or data is not outdated
|
|
278
|
-
if (
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
return;
|
|
501
|
+
if (!shouldRefetch && !applyingPromocode) {
|
|
502
|
+
return {
|
|
503
|
+
isRequestNotReady: false,
|
|
504
|
+
};
|
|
283
505
|
}
|
|
284
506
|
// If there is retries, stop loading for a moment and then showing the spinner again (this is just so customer can see that checkout is doing something and not stuck)
|
|
285
507
|
if (retries) {
|
|
@@ -292,24 +514,31 @@ const stripeStorePrefetchLandedCost = async (params) => {
|
|
|
292
514
|
stripeStore.isFetchingLandedCost = true;
|
|
293
515
|
}
|
|
294
516
|
if (stripeStore.stripeAddressEventData) {
|
|
295
|
-
stripeStore.stripeAddressUsedWhenFetchingLC =
|
|
517
|
+
stripeStore.stripeAddressUsedWhenFetchingLC = {
|
|
518
|
+
countryCode: stripeStore.stripeAddressEventData.value.address.country,
|
|
519
|
+
postalCode: stripeStore.stripeAddressEventData.value.address.postal_code,
|
|
520
|
+
state: stripeStore.stripeAddressEventData.value.address.state,
|
|
521
|
+
};
|
|
296
522
|
}
|
|
297
523
|
if (stripeStore.stripeBillingAddressEventData) {
|
|
298
|
-
stripeStore.stripeBillingAddressUsedWhenFetchingLC =
|
|
524
|
+
stripeStore.stripeBillingAddressUsedWhenFetchingLC = {
|
|
525
|
+
countryCode: stripeStore.stripeBillingAddressEventData.value.address.country,
|
|
526
|
+
postalCode: stripeStore.stripeBillingAddressEventData.value.address.postal_code,
|
|
527
|
+
state: stripeStore.stripeBillingAddressEventData.value.address.state,
|
|
528
|
+
};
|
|
299
529
|
}
|
|
300
530
|
if (stripeStore.stripeLinkEventData) {
|
|
301
531
|
stripeStore.stripeLinkUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeLinkEventData);
|
|
302
532
|
}
|
|
303
|
-
stripeStore.taxIdUsedWhenFetchingLC = stripeStore.taxId;
|
|
304
533
|
try {
|
|
305
534
|
// Reset cart items to non-restricted state and restricted item list
|
|
306
535
|
cartStoreResetCartItems();
|
|
307
536
|
// fetch and apply landed cost
|
|
308
537
|
await stripeCalculateLandedCost();
|
|
309
538
|
// This is the cheapest service level since we already sorted them after fetching landed cost
|
|
310
|
-
const cheapestServiceLevel = (
|
|
539
|
+
const cheapestServiceLevel = (_b = cartStore.shippingData) === null || _b === void 0 ? void 0 : _b.find(Boolean);
|
|
311
540
|
// Landed cost that matches with service level
|
|
312
|
-
const matchLandedCost = (
|
|
541
|
+
const matchLandedCost = (_c = cartStore.landedCostData) === null || _c === void 0 ? void 0 : _c.find(x => x.landedCost.shipmentRating.id === (cheapestServiceLevel === null || cheapestServiceLevel === void 0 ? void 0 : cheapestServiceLevel.id));
|
|
313
542
|
// apply new subtotal and total, this is mainly to show items in the presentment currency
|
|
314
543
|
const subtotals = !!matchLandedCost ? matchLandedCost.subtotals : null;
|
|
315
544
|
if (subtotals) {
|
|
@@ -333,9 +562,11 @@ const stripeStorePrefetchLandedCost = async (params) => {
|
|
|
333
562
|
if (retries < 1) {
|
|
334
563
|
// retry fetching landed cost one more time
|
|
335
564
|
await stripeStorePrefetchLandedCost(Object.assign(Object.assign({}, params), { retries: (retries || 0) + 1 }));
|
|
336
|
-
return
|
|
565
|
+
return {
|
|
566
|
+
isRequestNotReady: false,
|
|
567
|
+
};
|
|
337
568
|
}
|
|
338
|
-
const shipToAddress = (
|
|
569
|
+
const shipToAddress = (_d = stripeStore.stripeAddressEventData) === null || _d === void 0 ? void 0 : _d.value;
|
|
339
570
|
void sendErrorLog({
|
|
340
571
|
endpoint: `Failed to fetch landed cost (${retries} retries)`,
|
|
341
572
|
errors: [err.message],
|
|
@@ -348,6 +579,9 @@ const stripeStorePrefetchLandedCost = async (params) => {
|
|
|
348
579
|
logError(err);
|
|
349
580
|
}
|
|
350
581
|
stripeStore.isFetchingLandedCost = false;
|
|
582
|
+
return {
|
|
583
|
+
isRequestNotReady: false,
|
|
584
|
+
};
|
|
351
585
|
};
|
|
352
586
|
const stripeStoreApplyPromoCode = async () => {
|
|
353
587
|
var _a, _b;
|
|
@@ -358,6 +592,8 @@ const stripeStoreApplyPromoCode = async () => {
|
|
|
358
592
|
if (cartStore.step === 'payment') {
|
|
359
593
|
cartStorePreviousStep();
|
|
360
594
|
}
|
|
595
|
+
// async update address with new root id from the new quote
|
|
596
|
+
await stripeStoreAsyncAddressUpdate();
|
|
361
597
|
// This is the cheapest service level since we already sorted them after fetching landed cost
|
|
362
598
|
const cheapestServiceLevel = (_a = cartStore.shippingData) === null || _a === void 0 ? void 0 : _a.find(Boolean);
|
|
363
599
|
// Landed cost that matches with service level
|
|
@@ -736,6 +972,7 @@ const stripeStoreUpdateCheckoutSession = async ({ adjustmentsAmount, cartId, cur
|
|
|
736
972
|
const { errors, json } = await handleFetch('/api/zonos-elements/update-checkout-session', {
|
|
737
973
|
body: {
|
|
738
974
|
adjustmentsAmount,
|
|
975
|
+
billToPartyId: stripeStore.partyBillingId,
|
|
739
976
|
cartId,
|
|
740
977
|
currency,
|
|
741
978
|
customerAuthenticationToken: cartStore.customerAuthenticationToken || undefined,
|
|
@@ -749,6 +986,7 @@ const stripeStoreUpdateCheckoutSession = async ({ adjustmentsAmount, cartId, cur
|
|
|
749
986
|
},
|
|
750
987
|
],
|
|
751
988
|
presentmentCountryCode,
|
|
989
|
+
shipToPartyId: stripeStore.partyShippingId,
|
|
752
990
|
skipPaymentIntent: stripeStore.skipPaymentIntent,
|
|
753
991
|
varianceTestInput,
|
|
754
992
|
},
|
|
@@ -888,4 +1126,4 @@ stripeStoreOnChange('clientSecret', clientSecret => {
|
|
|
888
1126
|
sessionStorage.removeItem('zonos--client-secret');
|
|
889
1127
|
}
|
|
890
1128
|
});
|
|
891
|
-
export { initStripeElements, stripeCalculateLandedCost, stripeStore, stripeStoreApplyPromoCode, stripeStoreCleanupDomesticShippingSession, stripeStoreConfirmPayment, stripeStoreGetDomesticShippingSession, stripeStoreGetPaymentIntent, stripeStoreHandleInventoryCheck, stripeStoreHandleInventoryRefund, stripeStoreInitCheckoutSession, stripeStoreMessageBasedOnStatus, stripeStoreOnChange, stripeStorePrefetchLandedCost, stripeStoreRemovePromoCode, stripeStoreReset, stripeStoreResetPromoCode, stripeStoreRetrievePayment, stripeStoreSaveDomesticShippingSession, stripeStoreTranslateAddressToLatin, stripeStoreUpdateCheckoutSession, stripeStoreUpdateCheckoutSessionBaseCurrency, };
|
|
1129
|
+
export { initStripeElements, stripeCalculateLandedCost, stripeStore, stripeStoreApplyPromoCode, stripeStoreAsyncAddressUpdate, stripeStoreCleanupDomesticShippingSession, stripeStoreConfirmPayment, stripeStoreGetDomesticShippingSession, stripeStoreGetPaymentIntent, stripeStoreHandleInventoryCheck, stripeStoreHandleInventoryRefund, stripeStoreInitCheckoutSession, stripeStoreMessageBasedOnStatus, stripeStoreOnChange, stripeStorePrefetchLandedCost, stripeStoreRemovePromoCode, stripeStoreReset, stripeStoreResetPromoCode, stripeStoreRetrievePayment, stripeStoreSaveDomesticShippingSession, stripeStoreTranslateAddressToLatin, stripeStoreUpdateCheckoutSession, stripeStoreUpdateCheckoutSessionBaseCurrency, };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { h, Host, } from "@stencil/core";
|
|
2
|
-
import
|
|
2
|
+
import throttle from "lodash/throttle";
|
|
3
|
+
import { stripeStore, stripeStorePrefetchLandedCost, } from "../../store/checkout/stripe";
|
|
3
4
|
import { getFallbackDefaultCountryCode, localizationStore, } from "../../store/hello/localization";
|
|
4
5
|
import { storageStore, storageStoreOnChange, } from "../../store/storageStore";
|
|
5
6
|
import { translate } from "../../store/translationStore";
|
|
@@ -41,10 +42,16 @@ export class ZonosAddress {
|
|
|
41
42
|
* Local checkout session id to check if the address is filled after checkout is loaded
|
|
42
43
|
*/
|
|
43
44
|
this.checkoutSessionId = storageStore.checkoutSessionId;
|
|
45
|
+
/**
|
|
46
|
+
* Track previous country and postal code to detect changes
|
|
47
|
+
*/
|
|
48
|
+
this.prevCountry = null;
|
|
49
|
+
this.prevPostalCode = null;
|
|
44
50
|
/**
|
|
45
51
|
* Check if the tracking event is sent
|
|
46
52
|
*/
|
|
47
53
|
this.trackingSent = false;
|
|
54
|
+
this.prefetchLandedCost = throttle(stripeStorePrefetchLandedCost, 1000);
|
|
48
55
|
this.onStoreCheckoutSessionIdChanged = () => {
|
|
49
56
|
const onCheckoutSessionIdChange = () => {
|
|
50
57
|
this.checkoutSessionId = storageStore.checkoutSessionId;
|
|
@@ -78,6 +85,13 @@ export class ZonosAddress {
|
|
|
78
85
|
break;
|
|
79
86
|
}
|
|
80
87
|
}
|
|
88
|
+
// Only trigger landed cost prefetch for shipping address
|
|
89
|
+
if (type === 'shipping') {
|
|
90
|
+
// if line 1 has something, trigger prefetch
|
|
91
|
+
if (event.value.address.line1.length) {
|
|
92
|
+
void this.prefetchLandedCost();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
81
95
|
}
|
|
82
96
|
isAddressFilledChanged() {
|
|
83
97
|
// Sometimes address elements is loaded with prefilled data before checkout is loaded, need to not send the event if checkout session id is not available, and send the event after checkout is loaded
|
|
@@ -149,6 +163,11 @@ export class ZonosAddress {
|
|
|
149
163
|
},
|
|
150
164
|
});
|
|
151
165
|
addressElement.mount(this.el.querySelector('.zonos--address-component'));
|
|
166
|
+
// Initialize previous values if address data exists
|
|
167
|
+
if (stripeAddressEventData === null || stripeAddressEventData === void 0 ? void 0 : stripeAddressEventData.value.address) {
|
|
168
|
+
this.prevCountry = stripeAddressEventData.value.address.country;
|
|
169
|
+
this.prevPostalCode = stripeAddressEventData.value.address.postal_code;
|
|
170
|
+
}
|
|
152
171
|
addressElement.on('change', event => {
|
|
153
172
|
const eventValue = event.value;
|
|
154
173
|
if (!this.isDirtyAddress && eventValue.address.line1.length >= 3) {
|
|
@@ -280,7 +299,7 @@ export class ZonosAddress {
|
|
|
280
299
|
this.isAddressFilled = true;
|
|
281
300
|
}
|
|
282
301
|
// this component loads iframe from the stripe elements and puts here, so we don't need to do anything here
|
|
283
|
-
return (h(Host, { key: '
|
|
302
|
+
return (h(Host, { key: '6cb2f40dc810982251bdb24bd373ef5dc5b26cd2', class: "zonos--address zonos--elements" }, h("zonos-text", { key: 'f7b393a508bc5f1921924090c365cdf41f23f0e7', class: "zonos--title", type: "semiBoldLabel" }, this.titleText), this.renderCompanyNameInput(), this.renderTaxIdInput(), h("div", { key: '9bd11de0b90f7ad7328cf37694c7d4e2a2d73f06', class: "zonos--address-component" })));
|
|
284
303
|
}
|
|
285
304
|
static get is() { return "zonos-address"; }
|
|
286
305
|
static get encapsulation() { return "scoped"; }
|
|
@@ -385,7 +404,9 @@ export class ZonosAddress {
|
|
|
385
404
|
"stripe": {},
|
|
386
405
|
"isDirtyAddress": {},
|
|
387
406
|
"isAddressFilled": {},
|
|
388
|
-
"checkoutSessionId": {}
|
|
407
|
+
"checkoutSessionId": {},
|
|
408
|
+
"prevCountry": {},
|
|
409
|
+
"prevPostalCode": {}
|
|
389
410
|
};
|
|
390
411
|
}
|
|
391
412
|
static get events() {
|
|
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
};
|
|
13
13
|
import { h, Host, } from "@stencil/core";
|
|
14
14
|
import throttle from "lodash/throttle";
|
|
15
|
-
import { stripeStore } from "../../store/checkout/stripe";
|
|
15
|
+
import { stripeStore, stripeStorePrefetchLandedCost, } from "../../store/checkout/stripe";
|
|
16
16
|
import { localizationStore } from "../../store/hello/localization";
|
|
17
17
|
import { storageStore, storageStoreOnChange, } from "../../store/storageStore";
|
|
18
18
|
import { translate } from "../../store/translationStore";
|
|
@@ -283,6 +283,8 @@ export class ZonosAddress {
|
|
|
283
283
|
break;
|
|
284
284
|
default: {
|
|
285
285
|
stripeStore.stripeAddressEventData = event;
|
|
286
|
+
// send request to prefetch landed cost
|
|
287
|
+
void stripeStorePrefetchLandedCost();
|
|
286
288
|
break;
|
|
287
289
|
}
|
|
288
290
|
}
|
|
@@ -803,7 +805,7 @@ export class ZonosAddress {
|
|
|
803
805
|
this.state = event.detail;
|
|
804
806
|
}, options: stateOptions, required: (_k = this.countryField) === null || _k === void 0 ? void 0 : _k.stateRequired, selectLabel: translate(((_l = this.countryField) === null || _l === void 0 ? void 0 : _l.stateLabel) || 'State'), selectedValue: stripeAddressEventData === null || stripeAddressEventData === void 0 ? void 0 : stripeAddressEventData.value.address.state, title: `${this.type} state` })), ((_m = this.countryField) === null || _m === void 0 ? void 0 : _m.zipShow) && (h("zonos-stripe-input", { "aria-describedby": ((_o = this.countryField) === null || _o === void 0 ? void 0 : _o.zipFormat)
|
|
805
807
|
? `zip-format-${this.type}`
|
|
806
|
-
: undefined, "aria-required": ((_p = this.countryField) === null || _p === void 0 ? void 0 : _p.zipRequired) ? 'true' : 'false', autoComplete: "shipping postal-code", class: "zonos--custom-address-form-input", error: showError ? customAddressErrors.postalCode : undefined, inputLabel: translate(((_q = this.countryField) === null || _q === void 0 ? void 0 : _q.zipLabel) || 'Zip'), inputValue: (stripeAddressEventData === null || stripeAddressEventData === void 0 ? void 0 : stripeAddressEventData.value.address.postal_code) || '', onInputChange: (event) => {
|
|
808
|
+
: undefined, "aria-required": ((_p = this.countryField) === null || _p === void 0 ? void 0 : _p.zipRequired) ? 'true' : 'false', autoComplete: "shipping postal-code", class: "zonos--custom-address-form-input", error: showError ? customAddressErrors.postalCode : undefined, inputLabel: translate(((_q = this.countryField) === null || _q === void 0 ? void 0 : _q.zipLabel) || 'Zip'), inputValue: (stripeAddressEventData === null || stripeAddressEventData === void 0 ? void 0 : stripeAddressEventData.value.address.postal_code) || '', name: "postalCode", onInputChange: (event) => {
|
|
807
809
|
this.validate({
|
|
808
810
|
type: this.type,
|
|
809
811
|
value: event.detail,
|
|
@@ -817,7 +819,7 @@ export class ZonosAddress {
|
|
|
817
819
|
* Therefore, we must update the value after validation to ensure correct error state
|
|
818
820
|
*/
|
|
819
821
|
this.postalCode = event.detail;
|
|
820
|
-
}, required: (_r = this.countryField) === null || _r === void 0 ? void 0 : _r.zipRequired }))), h("zonos-stripe-phone-input", { autoComplete: "shipping tel", class: "zonos--custom-address-form-input", countryCode: stripeAddressEventData === null || stripeAddressEventData === void 0 ? void 0 : stripeAddressEventData.value.address.country, countryOptions: (_s = zonosStore.genericSettings) === null || _s === void 0 ? void 0 : _s.countryFields, error: showError ? customAddressErrors.phone : undefined, inputLabel: translate('Phone number'), inputValue: (stripeAddressEventData === null || stripeAddressEventData === void 0 ? void 0 : stripeAddressEventData.value.phone) || '', onInputValueChange: event => {
|
|
822
|
+
}, required: (_r = this.countryField) === null || _r === void 0 ? void 0 : _r.zipRequired, title: `${this.type} zip code` }))), h("zonos-stripe-phone-input", { autoComplete: "shipping tel", class: "zonos--custom-address-form-input", countryCode: stripeAddressEventData === null || stripeAddressEventData === void 0 ? void 0 : stripeAddressEventData.value.address.country, countryOptions: (_s = zonosStore.genericSettings) === null || _s === void 0 ? void 0 : _s.countryFields, error: showError ? customAddressErrors.phone : undefined, inputLabel: translate('Phone number'), inputValue: (stripeAddressEventData === null || stripeAddressEventData === void 0 ? void 0 : stripeAddressEventData.value.phone) || '', onInputValueChange: event => {
|
|
821
823
|
const { isEmpty, phoneNumber, valid, wrongFormat } = event.detail;
|
|
822
824
|
// Validate the phone number
|
|
823
825
|
this.validate({
|
|
@@ -888,10 +890,10 @@ export class ZonosAddress {
|
|
|
888
890
|
this.country = localizationStore.selectedCountryCode;
|
|
889
891
|
}
|
|
890
892
|
// this component loads iframe from the stripe elements and puts here, so we don't need to do anything here
|
|
891
|
-
return (h(Host, { key: '
|
|
893
|
+
return (h(Host, { key: '668f481c1b31dd6e756d95b5c382592681cea23d', class: classes([
|
|
892
894
|
'zonos--address zonos--elements',
|
|
893
895
|
`zonos--${this.type}-address`,
|
|
894
|
-
]) }, h("zonos-text", { key: '
|
|
896
|
+
]) }, h("zonos-text", { key: 'a31cd25d43d9262d408e6ced8330cbe1c51bdd47', class: "zonos--title", type: "semiBoldLabel" }, this.titleText), this.renderCompanyNameInput(), this.renderTaxIdInput(), this.renderCustomAddressForm()));
|
|
895
897
|
}
|
|
896
898
|
static get is() { return "zonos-custom-address"; }
|
|
897
899
|
static get encapsulation() { return "scoped"; }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { prepCartCalculateLandedCost } from "./prepCalculateLandedCost";
|
|
2
2
|
import { handleFetch } from "../handleFetch";
|
|
3
3
|
export const cartCalculateLandedCost = async ({ abortController, cartId, }) => {
|
|
4
|
-
var _a;
|
|
4
|
+
var _a, _b;
|
|
5
5
|
// request to get landed cost info
|
|
6
6
|
const { errors, json } = await handleFetch('/api/zonos-elements/cart-calculate-landed-cost', {
|
|
7
7
|
body: prepCartCalculateLandedCost(cartId),
|
|
@@ -9,7 +9,8 @@ export const cartCalculateLandedCost = async ({ abortController, cartId, }) => {
|
|
|
9
9
|
signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
|
|
10
10
|
});
|
|
11
11
|
if (errors.length || !json) {
|
|
12
|
-
const isAbortedRequest = ((_a = errors[0]) === null || _a === void 0 ? void 0 : _a.message) === 'The user aborted a request.'
|
|
12
|
+
const isAbortedRequest = ((_a = errors[0]) === null || _a === void 0 ? void 0 : _a.message) === 'The user aborted a request.' ||
|
|
13
|
+
((_b = errors[0]) === null || _b === void 0 ? void 0 : _b.message.includes('signal is aborted'));
|
|
13
14
|
const errorMessage = isAbortedRequest
|
|
14
15
|
? 'The landed cost calculation request was aborted to initiate a new one.'
|
|
15
16
|
: 'Failed to calculate landed cost';
|