@zonos/elements 1.3.216 → 1.3.217
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-96520eab.js → cart-54ff39d6.js} +2 -2
- package/dist/cjs/{handleFetch-b821ed5d.js → handleFetch-0313ebba.js} +1 -1
- package/dist/cjs/index.cjs.js +8 -8
- package/dist/cjs/{localization-e241e025.js → localization-721a5ec3.js} +1 -1
- package/dist/cjs/{paypal-97ac0999.js → paypal-e7504122.js} +3 -3
- package/dist/cjs/{updateCheckoutSessionAttributes-5f794550.js → updateCheckoutSessionAttributes-8db49644.js} +1 -1
- package/dist/cjs/zonos-address_11.cjs.entry.js +3 -3
- package/dist/cjs/zonos-cart-items_14.cjs.entry.js +5 -5
- package/dist/cjs/zonos-checkout.cjs.entry.js +5 -5
- package/dist/cjs/zonos-controller.cjs.entry.js +3 -3
- package/dist/cjs/zonos-country-flag.cjs.entry.js +2 -2
- package/dist/cjs/zonos-country-select_4.cjs.entry.js +2 -2
- package/dist/cjs/zonos-empty-state-payment_4.cjs.entry.js +4 -4
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +2 -2
- package/dist/cjs/zonos-hello.cjs.entry.js +2 -2
- package/dist/cjs/zonos-language-select_2.cjs.entry.js +2 -2
- package/dist/collection/components/utils/getNextFallbackApi.js +1 -1
- package/dist/esm/{cart-011aa510.js → cart-010402f9.js} +2 -2
- package/dist/esm/{handleFetch-bb221e63.js → handleFetch-fa90f7f6.js} +1 -1
- package/dist/esm/index.js +8 -8
- package/dist/esm/{localization-b3bdf691.js → localization-9db8b6e9.js} +1 -1
- package/dist/esm/{paypal-8af04edf.js → paypal-70b140d9.js} +3 -3
- package/dist/esm/{updateCheckoutSessionAttributes-fa58ba66.js → updateCheckoutSessionAttributes-691cdc6d.js} +1 -1
- package/dist/esm/zonos-address_11.entry.js +3 -3
- package/dist/esm/zonos-cart-items_14.entry.js +5 -5
- package/dist/esm/zonos-checkout.entry.js +5 -5
- package/dist/esm/zonos-controller.entry.js +3 -3
- package/dist/esm/zonos-country-flag.entry.js +2 -2
- package/dist/esm/zonos-country-select_4.entry.js +2 -2
- package/dist/esm/zonos-empty-state-payment_4.entry.js +4 -4
- package/dist/esm/zonos-hello-dialog.entry.js +2 -2
- package/dist/esm/zonos-hello.entry.js +2 -2
- package/dist/esm/zonos-language-select_2.entry.js +2 -2
- package/dist/esm-es5/{cart-011aa510.js → cart-010402f9.js} +1 -1
- package/dist/esm-es5/{handleFetch-bb221e63.js → handleFetch-fa90f7f6.js} +1 -1
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/{localization-b3bdf691.js → localization-9db8b6e9.js} +1 -1
- package/dist/esm-es5/{paypal-8af04edf.js → paypal-70b140d9.js} +1 -1
- package/dist/esm-es5/{updateCheckoutSessionAttributes-fa58ba66.js → updateCheckoutSessionAttributes-691cdc6d.js} +1 -1
- package/dist/esm-es5/zonos-address_11.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_14.entry.js +1 -1
- package/dist/esm-es5/zonos-checkout.entry.js +1 -1
- package/dist/esm-es5/zonos-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-empty-state-payment_4.entry.js +1 -1
- package/dist/esm-es5/zonos-hello-dialog.entry.js +1 -1
- package/dist/esm-es5/zonos-hello.entry.js +1 -1
- package/dist/esm-es5/zonos-language-select_2.entry.js +1 -1
- package/dist/scripts/index.d.ts +1 -1
- 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/utils/getNextFallbackApi.d.ts +2 -2
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/{p-8037d54c.entry.js → p-0a7ef032.entry.js} +1 -1
- package/dist/zonos-elements/{p-f08d180a.js → p-0e8bdf5c.js} +1 -1
- package/dist/zonos-elements/{p-62cb568d.system.entry.js → p-164ba7ae.system.entry.js} +1 -1
- package/dist/zonos-elements/p-1efc348b.system.js +1 -0
- package/dist/zonos-elements/{p-4f2994f9.system.entry.js → p-242dd7ca.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-cd62465e.system.entry.js → p-300e0d47.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-a3e6cf3e.system.entry.js → p-37aa481c.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-0627d793.js → p-425096c9.js} +1 -1
- package/dist/zonos-elements/{p-db07e61c.entry.js → p-4cd33d08.entry.js} +1 -1
- package/dist/zonos-elements/{p-2fa8f2b8.system.entry.js → p-57f391e6.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-547babdd.entry.js → p-58b3a0fc.entry.js} +1 -1
- package/dist/zonos-elements/{p-9d717d8d.system.js → p-608f965f.system.js} +1 -1
- package/dist/zonos-elements/{p-b6dfa589.js → p-65c68531.js} +1 -1
- package/dist/zonos-elements/{p-3940f15d.entry.js → p-680149ed.entry.js} +1 -1
- package/dist/zonos-elements/{p-6cd4160d.system.js → p-6d44f441.system.js} +1 -1
- package/dist/zonos-elements/{p-592cdd54.entry.js → p-7c88d2ac.entry.js} +1 -1
- package/dist/zonos-elements/p-81b357f7.system.js +1 -1
- package/dist/zonos-elements/{p-4ec7abf7.system.entry.js → p-9ddb4533.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-24043e4f.system.entry.js → p-a91024b6.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-573b0565.system.entry.js → p-a9d41e7c.system.entry.js} +1 -1
- package/dist/zonos-elements/p-ad8b1fe8.entry.js +1 -0
- package/dist/zonos-elements/{p-da079b20.js → p-afa4b4f0.js} +1 -1
- package/dist/zonos-elements/{p-54fd7799.system.js → p-b83b382e.system.js} +1 -1
- package/dist/zonos-elements/{p-56a2d942.system.js → p-c1d86f32.system.js} +1 -1
- package/dist/zonos-elements/{p-e4d475c3.js → p-d93ecc57.js} +1 -1
- package/dist/zonos-elements/{p-f1ba6a31.entry.js → p-dcedcdda.entry.js} +1 -1
- package/dist/zonos-elements/{p-5a7130da.entry.js → p-e11c61a5.entry.js} +1 -1
- package/dist/zonos-elements/{p-801919e5.system.js → p-e17ac0d1.system.js} +1 -1
- package/dist/zonos-elements/{p-c4b7b1a4.system.entry.js → p-e1a7a85f.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-f530cb04.entry.js → p-ef34e1ce.entry.js} +1 -1
- package/dist/zonos-elements/{p-8cafb9a4.entry.js → p-f54123b5.entry.js} +1 -1
- package/dist/zonos-elements/{p-f04bad33.system.entry.js → p-f7300f5b.system.entry.js} +1 -1
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +1 -1
- package/dist/zonos-elements/p-48b2fbb7.entry.js +0 -1
- package/dist/zonos-elements/p-ef76be6f.system.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{z as e,c as t}from"./p-7ce093aa.js";import{s as o,l as n,t as s,f as r,b as i}from"./p-b6dfa589.js";import{l as a,f as d,h as l,g as c,a as u,s as m,d as v,b as p,j as h}from"./p-e4d475c3.js";import{i as y}from"./p-56e0ed65.js";import{g as w}from"./p-2b9c124d.js";const g=({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()||""}},f=({currentAddress:e,translatedAddress:t})=>{var o,n,s,r,i,a;const{city:d,country:l,line1:c,line2:u,postal_code:m,state:v}=e.value.address,p=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[p])||p,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[v])||v}},b=e=>{var t;const n="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),s=P.stripeLinkEventData,r=P.stripeAddressEventData,i=P.stripeShippingSameAsBilling?P.stripeAddressEventData:P.stripeBillingAddressEventData;if(!r||!i)throw new Error("Missing stripe address data");const a=f({currentAddress:r,translatedAddress:P.translatedAddress.address}),{firstName:d,lastName:l}=g({name:a.name}),c=f({currentAddress:i,translatedAddress:P.translatedAddress.address}),{firstName:u,lastName:m}=g({name:c.name});return{billingAddress:{addressLine1:c.line1,addressLine2:c.line2||"",city:c.city,country:c.country,postalCode:c.postal_code,state:c.state},billingContact:{firstName:u,lastName:m,phone:c.phone},cartCurrencyCode:null===(t=ne.items[0])||void 0===t?void 0:t.currencyCode,cartId:e,checkoutSessionId:o.checkoutSessionId||"",contact:{companyName:P.companyName,email:null==s?void 0:s.value.email,firstName:d,lastName:l,phone:a.phone},isTest:!!n,landedCostAdjustments:ne.promoCode?[{amount:0,productId:null,promoCode:ne.promoCode,sku:null,type:"PROMO_CODE"}]:[],shipToTaxId:P.taxId,shippingAddress:{addressLine1:a.line1,addressLine2:a.line2,city:a.city,country:a.country,postalCode:a.postal_code,state:a.state}}},S=()=>{const e="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),t=P.stripeLinkEventData,n=P.stripeAddressEventData,s=P.stripeShippingSameAsBilling?P.stripeAddressEventData:P.stripeBillingAddressEventData;if(a({stripeAddressData:n,stripeBillingAddressData:s},"info"),!n||!s)throw new Error("Missing stripe address data");const r=f({currentAddress:n,translatedAddress:P.translatedAddress.address}),{firstName:i,lastName:d}=g({name:r.name}),l=f({currentAddress:s,translatedAddress:P.translatedAddress.address}),{firstName:c,lastName:u}=g({name:l.name}),m=ne.adjustments.map((e=>({amount:e.amount,name:e.description||null,productId:e.productId,sku:e.sku,type:e.type}))),v=ne.promoCode?[{amount:0,productId:null,promoCode:ne.promoCode,sku:null,type:"PROMO_CODE"},...m]:m;return{billingAddress:{addressLine1:l.line1,addressLine2:l.line2||"",city:l.city,country:l.country,postalCode:l.postal_code,state:l.state},billingContact:{firstName:c,lastName:u,phone:l.phone},checkoutSessionId:o.checkoutSessionId||"",contact:{companyName:P.companyName,email:null==t?void 0:t.value.email,firstName:i,lastName:d,phone:r.phone},isTest:e,items:ne.items,landedCostAdjustments:v,shipToTaxId:P.taxId,shippingAddress:{addressLine1:r.line1,addressLine2:r.line2,city:r.city,country:r.country,postalCode:r.postal_code,state:r.state}}};const C=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=S(),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});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:S(),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:b(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})},O=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 h=n.selectedCountryCode,y=e.organizationId;if(!t)return void m({endpoint:"trackConversionEventMetric",errors:[`Event "${o}" - No checkout session id found`],metadata:{allLogs:v,checkoutSessionId:t,eventName:o,metadata:s,organizationId:y,trackEventLogs:d}});y||m({endpoint:"trackConversionEventMetric",errors:[`Event "${o}" - No organization id found`],metadata:{allLogs:v,checkoutSessionId:t,eventName:o,metadata:s,organizationId:y,trackEventLogs:d}});const w={checkoutSessionId:t,countryCode:h,eventCreated:a,eventName:o,metadata:Object.assign(Object.assign({},s),{trackEventLogs:d}),organizationId:y};await l("/api/zonos-elements/track-conversion-event",{body:w,method:"POST"})},A=({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},k=e=>e.sort(((e,t)=>e.amount-t.amount)),I=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:v}}),{errorMessage:s("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:v}}),{errorMessage:s('No shipment rating selected. Please go back to the "Shipping" step and select a shipment rating to proceed.'),valid:!1})},N=({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},j=({borderStyle:e,theme:t})=>"DARK"===t?{borderRadius:w({overrideBorderStyle:e}),colorBackground:"#101117",colorBackgroundText:"#C5C6CA",colorText:"#C5C6CA",colorTextPlaceholder:"#C5C6CA"}:{borderRadius:w({overrideBorderStyle:e}),iconMenuColor:"var(--colorText)",iconMenuHoverColor:"var(--colorText)"},{onChange:T,reset:E,state:P}=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")},D=e=>{window.sessionStorage.setItem("zonos--bigcommerce-domestic-checkout-shipping",JSON.stringify(e))},x=()=>{const e=window.sessionStorage.getItem("zonos--bigcommerce-domestic-checkout-shipping");return h(e)},R=async t=>{var o,s;const r=P.clientSecret;if(!P.stripe)return void a("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=d&&y(d)?"night":"flat",u="DARK"===i?"night":"flat",m=a?["external_paypal"]:[];return{appearance:{labels:"floating",rules:Object.assign({},N({theme:i||"LIGHT"})),theme:i?u:c,variables:Object.assign(Object.assign({},j({borderStyle:o,theme:"LIGHT"})),{colorPrimary:l})},clientSecret:t||void 0,customerSessionClientSecret:P.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}),d=JSON.stringify(i)===JSON.stringify(P.stripeElementsOptions);if(!P.stripeElements||!P.stripeElementsForBillingAddress)return P.stripeElements=null===(o=P.stripe)||void 0===o?void 0:o.elements(i),P.stripeElementsOptions=i,a("Stripe elements initialized"),P.stripeElementsForBillingAddress=null===(s=P.stripe)||void 0===s?void 0:s.elements(i),void a("Stripe elements for billing address initialized");d||(P.stripeElements.update(i),P.stripeElementsForBillingAddress.update(i),P.stripeElementsOptions=i,P.stripeElements.fetchUpdates()),a("Stripe elements updated")},_=()=>{sessionStorage.removeItem("zonos--client-secret"),E(),P.stripe=window.Zonos.stripe},z=({address:e,firstName:t,lastName:n,name:s,phone:r})=>{const{firstName:i,lastName:a}=g({firstName:t,lastName:n,name:s});return i&&a||m({endpoint:"PARTY_CREATE_NO_NAME_FOUND",errors:["No name found"],metadata:{allLogs:v,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:v,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}},U=async()=>{var e,t,n,s;if(!(null===(e=P.stripeAddressEventData)||void 0===e?void 0:e.complete)||!P.stripeShippingSameAsBilling&&!(null===(t=P.stripeBillingAddressEventData)||void 0===t?void 0:t.complete)||!P.stripeBillingAddressEventData)return{partiesCreated:!1};if(!ne.landedCostData)return{partiesCreated:!1};const r=null===(n=ne.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:v,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId}}),{partiesCreated:!1};const i=(()=>{var e,t,o,n,s,r;const i=JSON.stringify(null===(e=P.stripeLinkUsedWhenFetchingLC)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=P.stripeLinkEventData)||void 0===t?void 0:t.value),a=JSON.stringify(null===(o=P.stripeAddressUsedWhenAsyncAddressUpdate)||void 0===o?void 0:o.value)!==JSON.stringify(null===(n=P.stripeAddressEventData)||void 0===n?void 0:n.value),d=!P.stripeShippingSameAsBilling&&JSON.stringify(null===(s=P.stripeBillingAddressUsedWhenAsyncAddressUpdate)||void 0===s?void 0:s.value)!==JSON.stringify(null===(r=P.stripeBillingAddressEventData)||void 0===r?void 0:r.value);return i||a||d||P.taxIdUsedWhenAsyncAddressUpdate!==P.taxId||P.companyNameUsedWhenAsyncAddressUpdate!==P.companyName})();if(!i)return{partiesCreated:!1};const a=z({address:P.stripeAddressEventData.value.address,firstName:P.stripeAddressEventData.value.firstName,lastName:P.stripeAddressEventData.value.lastName,name:P.stripeAddressEventData.value.name,phone:P.stripeAddressEventData.value.phone}),d=P.stripeShippingSameAsBilling?a:z({address:P.stripeBillingAddressEventData.value.address,firstName:P.stripeBillingAddressEventData.value.firstName,lastName:P.stripeBillingAddressEventData.value.lastName,name:P.stripeBillingAddressEventData.value.name,phone:P.stripeBillingAddressEventData.value.phone}),c="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),{errors:u,json:h}=await l("/api/zonos-elements/create-parties",{body:{address:a,billingAddress:d,companyName:P.companyName,email:(null===(s=P.stripeLinkEventData)||void 0===s?void 0:s.value.email)||"",isTest:c,rootId:r,taxId:P.taxId},method:"POST"});return u.length||!h?(p("Error occurs when creating parties",JSON.stringify(u,null,2)),m({endpoint:"PF_PARTY_CREATE_FAILED",errors:["Failed to create parties"],metadata:{allLogs:v,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,errors:u,json:h}}),{partiesCreated:!1}):(P.companyNameUsedWhenAsyncAddressUpdate=P.companyName,P.stripeAddressUsedWhenAsyncAddressUpdate=P.stripeAddressEventData,P.stripeBillingAddressUsedWhenAsyncAddressUpdate=P.stripeBillingAddressEventData,P.taxIdUsedWhenAsyncAddressUpdate=P.taxId,P.partyBillingId=h.billToPartyId,P.partyShippingId=h.shipToPartyId,{partiesCreated:!0})},B=e=>({countryCode:e.address.country,postalCode:e.address.postal_code,state:e.address.state}),F=async t=>{var n,s,r,i;const d=(null==t?void 0:t.retries)||0,l=!!(null==t?void 0:t.applyingPromocode),c=(()=>{var e;const t=ne.landedCostData&&(null===(e=ne.landedCostData.find(Boolean))||void 0===e?void 0:e.subtotals.items)!==ne.subtotal,o=(()=>{var e,t;const o=JSON.stringify(null===(e=P.stripeLinkUsedWhenFetchingLC)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=P.stripeLinkEventData)||void 0===t?void 0:t.value),n=P.stripeAddressEventData&&JSON.stringify(B(P.stripeAddressEventData.value))!==JSON.stringify(P.stripeAddressUsedWhenFetchingLC),s=!P.stripeShippingSameAsBilling&&P.stripeBillingAddressEventData&&JSON.stringify(B(P.stripeBillingAddressEventData.value))!==JSON.stringify(P.stripeBillingAddressUsedWhenFetchingLC);return o||n||s})();return a("isPrefetchInfoOutdated","info",{isAddressOutdated:o}),!ne.landedCostData&&!P.isFetchingLandedCost||o||t})();if(!(()=>{var t,o,n,s;const r=!!(null===(t=P.stripeLinkEventData)||void 0===t?void 0:t.complete),i=!!(null===(o=P.stripeAddressEventData)||void 0===o?void 0:o.complete),a=P.stripeShippingSameAsBilling?i:!!(null===(n=P.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"===ne.addressFormRenderType&&(r&&t in r?r[t]:null)||(s&&t in s?s[t]:null)})((null===(s=P.stripeAddressEventData)||void 0===s?void 0:s.value.address.country)||"US");return!!(i&&a&&r)||(d&&P.stripeAddressEventData?r&&P.stripeAddressEventData.value.firstName&&P.stripeAddressEventData.value.lastName&&P.stripeAddressEventData.value.address.line1.length>0&&(!d.stateRequired||d.stateRequired&&P.stripeAddressEventData.value.address.state.length>0)&&(!d.zipRequired||d.zipRequired&&P.stripeAddressEventData.value.address.postal_code.length>=3)&&P.stripeAddressEventData.value.phone&&P.stripeAddressEventData.value.phone.length>0:i&&a&&r)})())return{isRequestNotReady:!0};if(c&&(null===(n=P.fetchingLandedCostAbortController)||void 0===n||n.abort(),P.fetchingLandedCostAbortController=null),!c&&!l)return{isRequestNotReady:!1};d?(P.isFetchingLandedCost=!1,setTimeout((()=>{P.isFetchingLandedCost=!0}),300)):P.isFetchingLandedCost=!0,P.stripeAddressEventData&&(P.stripeAddressUsedWhenFetchingLC={countryCode:P.stripeAddressEventData.value.address.country,postalCode:P.stripeAddressEventData.value.address.postal_code,state:P.stripeAddressEventData.value.address.state}),P.stripeBillingAddressEventData&&(P.stripeBillingAddressUsedWhenFetchingLC={countryCode:P.stripeBillingAddressEventData.value.address.country,postalCode:P.stripeBillingAddressEventData.value.address.postal_code,state:P.stripeBillingAddressEventData.value.address.state}),P.stripeLinkEventData&&(P.stripeLinkUsedWhenFetchingLC=Object.assign({},P.stripeLinkEventData));try{ge(),await(async()=>{var e;const t=new AbortController;P.fetchingLandedCostAbortController=t,ge();const{checkoutSessionWorkflow:n,errors:s,itemCreateWorkflow:r,landedCostCalculateWorkflow:i,partyCreateWorkflow:a,shipmentRatingCalculateWorkflow:d}=await C(t);ne.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,ne.shippingData=k((null==d?void 0:d.filter(Boolean))||[]),ae(r),P.fetchingLandedCostAbortController=null,ne.partiesData=(null==a?void 0:a.filter(Boolean))||[],ne.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)&&O({checkoutSessionId:o.checkoutSessionId,eventName:"checkout_quoteReceived"});const l=ne.promoCodeApplied&&!ne.landedCostData.find((e=>{var t;return null===(t=e.landedCost.appliedAdjustments)||void 0===t?void 0:t.find((e=>"PROMO_CODE"===e.type))}));ne.promoCodeError=l,l||sessionStorage.setItem("zonos--promo-code",ne.promoCode)})();const e=null===(s=ne.shippingData)||void 0===s?void 0:s.find(Boolean),t=null===(r=ne.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&&ce({method:(null==t?void 0:t.landedCost.method)||"DDP",subtotals:n})}catch(e){if(ne.landedCostData=[],ne.shippingData=[],e instanceof Error&&e.message&&!["The landed cost calculation request was aborted to initiate a new one."].includes(e.message)){if(d<1)return await F(Object.assign(Object.assign({},t),{retries:(d||0)+1})),{isRequestNotReady:!1};const o=null===(i=P.stripeAddressEventData)||void 0===i?void 0:i.value;m({endpoint:`Failed to fetch landed cost (${d} retries)`,errors:[e.message],metadata:{cartId:window.Zonos.cartId,shipToAddress:o}})}p(e)}return P.isFetchingLandedCost=!1,{isRequestNotReady:!1}},J=async()=>{var e,t;await F({applyingPromocode:!0}),"payment"===ne.step&&be(),await U();const o=null===(e=ne.shippingData)||void 0===e?void 0:e.find(Boolean),n=null===(t=ne.landedCostData)||void 0===t?void 0:t.find((e=>e.landedCost.id===(null==o?void 0:o.id)));o&&n&&await he(o,n.landedCostId)},M=()=>{ne.promoCode="",sessionStorage.removeItem("zonos--promo-code"),ne.promoCodeError=!1,ne.promoCodeApplied=!1},$=async()=>{"payment"===ne.step&&be(),M(),await J()},W=e=>{let t=[],o=!0;switch(e){case"succeeded":t=[s("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."),"",s("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.")],o=!1;break;case"requires_capture":case"processing":t=[s("Payment processing. We'll update you when payment is received.")],o=!1;break;case"requires_payment_method":t=[s("Payment failed. Please try another payment method.")];break;case"requires_action":o=!1,t=[s("Your selected payment method requires additional verification. Please follow the instructions provided by your payment provider to complete the transaction.")];default:t=[s("Something went wrong.")]}return{isError:o,messages:t}},q=async()=>{var t,o;const{onInventoryCheck:n}=e.checkoutSettings,r=!!(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&&r){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?(P.shouldInventoryRefund=!0,null):null:s("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:ne.items})}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:ne.items}}),e}},Y=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"})},H=async({clientSecret:e,storybookForceStatus:t})=>{if(t){const{isError:e,messages:o}=W(t);return{error:e,messages:o}}const o=e||P.clientSecret;if(!P.stripe||!o)return p("Failed to retrieve payment intent. Stripe is not initialized"),{error:!0,message:[s("Something went wrong.")]};const{paymentIntent:n}=await P.stripe.retrievePaymentIntent(o),r=null==n?void 0:n.status,{isError:i,messages:a}=W(r);return{error:i,messages:a,paymentIntentId:null==n?void 0:n.id,paymentMethod:null==n?void 0:n.payment_method,status:r}},K=async()=>{var e,t;const n=!!(null===(e=P.stripePaymentEventData)||void 0===e?void 0:e.complete),r=P.stripeElements,i=P.stripe,d=P.clientSecret;if(P.customErrorMessage=null,!(null===(t=ne.selectedLandedCost)||void 0===t?void 0:t.landedCost.id))throw new Error("Attempted to confirm the payment when no landed cost is found in store");const l=await I();if(!l.valid)throw P.customErrorMessage=l.errorMessage,new Error(l.errorMessage);const c=o.checkoutSessionId;if(i&&r&&n&&d&&c){const e=new URL(window.location.href);e.searchParams.set("payment_intent_client_secret",d),e.searchParams.set("zonosCheckoutSessionId",c),O({checkoutSessionId:c,eventName:"checkout_paymentInfoCompleted"});const{error:t,paymentIntent:o}=await i.confirmPayment({confirmParams:{return_url:e.toString()},elements:r,redirect:"if_required"});if(a("Payment intent confirmed","info",{error:t,paymentIntent:o}),"requires_action"===(null==o?void 0:o.status))throw new Error(s("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(s("Payment failed. Please try another payment method."))}},G=()=>{var e;const t=ne.items.reduce(((e,t)=>e+t.amount*t.quantity),0),s=o.enabledVariantTestKeys||[];return{adjustmentsAmount:ne.adjustments.reduce(((e,t)=>e+t.amount),0),cartId:window.Zonos.cartId,currency:(null===(e=ne.items.find(Boolean))||void 0===e?void 0:e.currencyCode)||"",customerAuthenticationToken:ne.customerAuthenticationToken||void 0,itemsAmount:t,metadata:[{key:"language",value:n.selectedLocale}],presentmentCountryCode:n.selectedCountryCode,skipPaymentIntent:P.skipPaymentIntent,varianceTestInput:s}},V=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:v,cartId:window.Zonos.cartId}}),void le({messages:[s("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:s("Error creating Checkout")});const{errors:t,json:n}=await l("/api/zonos-elements/create-payment-intent",{body:{checkoutSessionId:o.checkoutSessionId},method:"POST"}),r=null===(e=null==n?void 0:n.checkoutSessionPaymentIntentCreate)||void 0===e?void 0:e.clientSecret;if(t.length||!r)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:v,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,clientSecret:r}}),void le({messages:[s("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:s("Error creating Checkout")});me(n.checkoutSessionPaymentIntentCreate)},Z=async()=>{var e,t;if(!n.targetCurrency)return p("Failed to create checkout session - missing localizationStore.targetCurrency"),!1;P.isFetchingSession=!0;const o=G();a("Checkout session body","info",o);const{errors:s,json:r}=await l("/api/zonos-elements/create-checkout-session",{body:o,method:"POST"});if(P.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 me(i),ce({method:(null===(t=i.landedCost)||void 0===t?void 0:t.method)||"DDP",subtotals:i.subtotals}),a("Exchange rate updated for cart items (checkout session create)","info",ne.exchangeRate),a("done-init-checkout-session"),!0},Q=async()=>{const t=o.checkoutSessionId;if(!t)return p("Failed to update checkout session base currency"),!1;if("LOCAL"===e.checkoutSettings.allowedSettlementCurrencies)return a('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:P.checkoutSettlementCurrency},method:"POST"}),s=null==n?void 0:n.checkoutSessionBaseCurrencyUpdate.subtotals.presentmentCurrencyCode;return n&&s===P.checkoutSettlementCurrency?(a(`Updated checkout session to settlement currency "${s}".`),!0):(p("Failed to update checkout session base currency"),!1)},X=({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},ee=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}=g({firstName:i.firstName,lastName:i.lastName,name:i.name}),c=`${d} ${l}`,{firstName:u,lastName:m}=g({firstName:null==a?void 0:a.firstName,lastName:null==a?void 0:a.lastName,name:(null==a?void 0:a.name)||""}),v=u&&m?`${u} ${m}`:"",p=i.address,h=null==a?void 0:a.address;return{address:A({address:Object.assign(Object.assign({},p),{name:c}),invalidAdddressList:e}),billingAddress:s?void 0:A({address:h?Object.assign(Object.assign({},h),{name:v}):null,invalidAdddressList:t}),destinationCountry:p.country}})({addressInvalidCharactersList:e,billingAddressInvalidCharactersList:t,stripeAddressEventData:P.stripeAddressEventData,stripeBillingAddressEventData:P.stripeBillingAddressEventData,stripeShippingSameAsBilling:P.stripeShippingSameAsBilling});if(!i)return void(P.translatedAddress={address:{},billingAddress:{}});const a=(()=>{var e,t,o,n;const s=JSON.stringify(null===(e=P.stripeAddressUsedWhenValidatingAddress)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=P.stripeAddressEventData)||void 0===t?void 0:t.value),r=!P.stripeShippingSameAsBilling&&JSON.stringify(null===(o=P.stripeBillingAddressEventData)||void 0===o?void 0:o.value)!==JSON.stringify(null===(n=P.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(P.translatedAddress={address:{},billingAddress:{}});P.stripeAddressUsedWhenValidatingAddress=P.stripeAddressEventData,P.stripeBillingAddressUsedWhenValidatingAddress=P.stripeBillingAddressEventData;const u=null===(o=P.stripeAddressEventData)||void 0===o?void 0:o.value.address,m=null===(n=P.stripeBillingAddressEventData)||void 0===n?void 0:n.value.address;P.translatedAddress={address:u?X({currentAddress:Object.assign(Object.assign({},u),{name:null===(s=P.stripeAddressEventData)||void 0===s?void 0:s.value.name}),translatedAddressResult:c.address||null}):{},billingAddress:P.stripeShippingSameAsBilling?{}:X({currentAddress:Object.assign(Object.assign({},m),{name:null===(r=P.stripeBillingAddressEventData)||void 0===r?void 0:r.value.name}),translatedAddressResult:c.billingAddress||null})}};T("clientSecret",(e=>{e&&P.stripe&&sessionStorage.setItem("zonos--client-secret",e),e||sessionStorage.removeItem("zonos--client-secret")}));const{onChange:te,reset:oe,state:ne}=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}))),se=e=>{switch(e){case"DAYS":return s("days");case"WEEKS":return s("weeks");default:return s("business days")}},re=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:se(o.type)}:null},ie=({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),ae=e=>{a("Checking item restrictions");const t=e.map((e=>{if(!e.restriction)return null;const{restriction:t}=e,o=ne.items.find((t=>ie({item1:t,item2:e})));return Object.assign(Object.assign({matchedItem:o},e),{restriction:t})})).filter(Boolean);return ne.restrictedItems=t,ne.items=ne.items.map((e=>Object.assign(Object.assign({},e),{isRestricted:!!t.find((t=>ie({item1:t,item2:e})))}))),{cartItems:ne.items,restrictedItems:t}},de=()=>{o.checkoutSessionId=null,oe()},le=({messages:e,title:t})=>{de(),_(),ne.step="error",ne.error={messages:e,title:t}},ce=({dutiesTaxesFeesEstimate:e,method:t,subtotals:o})=>{ne.exchangeRate=o.exchangeRate,ne.adjustmentTotal=o.adjustments,ne.dutiesTaxesFees="DAP"===t?null:o.landedCostTotal,ne.subtotal=o.items,ne.total=o.total,ne.currency=o.presentmentCurrencyCode,ne.dutiesTaxesFeesEstimate=e||null},ue=()=>!!ne.items.filter((e=>e.amount>0)).find((e=>!e.isRestricted)),me=e=>{var t,n,s,d,l;P.clientSecret=e.clientSecret,P.stripeCustomerSessionClientSecret=e.customerSessionClientSecret,P.customerProfile=e.customerProfile,ne.checkoutSession=e,e.id||m({endpoint:"cartStoreSetCheckoutSession",errors:["Missing checkout session id in checkout session"],metadata:{allLogs:v,checkoutSession:e}}),e.id&&(o.checkoutSessionId=e.id);const c=r(e.varianceTestResults||[]);i(c);const u=(null===(s=null===(n=null===(t=ne.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===(l=null===(d=window.Zonos.cartData)||void 0===d?void 0:d.metadata.find((e=>"externalConfirmationPageURL"===(null==e?void 0:e.key))))||void 0===l?void 0:l.value)||null;u&&(a(`Found externalConfirmationPageURL: ${u}`),ne.externalConfirmationPageURL=u)},ve=async({adjustmentsAmount:e,cartId:t,currency:r,dutiesTaxesFeesEstimate:i,itemsAmount:d,landedCostId:c,shouldInitSessionOnFailure:u})=>{var m;if(c&&ne.selectedLandedCost&&(ce({dutiesTaxesFeesEstimate:i,method:ne.landedCostMethod,subtotals:ne.selectedLandedCost.subtotals}),a("Exchange rate updated for cart items (landed cost subtotal)","info",ne.exchangeRate)),!o.checkoutSessionId)return a("Could not update cart total without checkout session id","info"),!1;const{errors:v,json:h}=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:P.partyBillingId,cartId:t,currency:s,customerAuthenticationToken:ne.customerAuthenticationToken||void 0,id:r,itemsAmount:i,landedCostId:a,metadata:[{key:"language",value:n.selectedLocale}],presentmentCountryCode:d,shipToPartyId:P.partyShippingId,skipPaymentIntent:P.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:P.partyBillingId,cartId:t,currency:r,id:o.checkoutSessionId,itemsAmount:d,landedCostId:c,presentmentCountryCode:n.selectedCountryCode,shipToPartyId:P.partyShippingId,varianceTestInput:o.enabledVariantTestKeys||[]});if(v.length>0||!h){if(p("Error occurs when updating checkout session."),u){a("Initiating checkout session on failure","info");const e=await Z();return a(`stripeStoreInitCheckoutSession: ${e}`),!!e||(le({messages:[s("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:s("Error creating Checkout")}),!1)}return!1}return c||(ce({method:(null===(m=h.checkoutSessionUpdate.landedCost)||void 0===m?void 0:m.method)||"DDP",subtotals:h.checkoutSessionUpdate.subtotals}),a("Exchange rate updated for cart items (checkout session update)","info",ne.exchangeRate)),me(h.checkoutSessionUpdate),!0},pe=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=P.stripeAddressEventData)||void 0===s?void 0:s.value.address.country)||"US"))||"DAP"===t.method&&t.remittance.length&&"ZONOS"===t.landedCostGuaranteeCode?"DDP":t.method},he=async(t,n)=>{var s,r,i,d,l,c,u,m,v,p,h;ne.selectedShippingOption=t;const y=re(ne.selectedShippingOption);if(y){const{maxTransit:e,minTransit:t,unit:o}=y;ne.selectedShippingOptionTransitTime=`${t}-${e} ${o}`}else ne.selectedShippingOptionTransitTime="";const w=null===(s=ne.landedCostData)||void 0===s?void 0:s.find((e=>e.landedCostId===n));if(ne.selectedLandedCost=w||null,!w)return!1;const g=((null===(r=w.landedCost.amountSubtotals)||void 0===r?void 0:r.landedCostTotal)||0)*w.subtotals.exchangeRate.rate;g&&a(`DAP quote, using estimate: ${g}`,"info"),ne.landedCostMethod=pe(w.landedCost),ne.shipping=w.subtotals.shipping;const f="ZONOS"===(null===(i=null==w?void 0:w.landedCost)||void 0===i?void 0:i.landedCostGuaranteeCode),b=!!(null===(l=null===(d=null==w?void 0:w.landedCost)||void 0===d?void 0:d.deMinimis)||void 0===l?void 0:l.find((e=>["DUTY","TAX"].includes(e.type)&&"ABOVE"===e.threshold)));ne.isSelectedShippingAboveDeminimis=b,ne.isSelectedShippingGuarantee=f;const S=await ve({adjustmentsAmount:ne.adjustmentTotal,billToPartyId:P.partyBillingId,cartId:window.Zonos.cartId,dutiesTaxesFeesEstimate:g,landedCostId:null===(c=w.landedCost)||void 0===c?void 0:c.id,shipToPartyId:P.partyShippingId,varianceTestInput:o.enabledVariantTestKeys||[]}),C=null===(u=ne.items.find(Boolean))||void 0===u?void 0:u.currencyCode,O=(null===(m=P.stripeAddressEventData)||void 0===m?void 0:m.value.address.country)||"US";return P.shouldRenderPayInUsdButton="USD"===C&&"LOCAL_AND_USD"===e.checkoutSettings.allowedSettlementCurrencies&&"USD"!==(null===(v=ne.checkoutSession)||void 0===v?void 0:v.subtotals.presentmentCurrencyCode)&&!!(null===(h=null===(p=e.genericSettings)||void 0===p?void 0:p.usdSettlementCountryEnabled)||void 0===h?void 0:h.includes(O)),S},ye=({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;a(`==START CHECKOUT TIMEOUT - ${n}==`),ne.checkoutTimeoutInterval=setTimeout((()=>{ne.checkoutSessionTimeoutShow=!0}),n)},we=()=>{ne.checkoutTimeoutInterval&&(clearTimeout(ne.checkoutTimeoutInterval),ne.checkoutTimeoutInterval=null)},ge=()=>{ne.items=ne.items.map((e=>Object.assign(Object.assign({},e),{isRestricted:!1}))),ne.restrictedItems=[]},fe=async({adjustments:e,cartItems:t})=>{var n;ne.adjustments=e,ne.items=t.map((e=>Object.assign(Object.assign({},e),{isRestricted:!1})));const s=null===(n=t.find(Boolean))||void 0===n?void 0:n.currencyCode,r=t.reduce(((e,t)=>e+t.amount*t.quantity),0),i=e.reduce(((e,t)=>e+t.amount),0);s&&r&&(ne.currency=s,P.isFetchingSession=!0,await ve({adjustmentsAmount:i,billToPartyId:P.partyBillingId,cartId:window.Zonos.cartId,currency:s,dutiesTaxesFeesEstimate:0,itemsAmount:r,shipToPartyId:P.partyShippingId,shouldInitSessionOnFailure:!0,varianceTestInput:o.enabledVariantTestKeys||[]}),P.isFetchingSession=!1)},be=()=>{"shipping"===ne.step?(ne.step="customer-info",ne.tabItems=Object.assign(Object.assign({},ne.tabItems),{"customer-info":Object.assign(Object.assign({},ne.tabItems.shipping),{isDone:!1})})):"payment"===ne.step?(ne.step="shipping",ne.tabItems=Object.assign(Object.assign({},ne.tabItems),{shipping:Object.assign(Object.assign({},ne.tabItems.shipping),{isDone:!1})})):"finish"===ne.step&&(ne.step="payment",ne.tabItems=Object.assign(Object.assign({},ne.tabItems),{payment:Object.assign(Object.assign({},ne.tabItems.payment),{isDone:!1})}))},Se=()=>{"customer-info"===ne.step?(ne.step="shipping",ne.tabItems=Object.assign(Object.assign({},ne.tabItems),{"customer-info":Object.assign(Object.assign({},ne.tabItems["customer-info"]),{isDone:!0})})):"shipping"===ne.step?(ne.step="payment",ne.tabItems=Object.assign(Object.assign({},ne.tabItems),{shipping:Object.assign(Object.assign({},ne.tabItems.shipping),{isDone:!0})})):"payment"===ne.step&&(ne.step="finish")},Ce=()=>{ne.step="customer-info",ne.tabItems=Object.assign(Object.assign({},ne.tabItems),{"customer-info":Object.assign(Object.assign({},ne.tabItems["customer-info"]),{isDone:!1}),payment:Object.assign(Object.assign({},ne.tabItems.payment),{isDone:!1}),shipping:Object.assign(Object.assign({},ne.tabItems.shipping),{isDone:!1})}),ne.selectedShippingOption=null,ne.isSelectedShippingAboveDeminimis=!1,ne.isSelectedShippingGuarantee=!1,ne.selectedShippingOptionTransitTime="",ne.dutiesTaxesFees=0,ne.dutiesTaxesFeesEstimate=0,ne.shipping=0,ne.total=ne.subtotal};export{ue as A,J as B,$ as C,M as D,W as E,ee as F,g as G,te as H,U as I,he as J,re as K,pe as L,k as M,L as a,D as b,P as c,H as d,ne as e,fe as f,de as g,Ce as h,R as i,we as j,Z as k,V as l,ye as m,G as n,le as o,me as p,F as q,Se as r,x as s,O as t,Q as u,q as v,K as w,Y as x,_ as y,I as z}
|
|
1
|
+
import{z as e,c as t}from"./p-7ce093aa.js";import{s as o,l as n,t as s,f as r,b as i}from"./p-65c68531.js";import{l as a,f as d,h as l,g as c,a as u,s as m,d as v,b as p,j as h}from"./p-d93ecc57.js";import{i as y}from"./p-56e0ed65.js";import{g as w}from"./p-2b9c124d.js";const g=({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()||""}},f=({currentAddress:e,translatedAddress:t})=>{var o,n,s,r,i,a;const{city:d,country:l,line1:c,line2:u,postal_code:m,state:v}=e.value.address,p=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[p])||p,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[v])||v}},b=e=>{var t;const n="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),s=P.stripeLinkEventData,r=P.stripeAddressEventData,i=P.stripeShippingSameAsBilling?P.stripeAddressEventData:P.stripeBillingAddressEventData;if(!r||!i)throw new Error("Missing stripe address data");const a=f({currentAddress:r,translatedAddress:P.translatedAddress.address}),{firstName:d,lastName:l}=g({name:a.name}),c=f({currentAddress:i,translatedAddress:P.translatedAddress.address}),{firstName:u,lastName:m}=g({name:c.name});return{billingAddress:{addressLine1:c.line1,addressLine2:c.line2||"",city:c.city,country:c.country,postalCode:c.postal_code,state:c.state},billingContact:{firstName:u,lastName:m,phone:c.phone},cartCurrencyCode:null===(t=ne.items[0])||void 0===t?void 0:t.currencyCode,cartId:e,checkoutSessionId:o.checkoutSessionId||"",contact:{companyName:P.companyName,email:null==s?void 0:s.value.email,firstName:d,lastName:l,phone:a.phone},isTest:!!n,landedCostAdjustments:ne.promoCode?[{amount:0,productId:null,promoCode:ne.promoCode,sku:null,type:"PROMO_CODE"}]:[],shipToTaxId:P.taxId,shippingAddress:{addressLine1:a.line1,addressLine2:a.line2,city:a.city,country:a.country,postalCode:a.postal_code,state:a.state}}},S=()=>{const e="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),t=P.stripeLinkEventData,n=P.stripeAddressEventData,s=P.stripeShippingSameAsBilling?P.stripeAddressEventData:P.stripeBillingAddressEventData;if(a({stripeAddressData:n,stripeBillingAddressData:s},"info"),!n||!s)throw new Error("Missing stripe address data");const r=f({currentAddress:n,translatedAddress:P.translatedAddress.address}),{firstName:i,lastName:d}=g({name:r.name}),l=f({currentAddress:s,translatedAddress:P.translatedAddress.address}),{firstName:c,lastName:u}=g({name:l.name}),m=ne.adjustments.map((e=>({amount:e.amount,name:e.description||null,productId:e.productId,sku:e.sku,type:e.type}))),v=ne.promoCode?[{amount:0,productId:null,promoCode:ne.promoCode,sku:null,type:"PROMO_CODE"},...m]:m;return{billingAddress:{addressLine1:l.line1,addressLine2:l.line2||"",city:l.city,country:l.country,postalCode:l.postal_code,state:l.state},billingContact:{firstName:c,lastName:u,phone:l.phone},checkoutSessionId:o.checkoutSessionId||"",contact:{companyName:P.companyName,email:null==t?void 0:t.value.email,firstName:i,lastName:d,phone:r.phone},isTest:e,items:ne.items,landedCostAdjustments:v,shipToTaxId:P.taxId,shippingAddress:{addressLine1:r.line1,addressLine2:r.line2,city:r.city,country:r.country,postalCode:r.postal_code,state:r.state}}};const C=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=S(),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});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:S(),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:b(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})},O=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 h=n.selectedCountryCode,y=e.organizationId;if(!t)return void m({endpoint:"trackConversionEventMetric",errors:[`Event "${o}" - No checkout session id found`],metadata:{allLogs:v,checkoutSessionId:t,eventName:o,metadata:s,organizationId:y,trackEventLogs:d}});y||m({endpoint:"trackConversionEventMetric",errors:[`Event "${o}" - No organization id found`],metadata:{allLogs:v,checkoutSessionId:t,eventName:o,metadata:s,organizationId:y,trackEventLogs:d}});const w={checkoutSessionId:t,countryCode:h,eventCreated:a,eventName:o,metadata:Object.assign(Object.assign({},s),{trackEventLogs:d}),organizationId:y};await l("/api/zonos-elements/track-conversion-event",{body:w,method:"POST"})},A=({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},k=e=>e.sort(((e,t)=>e.amount-t.amount)),I=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:v}}),{errorMessage:s("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:v}}),{errorMessage:s('No shipment rating selected. Please go back to the "Shipping" step and select a shipment rating to proceed.'),valid:!1})},N=({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},j=({borderStyle:e,theme:t})=>"DARK"===t?{borderRadius:w({overrideBorderStyle:e}),colorBackground:"#101117",colorBackgroundText:"#C5C6CA",colorText:"#C5C6CA",colorTextPlaceholder:"#C5C6CA"}:{borderRadius:w({overrideBorderStyle:e}),iconMenuColor:"var(--colorText)",iconMenuHoverColor:"var(--colorText)"},{onChange:T,reset:E,state:P}=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")},D=e=>{window.sessionStorage.setItem("zonos--bigcommerce-domestic-checkout-shipping",JSON.stringify(e))},x=()=>{const e=window.sessionStorage.getItem("zonos--bigcommerce-domestic-checkout-shipping");return h(e)},R=async t=>{var o,s;const r=P.clientSecret;if(!P.stripe)return void a("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=d&&y(d)?"night":"flat",u="DARK"===i?"night":"flat",m=a?["external_paypal"]:[];return{appearance:{labels:"floating",rules:Object.assign({},N({theme:i||"LIGHT"})),theme:i?u:c,variables:Object.assign(Object.assign({},j({borderStyle:o,theme:"LIGHT"})),{colorPrimary:l})},clientSecret:t||void 0,customerSessionClientSecret:P.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}),d=JSON.stringify(i)===JSON.stringify(P.stripeElementsOptions);if(!P.stripeElements||!P.stripeElementsForBillingAddress)return P.stripeElements=null===(o=P.stripe)||void 0===o?void 0:o.elements(i),P.stripeElementsOptions=i,a("Stripe elements initialized"),P.stripeElementsForBillingAddress=null===(s=P.stripe)||void 0===s?void 0:s.elements(i),void a("Stripe elements for billing address initialized");d||(P.stripeElements.update(i),P.stripeElementsForBillingAddress.update(i),P.stripeElementsOptions=i,P.stripeElements.fetchUpdates()),a("Stripe elements updated")},_=()=>{sessionStorage.removeItem("zonos--client-secret"),E(),P.stripe=window.Zonos.stripe},z=({address:e,firstName:t,lastName:n,name:s,phone:r})=>{const{firstName:i,lastName:a}=g({firstName:t,lastName:n,name:s});return i&&a||m({endpoint:"PARTY_CREATE_NO_NAME_FOUND",errors:["No name found"],metadata:{allLogs:v,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:v,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}},U=async()=>{var e,t,n,s;if(!(null===(e=P.stripeAddressEventData)||void 0===e?void 0:e.complete)||!P.stripeShippingSameAsBilling&&!(null===(t=P.stripeBillingAddressEventData)||void 0===t?void 0:t.complete)||!P.stripeBillingAddressEventData)return{partiesCreated:!1};if(!ne.landedCostData)return{partiesCreated:!1};const r=null===(n=ne.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:v,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId}}),{partiesCreated:!1};const i=(()=>{var e,t,o,n,s,r;const i=JSON.stringify(null===(e=P.stripeLinkUsedWhenFetchingLC)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=P.stripeLinkEventData)||void 0===t?void 0:t.value),a=JSON.stringify(null===(o=P.stripeAddressUsedWhenAsyncAddressUpdate)||void 0===o?void 0:o.value)!==JSON.stringify(null===(n=P.stripeAddressEventData)||void 0===n?void 0:n.value),d=!P.stripeShippingSameAsBilling&&JSON.stringify(null===(s=P.stripeBillingAddressUsedWhenAsyncAddressUpdate)||void 0===s?void 0:s.value)!==JSON.stringify(null===(r=P.stripeBillingAddressEventData)||void 0===r?void 0:r.value);return i||a||d||P.taxIdUsedWhenAsyncAddressUpdate!==P.taxId||P.companyNameUsedWhenAsyncAddressUpdate!==P.companyName})();if(!i)return{partiesCreated:!1};const a=z({address:P.stripeAddressEventData.value.address,firstName:P.stripeAddressEventData.value.firstName,lastName:P.stripeAddressEventData.value.lastName,name:P.stripeAddressEventData.value.name,phone:P.stripeAddressEventData.value.phone}),d=P.stripeShippingSameAsBilling?a:z({address:P.stripeBillingAddressEventData.value.address,firstName:P.stripeBillingAddressEventData.value.firstName,lastName:P.stripeBillingAddressEventData.value.lastName,name:P.stripeBillingAddressEventData.value.name,phone:P.stripeBillingAddressEventData.value.phone}),c="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),{errors:u,json:h}=await l("/api/zonos-elements/create-parties",{body:{address:a,billingAddress:d,companyName:P.companyName,email:(null===(s=P.stripeLinkEventData)||void 0===s?void 0:s.value.email)||"",isTest:c,rootId:r,taxId:P.taxId},method:"POST"});return u.length||!h?(p("Error occurs when creating parties",JSON.stringify(u,null,2)),m({endpoint:"PF_PARTY_CREATE_FAILED",errors:["Failed to create parties"],metadata:{allLogs:v,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,errors:u,json:h}}),{partiesCreated:!1}):(P.companyNameUsedWhenAsyncAddressUpdate=P.companyName,P.stripeAddressUsedWhenAsyncAddressUpdate=P.stripeAddressEventData,P.stripeBillingAddressUsedWhenAsyncAddressUpdate=P.stripeBillingAddressEventData,P.taxIdUsedWhenAsyncAddressUpdate=P.taxId,P.partyBillingId=h.billToPartyId,P.partyShippingId=h.shipToPartyId,{partiesCreated:!0})},B=e=>({countryCode:e.address.country,postalCode:e.address.postal_code,state:e.address.state}),F=async t=>{var n,s,r,i;const d=(null==t?void 0:t.retries)||0,l=!!(null==t?void 0:t.applyingPromocode),c=(()=>{var e;const t=ne.landedCostData&&(null===(e=ne.landedCostData.find(Boolean))||void 0===e?void 0:e.subtotals.items)!==ne.subtotal,o=(()=>{var e,t;const o=JSON.stringify(null===(e=P.stripeLinkUsedWhenFetchingLC)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=P.stripeLinkEventData)||void 0===t?void 0:t.value),n=P.stripeAddressEventData&&JSON.stringify(B(P.stripeAddressEventData.value))!==JSON.stringify(P.stripeAddressUsedWhenFetchingLC),s=!P.stripeShippingSameAsBilling&&P.stripeBillingAddressEventData&&JSON.stringify(B(P.stripeBillingAddressEventData.value))!==JSON.stringify(P.stripeBillingAddressUsedWhenFetchingLC);return o||n||s})();return a("isPrefetchInfoOutdated","info",{isAddressOutdated:o}),!ne.landedCostData&&!P.isFetchingLandedCost||o||t})();if(!(()=>{var t,o,n,s;const r=!!(null===(t=P.stripeLinkEventData)||void 0===t?void 0:t.complete),i=!!(null===(o=P.stripeAddressEventData)||void 0===o?void 0:o.complete),a=P.stripeShippingSameAsBilling?i:!!(null===(n=P.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"===ne.addressFormRenderType&&(r&&t in r?r[t]:null)||(s&&t in s?s[t]:null)})((null===(s=P.stripeAddressEventData)||void 0===s?void 0:s.value.address.country)||"US");return!!(i&&a&&r)||(d&&P.stripeAddressEventData?r&&P.stripeAddressEventData.value.firstName&&P.stripeAddressEventData.value.lastName&&P.stripeAddressEventData.value.address.line1.length>0&&(!d.stateRequired||d.stateRequired&&P.stripeAddressEventData.value.address.state.length>0)&&(!d.zipRequired||d.zipRequired&&P.stripeAddressEventData.value.address.postal_code.length>=3)&&P.stripeAddressEventData.value.phone&&P.stripeAddressEventData.value.phone.length>0:i&&a&&r)})())return{isRequestNotReady:!0};if(c&&(null===(n=P.fetchingLandedCostAbortController)||void 0===n||n.abort(),P.fetchingLandedCostAbortController=null),!c&&!l)return{isRequestNotReady:!1};d?(P.isFetchingLandedCost=!1,setTimeout((()=>{P.isFetchingLandedCost=!0}),300)):P.isFetchingLandedCost=!0,P.stripeAddressEventData&&(P.stripeAddressUsedWhenFetchingLC={countryCode:P.stripeAddressEventData.value.address.country,postalCode:P.stripeAddressEventData.value.address.postal_code,state:P.stripeAddressEventData.value.address.state}),P.stripeBillingAddressEventData&&(P.stripeBillingAddressUsedWhenFetchingLC={countryCode:P.stripeBillingAddressEventData.value.address.country,postalCode:P.stripeBillingAddressEventData.value.address.postal_code,state:P.stripeBillingAddressEventData.value.address.state}),P.stripeLinkEventData&&(P.stripeLinkUsedWhenFetchingLC=Object.assign({},P.stripeLinkEventData));try{ge(),await(async()=>{var e;const t=new AbortController;P.fetchingLandedCostAbortController=t,ge();const{checkoutSessionWorkflow:n,errors:s,itemCreateWorkflow:r,landedCostCalculateWorkflow:i,partyCreateWorkflow:a,shipmentRatingCalculateWorkflow:d}=await C(t);ne.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,ne.shippingData=k((null==d?void 0:d.filter(Boolean))||[]),ae(r),P.fetchingLandedCostAbortController=null,ne.partiesData=(null==a?void 0:a.filter(Boolean))||[],ne.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)&&O({checkoutSessionId:o.checkoutSessionId,eventName:"checkout_quoteReceived"});const l=ne.promoCodeApplied&&!ne.landedCostData.find((e=>{var t;return null===(t=e.landedCost.appliedAdjustments)||void 0===t?void 0:t.find((e=>"PROMO_CODE"===e.type))}));ne.promoCodeError=l,l||sessionStorage.setItem("zonos--promo-code",ne.promoCode)})();const e=null===(s=ne.shippingData)||void 0===s?void 0:s.find(Boolean),t=null===(r=ne.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&&ce({method:(null==t?void 0:t.landedCost.method)||"DDP",subtotals:n})}catch(e){if(ne.landedCostData=[],ne.shippingData=[],e instanceof Error&&e.message&&!["The landed cost calculation request was aborted to initiate a new one."].includes(e.message)){if(d<1)return await F(Object.assign(Object.assign({},t),{retries:(d||0)+1})),{isRequestNotReady:!1};const o=null===(i=P.stripeAddressEventData)||void 0===i?void 0:i.value;m({endpoint:`Failed to fetch landed cost (${d} retries)`,errors:[e.message],metadata:{cartId:window.Zonos.cartId,shipToAddress:o}})}p(e)}return P.isFetchingLandedCost=!1,{isRequestNotReady:!1}},J=async()=>{var e,t;await F({applyingPromocode:!0}),"payment"===ne.step&&be(),await U();const o=null===(e=ne.shippingData)||void 0===e?void 0:e.find(Boolean),n=null===(t=ne.landedCostData)||void 0===t?void 0:t.find((e=>e.landedCost.id===(null==o?void 0:o.id)));o&&n&&await he(o,n.landedCostId)},M=()=>{ne.promoCode="",sessionStorage.removeItem("zonos--promo-code"),ne.promoCodeError=!1,ne.promoCodeApplied=!1},$=async()=>{"payment"===ne.step&&be(),M(),await J()},W=e=>{let t=[],o=!0;switch(e){case"succeeded":t=[s("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."),"",s("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.")],o=!1;break;case"requires_capture":case"processing":t=[s("Payment processing. We'll update you when payment is received.")],o=!1;break;case"requires_payment_method":t=[s("Payment failed. Please try another payment method.")];break;case"requires_action":o=!1,t=[s("Your selected payment method requires additional verification. Please follow the instructions provided by your payment provider to complete the transaction.")];default:t=[s("Something went wrong.")]}return{isError:o,messages:t}},q=async()=>{var t,o;const{onInventoryCheck:n}=e.checkoutSettings,r=!!(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&&r){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?(P.shouldInventoryRefund=!0,null):null:s("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:ne.items})}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:ne.items}}),e}},Y=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"})},H=async({clientSecret:e,storybookForceStatus:t})=>{if(t){const{isError:e,messages:o}=W(t);return{error:e,messages:o}}const o=e||P.clientSecret;if(!P.stripe||!o)return p("Failed to retrieve payment intent. Stripe is not initialized"),{error:!0,message:[s("Something went wrong.")]};const{paymentIntent:n}=await P.stripe.retrievePaymentIntent(o),r=null==n?void 0:n.status,{isError:i,messages:a}=W(r);return{error:i,messages:a,paymentIntentId:null==n?void 0:n.id,paymentMethod:null==n?void 0:n.payment_method,status:r}},K=async()=>{var e,t;const n=!!(null===(e=P.stripePaymentEventData)||void 0===e?void 0:e.complete),r=P.stripeElements,i=P.stripe,d=P.clientSecret;if(P.customErrorMessage=null,!(null===(t=ne.selectedLandedCost)||void 0===t?void 0:t.landedCost.id))throw new Error("Attempted to confirm the payment when no landed cost is found in store");const l=await I();if(!l.valid)throw P.customErrorMessage=l.errorMessage,new Error(l.errorMessage);const c=o.checkoutSessionId;if(i&&r&&n&&d&&c){const e=new URL(window.location.href);e.searchParams.set("payment_intent_client_secret",d),e.searchParams.set("zonosCheckoutSessionId",c),O({checkoutSessionId:c,eventName:"checkout_paymentInfoCompleted"});const{error:t,paymentIntent:o}=await i.confirmPayment({confirmParams:{return_url:e.toString()},elements:r,redirect:"if_required"});if(a("Payment intent confirmed","info",{error:t,paymentIntent:o}),"requires_action"===(null==o?void 0:o.status))throw new Error(s("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(s("Payment failed. Please try another payment method."))}},G=()=>{var e;const t=ne.items.reduce(((e,t)=>e+t.amount*t.quantity),0),s=o.enabledVariantTestKeys||[];return{adjustmentsAmount:ne.adjustments.reduce(((e,t)=>e+t.amount),0),cartId:window.Zonos.cartId,currency:(null===(e=ne.items.find(Boolean))||void 0===e?void 0:e.currencyCode)||"",customerAuthenticationToken:ne.customerAuthenticationToken||void 0,itemsAmount:t,metadata:[{key:"language",value:n.selectedLocale}],presentmentCountryCode:n.selectedCountryCode,skipPaymentIntent:P.skipPaymentIntent,varianceTestInput:s}},V=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:v,cartId:window.Zonos.cartId}}),void le({messages:[s("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:s("Error creating Checkout")});const{errors:t,json:n}=await l("/api/zonos-elements/create-payment-intent",{body:{checkoutSessionId:o.checkoutSessionId},method:"POST"}),r=null===(e=null==n?void 0:n.checkoutSessionPaymentIntentCreate)||void 0===e?void 0:e.clientSecret;if(t.length||!r)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:v,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,clientSecret:r}}),void le({messages:[s("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:s("Error creating Checkout")});me(n.checkoutSessionPaymentIntentCreate)},Z=async()=>{var e,t;if(!n.targetCurrency)return p("Failed to create checkout session - missing localizationStore.targetCurrency"),!1;P.isFetchingSession=!0;const o=G();a("Checkout session body","info",o);const{errors:s,json:r}=await l("/api/zonos-elements/create-checkout-session",{body:o,method:"POST"});if(P.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 me(i),ce({method:(null===(t=i.landedCost)||void 0===t?void 0:t.method)||"DDP",subtotals:i.subtotals}),a("Exchange rate updated for cart items (checkout session create)","info",ne.exchangeRate),a("done-init-checkout-session"),!0},Q=async()=>{const t=o.checkoutSessionId;if(!t)return p("Failed to update checkout session base currency"),!1;if("LOCAL"===e.checkoutSettings.allowedSettlementCurrencies)return a('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:P.checkoutSettlementCurrency},method:"POST"}),s=null==n?void 0:n.checkoutSessionBaseCurrencyUpdate.subtotals.presentmentCurrencyCode;return n&&s===P.checkoutSettlementCurrency?(a(`Updated checkout session to settlement currency "${s}".`),!0):(p("Failed to update checkout session base currency"),!1)},X=({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},ee=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}=g({firstName:i.firstName,lastName:i.lastName,name:i.name}),c=`${d} ${l}`,{firstName:u,lastName:m}=g({firstName:null==a?void 0:a.firstName,lastName:null==a?void 0:a.lastName,name:(null==a?void 0:a.name)||""}),v=u&&m?`${u} ${m}`:"",p=i.address,h=null==a?void 0:a.address;return{address:A({address:Object.assign(Object.assign({},p),{name:c}),invalidAdddressList:e}),billingAddress:s?void 0:A({address:h?Object.assign(Object.assign({},h),{name:v}):null,invalidAdddressList:t}),destinationCountry:p.country}})({addressInvalidCharactersList:e,billingAddressInvalidCharactersList:t,stripeAddressEventData:P.stripeAddressEventData,stripeBillingAddressEventData:P.stripeBillingAddressEventData,stripeShippingSameAsBilling:P.stripeShippingSameAsBilling});if(!i)return void(P.translatedAddress={address:{},billingAddress:{}});const a=(()=>{var e,t,o,n;const s=JSON.stringify(null===(e=P.stripeAddressUsedWhenValidatingAddress)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=P.stripeAddressEventData)||void 0===t?void 0:t.value),r=!P.stripeShippingSameAsBilling&&JSON.stringify(null===(o=P.stripeBillingAddressEventData)||void 0===o?void 0:o.value)!==JSON.stringify(null===(n=P.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(P.translatedAddress={address:{},billingAddress:{}});P.stripeAddressUsedWhenValidatingAddress=P.stripeAddressEventData,P.stripeBillingAddressUsedWhenValidatingAddress=P.stripeBillingAddressEventData;const u=null===(o=P.stripeAddressEventData)||void 0===o?void 0:o.value.address,m=null===(n=P.stripeBillingAddressEventData)||void 0===n?void 0:n.value.address;P.translatedAddress={address:u?X({currentAddress:Object.assign(Object.assign({},u),{name:null===(s=P.stripeAddressEventData)||void 0===s?void 0:s.value.name}),translatedAddressResult:c.address||null}):{},billingAddress:P.stripeShippingSameAsBilling?{}:X({currentAddress:Object.assign(Object.assign({},m),{name:null===(r=P.stripeBillingAddressEventData)||void 0===r?void 0:r.value.name}),translatedAddressResult:c.billingAddress||null})}};T("clientSecret",(e=>{e&&P.stripe&&sessionStorage.setItem("zonos--client-secret",e),e||sessionStorage.removeItem("zonos--client-secret")}));const{onChange:te,reset:oe,state:ne}=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}))),se=e=>{switch(e){case"DAYS":return s("days");case"WEEKS":return s("weeks");default:return s("business days")}},re=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:se(o.type)}:null},ie=({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),ae=e=>{a("Checking item restrictions");const t=e.map((e=>{if(!e.restriction)return null;const{restriction:t}=e,o=ne.items.find((t=>ie({item1:t,item2:e})));return Object.assign(Object.assign({matchedItem:o},e),{restriction:t})})).filter(Boolean);return ne.restrictedItems=t,ne.items=ne.items.map((e=>Object.assign(Object.assign({},e),{isRestricted:!!t.find((t=>ie({item1:t,item2:e})))}))),{cartItems:ne.items,restrictedItems:t}},de=()=>{o.checkoutSessionId=null,oe()},le=({messages:e,title:t})=>{de(),_(),ne.step="error",ne.error={messages:e,title:t}},ce=({dutiesTaxesFeesEstimate:e,method:t,subtotals:o})=>{ne.exchangeRate=o.exchangeRate,ne.adjustmentTotal=o.adjustments,ne.dutiesTaxesFees="DAP"===t?null:o.landedCostTotal,ne.subtotal=o.items,ne.total=o.total,ne.currency=o.presentmentCurrencyCode,ne.dutiesTaxesFeesEstimate=e||null},ue=()=>!!ne.items.filter((e=>e.amount>0)).find((e=>!e.isRestricted)),me=e=>{var t,n,s,d,l;P.clientSecret=e.clientSecret,P.stripeCustomerSessionClientSecret=e.customerSessionClientSecret,P.customerProfile=e.customerProfile,ne.checkoutSession=e,e.id||m({endpoint:"cartStoreSetCheckoutSession",errors:["Missing checkout session id in checkout session"],metadata:{allLogs:v,checkoutSession:e}}),e.id&&(o.checkoutSessionId=e.id);const c=r(e.varianceTestResults||[]);i(c);const u=(null===(s=null===(n=null===(t=ne.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===(l=null===(d=window.Zonos.cartData)||void 0===d?void 0:d.metadata.find((e=>"externalConfirmationPageURL"===(null==e?void 0:e.key))))||void 0===l?void 0:l.value)||null;u&&(a(`Found externalConfirmationPageURL: ${u}`),ne.externalConfirmationPageURL=u)},ve=async({adjustmentsAmount:e,cartId:t,currency:r,dutiesTaxesFeesEstimate:i,itemsAmount:d,landedCostId:c,shouldInitSessionOnFailure:u})=>{var m;if(c&&ne.selectedLandedCost&&(ce({dutiesTaxesFeesEstimate:i,method:ne.landedCostMethod,subtotals:ne.selectedLandedCost.subtotals}),a("Exchange rate updated for cart items (landed cost subtotal)","info",ne.exchangeRate)),!o.checkoutSessionId)return a("Could not update cart total without checkout session id","info"),!1;const{errors:v,json:h}=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:P.partyBillingId,cartId:t,currency:s,customerAuthenticationToken:ne.customerAuthenticationToken||void 0,id:r,itemsAmount:i,landedCostId:a,metadata:[{key:"language",value:n.selectedLocale}],presentmentCountryCode:d,shipToPartyId:P.partyShippingId,skipPaymentIntent:P.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:P.partyBillingId,cartId:t,currency:r,id:o.checkoutSessionId,itemsAmount:d,landedCostId:c,presentmentCountryCode:n.selectedCountryCode,shipToPartyId:P.partyShippingId,varianceTestInput:o.enabledVariantTestKeys||[]});if(v.length>0||!h){if(p("Error occurs when updating checkout session."),u){a("Initiating checkout session on failure","info");const e=await Z();return a(`stripeStoreInitCheckoutSession: ${e}`),!!e||(le({messages:[s("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:s("Error creating Checkout")}),!1)}return!1}return c||(ce({method:(null===(m=h.checkoutSessionUpdate.landedCost)||void 0===m?void 0:m.method)||"DDP",subtotals:h.checkoutSessionUpdate.subtotals}),a("Exchange rate updated for cart items (checkout session update)","info",ne.exchangeRate)),me(h.checkoutSessionUpdate),!0},pe=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=P.stripeAddressEventData)||void 0===s?void 0:s.value.address.country)||"US"))||"DAP"===t.method&&t.remittance.length&&"ZONOS"===t.landedCostGuaranteeCode?"DDP":t.method},he=async(t,n)=>{var s,r,i,d,l,c,u,m,v,p,h;ne.selectedShippingOption=t;const y=re(ne.selectedShippingOption);if(y){const{maxTransit:e,minTransit:t,unit:o}=y;ne.selectedShippingOptionTransitTime=`${t}-${e} ${o}`}else ne.selectedShippingOptionTransitTime="";const w=null===(s=ne.landedCostData)||void 0===s?void 0:s.find((e=>e.landedCostId===n));if(ne.selectedLandedCost=w||null,!w)return!1;const g=((null===(r=w.landedCost.amountSubtotals)||void 0===r?void 0:r.landedCostTotal)||0)*w.subtotals.exchangeRate.rate;g&&a(`DAP quote, using estimate: ${g}`,"info"),ne.landedCostMethod=pe(w.landedCost),ne.shipping=w.subtotals.shipping;const f="ZONOS"===(null===(i=null==w?void 0:w.landedCost)||void 0===i?void 0:i.landedCostGuaranteeCode),b=!!(null===(l=null===(d=null==w?void 0:w.landedCost)||void 0===d?void 0:d.deMinimis)||void 0===l?void 0:l.find((e=>["DUTY","TAX"].includes(e.type)&&"ABOVE"===e.threshold)));ne.isSelectedShippingAboveDeminimis=b,ne.isSelectedShippingGuarantee=f;const S=await ve({adjustmentsAmount:ne.adjustmentTotal,billToPartyId:P.partyBillingId,cartId:window.Zonos.cartId,dutiesTaxesFeesEstimate:g,landedCostId:null===(c=w.landedCost)||void 0===c?void 0:c.id,shipToPartyId:P.partyShippingId,varianceTestInput:o.enabledVariantTestKeys||[]}),C=null===(u=ne.items.find(Boolean))||void 0===u?void 0:u.currencyCode,O=(null===(m=P.stripeAddressEventData)||void 0===m?void 0:m.value.address.country)||"US";return P.shouldRenderPayInUsdButton="USD"===C&&"LOCAL_AND_USD"===e.checkoutSettings.allowedSettlementCurrencies&&"USD"!==(null===(v=ne.checkoutSession)||void 0===v?void 0:v.subtotals.presentmentCurrencyCode)&&!!(null===(h=null===(p=e.genericSettings)||void 0===p?void 0:p.usdSettlementCountryEnabled)||void 0===h?void 0:h.includes(O)),S},ye=({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;a(`==START CHECKOUT TIMEOUT - ${n}==`),ne.checkoutTimeoutInterval=setTimeout((()=>{ne.checkoutSessionTimeoutShow=!0}),n)},we=()=>{ne.checkoutTimeoutInterval&&(clearTimeout(ne.checkoutTimeoutInterval),ne.checkoutTimeoutInterval=null)},ge=()=>{ne.items=ne.items.map((e=>Object.assign(Object.assign({},e),{isRestricted:!1}))),ne.restrictedItems=[]},fe=async({adjustments:e,cartItems:t})=>{var n;ne.adjustments=e,ne.items=t.map((e=>Object.assign(Object.assign({},e),{isRestricted:!1})));const s=null===(n=t.find(Boolean))||void 0===n?void 0:n.currencyCode,r=t.reduce(((e,t)=>e+t.amount*t.quantity),0),i=e.reduce(((e,t)=>e+t.amount),0);s&&r&&(ne.currency=s,P.isFetchingSession=!0,await ve({adjustmentsAmount:i,billToPartyId:P.partyBillingId,cartId:window.Zonos.cartId,currency:s,dutiesTaxesFeesEstimate:0,itemsAmount:r,shipToPartyId:P.partyShippingId,shouldInitSessionOnFailure:!0,varianceTestInput:o.enabledVariantTestKeys||[]}),P.isFetchingSession=!1)},be=()=>{"shipping"===ne.step?(ne.step="customer-info",ne.tabItems=Object.assign(Object.assign({},ne.tabItems),{"customer-info":Object.assign(Object.assign({},ne.tabItems.shipping),{isDone:!1})})):"payment"===ne.step?(ne.step="shipping",ne.tabItems=Object.assign(Object.assign({},ne.tabItems),{shipping:Object.assign(Object.assign({},ne.tabItems.shipping),{isDone:!1})})):"finish"===ne.step&&(ne.step="payment",ne.tabItems=Object.assign(Object.assign({},ne.tabItems),{payment:Object.assign(Object.assign({},ne.tabItems.payment),{isDone:!1})}))},Se=()=>{"customer-info"===ne.step?(ne.step="shipping",ne.tabItems=Object.assign(Object.assign({},ne.tabItems),{"customer-info":Object.assign(Object.assign({},ne.tabItems["customer-info"]),{isDone:!0})})):"shipping"===ne.step?(ne.step="payment",ne.tabItems=Object.assign(Object.assign({},ne.tabItems),{shipping:Object.assign(Object.assign({},ne.tabItems.shipping),{isDone:!0})})):"payment"===ne.step&&(ne.step="finish")},Ce=()=>{ne.step="customer-info",ne.tabItems=Object.assign(Object.assign({},ne.tabItems),{"customer-info":Object.assign(Object.assign({},ne.tabItems["customer-info"]),{isDone:!1}),payment:Object.assign(Object.assign({},ne.tabItems.payment),{isDone:!1}),shipping:Object.assign(Object.assign({},ne.tabItems.shipping),{isDone:!1})}),ne.selectedShippingOption=null,ne.isSelectedShippingAboveDeminimis=!1,ne.isSelectedShippingGuarantee=!1,ne.selectedShippingOptionTransitTime="",ne.dutiesTaxesFees=0,ne.dutiesTaxesFeesEstimate=0,ne.shipping=0,ne.total=ne.subtotal};export{ue as A,J as B,$ as C,M as D,W as E,ee as F,g as G,te as H,U as I,he as J,re as K,pe as L,k as M,L as a,D as b,P as c,H as d,ne as e,fe as f,de as g,Ce as h,R as i,we as j,Z as k,V as l,ye as m,G as n,le as o,me as p,F as q,Se as r,x as s,O as t,Q as u,q as v,K as w,Y as x,_ as y,I as z}
|