@zonos/elements 1.3.243 → 1.3.244
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-6d254f1a.js → cart-52cf3366.js} +1 -1
- package/dist/cjs/{hasInclusivePrice-ac0440e7.js → hasInclusivePrice-dbb82df8.js} +1 -1
- package/dist/cjs/index.cjs.js +7 -7
- package/dist/cjs/{invoice-8984eb26.js → invoice-972f1ab3.js} +2 -2
- package/dist/cjs/{isCollectMobileTablet-7e929884.js → isCollectMobileTablet-fd11246c.js} +2 -2
- package/dist/cjs/{localization-ec5a6780.js → localization-b1075a8c.js} +60 -0
- package/dist/cjs/{paypal-0f4b77fd.js → paypal-e339cc8c.js} +2 -2
- package/dist/cjs/{placeTestOrder-6cc9d040.js → placeTestOrder-3dfbe3d6.js} +2 -2
- package/dist/cjs/{renderCheckoutCurrency-df60f3a6.js → renderCheckoutCurrency-55056c97.js} +2 -2
- package/dist/cjs/zonos-address-display_9.cjs.entry.js +2 -2
- package/dist/cjs/zonos-address_4.cjs.entry.js +2 -2
- package/dist/cjs/zonos-card_5.cjs.entry.js +3 -3
- package/dist/cjs/zonos-cart-items_12.cjs.entry.js +19 -6
- package/dist/cjs/zonos-checkout.cjs.entry.js +3 -3
- package/dist/cjs/zonos-collect-cart-items_3.cjs.entry.js +2 -2
- package/dist/cjs/zonos-collect-finish_6.cjs.entry.js +6 -6
- package/dist/cjs/zonos-collect.cjs.entry.js +4 -4
- package/dist/cjs/zonos-controller.cjs.entry.js +2 -2
- package/dist/cjs/zonos-country-flag.cjs.entry.js +1 -1
- package/dist/cjs/zonos-country-select_4.cjs.entry.js +1 -1
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +2 -2
- package/dist/cjs/zonos-hello.cjs.entry.js +1 -1
- package/dist/cjs/zonos-invoice-cart-items_2.cjs.entry.js +4 -4
- package/dist/cjs/zonos-invoice-finish_5.cjs.entry.js +6 -6
- package/dist/cjs/zonos-invoice.cjs.entry.js +4 -4
- package/dist/cjs/zonos-language-select_2.cjs.entry.js +1 -1
- package/dist/collection/components/store/translationStore/strings.arabic.js +3 -0
- package/dist/collection/components/store/translationStore/strings.base.js +3 -0
- package/dist/collection/components/store/translationStore/strings.chinese.js +3 -0
- package/dist/collection/components/store/translationStore/strings.danish.js +3 -0
- package/dist/collection/components/store/translationStore/strings.dutch.js +3 -0
- package/dist/collection/components/store/translationStore/strings.french.js +3 -0
- package/dist/collection/components/store/translationStore/strings.german.js +3 -0
- package/dist/collection/components/store/translationStore/strings.hebrew.js +3 -0
- package/dist/collection/components/store/translationStore/strings.indonesian.js +3 -0
- package/dist/collection/components/store/translationStore/strings.italian.js +3 -0
- package/dist/collection/components/store/translationStore/strings.japanese.js +3 -0
- package/dist/collection/components/store/translationStore/strings.korean.js +3 -0
- package/dist/collection/components/store/translationStore/strings.norwegian.js +3 -0
- package/dist/collection/components/store/translationStore/strings.polish.js +3 -0
- package/dist/collection/components/store/translationStore/strings.portuguese.js +3 -0
- package/dist/collection/components/store/translationStore/strings.russian.js +3 -0
- package/dist/collection/components/store/translationStore/strings.spanish.js +3 -0
- package/dist/collection/components/store/translationStore/strings.swedish.js +3 -0
- package/dist/collection/components/store/translationStore/strings.turkish.js +3 -0
- package/dist/collection/components/store/translationStore/strings.vietnamese.js +3 -0
- package/dist/collection/components/utils/taxIdValidationResult.js +13 -0
- package/dist/esm/{cart-00134a17.js → cart-7f4704dc.js} +1 -1
- package/dist/esm/{hasInclusivePrice-f41e52b8.js → hasInclusivePrice-3958ed11.js} +1 -1
- package/dist/esm/index.js +7 -7
- package/dist/esm/{invoice-4a8178f8.js → invoice-d3d256fb.js} +2 -2
- package/dist/esm/{isCollectMobileTablet-70fa91b6.js → isCollectMobileTablet-27693de5.js} +2 -2
- package/dist/esm/{localization-ee8bb238.js → localization-401ec6d4.js} +60 -0
- package/dist/esm/{paypal-2e28d0e7.js → paypal-61270b79.js} +2 -2
- package/dist/esm/{placeTestOrder-aa884e31.js → placeTestOrder-c2180600.js} +2 -2
- package/dist/esm/{renderCheckoutCurrency-54994d08.js → renderCheckoutCurrency-dea06d44.js} +2 -2
- package/dist/esm/zonos-address-display_9.entry.js +2 -2
- package/dist/esm/zonos-address_4.entry.js +2 -2
- package/dist/esm/zonos-card_5.entry.js +3 -3
- package/dist/esm/zonos-cart-items_12.entry.js +19 -6
- package/dist/esm/zonos-checkout.entry.js +3 -3
- package/dist/esm/zonos-collect-cart-items_3.entry.js +2 -2
- package/dist/esm/zonos-collect-finish_6.entry.js +6 -6
- package/dist/esm/zonos-collect.entry.js +4 -4
- package/dist/esm/zonos-controller.entry.js +2 -2
- package/dist/esm/zonos-country-flag.entry.js +1 -1
- package/dist/esm/zonos-country-select_4.entry.js +1 -1
- package/dist/esm/zonos-hello-dialog.entry.js +2 -2
- package/dist/esm/zonos-hello.entry.js +1 -1
- package/dist/esm/zonos-invoice-cart-items_2.entry.js +4 -4
- package/dist/esm/zonos-invoice-finish_5.entry.js +6 -6
- package/dist/esm/zonos-invoice.entry.js +4 -4
- package/dist/esm/zonos-language-select_2.entry.js +1 -1
- package/dist/esm-es5/{cart-00134a17.js → cart-7f4704dc.js} +1 -1
- package/dist/esm-es5/{hasInclusivePrice-f41e52b8.js → hasInclusivePrice-3958ed11.js} +1 -1
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/{invoice-4a8178f8.js → invoice-d3d256fb.js} +1 -1
- package/dist/esm-es5/{isCollectMobileTablet-70fa91b6.js → isCollectMobileTablet-27693de5.js} +1 -1
- package/dist/esm-es5/localization-401ec6d4.js +1 -0
- package/dist/esm-es5/{paypal-2e28d0e7.js → paypal-61270b79.js} +1 -1
- package/dist/esm-es5/{placeTestOrder-aa884e31.js → placeTestOrder-c2180600.js} +1 -1
- package/dist/esm-es5/{renderCheckoutCurrency-54994d08.js → renderCheckoutCurrency-dea06d44.js} +1 -1
- package/dist/esm-es5/zonos-address-display_9.entry.js +1 -1
- package/dist/esm-es5/zonos-address_4.entry.js +1 -1
- package/dist/esm-es5/zonos-card_5.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_12.entry.js +1 -1
- package/dist/esm-es5/zonos-checkout.entry.js +1 -1
- package/dist/esm-es5/zonos-collect-cart-items_3.entry.js +1 -1
- package/dist/esm-es5/zonos-collect-finish_6.entry.js +1 -1
- package/dist/esm-es5/zonos-collect.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-hello-dialog.entry.js +1 -1
- package/dist/esm-es5/zonos-hello.entry.js +1 -1
- package/dist/esm-es5/zonos-invoice-cart-items_2.entry.js +1 -1
- package/dist/esm-es5/zonos-invoice-finish_5.entry.js +1 -1
- package/dist/esm-es5/zonos-invoice.entry.js +1 -1
- package/dist/esm-es5/zonos-language-select_2.entry.js +1 -1
- package/dist/scripts/index.d.ts +3 -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/store/translationStore/strings.arabic.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.base.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.chinese.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.danish.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.dutch.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.french.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.german.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.hebrew.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.indonesian.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.italian.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.japanese.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.korean.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.norwegian.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.polish.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.portuguese.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.russian.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.spanish.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.swedish.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.turkish.d.ts +3 -0
- package/dist/types/components/store/translationStore/strings.vietnamese.d.ts +3 -0
- package/dist/types/components/utils/taxIdValidationResult.d.ts +1 -1
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/{p-cfb2b5c7.entry.js → p-0aada8ab.entry.js} +1 -1
- package/dist/zonos-elements/{p-41147617.entry.js → p-1216cfb3.entry.js} +1 -1
- package/dist/zonos-elements/{p-e3b4a218.system.entry.js → p-133e9ce7.system.entry.js} +1 -1
- package/dist/zonos-elements/p-1d91e5d1.entry.js +1 -0
- package/dist/zonos-elements/p-21fb6b39.js +1 -0
- package/dist/zonos-elements/{p-10b1f35f.entry.js → p-2601538e.entry.js} +1 -1
- package/dist/zonos-elements/{p-914149a4.js → p-276faa43.js} +1 -1
- package/dist/zonos-elements/{p-20c5d640.system.entry.js → p-2889a485.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-c9db8939.js → p-288aab46.js} +1 -1
- package/dist/zonos-elements/{p-0e70900c.entry.js → p-291b85f7.entry.js} +1 -1
- package/dist/zonos-elements/{p-6b1091f1.system.entry.js → p-367c13db.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-1db4ae37.system.entry.js → p-38bdbdcc.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-599347f4.system.entry.js → p-3b1898bc.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-56107bdf.system.entry.js → p-3f078bf5.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-dbea1f9b.entry.js → p-3f46d83e.entry.js} +1 -1
- package/dist/zonos-elements/{p-0fcd7a94.system.js → p-415c2a90.system.js} +1 -1
- package/dist/zonos-elements/{p-29bb70e0.entry.js → p-4bd8a16c.entry.js} +1 -1
- package/dist/zonos-elements/{p-7a4a4b52.entry.js → p-4d7b82b5.entry.js} +1 -1
- package/dist/zonos-elements/{p-11e79ab7.system.js → p-515cff20.system.js} +1 -1
- package/dist/zonos-elements/{p-633017f0.system.entry.js → p-5be33a13.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-d042455d.entry.js → p-5f956a0d.entry.js} +1 -1
- package/dist/zonos-elements/{p-90e10b7e.system.entry.js → p-6b9b7cfb.system.entry.js} +1 -1
- package/dist/zonos-elements/p-74e258ff.system.js +1 -0
- package/dist/zonos-elements/{p-73e79407.entry.js → p-7521549c.entry.js} +1 -1
- package/dist/zonos-elements/{p-675dd093.system.js → p-775c1122.system.js} +1 -1
- package/dist/zonos-elements/{p-f7e6c1b5.system.entry.js → p-78c8bb58.system.entry.js} +1 -1
- package/dist/zonos-elements/p-85430ec1.js +1 -0
- package/dist/zonos-elements/{p-c11668b5.system.entry.js → p-8d2e24a4.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-47f02d2a.system.entry.js → p-8dc7d82f.system.entry.js} +1 -1
- package/dist/zonos-elements/p-95524f54.js +1 -0
- package/dist/zonos-elements/{p-899c3878.system.entry.js → p-95703417.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-67e19c00.system.entry.js → p-993723c2.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-6d82c3a4.js → p-a0a62b7e.js} +2 -2
- package/dist/zonos-elements/{p-6beaff11.entry.js → p-a3411f20.entry.js} +1 -1
- package/dist/zonos-elements/{p-069e8b40.entry.js → p-a53d3d46.entry.js} +1 -1
- package/dist/zonos-elements/{p-6fad6110.system.js → p-a556ec07.system.js} +1 -1
- package/dist/zonos-elements/{p-f5cfce05.js → p-a6489088.js} +1 -1
- package/dist/zonos-elements/{p-c02e3fef.js → p-a79f3685.js} +1 -1
- package/dist/zonos-elements/{p-975c6928.system.js → p-acc0eee3.system.js} +1 -1
- package/dist/zonos-elements/{p-0a1b82df.entry.js → p-ba228769.entry.js} +1 -1
- package/dist/zonos-elements/p-c2442878.system.js +1 -1
- package/dist/zonos-elements/{p-af7e37c1.system.entry.js → p-c62b6741.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-ea1d5802.entry.js → p-c708f7e9.entry.js} +1 -1
- package/dist/zonos-elements/{p-4fc549f4.system.entry.js → p-c88cd318.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-343dee8b.system.js → p-d1effb76.system.js} +1 -1
- package/dist/zonos-elements/{p-68f419f1.system.js → p-e0809901.system.js} +1 -1
- package/dist/zonos-elements/{p-b3dbe0ec.system.js → p-e7543082.system.js} +1 -1
- package/dist/zonos-elements/{p-9691381e.entry.js → p-e90e9584.entry.js} +1 -1
- package/dist/zonos-elements/{p-c8e5bb8a.entry.js → p-ebef34e3.entry.js} +1 -1
- package/dist/zonos-elements/{p-60443628.system.entry.js → p-f6c6b6d3.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-a04c7b1e.entry.js → p-faae5eca.entry.js} +1 -1
- package/dist/zonos-elements/{p-75813a38.system.entry.js → p-fe699cc5.system.entry.js} +1 -1
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +1 -1
- package/dist/esm-es5/localization-ee8bb238.js +0 -1
- package/dist/zonos-elements/p-2dd9b3e0.entry.js +0 -1
- package/dist/zonos-elements/p-4d2ed8d5.js +0 -1
- package/dist/zonos-elements/p-6dc9b9e5.js +0 -1
- package/dist/zonos-elements/p-752dae00.system.js +0 -1
- package/dist/zonos-elements/p-fab5f272.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{z as e,c as t}from"./p-b2a0ab4a.js";import{s as o,l as n,e as s,t as r,f as i,b as a}from"./p-fab5f272.js";import{f as d,h as l,g as c,a as u,s as m,l as p,j as v}from"./p-41dd1cb8.js";import{l as h,b as y}from"./p-0a377722.js";import{i as w}from"./p-57fa64d7.js";import{g}from"./p-1f894984.js";const f=({firstName:e,lastName:t,name:o})=>{var n;if(!o&&!e&&!t)return{firstName:"",lastName:""};const s=(null==o?void 0:o.split(/\s+/))||[];return{firstName:(null==e?void 0:e.trim())||(null===(n=s[0])||void 0===n?void 0:n.trim())||"",lastName:(null==t?void 0:t.trim())||s.slice(1).join(" ").trim()||""}},b=({currentAddress:e,translatedAddress:t})=>{var o,n,s,r,i,a;const{city:d,country:l,line1:c,line2:u,postal_code:m,state:p}=e.value.address,v=e.value.name||[e.value.firstName,e.value.lastName].join(" ");return{city:(null===(o=t.city)||void 0===o?void 0:o[d])||d,country:l,line1:(null===(n=t.line1)||void 0===n?void 0:n[c])||c,line2:(null===(s=t.line2)||void 0===s?void 0:s[u||""])||u||"",name:(null===(r=t.name)||void 0===r?void 0:r[v])||v,phone:e.value.phone||"",postal_code:(null===(i=t.postal_code)||void 0===i?void 0:i[m])||m,state:(null===(a=t.state)||void 0===a?void 0:a[p])||p}},S=e=>{var t;const r="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),i=D.stripeLinkEventData,a=D.stripeAddressEventData,d=D.stripeShippingSameAsBilling?D.stripeAddressEventData:D.stripeBillingAddressEventData;if(!a||!d)throw new Error("Missing stripe address data");const l=b({currentAddress:a,translatedAddress:D.translatedAddress.address}),{firstName:c,lastName:u}=f({name:l.name}),m=b({currentAddress:d,translatedAddress:D.translatedAddress.address}),{firstName:p,lastName:v}=f({name:m.name}),h=s()||"US";return{billingAddress:{addressLine1:m.line1,addressLine2:m.line2||"",city:m.city,country:m.country,postalCode:m.postal_code,state:m.state},billingContact:{firstName:p,lastName:v,phone:m.phone},cartCurrencyCode:null===(t=se.items[0])||void 0===t?void 0:t.currencyCode,cartId:e,checkoutSessionCountry:h||n.selectedCountryCode||void 0,checkoutSessionId:o.checkoutSessionId||"",contact:{companyName:D.companyName,email:null==i?void 0:i.value.email,firstName:c,lastName:u,phone:l.phone},isTest:!!r,landedCostAdjustments:se.promoCode?[{amount:0,productId:null,promoCode:se.promoCode,sku:null,type:"PROMO_CODE"}]:[],shipToTaxId:D.taxId,shippingAddress:{addressLine1:l.line1,addressLine2:l.line2,city:l.city,country:l.country,postalCode:l.postal_code,state:l.state}}},C=()=>{const e="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),t=D.stripeLinkEventData,n=D.stripeAddressEventData,s=D.stripeShippingSameAsBilling?D.stripeAddressEventData:D.stripeBillingAddressEventData;if(h({stripeAddressData:n,stripeBillingAddressData:s},"info"),!n||!s)throw new Error("Missing stripe address data");const r=b({currentAddress:n,translatedAddress:D.translatedAddress.address}),{firstName:i,lastName:a}=f({name:r.name}),d=b({currentAddress:s,translatedAddress:D.translatedAddress.address}),{firstName:l,lastName:c}=f({name:d.name}),u=se.adjustments.map((e=>({amount:e.amount,name:e.description||null,productId:e.productId,sku:e.sku,type:e.type}))),m=se.promoCode?[{amount:0,productId:null,promoCode:se.promoCode,sku:null,type:"PROMO_CODE"},...u]:u;return{billingAddress:{addressLine1:d.line1,addressLine2:d.line2||"",city:d.city,country:d.country,postalCode:d.postal_code,state:d.state},billingContact:{firstName:l,lastName:c,phone:d.phone},checkoutSessionId:o.checkoutSessionId||"",contact:{companyName:D.companyName,email:null==t?void 0:t.value.email,firstName:i,lastName:a,phone:r.phone},isTest:e,items:se.items,landedCostAdjustments:m,shipToTaxId:D.taxId,shippingAddress:{addressLine1:r.line1,addressLine2:r.line2,city:r.city,country:r.country,postalCode:r.postal_code,state:r.state}}};const O=async t=>{const o=window.Zonos.cartId;if(!o)return await(async t=>{var o;const n=e.checkoutSettings.buildLandedCost;if(n){const e=await(async e=>{var t,o,n,s,r;const i=C(),a=await e({billingAddress:i.billingAddress,billingContact:i.billingContact,checkoutSessionId:i.checkoutSessionId,contact:i.contact,landedCostAdjustments:i.landedCostAdjustments,publicCredential:window.Zonos.zonosApiKey||"",shippingAddress:i.shippingAddress,zonosApiRoute:d.vercel},{promoCode:se.promoCode});if(!a||!(null===(t=a.checkoutSessionWorkflow)||void 0===t?void 0:t.length)&&(null===(o=a.errors)||void 0===o?void 0:o.length))throw new Error(`Failed to build landed cost: ${(null===(s=null===(n=null==a?void 0:a.errors)||void 0===n?void 0:n[0])||void 0===s?void 0:s.message)||"Unknown error"}`);const{errors:c,json:u}=await l("/api/zonos-elements/validate-landed-cost",{body:a,headers:{"Content-Type":"application/json"},method:"POST"});if(!u||c.length)throw new Error(`Invalid landed cost object: ${(null===(r=c.find(Boolean))||void 0===r?void 0:r.message)||"Unknown error"}`);return a})(n);return e}const{errors:s,json:r}=await l("/api/zonos-elements/calculate-landed-cost",{body:C(),method:"POST",signal:null==t?void 0:t.signal});if(s.length||!r){if("The user aborted a request."===(null===(o=s[0])||void 0===o?void 0:o.message))throw new Error("The landed cost calculation request was aborted to initiate a new one.");if(s.forEach((e=>{console.warn(`Error calculating landed cost: ${e.message}`)})),!r)throw new Error("Failed to calculate landed cost");return r}return r})(t);const n=await(async({abortController:e,cartId:t})=>{var o,n,s,r,i;const{errors:a,json:d}=await l("/api/zonos-elements/cart-calculate-landed-cost",{body:S(t),method:"POST",signal:null==e?void 0:e.signal});if(a.length||!d){const e="string"==typeof(null===(o=a[0])||void 0===o?void 0:o.message)&&("The user aborted a request."===(null===(n=a[0])||void 0===n?void 0:n.message)||(null===(s=a[0])||void 0===s?void 0:s.message.includes("signal is aborted"))||(null===(r=a[0])||void 0===r?void 0:r.message.includes("The operation was aborted"))||(null===(i=a[0])||void 0===i?void 0:i.message.includes("Fetch is aborted")));throw new Error(e?"The landed cost calculation request was aborted to initiate a new one.":"Failed to calculate landed cost")}return d})({abortController:t,cartId:o}),{cartWorkflow:s}=n,r=function(e,t){var o={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++)t.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(o[n[s]]=e[n[s]])}return o}(n,["cartWorkflow"]);return Object.assign(Object.assign({},r),{itemCreateWorkflow:s.items})},A=async({checkoutSessionId:t,eventName:o,metadata:s})=>{var r,i;const a=Date.now(),d=[...window.Zonos.trackEventLogs];window.Zonos.trackEventLogs.push({checkoutSessionId:t,eventCreated:a,eventName:o});const p=window.location.href.includes("zonos.com")&&!window.location.href.includes("checkout.zonos.com")||!!(null===(r=window.Zonos)||void 0===r?void 0:r.zonosQaUrl)||!!(null===(i=window.Zonos)||void 0===i?void 0:i.debug);if((c()||u()||p)&&!window.Zonos.zonosConversionTest)return;const v=n.selectedCountryCode,h=e.organizationId;if(!t)return void m({endpoint:"trackConversionEventMetric",errors:[`Event "${o}" - No checkout session id found`],metadata:{allLogs:y,checkoutSessionId:t,eventName:o,metadata:s,organizationId:h,trackEventLogs:d}});h||m({endpoint:"trackConversionEventMetric",errors:[`Event "${o}" - No organization id found`],metadata:{allLogs:y,checkoutSessionId:t,eventName:o,metadata:s,organizationId:h,trackEventLogs:d}});const w={checkoutSessionId:t,countryCode:v,eventCreated:a,eventName:o,metadata:Object.assign(Object.assign({},s),{trackEventLogs:d}),organizationId:h};await l("/api/zonos-elements/track-conversion-event",{body:w,method:"POST"})},k=({address:e,invalidAdddressList:t})=>{if(!e)return;if(!t)return;const o={};return t.city&&(o.city=e.city),t.line1&&(o.line1=e.line1),t.line2&&(o.line2=e.line2),t.postal_code&&(o.postal_code=e.postal_code),t.state&&(o.state=e.state),t.name&&(o.name=e.name),Object.keys(o).length?o:void 0},I=e=>e.sort(((e,t)=>e.amount-t.amount)),N=async()=>{var e;const{errors:t,json:n}=await(async()=>{if(!o.checkoutSessionId)return{errors:[{message:"No checkout session id found"}],json:null};const e=new URLSearchParams;e.set("checkoutSessionId",o.checkoutSessionId);const{errors:t,json:n}=await l(`/api/zonos-elements/get-checkout-session?${e.toString()}`);return{errors:t,json:n}})();return t.length||!n?(p("Failed to retrieve checkout session info before confirming payment ",t),m({endpoint:"validateCheckoutSession",errors:t.map((e=>e.message)),metadata:{allLogs:y}}),{errorMessage:r("Unable to retrieve the checkout session at the moment. Please try again or contact our support team."),valid:!1}):(null===(e=n.checkoutSession.landedCost)||void 0===e?void 0:e.id)?{errorMessage:"",valid:!0}:(p("Landed cost is not found in the checkout session before confirming payment."),m({endpoint:"validateCheckoutSession",errors:["No landed cost found before confirming payment"],metadata:{allLogs:y}}),{errorMessage:r('No shipment rating selected. Please go back to the "Shipping" step and select a shipment rating to proceed.'),valid:!1})},j=({theme:t})=>{const o={".AccordionItem":{color:"var(--colorText)"},".AccordionItem--selected":{color:"var(--colorText)"},".Action":{color:"var(--colorText)"},".Input":{boxShadow:"none",fontSize:e.appearance.fontSizeInputValue?`${e.appearance.fontSizeInputValue}px`:void 0,padding:"0",paddingBottom:"8px",paddingLeft:"16px",paddingRight:"8px",paddingTop:"6px"},".Label--resting":{fontSize:e.appearance.fontSizeInputLabel?`${e.appearance.fontSizeInputLabel}px`:void 0},".PickerItem--highlight":{boxShadow:"0 0 0 2px var(--colorBackground)"},".PickerItem--highlight:hover":{backgroundColor:"var(--colorBackground)",boxShadow:"none"},".PickerItem--new":{color:"var(--colorText)"},".Tab--selected":{borderStyle:"solid",borderWidth:"1px"}};return"DARK"===t?Object.assign(Object.assign({},o),{".Action":Object.assign(Object.assign({},o[".Action"]),{color:"white"}),".PickerItem--new":Object.assign(Object.assign({},o[".PickerItem--new"]),{color:"white"})}):o},T=({borderStyle:e,theme:t})=>"DARK"===t?{borderRadius:g({overrideBorderStyle:e}),colorBackground:"#101117",colorBackgroundText:"#C5C6CA",colorText:"#C5C6CA",colorTextPlaceholder:"#C5C6CA"}:{borderRadius:g({overrideBorderStyle:e}),iconMenuColor:"var(--colorText)",iconMenuHoverColor:"var(--colorText)"},{onChange:E,reset:P,state:D}=t((()=>({checkoutSettlementCurrency:"USD",clientSecret:sessionStorage.getItem("zonos--client-secret")||"",companyName:"",companyNameUsedWhenAsyncAddressUpdate:"",customAddressErrors:{city:"",firstName:"",lastName:"",line1:"",phone:"",postalCode:"",showError:!1,state:""},customBillingAddressErrors:{city:"",firstName:"",lastName:"",line1:"",phone:"",postalCode:"",showError:!1,state:""},customErrorMessage:null,customerProfile:null,fetchingLandedCostAbortController:null,hasPaymentError:!1,isFetchingLandedCost:!1,isFetchingSession:!1,partyBillingId:null,partyShippingId:null,shouldInventoryRefund:!1,shouldRenderPayInUsdButton:!1,skipPaymentIntent:"0"!==new URLSearchParams(window.location.search).get("skipPaymentIntent"),stripe:null,stripeAddressElement:null,stripeAddressEventData:null,stripeAddressUsedWhenAsyncAddressUpdate:null,stripeAddressUsedWhenFetchingLC:null,stripeAddressUsedWhenValidatingAddress:null,stripeBillingAddressElement:null,stripeBillingAddressEventData:null,stripeBillingAddressUsedWhenAsyncAddressUpdate:null,stripeBillingAddressUsedWhenFetchingLC:null,stripeBillingAddressUsedWhenValidatingAddress:null,stripeCustomerSessionClientSecret:null,stripeElements:null,stripeElementsForBillingAddress:null,stripeElementsOptions:null,stripeLinkElement:null,stripeLinkEventData:null,stripeLinkUsedWhenFetchingLC:null,stripePaymentElement:null,stripePaymentEventData:null,stripeShippingSameAsBilling:!0,taxId:"",taxIdUsedWhenAsyncAddressUpdate:"",translatedAddress:{address:{},billingAddress:{},firstName:{},lastName:{},name:{}}}))),L=()=>{window.sessionStorage.removeItem("zonos--bigcommerce-domestic-checkout-shipping")},x=e=>{window.sessionStorage.setItem("zonos--bigcommerce-domestic-checkout-shipping",JSON.stringify(e))},R=()=>{const e=window.sessionStorage.getItem("zonos--bigcommerce-domestic-checkout-shipping");return v(e)},z=async t=>{var o,s;const r=D.clientSecret;if(!D.stripe)return void h("Skip. Stripe is not initialized");const i=(({clientSecret:t,overrideBorderRadius:o,overridePrimaryColor:s,overrideSecondaryColor:r,overrideTheme:i,paypalEnabled:a})=>{const d=s||e.appearance.colorPrimary,l=r||e.appearance.colorSecondary,c=(window.Zonos.isCollect||window.Zonos.isInvoice?"DARK"===e.appearance.theme:d&&w(d))?"night":"flat",u="DARK"===i?"night":"flat",m=a?["external_paypal"]:[];return{appearance:{labels:"floating",rules:Object.assign({},j({theme:i||"LIGHT"})),theme:i?u:c,variables:Object.assign(Object.assign({},T({borderStyle:o,theme:"LIGHT"})),{colorPrimary:l})},clientSecret:t||void 0,customerSessionClientSecret:D.stripeCustomerSessionClientSecret||void 0,externalPaymentMethodTypes:[...m],locale:n.selectedLocale}})({clientSecret:r,overrideBorderRadius:null==t?void 0:t.overrideBorderRadius,overridePrimaryColor:null==t?void 0:t.overridePrimaryColor,overrideSecondaryColor:null==t?void 0:t.overrideSecondaryColor,overrideTheme:null==t?void 0:t.overrideTheme,paypalEnabled:null==t?void 0:t.paypalEnabled}),a=JSON.stringify(i)===JSON.stringify(D.stripeElementsOptions);if(!D.stripeElements||!D.stripeElementsForBillingAddress)return D.stripeElementsForBillingAddress=null===(o=D.stripe)||void 0===o?void 0:o.elements(i),h("Stripe elements for billing address initialized"),D.stripeElements=null===(s=D.stripe)||void 0===s?void 0:s.elements(i),D.stripeElementsOptions=i,void h("Stripe elements initialized");a||(D.stripeElements.update(i),D.stripeElementsForBillingAddress.update(i),D.stripeElementsOptions=i,D.stripeElements.fetchUpdates()),h("Stripe elements updated")},U=()=>{sessionStorage.removeItem("zonos--client-secret"),P(),D.stripe=window.Zonos.stripe},_=({address:e,firstName:t,lastName:n,name:s,phone:r})=>{const{firstName:i,lastName:a}=f({firstName:t,lastName:n,name:s});return i&&a||m({endpoint:"PARTY_CREATE_NO_NAME_FOUND",errors:["No name found"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,firstName:t,lastName:n,name:s}}),r||m({endpoint:"PARTY_CREATE_NO_PHONE_FOUND",errors:["No phone found"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,phone:r}}),{city:e.city,country:e.country,firstName:i,lastName:a,line1:e.line1,line2:e.line2,phone:r||"",postal_code:e.postal_code,state:e.state}},B=async()=>{var e,t,n,s;if(!(null===(e=D.stripeAddressEventData)||void 0===e?void 0:e.complete)||!D.stripeShippingSameAsBilling&&!(null===(t=D.stripeBillingAddressEventData)||void 0===t?void 0:t.complete)||!D.stripeBillingAddressEventData)return{partiesCreated:!1};if(!se.landedCostData)return{partiesCreated:!1};const r=null===(n=se.landedCostData.find(Boolean))||void 0===n?void 0:n.landedCost.rootId;if(!r)return m({endpoint:"PF_NO_SELECTED_LANDED_COST",errors:["No selected landed cost"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId}}),{partiesCreated:!1};const i=(()=>{var e,t,o,n,s,r;const i=JSON.stringify(null===(e=D.stripeLinkUsedWhenFetchingLC)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=D.stripeLinkEventData)||void 0===t?void 0:t.value),a=JSON.stringify(null===(o=D.stripeAddressUsedWhenAsyncAddressUpdate)||void 0===o?void 0:o.value)!==JSON.stringify(null===(n=D.stripeAddressEventData)||void 0===n?void 0:n.value),d=!D.stripeShippingSameAsBilling&&JSON.stringify(null===(s=D.stripeBillingAddressUsedWhenAsyncAddressUpdate)||void 0===s?void 0:s.value)!==JSON.stringify(null===(r=D.stripeBillingAddressEventData)||void 0===r?void 0:r.value);return i||a||d||D.taxIdUsedWhenAsyncAddressUpdate!==D.taxId||D.companyNameUsedWhenAsyncAddressUpdate!==D.companyName})();if(!i)return{partiesCreated:!1};const a=_({address:D.stripeAddressEventData.value.address,firstName:D.stripeAddressEventData.value.firstName,lastName:D.stripeAddressEventData.value.lastName,name:D.stripeAddressEventData.value.name,phone:D.stripeAddressEventData.value.phone}),d=D.stripeShippingSameAsBilling?a:_({address:D.stripeBillingAddressEventData.value.address,firstName:D.stripeBillingAddressEventData.value.firstName,lastName:D.stripeBillingAddressEventData.value.lastName,name:D.stripeBillingAddressEventData.value.name,phone:D.stripeBillingAddressEventData.value.phone}),c="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),{errors:u,json:v}=await l("/api/zonos-elements/create-parties",{body:{address:a,billingAddress:d,companyName:D.companyName,email:(null===(s=D.stripeLinkEventData)||void 0===s?void 0:s.value.email)||"",isTest:c,rootId:r,taxId:D.taxId},method:"POST"});return u.length||!v?(p("Error occurs when creating parties",JSON.stringify(u,null,2)),m({endpoint:"PF_PARTY_CREATE_FAILED",errors:["Failed to create parties"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,errors:u,json:v}}),{partiesCreated:!1}):(D.companyNameUsedWhenAsyncAddressUpdate=D.companyName,D.stripeAddressUsedWhenAsyncAddressUpdate=D.stripeAddressEventData,D.stripeBillingAddressUsedWhenAsyncAddressUpdate=D.stripeBillingAddressEventData,D.taxIdUsedWhenAsyncAddressUpdate=D.taxId,D.partyBillingId=v.billToPartyId,D.partyShippingId=v.shipToPartyId,{partiesCreated:!0})},F=e=>({countryCode:e.address.country,postalCode:e.address.postal_code,state:e.address.state}),J=async t=>{var n,s,r,i;const a=(null==t?void 0:t.retries)||0,d=!!(null==t?void 0:t.applyingPromocode),l=(()=>{var e;const t=se.landedCostData&&(null===(e=se.landedCostData.find(Boolean))||void 0===e?void 0:e.subtotals.items)!==se.subtotal,o=(()=>{var e,t;const o=JSON.stringify(null===(e=D.stripeLinkUsedWhenFetchingLC)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=D.stripeLinkEventData)||void 0===t?void 0:t.value),n=D.stripeAddressEventData&&JSON.stringify(F(D.stripeAddressEventData.value))!==JSON.stringify(D.stripeAddressUsedWhenFetchingLC),s=!D.stripeShippingSameAsBilling&&D.stripeBillingAddressEventData&&JSON.stringify(F(D.stripeBillingAddressEventData.value))!==JSON.stringify(D.stripeBillingAddressUsedWhenFetchingLC);return o||n||s})();return h("isPrefetchInfoOutdated","info",{isAddressOutdated:o}),!se.landedCostData&&!D.isFetchingLandedCost||o||t})();if(!(()=>{var t,o,n,s;const r=!!(null===(t=D.stripeLinkEventData)||void 0===t?void 0:t.complete),i=!!(null===(o=D.stripeAddressEventData)||void 0===o?void 0:o.complete),a=D.stripeShippingSameAsBilling?i:!!(null===(n=D.stripeBillingAddressEventData)||void 0===n?void 0:n.complete),d=(t=>{var o,n;const s=null===(o=e.genericSettings)||void 0===o?void 0:o.countryFields,r=null===(n=e.genericSettings)||void 0===n?void 0:n.stripeCountryFieldLabels;return"stripe"===se.addressFormRenderType&&(r&&t in r?r[t]:null)||(s&&t in s?s[t]:null)})((null===(s=D.stripeAddressEventData)||void 0===s?void 0:s.value.address.country)||"US");return!!(i&&a&&r)||(d&&D.stripeAddressEventData?r&&D.stripeAddressEventData.value.firstName&&D.stripeAddressEventData.value.lastName&&D.stripeAddressEventData.value.address.line1.length>0&&(!d.stateRequired||d.stateRequired&&D.stripeAddressEventData.value.address.state.length>0)&&(!d.zipRequired||d.zipRequired&&D.stripeAddressEventData.value.address.postal_code.length>=3)&&D.stripeAddressEventData.value.phone&&D.stripeAddressEventData.value.phone.length>0:i&&a&&r)})())return{isRequestNotReady:!0};if(l&&(null===(n=D.fetchingLandedCostAbortController)||void 0===n||n.abort(),D.fetchingLandedCostAbortController=null),!l&&!d)return{isRequestNotReady:!1};a?(D.isFetchingLandedCost=!1,setTimeout((()=>{D.isFetchingLandedCost=!0}),300)):D.isFetchingLandedCost=!0,D.stripeAddressEventData&&(D.stripeAddressUsedWhenFetchingLC={countryCode:D.stripeAddressEventData.value.address.country,postalCode:D.stripeAddressEventData.value.address.postal_code,state:D.stripeAddressEventData.value.address.state}),D.stripeBillingAddressEventData&&(D.stripeBillingAddressUsedWhenFetchingLC={countryCode:D.stripeBillingAddressEventData.value.address.country,postalCode:D.stripeBillingAddressEventData.value.address.postal_code,state:D.stripeBillingAddressEventData.value.address.state}),D.stripeLinkEventData&&(D.stripeLinkUsedWhenFetchingLC=Object.assign({},D.stripeLinkEventData));try{fe(),await(async()=>{var e;const t=new AbortController;D.fetchingLandedCostAbortController=t,fe();const{checkoutSessionWorkflow:n,errors:s,itemCreateWorkflow:r,landedCostCalculateWorkflow:i,partyCreateWorkflow:a,shipmentRatingCalculateWorkflow:d}=await O(t);se.customQuotingError=(null===(e=null==s?void 0:s.find((e=>{var t;return"CUSTOM"===(null===(t=e.extensions)||void 0===t?void 0:t.ruleMessageType)})))||void 0===e?void 0:e.message)||null,se.shippingData=I((null==d?void 0:d.filter(Boolean))||[]),de(r),D.fetchingLandedCostAbortController=null,se.partiesData=(null==a?void 0:a.filter(Boolean))||[],se.landedCostData=(null==n?void 0:n.map((e=>{const t=null==i?void 0:i.find((t=>(null==t?void 0:t.id)===e.landedCostId));return t?Object.assign(Object.assign({},e),{landedCost:t}):null})).filter(Boolean))||[],(null==n?void 0:n.length)&&A({checkoutSessionId:o.checkoutSessionId,eventName:"checkout_quoteReceived"});const l=se.promoCodeApplied&&!se.landedCostData.find((e=>{var t;return null===(t=e.landedCost.appliedAdjustments)||void 0===t?void 0:t.find((e=>"PROMO_CODE"===e.type))}));se.promoCodeError=l,l||sessionStorage.setItem("zonos--promo-code",se.promoCode)})();const e=null===(s=se.shippingData)||void 0===s?void 0:s.find(Boolean),t=null===(r=se.landedCostData)||void 0===r?void 0:r.find((t=>t.landedCost.shipmentRating.id===(null==e?void 0:e.id))),n=t?t.subtotals:null;n&&ue({method:(null==t?void 0:t.landedCost.method)||"DDP",subtotals:n})}catch(e){if(se.landedCostData=[],se.shippingData=[],e instanceof Error&&e.message&&!["The landed cost calculation request was aborted to initiate a new one."].includes(e.message)){if(a<1)return await J(Object.assign(Object.assign({},t),{retries:(a||0)+1})),{isRequestNotReady:!1};const o=null===(i=D.stripeAddressEventData)||void 0===i?void 0:i.value;m({endpoint:`Failed to fetch landed cost (${a} retries)`,errors:[e.message],metadata:{cartId:window.Zonos.cartId,shipToAddress:o}})}p(e)}return D.isFetchingLandedCost=!1,{isRequestNotReady:!1}},M=async()=>{var e,t;await J({applyingPromocode:!0}),"payment"===se.step&&Se(),await B();const o=null===(e=se.shippingData)||void 0===e?void 0:e.find(Boolean),n=null===(t=se.landedCostData)||void 0===t?void 0:t.find((e=>e.landedCost.id===(null==o?void 0:o.id)));o&&n&&await ye({applySubtotalsOnly:!1,landedCostId:n.landedCostId,selectedShippingOption:o})},W=()=>{se.promoCode="",sessionStorage.removeItem("zonos--promo-code"),se.promoCodeError=!1,se.promoCodeApplied=!1},$=async()=>{"payment"===se.step&&Se(),W(),await M()},q=e=>{let t=[],o=!0;const n=window.Zonos.isCollect,s=window.Zonos.isInvoice;switch(e){case"succeeded":t=[r("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."),"",r("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.")],(n||s)&&(t=[r("Thank you for submitting your payment. We appreciate your prompt attention."),"",r("A confirmation email with your payment details has been sent for your records. If you have any questions or need support, our team is here to help.")]),o=!1;break;case"requires_capture":case"processing":t=[r("Payment processing. We'll update you when payment is received.")],o=!1;break;case"requires_payment_method":t=[r("Payment failed. Please try another payment method.")],n&&(t=[r("Payment failed. Please reload the page and try another payment method.")]);break;case"requires_action":o=!1,t=[r("Your selected payment method requires additional verification. Please follow the instructions provided by your payment provider to complete the transaction.")];default:t=[r("Something went wrong.")]}return{isError:o,messages:t}},Y=async()=>{var t,o;const{onInventoryCheck:n}=e.checkoutSettings,s=!!(null===(o=null===(t=window.Zonos.cartData)||void 0===t?void 0:t.metadata.find((e=>"referenceId"===e.key)))||void 0===o?void 0:o.value);if(window.Zonos.isLegacyCheckout&&window.Zonos.cartData&&s){const{errors:e,json:t}=await l("/api/zonos-elements/legacy/inventory-check",{body:{cartData:window.Zonos.cartData},method:"POST"});return e.length||!t?(p("Error occurs when handling inventory refund","warn",JSON.stringify(e)),null):t.available&&204!==t.status?t.available||200===t.status?(D.shouldInventoryRefund=!0,null):null:r("The item you're looking for is currently unavailable in our inventory. Please check back later or contact support for assistance with availability.")}if("function"!=typeof n)return null;try{return await n({items:se.items},{translate:r,zonosApiRoute:d.vercel})}catch(e){const t=e instanceof Error?e.message:"Unknown error";throw m({endpoint:"onInventoryCheck",errors:[`cartId: ${window.Zonos.cartId} - ${t}`],metadata:{cartId:window.Zonos.cartId,href:window.location.href,items:se.items}}),e}},H=async()=>{var e,t;const o=!!(null===(t=null===(e=window.Zonos.cartData)||void 0===e?void 0:e.metadata.find((e=>"referenceId"===e.key)))||void 0===t?void 0:t.value);window.Zonos.isLegacyCheckout&&window.Zonos.cartData&&o&&await l("/api/zonos-elements/legacy/inventory-refund",{body:{cartData:window.Zonos.cartData},method:"POST"})},K=async({clientSecret:e,storybookForceStatus:t})=>{if(t){const{isError:e,messages:o}=q(t);return{error:e,messages:o}}const o=e||D.clientSecret;if(!D.stripe||!o)return p("Failed to retrieve payment intent. Stripe is not initialized"),{error:!0,message:[r("Something went wrong.")]};const{paymentIntent:n}=await D.stripe.retrievePaymentIntent(o),s=null==n?void 0:n.status,{isError:i,messages:a}=q(s);return{error:i,messages:a,paymentIntentId:null==n?void 0:n.id,paymentMethod:null==n?void 0:n.payment_method,status:s}},G=async e=>{var t,n;const s=!!(null===(t=D.stripePaymentEventData)||void 0===t?void 0:t.complete),i=D.stripeElements,a=D.stripe,d=D.clientSecret;if(D.customErrorMessage=null,!(null===(n=se.selectedLandedCost)||void 0===n?void 0:n.landedCost.id)&&!(null==e?void 0:e.noLandedCostCheck))throw new Error("Attempted to confirm the payment when no landed cost is found in store");const l=await N();if(!l.valid)throw D.customErrorMessage=l.errorMessage,new Error(l.errorMessage);const c=o.checkoutSessionId;if(a&&i&&s&&d&&c){const e=new URL(window.location.href);e.searchParams.set("payment_intent_client_secret",d),e.searchParams.set("zonosCheckoutSessionId",c),A({checkoutSessionId:c,eventName:"checkout_paymentInfoCompleted"});const{error:t,paymentIntent:o}=await a.confirmPayment({confirmParams:{return_url:e.toString()},elements:i,redirect:"if_required"});if(h("Payment intent confirmed","info",{error:t,paymentIntent:o}),"requires_action"===(null==o?void 0:o.status))throw new Error(r("Your selected payment method requires additional verification. Please follow the instructions provided by your payment provider to complete the transaction."));if(t){if("card_error"===t.type||"validation_error"===t.type)throw new Error(t.message);if("invalid_request_error"===t.type&&"payment_intent_unexpected_state"===t.code)return;throw new Error("An unexpected error occurred.")}if("requires_payment_method"===o.status)throw new Error(r("Payment failed. Please try another payment method."))}},V=()=>{var e;const t=se.items.reduce(((e,t)=>e+t.amount*t.quantity),0),s=o.enabledVariantTestKeys||[];return{adjustmentsAmount:se.adjustments.reduce(((e,t)=>e+t.amount),0),cartId:window.Zonos.cartId,currency:(null===(e=se.items.find(Boolean))||void 0===e?void 0:e.currencyCode)||"",customerAuthenticationToken:se.customerAuthenticationToken||void 0,isCollect:!!window.Zonos.isCollect,isInvoice:!!window.Zonos.isInvoice,itemsAmount:t,metadata:[{key:"language",value:n.selectedLocale}],presentmentCountryCode:n.selectedCountryCode,skipPaymentIntent:D.skipPaymentIntent,varianceTestInput:s}},Z=async()=>{var e;if(!o.checkoutSessionId)return m({endpoint:"Error creating payment intent",errors:["No checkout session id found when retrieving payment intent"],metadata:{allLogs:y,cartId:window.Zonos.cartId}}),void ce({messages:[r("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:r("Error creating Checkout")});const{errors:t,json:n}=await l("/api/zonos-elements/create-payment-intent",{body:{checkoutSessionId:o.checkoutSessionId},method:"POST"}),s=null===(e=null==n?void 0:n.checkoutSessionPaymentIntentCreate)||void 0===e?void 0:e.clientSecret;if(t.length||!s)return p("Error occurs when getting payment intent",JSON.stringify(t,null,2)),m({endpoint:"Error creating payment intent",errors:t.map((e=>e.message)),metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,clientSecret:s}}),void ce({messages:[r("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:r("Error creating Checkout")});pe(n.checkoutSessionPaymentIntentCreate)},Q=async()=>{var e,t;if(!n.targetCurrency)return p("Failed to create checkout session - missing localizationStore.targetCurrency"),!1;D.isFetchingSession=!0;const o=V();h("Checkout session body","info",o);const{errors:s,json:r}=await l("/api/zonos-elements/create-checkout-session",{body:o,method:"POST"});if(D.isFetchingSession=!1,s.length||!r){const t=null===(e=s.find((e=>e.message)))||void 0===e?void 0:e.message;if(Array.isArray(t)&&t.some((e=>"Cart is expired."===e.message)))throw new Error("Cart is expired.");return p("Error occurred when creating checkout session",JSON.stringify(s,null,2)),!1}const i=r.checkoutSessionCreate;return pe(i),ue({method:(null===(t=i.landedCost)||void 0===t?void 0:t.method)||"DDP",subtotals:i.subtotals}),h("Exchange rate updated for cart items (checkout session create)","info",se.exchangeRate),h("done-init-checkout-session"),!0},X=async()=>{const t=o.checkoutSessionId;if(!t)return p("Failed to update checkout session base currency"),!1;if("LOCAL"===e.checkoutSettings.allowedSettlementCurrencies)return h('allowedSettlementCurrencies: "LOCAL". Skip updating checkout session base currency'),!0;const{json:n}=await l("/api/zonos-elements/update-checkout-session-base-currency",{body:{checkoutSessionId:t,currencyCode:D.checkoutSettlementCurrency},method:"POST"}),s=null==n?void 0:n.checkoutSessionBaseCurrencyUpdate.subtotals.presentmentCurrencyCode;return n&&s===D.checkoutSettlementCurrency?(h(`Updated checkout session to settlement currency "${s}".`),!0):(p("Failed to update checkout session base currency"),!1)},ee=({currentAddress:e,translatedAddressResult:t})=>{const o={};if(!t)return o;const{city:n,line1:s,line2:r,name:i,postal_code:a,state:d}=t;return e.city&&n&&(o.city={[e.city]:n}),e.line1&&s&&(o.line1={[e.line1]:s}),e.line2&&r&&(o.line2={[e.line2]:r}),e.postal_code&&a&&(o.postal_code={[e.postal_code]:a}),e.state&&d&&(o.state={[e.state]:d}),e.name&&i&&(o.name={[e.name]:i}),o},te=async({addressInvalidCharactersList:e,billingAddressInvalidCharactersList:t})=>{var o,n,s,r;const i=(({addressInvalidCharactersList:e,billingAddressInvalidCharactersList:t,stripeAddressEventData:o,stripeBillingAddressEventData:n,stripeShippingSameAsBilling:s})=>{const r=!!(null==o?void 0:o.complete);if(!r||!(s?r:null==n?void 0:n.complete))return null;if(!e&&!t)return null;const i=o.value,a=(null==n?void 0:n.value)||null,{firstName:d,lastName:l}=f({firstName:i.firstName,lastName:i.lastName,name:i.name}),c=`${d} ${l}`,{firstName:u,lastName:m}=f({firstName:null==a?void 0:a.firstName,lastName:null==a?void 0:a.lastName,name:(null==a?void 0:a.name)||""}),p=u&&m?`${u} ${m}`:"",v=i.address,h=null==a?void 0:a.address;return{address:k({address:Object.assign(Object.assign({},v),{name:c}),invalidAdddressList:e}),billingAddress:s?void 0:k({address:h?Object.assign(Object.assign({},h),{name:p}):null,invalidAdddressList:t}),destinationCountry:v.country}})({addressInvalidCharactersList:e,billingAddressInvalidCharactersList:t,stripeAddressEventData:D.stripeAddressEventData,stripeBillingAddressEventData:D.stripeBillingAddressEventData,stripeShippingSameAsBilling:D.stripeShippingSameAsBilling});if(!i)return void(D.translatedAddress={address:{},billingAddress:{}});const a=(()=>{var e,t,o,n;const s=JSON.stringify(null===(e=D.stripeAddressUsedWhenValidatingAddress)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=D.stripeAddressEventData)||void 0===t?void 0:t.value),r=!D.stripeShippingSameAsBilling&&JSON.stringify(null===(o=D.stripeBillingAddressEventData)||void 0===o?void 0:o.value)!==JSON.stringify(null===(n=D.stripeBillingAddressUsedWhenValidatingAddress)||void 0===n?void 0:n.value);return s||r})();if(!a)return;const{errors:d,json:c}=await l("/api/zonos-elements/validate-address",{body:i,method:"POST"});if(d.length||!c)return p("Error occurs when translating address to latin",JSON.stringify(d,null,2)),void(D.translatedAddress={address:{},billingAddress:{}});D.stripeAddressUsedWhenValidatingAddress=D.stripeAddressEventData,D.stripeBillingAddressUsedWhenValidatingAddress=D.stripeBillingAddressEventData;const u=null===(o=D.stripeAddressEventData)||void 0===o?void 0:o.value.address,m=null===(n=D.stripeBillingAddressEventData)||void 0===n?void 0:n.value.address;D.translatedAddress={address:u?ee({currentAddress:Object.assign(Object.assign({},u),{name:null===(s=D.stripeAddressEventData)||void 0===s?void 0:s.value.name}),translatedAddressResult:c.address||null}):{},billingAddress:D.stripeShippingSameAsBilling?{}:ee({currentAddress:Object.assign(Object.assign({},m),{name:null===(r=D.stripeBillingAddressEventData)||void 0===r?void 0:r.value.name}),translatedAddressResult:c.billingAddress||null})}};E("clientSecret",(e=>{e&&D.stripe&&sessionStorage.setItem("zonos--client-secret",e),e||sessionStorage.removeItem("zonos--client-secret")}));const{onChange:oe,reset:ne,state:se}=t((()=>({addressFormRenderType:"stripe",adjustmentTotal:0,adjustments:[],checkoutSession:null,checkoutSessionTimeoutShow:!1,checkoutTimeoutInterval:null,currency:"USD",customQuotingError:null,customerAuthenticationToken:null,displayBaseCurrency:!1,dutiesTaxesFees:null,dutiesTaxesFeesEstimate:null,error:null,exchangeRate:null,externalConfirmationPageURL:null,inventoryCheckErrorMessage:null,isSelectedShippingAboveDeminimis:!1,isSelectedShippingGuarantee:!1,isStagingMode:u(),items:[],landedCostData:null,landedCostMethod:"DDP",partiesData:[],promoCode:sessionStorage.getItem("zonos--promo-code")||"",promoCodeApplied:!!sessionStorage.getItem("zonos--promo-code"),promoCodeError:!1,restrictedItems:[],selectedLandedCost:null,selectedShippingOption:null,selectedShippingOptionExpectedDate:"",selectedShippingOptionTransitTime:"",shipping:0,shippingData:null,shouldHideDiscountInput:!1,step:"customer-info",subtotal:0,tabItems:{"customer-info":{index:1,isDone:!1,label:"Customer",value:"customer-info"},shipping:{index:2,isDone:!1,label:"Shipping",value:"shipping"},payment:{index:3,isDone:!1,label:"Payment",value:"payment"}},total:0}))),re=e=>{switch(e){case"DAYS":return r("days");case"WEEKS":return r("weeks");default:return r("business days")}},ie=e=>{var t;const o=null===(t=e.shippingProfile)||void 0===t?void 0:t.transitTime;return(null==o?void 0:o.min)&&(null==o?void 0:o.max)&&(null==o?void 0:o.type)?{maxTransit:o.max,minTransit:o.min,unit:re(o.type)}:null},ae=({item1:e,item2:t})=>!(!e||!t)&&(t.sku&&e.sku&&e.sku===t.sku||t.description&&e.description&&e.description===t.description||e.name&&t.name&&e.name===t.name),de=e=>{h("Checking item restrictions");const t=e.map((e=>{if(!e.restriction)return null;const{restriction:t}=e,o=se.items.find((t=>ae({item1:t,item2:e})));return Object.assign(Object.assign({matchedItem:o},e),{restriction:t})})).filter(Boolean);return se.restrictedItems=t,se.items=se.items.map((e=>Object.assign(Object.assign({},e),{isRestricted:!!t.find((t=>ae({item1:t,item2:e})))}))),{cartItems:se.items,restrictedItems:t}},le=()=>{o.checkoutSessionId=null,ne()},ce=({messages:e,title:t})=>{le(),U(),se.step="error",se.error={messages:e,title:t}},ue=({dutiesTaxesFeesEstimate:e,method:t,subtotals:o})=>{se.exchangeRate=o.exchangeRate,se.adjustmentTotal=o.adjustments,se.dutiesTaxesFees="DAP"===t?null:o.landedCostTotal,se.subtotal=o.items,se.total=o.total,se.currency=o.presentmentCurrencyCode,se.dutiesTaxesFeesEstimate=e||null},me=()=>!!se.items.filter((e=>e.amount>0)).find((e=>!e.isRestricted)),pe=e=>{var t,n,s,r,d;D.clientSecret=e.clientSecret,D.stripeCustomerSessionClientSecret=e.customerSessionClientSecret,D.customerProfile=e.customerProfile,se.checkoutSession=e,e.id||m({endpoint:"cartStoreSetCheckoutSession",errors:["Missing checkout session id in checkout session"],metadata:{allLogs:y,checkoutSession:e}}),e.id&&(o.checkoutSessionId=e.id);const l=i(e.varianceTestResults||[]);a(l);const c=(null===(s=null===(n=null===(t=se.checkoutSession)||void 0===t?void 0:t.metadata)||void 0===n?void 0:n.find((e=>"externalConfirmationPageURL"===(null==e?void 0:e.key))))||void 0===s?void 0:s.value)||(null===(d=null===(r=window.Zonos.cartData)||void 0===r?void 0:r.metadata.find((e=>"externalConfirmationPageURL"===(null==e?void 0:e.key))))||void 0===d?void 0:d.value)||null;c&&(h(`Found externalConfirmationPageURL: ${c}`),se.externalConfirmationPageURL=c)},ve=async({adjustmentsAmount:e,cartId:t,currency:s,dutiesTaxesFeesEstimate:i,itemsAmount:a,landedCostId:d,shouldInitSessionOnFailure:c})=>{var u;if(d&&se.selectedLandedCost&&(ue({dutiesTaxesFeesEstimate:i,method:se.landedCostMethod,subtotals:se.selectedLandedCost.subtotals}),h("Exchange rate updated for cart items (landed cost subtotal)","info",se.exchangeRate)),!o.checkoutSessionId)return h("Could not update cart total without checkout session id","info"),!1;const{errors:m,json:v}=await(async({adjustmentsAmount:e,cartId:t,currency:s,id:r,itemsAmount:i,landedCostId:a,presentmentCountryCode:d})=>{const c=o.enabledVariantTestKeys||[],{errors:u,json:m}=await l("/api/zonos-elements/update-checkout-session",{body:{adjustmentsAmount:e,billToPartyId:D.partyBillingId,cartId:t,currency:s,customerAuthenticationToken:se.customerAuthenticationToken||void 0,id:r,itemsAmount:i,landedCostId:a,metadata:[{key:"language",value:n.selectedLocale}],presentmentCountryCode:d,shipToPartyId:D.partyShippingId,skipPaymentIntent:D.skipPaymentIntent,varianceTestInput:c},method:"POST"});return u.length||!m?(p("Error occurs when updating checkout session",JSON.stringify(u,null,2)),{errors:u,json:m}):{errors:[],json:m}})({adjustmentsAmount:e,billToPartyId:D.partyBillingId,cartId:t,currency:s,id:o.checkoutSessionId,itemsAmount:a,landedCostId:d,presentmentCountryCode:n.selectedCountryCode,shipToPartyId:D.partyShippingId,varianceTestInput:o.enabledVariantTestKeys||[]});if(m.length>0||!v){if(p("Error occurs when updating checkout session."),c){h("Initiating checkout session on failure","info");const e=await Q();return h(`stripeStoreInitCheckoutSession: ${e}`),!!e||(ce({messages:[r("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:r("Error creating Checkout")}),!1)}return!1}return d||(ue({method:(null===(u=v.checkoutSessionUpdate.landedCost)||void 0===u?void 0:u.method)||"DDP",subtotals:v.checkoutSessionUpdate.subtotals}),h("Exchange rate updated for cart items (checkout session update)","info",se.exchangeRate)),pe(v.checkoutSessionUpdate),!0},he=t=>{var o,n,s;return"DAP"===t.method&&(null===(n=null===(o=e.genericSettings)||void 0===o?void 0:o.domesticCountries)||void 0===n?void 0:n.includes((null===(s=D.stripeAddressEventData)||void 0===s?void 0:s.value.address.country)||"US"))||"DAP"===t.method&&t.remittance.length&&"ZONOS"===t.landedCostGuaranteeCode?"DDP":t.method},ye=async({applySubtotalsOnly:t,landedCostId:n,selectedShippingOption:s})=>{var r,i,a,d,l,c,u,m,p,v,y;h("Updating selected shipping option","info",{landedCostId:n,selectedShippingOption:s}),se.selectedShippingOption=s;const w=ie(se.selectedShippingOption);if(w){const{maxTransit:e,minTransit:t,unit:o}=w;se.selectedShippingOptionTransitTime=`${t}-${e} ${o}`}else se.selectedShippingOptionTransitTime="";const g=null===(r=se.landedCostData)||void 0===r?void 0:r.find((e=>e.landedCostId===n));if(se.selectedLandedCost=g||null,!g)return!1;const f=((null===(i=g.landedCost.amountSubtotals)||void 0===i?void 0:i.landedCostTotal)||0)*g.subtotals.exchangeRate.rate;f&&h(`DAP quote, using estimate: ${f}`,"info"),se.landedCostMethod=he(g.landedCost),se.shipping=g.subtotals.shipping;const b="ZONOS"===(null===(a=null==g?void 0:g.landedCost)||void 0===a?void 0:a.landedCostGuaranteeCode),S=!!(null===(l=null===(d=null==g?void 0:g.landedCost)||void 0===d?void 0:d.deMinimis)||void 0===l?void 0:l.find((e=>["DUTY","TAX"].includes(e.type)&&"ABOVE"===e.threshold)));se.isSelectedShippingAboveDeminimis=S,se.isSelectedShippingGuarantee=b;let C=!1;t?(ue({dutiesTaxesFeesEstimate:f,method:se.landedCostMethod,subtotals:g.subtotals}),h("Exchange rate updated for cart items (landed cost subtotal)","info",se.exchangeRate),C=!0):C=await ve({adjustmentsAmount:se.adjustmentTotal,billToPartyId:D.partyBillingId,cartId:window.Zonos.cartId,dutiesTaxesFeesEstimate:f,landedCostId:null===(c=g.landedCost)||void 0===c?void 0:c.id,shipToPartyId:D.partyShippingId,varianceTestInput:o.enabledVariantTestKeys||[]});const O=null===(u=se.items.find(Boolean))||void 0===u?void 0:u.currencyCode,A=(null===(m=D.stripeAddressEventData)||void 0===m?void 0:m.value.address.country)||"US";return D.shouldRenderPayInUsdButton="USD"===O&&"LOCAL_AND_USD"===e.checkoutSettings.allowedSettlementCurrencies&&"USD"!==(null===(p=se.checkoutSession)||void 0===p?void 0:p.subtotals.presentmentCurrencyCode)&&!!(null===(y=null===(v=e.genericSettings)||void 0===v?void 0:v.usdSettlementCountryEnabled)||void 0===y?void 0:y.includes(A)),C},we=({isPreview:e,sessionTimeout:t})=>{if(e)return;const o=new URLSearchParams(window.location.search).get("zonosCheckoutTimeout"),n=o&&!isNaN(parseInt(o,10))?parseInt(o,10):t;h(`==START CHECKOUT TIMEOUT - ${n}==`),se.checkoutTimeoutInterval=setTimeout((()=>{se.checkoutSessionTimeoutShow=!0}),n)},ge=()=>{se.checkoutTimeoutInterval&&(clearTimeout(se.checkoutTimeoutInterval),se.checkoutTimeoutInterval=null)},fe=()=>{se.items=se.items.map((e=>Object.assign(Object.assign({},e),{isRestricted:!1}))),se.restrictedItems=[]},be=async({adjustments:e,cartItems:t,landedCostId:n,shouldInitSessionOnFailure:s=!0})=>{var r;se.adjustments=e,se.items=t.map((e=>Object.assign(Object.assign({},e),{isRestricted:!1})));const i=null===(r=t.find(Boolean))||void 0===r?void 0:r.currencyCode,a=t.reduce(((e,t)=>e+t.amount*t.quantity),0),d=e.reduce(((e,t)=>e+t.amount),0);i&&a&&(se.currency=i,D.isFetchingSession=!0,await ve({adjustmentsAmount:d,billToPartyId:D.partyBillingId,cartId:window.Zonos.cartId,currency:i,dutiesTaxesFeesEstimate:0,itemsAmount:a,landedCostId:n,shipToPartyId:D.partyShippingId,shouldInitSessionOnFailure:s,varianceTestInput:o.enabledVariantTestKeys||[]}),D.isFetchingSession=!1)},Se=()=>{"shipping"===se.step?(se.step="customer-info",se.tabItems=Object.assign(Object.assign({},se.tabItems),{"customer-info":Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!1})})):"payment"===se.step?(se.step="shipping",se.tabItems=Object.assign(Object.assign({},se.tabItems),{shipping:Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!1})})):"finish"===se.step&&(se.step="payment",se.tabItems=Object.assign(Object.assign({},se.tabItems),{payment:Object.assign(Object.assign({},se.tabItems.payment),{isDone:!1})}))},Ce=()=>{"customer-info"===se.step?(se.step="shipping",se.tabItems=Object.assign(Object.assign({},se.tabItems),{"customer-info":Object.assign(Object.assign({},se.tabItems["customer-info"]),{isDone:!0})})):"shipping"===se.step?(se.step="payment",se.tabItems=Object.assign(Object.assign({},se.tabItems),{shipping:Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!0})})):"payment"===se.step&&(se.step="finish")},Oe=()=>{se.step="customer-info",se.tabItems=Object.assign(Object.assign({},se.tabItems),{"customer-info":Object.assign(Object.assign({},se.tabItems["customer-info"]),{isDone:!1}),payment:Object.assign(Object.assign({},se.tabItems.payment),{isDone:!1}),shipping:Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!1})}),se.selectedShippingOption=null,se.isSelectedShippingAboveDeminimis=!1,se.isSelectedShippingGuarantee=!1,se.selectedShippingOptionTransitTime="",se.dutiesTaxesFees=0,se.dutiesTaxesFeesEstimate=0,se.shipping=0,se.total=se.subtotal};export{N as A,E as B,_ as C,ye as D,me as E,M as F,$ as G,W as H,q as I,te as J,f as K,B as L,ie as M,he as N,I as O,x as a,D as b,K as c,se as d,be as e,le as f,Oe as g,ge as h,z as i,Q as j,Z as k,we as l,V as m,ce as n,L as o,pe as p,J as q,Ce as r,R as s,A as t,X as u,Y as v,G as w,H as x,U as y,oe as z}
|
|
1
|
+
import{z as e,c as t}from"./p-b2a0ab4a.js";import{s as o,l as n,e as s,t as r,f as i,b as a}from"./p-21fb6b39.js";import{f as d,h as l,g as c,a as u,s as m,l as p,j as v}from"./p-41dd1cb8.js";import{l as h,b as y}from"./p-0a377722.js";import{i as w}from"./p-57fa64d7.js";import{g}from"./p-1f894984.js";const f=({firstName:e,lastName:t,name:o})=>{var n;if(!o&&!e&&!t)return{firstName:"",lastName:""};const s=(null==o?void 0:o.split(/\s+/))||[];return{firstName:(null==e?void 0:e.trim())||(null===(n=s[0])||void 0===n?void 0:n.trim())||"",lastName:(null==t?void 0:t.trim())||s.slice(1).join(" ").trim()||""}},b=({currentAddress:e,translatedAddress:t})=>{var o,n,s,r,i,a;const{city:d,country:l,line1:c,line2:u,postal_code:m,state:p}=e.value.address,v=e.value.name||[e.value.firstName,e.value.lastName].join(" ");return{city:(null===(o=t.city)||void 0===o?void 0:o[d])||d,country:l,line1:(null===(n=t.line1)||void 0===n?void 0:n[c])||c,line2:(null===(s=t.line2)||void 0===s?void 0:s[u||""])||u||"",name:(null===(r=t.name)||void 0===r?void 0:r[v])||v,phone:e.value.phone||"",postal_code:(null===(i=t.postal_code)||void 0===i?void 0:i[m])||m,state:(null===(a=t.state)||void 0===a?void 0:a[p])||p}},S=e=>{var t;const r="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),i=D.stripeLinkEventData,a=D.stripeAddressEventData,d=D.stripeShippingSameAsBilling?D.stripeAddressEventData:D.stripeBillingAddressEventData;if(!a||!d)throw new Error("Missing stripe address data");const l=b({currentAddress:a,translatedAddress:D.translatedAddress.address}),{firstName:c,lastName:u}=f({name:l.name}),m=b({currentAddress:d,translatedAddress:D.translatedAddress.address}),{firstName:p,lastName:v}=f({name:m.name}),h=s()||"US";return{billingAddress:{addressLine1:m.line1,addressLine2:m.line2||"",city:m.city,country:m.country,postalCode:m.postal_code,state:m.state},billingContact:{firstName:p,lastName:v,phone:m.phone},cartCurrencyCode:null===(t=se.items[0])||void 0===t?void 0:t.currencyCode,cartId:e,checkoutSessionCountry:h||n.selectedCountryCode||void 0,checkoutSessionId:o.checkoutSessionId||"",contact:{companyName:D.companyName,email:null==i?void 0:i.value.email,firstName:c,lastName:u,phone:l.phone},isTest:!!r,landedCostAdjustments:se.promoCode?[{amount:0,productId:null,promoCode:se.promoCode,sku:null,type:"PROMO_CODE"}]:[],shipToTaxId:D.taxId,shippingAddress:{addressLine1:l.line1,addressLine2:l.line2,city:l.city,country:l.country,postalCode:l.postal_code,state:l.state}}},C=()=>{const e="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),t=D.stripeLinkEventData,n=D.stripeAddressEventData,s=D.stripeShippingSameAsBilling?D.stripeAddressEventData:D.stripeBillingAddressEventData;if(h({stripeAddressData:n,stripeBillingAddressData:s},"info"),!n||!s)throw new Error("Missing stripe address data");const r=b({currentAddress:n,translatedAddress:D.translatedAddress.address}),{firstName:i,lastName:a}=f({name:r.name}),d=b({currentAddress:s,translatedAddress:D.translatedAddress.address}),{firstName:l,lastName:c}=f({name:d.name}),u=se.adjustments.map((e=>({amount:e.amount,name:e.description||null,productId:e.productId,sku:e.sku,type:e.type}))),m=se.promoCode?[{amount:0,productId:null,promoCode:se.promoCode,sku:null,type:"PROMO_CODE"},...u]:u;return{billingAddress:{addressLine1:d.line1,addressLine2:d.line2||"",city:d.city,country:d.country,postalCode:d.postal_code,state:d.state},billingContact:{firstName:l,lastName:c,phone:d.phone},checkoutSessionId:o.checkoutSessionId||"",contact:{companyName:D.companyName,email:null==t?void 0:t.value.email,firstName:i,lastName:a,phone:r.phone},isTest:e,items:se.items,landedCostAdjustments:m,shipToTaxId:D.taxId,shippingAddress:{addressLine1:r.line1,addressLine2:r.line2,city:r.city,country:r.country,postalCode:r.postal_code,state:r.state}}};const O=async t=>{const o=window.Zonos.cartId;if(!o)return await(async t=>{var o;const n=e.checkoutSettings.buildLandedCost;if(n){const e=await(async e=>{var t,o,n,s,r;const i=C(),a=await e({billingAddress:i.billingAddress,billingContact:i.billingContact,checkoutSessionId:i.checkoutSessionId,contact:i.contact,landedCostAdjustments:i.landedCostAdjustments,publicCredential:window.Zonos.zonosApiKey||"",shippingAddress:i.shippingAddress,zonosApiRoute:d.vercel},{promoCode:se.promoCode});if(!a||!(null===(t=a.checkoutSessionWorkflow)||void 0===t?void 0:t.length)&&(null===(o=a.errors)||void 0===o?void 0:o.length))throw new Error(`Failed to build landed cost: ${(null===(s=null===(n=null==a?void 0:a.errors)||void 0===n?void 0:n[0])||void 0===s?void 0:s.message)||"Unknown error"}`);const{errors:c,json:u}=await l("/api/zonos-elements/validate-landed-cost",{body:a,headers:{"Content-Type":"application/json"},method:"POST"});if(!u||c.length)throw new Error(`Invalid landed cost object: ${(null===(r=c.find(Boolean))||void 0===r?void 0:r.message)||"Unknown error"}`);return a})(n);return e}const{errors:s,json:r}=await l("/api/zonos-elements/calculate-landed-cost",{body:C(),method:"POST",signal:null==t?void 0:t.signal});if(s.length||!r){if("The user aborted a request."===(null===(o=s[0])||void 0===o?void 0:o.message))throw new Error("The landed cost calculation request was aborted to initiate a new one.");if(s.forEach((e=>{console.warn(`Error calculating landed cost: ${e.message}`)})),!r)throw new Error("Failed to calculate landed cost");return r}return r})(t);const n=await(async({abortController:e,cartId:t})=>{var o,n,s,r,i;const{errors:a,json:d}=await l("/api/zonos-elements/cart-calculate-landed-cost",{body:S(t),method:"POST",signal:null==e?void 0:e.signal});if(a.length||!d){const e="string"==typeof(null===(o=a[0])||void 0===o?void 0:o.message)&&("The user aborted a request."===(null===(n=a[0])||void 0===n?void 0:n.message)||(null===(s=a[0])||void 0===s?void 0:s.message.includes("signal is aborted"))||(null===(r=a[0])||void 0===r?void 0:r.message.includes("The operation was aborted"))||(null===(i=a[0])||void 0===i?void 0:i.message.includes("Fetch is aborted")));throw new Error(e?"The landed cost calculation request was aborted to initiate a new one.":"Failed to calculate landed cost")}return d})({abortController:t,cartId:o}),{cartWorkflow:s}=n,r=function(e,t){var o={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++)t.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(o[n[s]]=e[n[s]])}return o}(n,["cartWorkflow"]);return Object.assign(Object.assign({},r),{itemCreateWorkflow:s.items})},A=async({checkoutSessionId:t,eventName:o,metadata:s})=>{var r,i;const a=Date.now(),d=[...window.Zonos.trackEventLogs];window.Zonos.trackEventLogs.push({checkoutSessionId:t,eventCreated:a,eventName:o});const p=window.location.href.includes("zonos.com")&&!window.location.href.includes("checkout.zonos.com")||!!(null===(r=window.Zonos)||void 0===r?void 0:r.zonosQaUrl)||!!(null===(i=window.Zonos)||void 0===i?void 0:i.debug);if((c()||u()||p)&&!window.Zonos.zonosConversionTest)return;const v=n.selectedCountryCode,h=e.organizationId;if(!t)return void m({endpoint:"trackConversionEventMetric",errors:[`Event "${o}" - No checkout session id found`],metadata:{allLogs:y,checkoutSessionId:t,eventName:o,metadata:s,organizationId:h,trackEventLogs:d}});h||m({endpoint:"trackConversionEventMetric",errors:[`Event "${o}" - No organization id found`],metadata:{allLogs:y,checkoutSessionId:t,eventName:o,metadata:s,organizationId:h,trackEventLogs:d}});const w={checkoutSessionId:t,countryCode:v,eventCreated:a,eventName:o,metadata:Object.assign(Object.assign({},s),{trackEventLogs:d}),organizationId:h};await l("/api/zonos-elements/track-conversion-event",{body:w,method:"POST"})},k=({address:e,invalidAdddressList:t})=>{if(!e)return;if(!t)return;const o={};return t.city&&(o.city=e.city),t.line1&&(o.line1=e.line1),t.line2&&(o.line2=e.line2),t.postal_code&&(o.postal_code=e.postal_code),t.state&&(o.state=e.state),t.name&&(o.name=e.name),Object.keys(o).length?o:void 0},I=e=>e.sort(((e,t)=>e.amount-t.amount)),N=async()=>{var e;const{errors:t,json:n}=await(async()=>{if(!o.checkoutSessionId)return{errors:[{message:"No checkout session id found"}],json:null};const e=new URLSearchParams;e.set("checkoutSessionId",o.checkoutSessionId);const{errors:t,json:n}=await l(`/api/zonos-elements/get-checkout-session?${e.toString()}`);return{errors:t,json:n}})();return t.length||!n?(p("Failed to retrieve checkout session info before confirming payment ",t),m({endpoint:"validateCheckoutSession",errors:t.map((e=>e.message)),metadata:{allLogs:y}}),{errorMessage:r("Unable to retrieve the checkout session at the moment. Please try again or contact our support team."),valid:!1}):(null===(e=n.checkoutSession.landedCost)||void 0===e?void 0:e.id)?{errorMessage:"",valid:!0}:(p("Landed cost is not found in the checkout session before confirming payment."),m({endpoint:"validateCheckoutSession",errors:["No landed cost found before confirming payment"],metadata:{allLogs:y}}),{errorMessage:r('No shipment rating selected. Please go back to the "Shipping" step and select a shipment rating to proceed.'),valid:!1})},j=({theme:t})=>{const o={".AccordionItem":{color:"var(--colorText)"},".AccordionItem--selected":{color:"var(--colorText)"},".Action":{color:"var(--colorText)"},".Input":{boxShadow:"none",fontSize:e.appearance.fontSizeInputValue?`${e.appearance.fontSizeInputValue}px`:void 0,padding:"0",paddingBottom:"8px",paddingLeft:"16px",paddingRight:"8px",paddingTop:"6px"},".Label--resting":{fontSize:e.appearance.fontSizeInputLabel?`${e.appearance.fontSizeInputLabel}px`:void 0},".PickerItem--highlight":{boxShadow:"0 0 0 2px var(--colorBackground)"},".PickerItem--highlight:hover":{backgroundColor:"var(--colorBackground)",boxShadow:"none"},".PickerItem--new":{color:"var(--colorText)"},".Tab--selected":{borderStyle:"solid",borderWidth:"1px"}};return"DARK"===t?Object.assign(Object.assign({},o),{".Action":Object.assign(Object.assign({},o[".Action"]),{color:"white"}),".PickerItem--new":Object.assign(Object.assign({},o[".PickerItem--new"]),{color:"white"})}):o},T=({borderStyle:e,theme:t})=>"DARK"===t?{borderRadius:g({overrideBorderStyle:e}),colorBackground:"#101117",colorBackgroundText:"#C5C6CA",colorText:"#C5C6CA",colorTextPlaceholder:"#C5C6CA"}:{borderRadius:g({overrideBorderStyle:e}),iconMenuColor:"var(--colorText)",iconMenuHoverColor:"var(--colorText)"},{onChange:E,reset:P,state:D}=t((()=>({checkoutSettlementCurrency:"USD",clientSecret:sessionStorage.getItem("zonos--client-secret")||"",companyName:"",companyNameUsedWhenAsyncAddressUpdate:"",customAddressErrors:{city:"",firstName:"",lastName:"",line1:"",phone:"",postalCode:"",showError:!1,state:""},customBillingAddressErrors:{city:"",firstName:"",lastName:"",line1:"",phone:"",postalCode:"",showError:!1,state:""},customErrorMessage:null,customerProfile:null,fetchingLandedCostAbortController:null,hasPaymentError:!1,isFetchingLandedCost:!1,isFetchingSession:!1,partyBillingId:null,partyShippingId:null,shouldInventoryRefund:!1,shouldRenderPayInUsdButton:!1,skipPaymentIntent:"0"!==new URLSearchParams(window.location.search).get("skipPaymentIntent"),stripe:null,stripeAddressElement:null,stripeAddressEventData:null,stripeAddressUsedWhenAsyncAddressUpdate:null,stripeAddressUsedWhenFetchingLC:null,stripeAddressUsedWhenValidatingAddress:null,stripeBillingAddressElement:null,stripeBillingAddressEventData:null,stripeBillingAddressUsedWhenAsyncAddressUpdate:null,stripeBillingAddressUsedWhenFetchingLC:null,stripeBillingAddressUsedWhenValidatingAddress:null,stripeCustomerSessionClientSecret:null,stripeElements:null,stripeElementsForBillingAddress:null,stripeElementsOptions:null,stripeLinkElement:null,stripeLinkEventData:null,stripeLinkUsedWhenFetchingLC:null,stripePaymentElement:null,stripePaymentEventData:null,stripeShippingSameAsBilling:!0,taxId:"",taxIdUsedWhenAsyncAddressUpdate:"",translatedAddress:{address:{},billingAddress:{},firstName:{},lastName:{},name:{}}}))),L=()=>{window.sessionStorage.removeItem("zonos--bigcommerce-domestic-checkout-shipping")},x=e=>{window.sessionStorage.setItem("zonos--bigcommerce-domestic-checkout-shipping",JSON.stringify(e))},R=()=>{const e=window.sessionStorage.getItem("zonos--bigcommerce-domestic-checkout-shipping");return v(e)},z=async t=>{var o,s;const r=D.clientSecret;if(!D.stripe)return void h("Skip. Stripe is not initialized");const i=(({clientSecret:t,overrideBorderRadius:o,overridePrimaryColor:s,overrideSecondaryColor:r,overrideTheme:i,paypalEnabled:a})=>{const d=s||e.appearance.colorPrimary,l=r||e.appearance.colorSecondary,c=(window.Zonos.isCollect||window.Zonos.isInvoice?"DARK"===e.appearance.theme:d&&w(d))?"night":"flat",u="DARK"===i?"night":"flat",m=a?["external_paypal"]:[];return{appearance:{labels:"floating",rules:Object.assign({},j({theme:i||"LIGHT"})),theme:i?u:c,variables:Object.assign(Object.assign({},T({borderStyle:o,theme:"LIGHT"})),{colorPrimary:l})},clientSecret:t||void 0,customerSessionClientSecret:D.stripeCustomerSessionClientSecret||void 0,externalPaymentMethodTypes:[...m],locale:n.selectedLocale}})({clientSecret:r,overrideBorderRadius:null==t?void 0:t.overrideBorderRadius,overridePrimaryColor:null==t?void 0:t.overridePrimaryColor,overrideSecondaryColor:null==t?void 0:t.overrideSecondaryColor,overrideTheme:null==t?void 0:t.overrideTheme,paypalEnabled:null==t?void 0:t.paypalEnabled}),a=JSON.stringify(i)===JSON.stringify(D.stripeElementsOptions);if(!D.stripeElements||!D.stripeElementsForBillingAddress)return D.stripeElementsForBillingAddress=null===(o=D.stripe)||void 0===o?void 0:o.elements(i),h("Stripe elements for billing address initialized"),D.stripeElements=null===(s=D.stripe)||void 0===s?void 0:s.elements(i),D.stripeElementsOptions=i,void h("Stripe elements initialized");a||(D.stripeElements.update(i),D.stripeElementsForBillingAddress.update(i),D.stripeElementsOptions=i,D.stripeElements.fetchUpdates()),h("Stripe elements updated")},U=()=>{sessionStorage.removeItem("zonos--client-secret"),P(),D.stripe=window.Zonos.stripe},_=({address:e,firstName:t,lastName:n,name:s,phone:r})=>{const{firstName:i,lastName:a}=f({firstName:t,lastName:n,name:s});return i&&a||m({endpoint:"PARTY_CREATE_NO_NAME_FOUND",errors:["No name found"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,firstName:t,lastName:n,name:s}}),r||m({endpoint:"PARTY_CREATE_NO_PHONE_FOUND",errors:["No phone found"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,phone:r}}),{city:e.city,country:e.country,firstName:i,lastName:a,line1:e.line1,line2:e.line2,phone:r||"",postal_code:e.postal_code,state:e.state}},B=async()=>{var e,t,n,s;if(!(null===(e=D.stripeAddressEventData)||void 0===e?void 0:e.complete)||!D.stripeShippingSameAsBilling&&!(null===(t=D.stripeBillingAddressEventData)||void 0===t?void 0:t.complete)||!D.stripeBillingAddressEventData)return{partiesCreated:!1};if(!se.landedCostData)return{partiesCreated:!1};const r=null===(n=se.landedCostData.find(Boolean))||void 0===n?void 0:n.landedCost.rootId;if(!r)return m({endpoint:"PF_NO_SELECTED_LANDED_COST",errors:["No selected landed cost"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId}}),{partiesCreated:!1};const i=(()=>{var e,t,o,n,s,r;const i=JSON.stringify(null===(e=D.stripeLinkUsedWhenFetchingLC)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=D.stripeLinkEventData)||void 0===t?void 0:t.value),a=JSON.stringify(null===(o=D.stripeAddressUsedWhenAsyncAddressUpdate)||void 0===o?void 0:o.value)!==JSON.stringify(null===(n=D.stripeAddressEventData)||void 0===n?void 0:n.value),d=!D.stripeShippingSameAsBilling&&JSON.stringify(null===(s=D.stripeBillingAddressUsedWhenAsyncAddressUpdate)||void 0===s?void 0:s.value)!==JSON.stringify(null===(r=D.stripeBillingAddressEventData)||void 0===r?void 0:r.value);return i||a||d||D.taxIdUsedWhenAsyncAddressUpdate!==D.taxId||D.companyNameUsedWhenAsyncAddressUpdate!==D.companyName})();if(!i)return{partiesCreated:!1};const a=_({address:D.stripeAddressEventData.value.address,firstName:D.stripeAddressEventData.value.firstName,lastName:D.stripeAddressEventData.value.lastName,name:D.stripeAddressEventData.value.name,phone:D.stripeAddressEventData.value.phone}),d=D.stripeShippingSameAsBilling?a:_({address:D.stripeBillingAddressEventData.value.address,firstName:D.stripeBillingAddressEventData.value.firstName,lastName:D.stripeBillingAddressEventData.value.lastName,name:D.stripeBillingAddressEventData.value.name,phone:D.stripeBillingAddressEventData.value.phone}),c="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),{errors:u,json:v}=await l("/api/zonos-elements/create-parties",{body:{address:a,billingAddress:d,companyName:D.companyName,email:(null===(s=D.stripeLinkEventData)||void 0===s?void 0:s.value.email)||"",isTest:c,rootId:r,taxId:D.taxId},method:"POST"});return u.length||!v?(p("Error occurs when creating parties",JSON.stringify(u,null,2)),m({endpoint:"PF_PARTY_CREATE_FAILED",errors:["Failed to create parties"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,errors:u,json:v}}),{partiesCreated:!1}):(D.companyNameUsedWhenAsyncAddressUpdate=D.companyName,D.stripeAddressUsedWhenAsyncAddressUpdate=D.stripeAddressEventData,D.stripeBillingAddressUsedWhenAsyncAddressUpdate=D.stripeBillingAddressEventData,D.taxIdUsedWhenAsyncAddressUpdate=D.taxId,D.partyBillingId=v.billToPartyId,D.partyShippingId=v.shipToPartyId,{partiesCreated:!0})},F=e=>({countryCode:e.address.country,postalCode:e.address.postal_code,state:e.address.state}),J=async t=>{var n,s,r,i;const a=(null==t?void 0:t.retries)||0,d=!!(null==t?void 0:t.applyingPromocode),l=(()=>{var e;const t=se.landedCostData&&(null===(e=se.landedCostData.find(Boolean))||void 0===e?void 0:e.subtotals.items)!==se.subtotal,o=(()=>{var e,t;const o=JSON.stringify(null===(e=D.stripeLinkUsedWhenFetchingLC)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=D.stripeLinkEventData)||void 0===t?void 0:t.value),n=D.stripeAddressEventData&&JSON.stringify(F(D.stripeAddressEventData.value))!==JSON.stringify(D.stripeAddressUsedWhenFetchingLC),s=!D.stripeShippingSameAsBilling&&D.stripeBillingAddressEventData&&JSON.stringify(F(D.stripeBillingAddressEventData.value))!==JSON.stringify(D.stripeBillingAddressUsedWhenFetchingLC);return o||n||s})();return h("isPrefetchInfoOutdated","info",{isAddressOutdated:o}),!se.landedCostData&&!D.isFetchingLandedCost||o||t})();if(!(()=>{var t,o,n,s;const r=!!(null===(t=D.stripeLinkEventData)||void 0===t?void 0:t.complete),i=!!(null===(o=D.stripeAddressEventData)||void 0===o?void 0:o.complete),a=D.stripeShippingSameAsBilling?i:!!(null===(n=D.stripeBillingAddressEventData)||void 0===n?void 0:n.complete),d=(t=>{var o,n;const s=null===(o=e.genericSettings)||void 0===o?void 0:o.countryFields,r=null===(n=e.genericSettings)||void 0===n?void 0:n.stripeCountryFieldLabels;return"stripe"===se.addressFormRenderType&&(r&&t in r?r[t]:null)||(s&&t in s?s[t]:null)})((null===(s=D.stripeAddressEventData)||void 0===s?void 0:s.value.address.country)||"US");return!!(i&&a&&r)||(d&&D.stripeAddressEventData?r&&D.stripeAddressEventData.value.firstName&&D.stripeAddressEventData.value.lastName&&D.stripeAddressEventData.value.address.line1.length>0&&(!d.stateRequired||d.stateRequired&&D.stripeAddressEventData.value.address.state.length>0)&&(!d.zipRequired||d.zipRequired&&D.stripeAddressEventData.value.address.postal_code.length>=3)&&D.stripeAddressEventData.value.phone&&D.stripeAddressEventData.value.phone.length>0:i&&a&&r)})())return{isRequestNotReady:!0};if(l&&(null===(n=D.fetchingLandedCostAbortController)||void 0===n||n.abort(),D.fetchingLandedCostAbortController=null),!l&&!d)return{isRequestNotReady:!1};a?(D.isFetchingLandedCost=!1,setTimeout((()=>{D.isFetchingLandedCost=!0}),300)):D.isFetchingLandedCost=!0,D.stripeAddressEventData&&(D.stripeAddressUsedWhenFetchingLC={countryCode:D.stripeAddressEventData.value.address.country,postalCode:D.stripeAddressEventData.value.address.postal_code,state:D.stripeAddressEventData.value.address.state}),D.stripeBillingAddressEventData&&(D.stripeBillingAddressUsedWhenFetchingLC={countryCode:D.stripeBillingAddressEventData.value.address.country,postalCode:D.stripeBillingAddressEventData.value.address.postal_code,state:D.stripeBillingAddressEventData.value.address.state}),D.stripeLinkEventData&&(D.stripeLinkUsedWhenFetchingLC=Object.assign({},D.stripeLinkEventData));try{fe(),await(async()=>{var e;const t=new AbortController;D.fetchingLandedCostAbortController=t,fe();const{checkoutSessionWorkflow:n,errors:s,itemCreateWorkflow:r,landedCostCalculateWorkflow:i,partyCreateWorkflow:a,shipmentRatingCalculateWorkflow:d}=await O(t);se.customQuotingError=(null===(e=null==s?void 0:s.find((e=>{var t;return"CUSTOM"===(null===(t=e.extensions)||void 0===t?void 0:t.ruleMessageType)})))||void 0===e?void 0:e.message)||null,se.shippingData=I((null==d?void 0:d.filter(Boolean))||[]),de(r),D.fetchingLandedCostAbortController=null,se.partiesData=(null==a?void 0:a.filter(Boolean))||[],se.landedCostData=(null==n?void 0:n.map((e=>{const t=null==i?void 0:i.find((t=>(null==t?void 0:t.id)===e.landedCostId));return t?Object.assign(Object.assign({},e),{landedCost:t}):null})).filter(Boolean))||[],(null==n?void 0:n.length)&&A({checkoutSessionId:o.checkoutSessionId,eventName:"checkout_quoteReceived"});const l=se.promoCodeApplied&&!se.landedCostData.find((e=>{var t;return null===(t=e.landedCost.appliedAdjustments)||void 0===t?void 0:t.find((e=>"PROMO_CODE"===e.type))}));se.promoCodeError=l,l||sessionStorage.setItem("zonos--promo-code",se.promoCode)})();const e=null===(s=se.shippingData)||void 0===s?void 0:s.find(Boolean),t=null===(r=se.landedCostData)||void 0===r?void 0:r.find((t=>t.landedCost.shipmentRating.id===(null==e?void 0:e.id))),n=t?t.subtotals:null;n&&ue({method:(null==t?void 0:t.landedCost.method)||"DDP",subtotals:n})}catch(e){if(se.landedCostData=[],se.shippingData=[],e instanceof Error&&e.message&&!["The landed cost calculation request was aborted to initiate a new one."].includes(e.message)){if(a<1)return await J(Object.assign(Object.assign({},t),{retries:(a||0)+1})),{isRequestNotReady:!1};const o=null===(i=D.stripeAddressEventData)||void 0===i?void 0:i.value;m({endpoint:`Failed to fetch landed cost (${a} retries)`,errors:[e.message],metadata:{cartId:window.Zonos.cartId,shipToAddress:o}})}p(e)}return D.isFetchingLandedCost=!1,{isRequestNotReady:!1}},M=async()=>{var e,t;await J({applyingPromocode:!0}),"payment"===se.step&&Se(),await B();const o=null===(e=se.shippingData)||void 0===e?void 0:e.find(Boolean),n=null===(t=se.landedCostData)||void 0===t?void 0:t.find((e=>e.landedCost.id===(null==o?void 0:o.id)));o&&n&&await ye({applySubtotalsOnly:!1,landedCostId:n.landedCostId,selectedShippingOption:o})},W=()=>{se.promoCode="",sessionStorage.removeItem("zonos--promo-code"),se.promoCodeError=!1,se.promoCodeApplied=!1},$=async()=>{"payment"===se.step&&Se(),W(),await M()},q=e=>{let t=[],o=!0;const n=window.Zonos.isCollect,s=window.Zonos.isInvoice;switch(e){case"succeeded":t=[r("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."),"",r("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.")],(n||s)&&(t=[r("Thank you for submitting your payment. We appreciate your prompt attention."),"",r("A confirmation email with your payment details has been sent for your records. If you have any questions or need support, our team is here to help.")]),o=!1;break;case"requires_capture":case"processing":t=[r("Payment processing. We'll update you when payment is received.")],o=!1;break;case"requires_payment_method":t=[r("Payment failed. Please try another payment method.")],n&&(t=[r("Payment failed. Please reload the page and try another payment method.")]);break;case"requires_action":o=!1,t=[r("Your selected payment method requires additional verification. Please follow the instructions provided by your payment provider to complete the transaction.")];default:t=[r("Something went wrong.")]}return{isError:o,messages:t}},Y=async()=>{var t,o;const{onInventoryCheck:n}=e.checkoutSettings,s=!!(null===(o=null===(t=window.Zonos.cartData)||void 0===t?void 0:t.metadata.find((e=>"referenceId"===e.key)))||void 0===o?void 0:o.value);if(window.Zonos.isLegacyCheckout&&window.Zonos.cartData&&s){const{errors:e,json:t}=await l("/api/zonos-elements/legacy/inventory-check",{body:{cartData:window.Zonos.cartData},method:"POST"});return e.length||!t?(p("Error occurs when handling inventory refund","warn",JSON.stringify(e)),null):t.available&&204!==t.status?t.available||200===t.status?(D.shouldInventoryRefund=!0,null):null:r("The item you're looking for is currently unavailable in our inventory. Please check back later or contact support for assistance with availability.")}if("function"!=typeof n)return null;try{return await n({items:se.items},{translate:r,zonosApiRoute:d.vercel})}catch(e){const t=e instanceof Error?e.message:"Unknown error";throw m({endpoint:"onInventoryCheck",errors:[`cartId: ${window.Zonos.cartId} - ${t}`],metadata:{cartId:window.Zonos.cartId,href:window.location.href,items:se.items}}),e}},H=async()=>{var e,t;const o=!!(null===(t=null===(e=window.Zonos.cartData)||void 0===e?void 0:e.metadata.find((e=>"referenceId"===e.key)))||void 0===t?void 0:t.value);window.Zonos.isLegacyCheckout&&window.Zonos.cartData&&o&&await l("/api/zonos-elements/legacy/inventory-refund",{body:{cartData:window.Zonos.cartData},method:"POST"})},K=async({clientSecret:e,storybookForceStatus:t})=>{if(t){const{isError:e,messages:o}=q(t);return{error:e,messages:o}}const o=e||D.clientSecret;if(!D.stripe||!o)return p("Failed to retrieve payment intent. Stripe is not initialized"),{error:!0,message:[r("Something went wrong.")]};const{paymentIntent:n}=await D.stripe.retrievePaymentIntent(o),s=null==n?void 0:n.status,{isError:i,messages:a}=q(s);return{error:i,messages:a,paymentIntentId:null==n?void 0:n.id,paymentMethod:null==n?void 0:n.payment_method,status:s}},G=async e=>{var t,n;const s=!!(null===(t=D.stripePaymentEventData)||void 0===t?void 0:t.complete),i=D.stripeElements,a=D.stripe,d=D.clientSecret;if(D.customErrorMessage=null,!(null===(n=se.selectedLandedCost)||void 0===n?void 0:n.landedCost.id)&&!(null==e?void 0:e.noLandedCostCheck))throw new Error("Attempted to confirm the payment when no landed cost is found in store");const l=await N();if(!l.valid)throw D.customErrorMessage=l.errorMessage,new Error(l.errorMessage);const c=o.checkoutSessionId;if(a&&i&&s&&d&&c){const e=new URL(window.location.href);e.searchParams.set("payment_intent_client_secret",d),e.searchParams.set("zonosCheckoutSessionId",c),A({checkoutSessionId:c,eventName:"checkout_paymentInfoCompleted"});const{error:t,paymentIntent:o}=await a.confirmPayment({confirmParams:{return_url:e.toString()},elements:i,redirect:"if_required"});if(h("Payment intent confirmed","info",{error:t,paymentIntent:o}),"requires_action"===(null==o?void 0:o.status))throw new Error(r("Your selected payment method requires additional verification. Please follow the instructions provided by your payment provider to complete the transaction."));if(t){if("card_error"===t.type||"validation_error"===t.type)throw new Error(t.message);if("invalid_request_error"===t.type&&"payment_intent_unexpected_state"===t.code)return;throw new Error("An unexpected error occurred.")}if("requires_payment_method"===o.status)throw new Error(r("Payment failed. Please try another payment method."))}},V=()=>{var e;const t=se.items.reduce(((e,t)=>e+t.amount*t.quantity),0),s=o.enabledVariantTestKeys||[];return{adjustmentsAmount:se.adjustments.reduce(((e,t)=>e+t.amount),0),cartId:window.Zonos.cartId,currency:(null===(e=se.items.find(Boolean))||void 0===e?void 0:e.currencyCode)||"",customerAuthenticationToken:se.customerAuthenticationToken||void 0,isCollect:!!window.Zonos.isCollect,isInvoice:!!window.Zonos.isInvoice,itemsAmount:t,metadata:[{key:"language",value:n.selectedLocale}],presentmentCountryCode:n.selectedCountryCode,skipPaymentIntent:D.skipPaymentIntent,varianceTestInput:s}},Z=async()=>{var e;if(!o.checkoutSessionId)return m({endpoint:"Error creating payment intent",errors:["No checkout session id found when retrieving payment intent"],metadata:{allLogs:y,cartId:window.Zonos.cartId}}),void ce({messages:[r("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:r("Error creating Checkout")});const{errors:t,json:n}=await l("/api/zonos-elements/create-payment-intent",{body:{checkoutSessionId:o.checkoutSessionId},method:"POST"}),s=null===(e=null==n?void 0:n.checkoutSessionPaymentIntentCreate)||void 0===e?void 0:e.clientSecret;if(t.length||!s)return p("Error occurs when getting payment intent",JSON.stringify(t,null,2)),m({endpoint:"Error creating payment intent",errors:t.map((e=>e.message)),metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,clientSecret:s}}),void ce({messages:[r("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:r("Error creating Checkout")});pe(n.checkoutSessionPaymentIntentCreate)},Q=async()=>{var e,t;if(!n.targetCurrency)return p("Failed to create checkout session - missing localizationStore.targetCurrency"),!1;D.isFetchingSession=!0;const o=V();h("Checkout session body","info",o);const{errors:s,json:r}=await l("/api/zonos-elements/create-checkout-session",{body:o,method:"POST"});if(D.isFetchingSession=!1,s.length||!r){const t=null===(e=s.find((e=>e.message)))||void 0===e?void 0:e.message;if(Array.isArray(t)&&t.some((e=>"Cart is expired."===e.message)))throw new Error("Cart is expired.");return p("Error occurred when creating checkout session",JSON.stringify(s,null,2)),!1}const i=r.checkoutSessionCreate;return pe(i),ue({method:(null===(t=i.landedCost)||void 0===t?void 0:t.method)||"DDP",subtotals:i.subtotals}),h("Exchange rate updated for cart items (checkout session create)","info",se.exchangeRate),h("done-init-checkout-session"),!0},X=async()=>{const t=o.checkoutSessionId;if(!t)return p("Failed to update checkout session base currency"),!1;if("LOCAL"===e.checkoutSettings.allowedSettlementCurrencies)return h('allowedSettlementCurrencies: "LOCAL". Skip updating checkout session base currency'),!0;const{json:n}=await l("/api/zonos-elements/update-checkout-session-base-currency",{body:{checkoutSessionId:t,currencyCode:D.checkoutSettlementCurrency},method:"POST"}),s=null==n?void 0:n.checkoutSessionBaseCurrencyUpdate.subtotals.presentmentCurrencyCode;return n&&s===D.checkoutSettlementCurrency?(h(`Updated checkout session to settlement currency "${s}".`),!0):(p("Failed to update checkout session base currency"),!1)},ee=({currentAddress:e,translatedAddressResult:t})=>{const o={};if(!t)return o;const{city:n,line1:s,line2:r,name:i,postal_code:a,state:d}=t;return e.city&&n&&(o.city={[e.city]:n}),e.line1&&s&&(o.line1={[e.line1]:s}),e.line2&&r&&(o.line2={[e.line2]:r}),e.postal_code&&a&&(o.postal_code={[e.postal_code]:a}),e.state&&d&&(o.state={[e.state]:d}),e.name&&i&&(o.name={[e.name]:i}),o},te=async({addressInvalidCharactersList:e,billingAddressInvalidCharactersList:t})=>{var o,n,s,r;const i=(({addressInvalidCharactersList:e,billingAddressInvalidCharactersList:t,stripeAddressEventData:o,stripeBillingAddressEventData:n,stripeShippingSameAsBilling:s})=>{const r=!!(null==o?void 0:o.complete);if(!r||!(s?r:null==n?void 0:n.complete))return null;if(!e&&!t)return null;const i=o.value,a=(null==n?void 0:n.value)||null,{firstName:d,lastName:l}=f({firstName:i.firstName,lastName:i.lastName,name:i.name}),c=`${d} ${l}`,{firstName:u,lastName:m}=f({firstName:null==a?void 0:a.firstName,lastName:null==a?void 0:a.lastName,name:(null==a?void 0:a.name)||""}),p=u&&m?`${u} ${m}`:"",v=i.address,h=null==a?void 0:a.address;return{address:k({address:Object.assign(Object.assign({},v),{name:c}),invalidAdddressList:e}),billingAddress:s?void 0:k({address:h?Object.assign(Object.assign({},h),{name:p}):null,invalidAdddressList:t}),destinationCountry:v.country}})({addressInvalidCharactersList:e,billingAddressInvalidCharactersList:t,stripeAddressEventData:D.stripeAddressEventData,stripeBillingAddressEventData:D.stripeBillingAddressEventData,stripeShippingSameAsBilling:D.stripeShippingSameAsBilling});if(!i)return void(D.translatedAddress={address:{},billingAddress:{}});const a=(()=>{var e,t,o,n;const s=JSON.stringify(null===(e=D.stripeAddressUsedWhenValidatingAddress)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=D.stripeAddressEventData)||void 0===t?void 0:t.value),r=!D.stripeShippingSameAsBilling&&JSON.stringify(null===(o=D.stripeBillingAddressEventData)||void 0===o?void 0:o.value)!==JSON.stringify(null===(n=D.stripeBillingAddressUsedWhenValidatingAddress)||void 0===n?void 0:n.value);return s||r})();if(!a)return;const{errors:d,json:c}=await l("/api/zonos-elements/validate-address",{body:i,method:"POST"});if(d.length||!c)return p("Error occurs when translating address to latin",JSON.stringify(d,null,2)),void(D.translatedAddress={address:{},billingAddress:{}});D.stripeAddressUsedWhenValidatingAddress=D.stripeAddressEventData,D.stripeBillingAddressUsedWhenValidatingAddress=D.stripeBillingAddressEventData;const u=null===(o=D.stripeAddressEventData)||void 0===o?void 0:o.value.address,m=null===(n=D.stripeBillingAddressEventData)||void 0===n?void 0:n.value.address;D.translatedAddress={address:u?ee({currentAddress:Object.assign(Object.assign({},u),{name:null===(s=D.stripeAddressEventData)||void 0===s?void 0:s.value.name}),translatedAddressResult:c.address||null}):{},billingAddress:D.stripeShippingSameAsBilling?{}:ee({currentAddress:Object.assign(Object.assign({},m),{name:null===(r=D.stripeBillingAddressEventData)||void 0===r?void 0:r.value.name}),translatedAddressResult:c.billingAddress||null})}};E("clientSecret",(e=>{e&&D.stripe&&sessionStorage.setItem("zonos--client-secret",e),e||sessionStorage.removeItem("zonos--client-secret")}));const{onChange:oe,reset:ne,state:se}=t((()=>({addressFormRenderType:"stripe",adjustmentTotal:0,adjustments:[],checkoutSession:null,checkoutSessionTimeoutShow:!1,checkoutTimeoutInterval:null,currency:"USD",customQuotingError:null,customerAuthenticationToken:null,displayBaseCurrency:!1,dutiesTaxesFees:null,dutiesTaxesFeesEstimate:null,error:null,exchangeRate:null,externalConfirmationPageURL:null,inventoryCheckErrorMessage:null,isSelectedShippingAboveDeminimis:!1,isSelectedShippingGuarantee:!1,isStagingMode:u(),items:[],landedCostData:null,landedCostMethod:"DDP",partiesData:[],promoCode:sessionStorage.getItem("zonos--promo-code")||"",promoCodeApplied:!!sessionStorage.getItem("zonos--promo-code"),promoCodeError:!1,restrictedItems:[],selectedLandedCost:null,selectedShippingOption:null,selectedShippingOptionExpectedDate:"",selectedShippingOptionTransitTime:"",shipping:0,shippingData:null,shouldHideDiscountInput:!1,step:"customer-info",subtotal:0,tabItems:{"customer-info":{index:1,isDone:!1,label:"Customer",value:"customer-info"},shipping:{index:2,isDone:!1,label:"Shipping",value:"shipping"},payment:{index:3,isDone:!1,label:"Payment",value:"payment"}},total:0}))),re=e=>{switch(e){case"DAYS":return r("days");case"WEEKS":return r("weeks");default:return r("business days")}},ie=e=>{var t;const o=null===(t=e.shippingProfile)||void 0===t?void 0:t.transitTime;return(null==o?void 0:o.min)&&(null==o?void 0:o.max)&&(null==o?void 0:o.type)?{maxTransit:o.max,minTransit:o.min,unit:re(o.type)}:null},ae=({item1:e,item2:t})=>!(!e||!t)&&(t.sku&&e.sku&&e.sku===t.sku||t.description&&e.description&&e.description===t.description||e.name&&t.name&&e.name===t.name),de=e=>{h("Checking item restrictions");const t=e.map((e=>{if(!e.restriction)return null;const{restriction:t}=e,o=se.items.find((t=>ae({item1:t,item2:e})));return Object.assign(Object.assign({matchedItem:o},e),{restriction:t})})).filter(Boolean);return se.restrictedItems=t,se.items=se.items.map((e=>Object.assign(Object.assign({},e),{isRestricted:!!t.find((t=>ae({item1:t,item2:e})))}))),{cartItems:se.items,restrictedItems:t}},le=()=>{o.checkoutSessionId=null,ne()},ce=({messages:e,title:t})=>{le(),U(),se.step="error",se.error={messages:e,title:t}},ue=({dutiesTaxesFeesEstimate:e,method:t,subtotals:o})=>{se.exchangeRate=o.exchangeRate,se.adjustmentTotal=o.adjustments,se.dutiesTaxesFees="DAP"===t?null:o.landedCostTotal,se.subtotal=o.items,se.total=o.total,se.currency=o.presentmentCurrencyCode,se.dutiesTaxesFeesEstimate=e||null},me=()=>!!se.items.filter((e=>e.amount>0)).find((e=>!e.isRestricted)),pe=e=>{var t,n,s,r,d;D.clientSecret=e.clientSecret,D.stripeCustomerSessionClientSecret=e.customerSessionClientSecret,D.customerProfile=e.customerProfile,se.checkoutSession=e,e.id||m({endpoint:"cartStoreSetCheckoutSession",errors:["Missing checkout session id in checkout session"],metadata:{allLogs:y,checkoutSession:e}}),e.id&&(o.checkoutSessionId=e.id);const l=i(e.varianceTestResults||[]);a(l);const c=(null===(s=null===(n=null===(t=se.checkoutSession)||void 0===t?void 0:t.metadata)||void 0===n?void 0:n.find((e=>"externalConfirmationPageURL"===(null==e?void 0:e.key))))||void 0===s?void 0:s.value)||(null===(d=null===(r=window.Zonos.cartData)||void 0===r?void 0:r.metadata.find((e=>"externalConfirmationPageURL"===(null==e?void 0:e.key))))||void 0===d?void 0:d.value)||null;c&&(h(`Found externalConfirmationPageURL: ${c}`),se.externalConfirmationPageURL=c)},ve=async({adjustmentsAmount:e,cartId:t,currency:s,dutiesTaxesFeesEstimate:i,itemsAmount:a,landedCostId:d,shouldInitSessionOnFailure:c})=>{var u;if(d&&se.selectedLandedCost&&(ue({dutiesTaxesFeesEstimate:i,method:se.landedCostMethod,subtotals:se.selectedLandedCost.subtotals}),h("Exchange rate updated for cart items (landed cost subtotal)","info",se.exchangeRate)),!o.checkoutSessionId)return h("Could not update cart total without checkout session id","info"),!1;const{errors:m,json:v}=await(async({adjustmentsAmount:e,cartId:t,currency:s,id:r,itemsAmount:i,landedCostId:a,presentmentCountryCode:d})=>{const c=o.enabledVariantTestKeys||[],{errors:u,json:m}=await l("/api/zonos-elements/update-checkout-session",{body:{adjustmentsAmount:e,billToPartyId:D.partyBillingId,cartId:t,currency:s,customerAuthenticationToken:se.customerAuthenticationToken||void 0,id:r,itemsAmount:i,landedCostId:a,metadata:[{key:"language",value:n.selectedLocale}],presentmentCountryCode:d,shipToPartyId:D.partyShippingId,skipPaymentIntent:D.skipPaymentIntent,varianceTestInput:c},method:"POST"});return u.length||!m?(p("Error occurs when updating checkout session",JSON.stringify(u,null,2)),{errors:u,json:m}):{errors:[],json:m}})({adjustmentsAmount:e,billToPartyId:D.partyBillingId,cartId:t,currency:s,id:o.checkoutSessionId,itemsAmount:a,landedCostId:d,presentmentCountryCode:n.selectedCountryCode,shipToPartyId:D.partyShippingId,varianceTestInput:o.enabledVariantTestKeys||[]});if(m.length>0||!v){if(p("Error occurs when updating checkout session."),c){h("Initiating checkout session on failure","info");const e=await Q();return h(`stripeStoreInitCheckoutSession: ${e}`),!!e||(ce({messages:[r("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:r("Error creating Checkout")}),!1)}return!1}return d||(ue({method:(null===(u=v.checkoutSessionUpdate.landedCost)||void 0===u?void 0:u.method)||"DDP",subtotals:v.checkoutSessionUpdate.subtotals}),h("Exchange rate updated for cart items (checkout session update)","info",se.exchangeRate)),pe(v.checkoutSessionUpdate),!0},he=t=>{var o,n,s;return"DAP"===t.method&&(null===(n=null===(o=e.genericSettings)||void 0===o?void 0:o.domesticCountries)||void 0===n?void 0:n.includes((null===(s=D.stripeAddressEventData)||void 0===s?void 0:s.value.address.country)||"US"))||"DAP"===t.method&&t.remittance.length&&"ZONOS"===t.landedCostGuaranteeCode?"DDP":t.method},ye=async({applySubtotalsOnly:t,landedCostId:n,selectedShippingOption:s})=>{var r,i,a,d,l,c,u,m,p,v,y;h("Updating selected shipping option","info",{landedCostId:n,selectedShippingOption:s}),se.selectedShippingOption=s;const w=ie(se.selectedShippingOption);if(w){const{maxTransit:e,minTransit:t,unit:o}=w;se.selectedShippingOptionTransitTime=`${t}-${e} ${o}`}else se.selectedShippingOptionTransitTime="";const g=null===(r=se.landedCostData)||void 0===r?void 0:r.find((e=>e.landedCostId===n));if(se.selectedLandedCost=g||null,!g)return!1;const f=((null===(i=g.landedCost.amountSubtotals)||void 0===i?void 0:i.landedCostTotal)||0)*g.subtotals.exchangeRate.rate;f&&h(`DAP quote, using estimate: ${f}`,"info"),se.landedCostMethod=he(g.landedCost),se.shipping=g.subtotals.shipping;const b="ZONOS"===(null===(a=null==g?void 0:g.landedCost)||void 0===a?void 0:a.landedCostGuaranteeCode),S=!!(null===(l=null===(d=null==g?void 0:g.landedCost)||void 0===d?void 0:d.deMinimis)||void 0===l?void 0:l.find((e=>["DUTY","TAX"].includes(e.type)&&"ABOVE"===e.threshold)));se.isSelectedShippingAboveDeminimis=S,se.isSelectedShippingGuarantee=b;let C=!1;t?(ue({dutiesTaxesFeesEstimate:f,method:se.landedCostMethod,subtotals:g.subtotals}),h("Exchange rate updated for cart items (landed cost subtotal)","info",se.exchangeRate),C=!0):C=await ve({adjustmentsAmount:se.adjustmentTotal,billToPartyId:D.partyBillingId,cartId:window.Zonos.cartId,dutiesTaxesFeesEstimate:f,landedCostId:null===(c=g.landedCost)||void 0===c?void 0:c.id,shipToPartyId:D.partyShippingId,varianceTestInput:o.enabledVariantTestKeys||[]});const O=null===(u=se.items.find(Boolean))||void 0===u?void 0:u.currencyCode,A=(null===(m=D.stripeAddressEventData)||void 0===m?void 0:m.value.address.country)||"US";return D.shouldRenderPayInUsdButton="USD"===O&&"LOCAL_AND_USD"===e.checkoutSettings.allowedSettlementCurrencies&&"USD"!==(null===(p=se.checkoutSession)||void 0===p?void 0:p.subtotals.presentmentCurrencyCode)&&!!(null===(y=null===(v=e.genericSettings)||void 0===v?void 0:v.usdSettlementCountryEnabled)||void 0===y?void 0:y.includes(A)),C},we=({isPreview:e,sessionTimeout:t})=>{if(e)return;const o=new URLSearchParams(window.location.search).get("zonosCheckoutTimeout"),n=o&&!isNaN(parseInt(o,10))?parseInt(o,10):t;h(`==START CHECKOUT TIMEOUT - ${n}==`),se.checkoutTimeoutInterval=setTimeout((()=>{se.checkoutSessionTimeoutShow=!0}),n)},ge=()=>{se.checkoutTimeoutInterval&&(clearTimeout(se.checkoutTimeoutInterval),se.checkoutTimeoutInterval=null)},fe=()=>{se.items=se.items.map((e=>Object.assign(Object.assign({},e),{isRestricted:!1}))),se.restrictedItems=[]},be=async({adjustments:e,cartItems:t,landedCostId:n,shouldInitSessionOnFailure:s=!0})=>{var r;se.adjustments=e,se.items=t.map((e=>Object.assign(Object.assign({},e),{isRestricted:!1})));const i=null===(r=t.find(Boolean))||void 0===r?void 0:r.currencyCode,a=t.reduce(((e,t)=>e+t.amount*t.quantity),0),d=e.reduce(((e,t)=>e+t.amount),0);i&&a&&(se.currency=i,D.isFetchingSession=!0,await ve({adjustmentsAmount:d,billToPartyId:D.partyBillingId,cartId:window.Zonos.cartId,currency:i,dutiesTaxesFeesEstimate:0,itemsAmount:a,landedCostId:n,shipToPartyId:D.partyShippingId,shouldInitSessionOnFailure:s,varianceTestInput:o.enabledVariantTestKeys||[]}),D.isFetchingSession=!1)},Se=()=>{"shipping"===se.step?(se.step="customer-info",se.tabItems=Object.assign(Object.assign({},se.tabItems),{"customer-info":Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!1})})):"payment"===se.step?(se.step="shipping",se.tabItems=Object.assign(Object.assign({},se.tabItems),{shipping:Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!1})})):"finish"===se.step&&(se.step="payment",se.tabItems=Object.assign(Object.assign({},se.tabItems),{payment:Object.assign(Object.assign({},se.tabItems.payment),{isDone:!1})}))},Ce=()=>{"customer-info"===se.step?(se.step="shipping",se.tabItems=Object.assign(Object.assign({},se.tabItems),{"customer-info":Object.assign(Object.assign({},se.tabItems["customer-info"]),{isDone:!0})})):"shipping"===se.step?(se.step="payment",se.tabItems=Object.assign(Object.assign({},se.tabItems),{shipping:Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!0})})):"payment"===se.step&&(se.step="finish")},Oe=()=>{se.step="customer-info",se.tabItems=Object.assign(Object.assign({},se.tabItems),{"customer-info":Object.assign(Object.assign({},se.tabItems["customer-info"]),{isDone:!1}),payment:Object.assign(Object.assign({},se.tabItems.payment),{isDone:!1}),shipping:Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!1})}),se.selectedShippingOption=null,se.isSelectedShippingAboveDeminimis=!1,se.isSelectedShippingGuarantee=!1,se.selectedShippingOptionTransitTime="",se.dutiesTaxesFees=0,se.dutiesTaxesFeesEstimate=0,se.shipping=0,se.total=se.subtotal};export{N as A,E as B,_ as C,ye as D,me as E,M as F,$ as G,W as H,q as I,te as J,f as K,B as L,ie as M,he as N,I as O,x as a,D as b,K as c,se as d,be as e,le as f,Oe as g,ge as h,z as i,Q as j,Z as k,we as l,V as m,ce as n,L as o,pe as p,J as q,Ce as r,R as s,A as t,X as u,Y as v,G as w,H as x,U as y,oe as z}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as e,z as o}from"./p-b2a0ab4a.js";import{b as a,C as t,d as s,D as d}from"./p-
|
|
1
|
+
import{c as e,z as o}from"./p-b2a0ab4a.js";import{b as a,C as t,d as s,D as d}from"./p-a6489088.js";import{s as n}from"./p-21fb6b39.js";import{h as r,s as i,l}from"./p-41dd1cb8.js";import{b as c}from"./p-0a377722.js";const{state:p}=e((()=>({amountTotalDue:null,isFetchingPayorInfo:!0,landedCostShortId:null,partyBillingId:null,payorAddress:null}))),u=async({landedCostId:e,retries:a=5})=>{var t,d,n;p.isFetchingPayorInfo=!0;const l=await r("/api/zonos-elements/invoice/get-payor-info-by-lc-id",{body:{landedCostId:e},method:"POST"});if(l.errors.length)return a>0?(await new Promise((e=>setTimeout(e,1e3))),u({landedCostId:e,retries:a-1})):null;p.landedCostShortId=(null===(t=l.json)||void 0===t?void 0:t.landedCostShortId)||null,p.isFetchingPayorInfo=!1,p.payorAddress=(null===(d=l.json)||void 0===d?void 0:d.payor)||null;const c=null===(n=s.checkoutSession)||void 0===n?void 0:n.subtotals;p.amountTotalDue=(null==c?void 0:c.items)||0,0===p.amountTotalDue&&i({endpoint:"INVOICE_NO_TOTAL_DUE",errors:[],metadata:{landedCostId:e,organizationId:o.organizationId}})},I=async()=>{var e,o,d,u;if(!(null===(e=a.stripeBillingAddressEventData)||void 0===e?void 0:e.complete))return{partiesCreated:!1};const I=null===(d=null===(o=s.checkoutSession)||void 0===o?void 0:o.landedCost)||void 0===d?void 0:d.rootId;if(!I)return i({endpoint:"PF_NO_SELECTED_LANDED_COST",errors:["No selected landed cost"],metadata:{allLogs:c,cartId:window.Zonos.cartId,checkoutSessionId:n.checkoutSessionId}}),{partiesCreated:!1};if(!n.checkoutSessionId)return i({endpoint:"INVOICE_NO_CHECKOUT_SESSION_ID",errors:["No checkout session id"],metadata:{allLogs:c,cartId:window.Zonos.cartId,landedCostRootId:I}}),{partiesCreated:!1};const m=t({address:a.stripeBillingAddressEventData.value.address,firstName:a.stripeBillingAddressEventData.value.firstName,lastName:a.stripeBillingAddressEventData.value.lastName,name:a.stripeBillingAddressEventData.value.name,phone:a.stripeBillingAddressEventData.value.phone}),C="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),{errors:b,json:O}=await r("/api/zonos-elements/create-billing-party",{body:{billingAddress:m,checkoutSessionId:n.checkoutSessionId,companyName:a.companyName,email:(null===(u=a.stripeLinkEventData)||void 0===u?void 0:u.value.email)||"",isTest:C,rootId:I},method:"POST"});return b.length||!O?(l("Error occurs when creating billing party",JSON.stringify(b,null,2)),i({endpoint:"INVOICE_BILLING_PARTY_CREATE_FAILED",errors:["[INVOICE] Failed to create billing party"],metadata:{allLogs:c,cartId:window.Zonos.cartId,checkoutSessionId:n.checkoutSessionId,errors:b,json:O}}),{partiesCreated:!1}):(p.partyBillingId=O.billToPartyId,{partiesCreated:!0})},m=async e=>{const o=e.landedCost;return!!o&&(s.landedCostData=[Object.assign(Object.assign({},e),{landedCost:Object.assign({},o),landedCostId:o.id})],d({applySubtotalsOnly:!0,landedCostId:o.id,selectedShippingOption:o.shipmentRating}))};export{u as a,I as b,p as c,m as i}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(n,t,r,e){function i(n){return n instanceof r?n:new r((function(t){t(n)}))}return new(r||(r=Promise))((function(r,o){function u(n){try{c(e.next(n))}catch(n){o(n)}}function s(n){try{c(e["throw"](n))}catch(n){o(n)}}function c(n){n.done?r(n.value):i(n.value).then(u,s)}c((e=e.apply(n,t||[])).next())}))};var __generator=this&&this.__generator||function(n,t){var r={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},e,i,o,u;return u={next:s(0),throw:s(1),return:s(2)},typeof Symbol==="function"&&(u[Symbol.iterator]=function(){return this}),u;function s(n){return function(t){return c([n,t])}}function c(s){if(e)throw new TypeError("Generator is already executing.");while(u&&(u=0,s[0]&&(r=0)),r)try{if(e=1,i&&(o=s[0]&2?i["return"]:s[0]?i["throw"]||((o=i["return"])&&o.call(i),0):i.next)&&!(o=o.call(i,s[1])).done)return o;if(i=0,o)s=[s[0]&2,o.value];switch(s[0]){case 0:case 1:o=s;break;case 4:r.label++;return{value:s[1],done:false};case 5:r.label++;i=s[1];s=[0];continue;case 7:s=r.ops.pop();r.trys.pop();continue;default:if(!(o=r.trys,o=o.length>0&&o[o.length-1])&&(s[0]===6||s[0]===2)){r=0;continue}if(s[0]===3&&(!o||s[1]>o[0]&&s[1]<o[3])){r.label=s[1];break}if(s[0]===6&&r.label<o[1]){r.label=o[1];o=s;break}if(o&&r.label<o[2]){r.label=o[2];r.ops.push(s);break}if(o[2])r.ops.pop();r.trys.pop();continue}s=t.call(n,r)}catch(n){s=[6,n];i=0}finally{e=o=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};System.register(["./p-
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(n,t,r,e){function i(n){return n instanceof r?n:new r((function(t){t(n)}))}return new(r||(r=Promise))((function(r,o){function u(n){try{c(e.next(n))}catch(n){o(n)}}function s(n){try{c(e["throw"](n))}catch(n){o(n)}}function c(n){n.done?r(n.value):i(n.value).then(u,s)}c((e=e.apply(n,t||[])).next())}))};var __generator=this&&this.__generator||function(n,t){var r={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},e,i,o,u;return u={next:s(0),throw:s(1),return:s(2)},typeof Symbol==="function"&&(u[Symbol.iterator]=function(){return this}),u;function s(n){return function(t){return c([n,t])}}function c(s){if(e)throw new TypeError("Generator is already executing.");while(u&&(u=0,s[0]&&(r=0)),r)try{if(e=1,i&&(o=s[0]&2?i["return"]:s[0]?i["throw"]||((o=i["return"])&&o.call(i),0):i.next)&&!(o=o.call(i,s[1])).done)return o;if(i=0,o)s=[s[0]&2,o.value];switch(s[0]){case 0:case 1:o=s;break;case 4:r.label++;return{value:s[1],done:false};case 5:r.label++;i=s[1];s=[0];continue;case 7:s=r.ops.pop();r.trys.pop();continue;default:if(!(o=r.trys,o=o.length>0&&o[o.length-1])&&(s[0]===6||s[0]===2)){r=0;continue}if(s[0]===3&&(!o||s[1]>o[0]&&s[1]<o[3])){r.label=s[1];break}if(s[0]===6&&r.label<o[1]){r.label=o[1];o=s;break}if(o&&r.label<o[2]){r.label=o[2];r.ops.push(s);break}if(o[2])r.ops.pop();r.trys.pop();continue}s=t.call(n,r)}catch(n){s=[6,n];i=0}finally{e=o=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};System.register(["./p-775c1122.system.js","./p-74e258ff.system.js","./p-01174496.system.js"],(function(n){"use strict";var t,r,e,i;return{setters:[function(n){t=n.d},function(n){r=n.s},function(n){e=n.l;i=n.h}],execute:function(){var o=this;var u=n("p",(function(){return __awaiter(o,void 0,void 0,(function(){var n,o,u,s,c,a,f,l,d;return __generator(this,(function(h){switch(h.label){case 0:u=(n=t.partiesData.find((function(n){return n.type==="DESTINATION"})))===null||n===void 0?void 0:n.id;s=(o=t.partiesData.find((function(n){return n.type==="PAYOR"})))===null||o===void 0?void 0:o.id;c=r.checkoutSessionId;if(!c||!s||!u){e("Missing required data",{billToPartyId:s,checkoutSessionId:c,shipToPartyId:u});return[2,{errors:["Missing required data"],json:null}]}a={billToPartyId:s,checkoutSessionId:c,shipToPartyId:u};return[4,i("/api/zonos-elements/place-test-order",{body:a,method:"POST"})];case 1:f=h.sent(),l=f.errors,d=f.json;if(l.length||!d){e("Error occurs when placing test order",l);return[2,{errors:l.map((function(n){return n.message})),json:null}]}return[2,{errors:[],json:d}]}}))}))}))}}}));
|