@zonos/elements 1.3.235 → 1.3.236
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-22ced7cc.js → cart-e435a549.js} +1 -1
- package/dist/cjs/{hasInclusivePrice-ca85cabd.js → hasInclusivePrice-06d35d3c.js} +1 -1
- package/dist/cjs/index.cjs.js +7 -7
- package/dist/cjs/{invoice-8fd4242c.js → invoice-fc7bef1e.js} +2 -2
- package/dist/cjs/{isCollectMobileTablet-7962c57f.js → isCollectMobileTablet-aeeb0401.js} +2 -2
- package/dist/cjs/{localization-8ef6250a.js → localization-98db6c18.js} +7 -6
- package/dist/cjs/{paypal-4a086f84.js → paypal-a7bb03b5.js} +2 -2
- package/dist/cjs/{placeTestOrder-f25d08ee.js → placeTestOrder-6d99608b.js} +2 -2
- package/dist/cjs/{renderCheckoutCurrency-5494e45b.js → renderCheckoutCurrency-530fb636.js} +2 -2
- package/dist/cjs/zonos-address-display_9.cjs.entry.js +2 -2
- package/dist/cjs/zonos-address_4.cjs.entry.js +2 -2
- package/dist/cjs/zonos-card_5.cjs.entry.js +3 -3
- package/dist/cjs/zonos-cart-items_12.cjs.entry.js +6 -6
- package/dist/cjs/zonos-checkout.cjs.entry.js +3 -3
- package/dist/cjs/zonos-collect-cart-items_3.cjs.entry.js +2 -2
- package/dist/cjs/zonos-collect-finish_6.cjs.entry.js +6 -6
- package/dist/cjs/zonos-collect.cjs.entry.js +4 -4
- package/dist/cjs/zonos-controller.cjs.entry.js +2 -2
- package/dist/cjs/zonos-country-flag.cjs.entry.js +1 -1
- package/dist/cjs/zonos-country-select_4.cjs.entry.js +1 -1
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +2 -2
- package/dist/cjs/zonos-hello.cjs.entry.js +1 -1
- package/dist/cjs/zonos-invoice-cart-items_2.cjs.entry.js +4 -4
- package/dist/cjs/zonos-invoice-finish_5.cjs.entry.js +6 -6
- package/dist/cjs/zonos-invoice.cjs.entry.js +4 -4
- package/dist/cjs/zonos-language-select_2.cjs.entry.js +1 -1
- package/dist/collection/components/utils/hello/currencyConversion/currencyFormat.js +7 -6
- package/dist/esm/{cart-66aecbb3.js → cart-d802d953.js} +1 -1
- package/dist/esm/{hasInclusivePrice-2a1bf474.js → hasInclusivePrice-0285118a.js} +1 -1
- package/dist/esm/index.js +7 -7
- package/dist/esm/{invoice-c7452847.js → invoice-888ae8c9.js} +2 -2
- package/dist/esm/{isCollectMobileTablet-921002b0.js → isCollectMobileTablet-028f8611.js} +2 -2
- package/dist/esm/{localization-04b05867.js → localization-8f12d460.js} +7 -6
- package/dist/esm/{paypal-56564874.js → paypal-9b9e6231.js} +2 -2
- package/dist/esm/{placeTestOrder-6b9eda9e.js → placeTestOrder-42778584.js} +2 -2
- package/dist/esm/{renderCheckoutCurrency-cb808110.js → renderCheckoutCurrency-db3ce341.js} +2 -2
- package/dist/esm/zonos-address-display_9.entry.js +2 -2
- package/dist/esm/zonos-address_4.entry.js +2 -2
- package/dist/esm/zonos-card_5.entry.js +3 -3
- package/dist/esm/zonos-cart-items_12.entry.js +6 -6
- package/dist/esm/zonos-checkout.entry.js +3 -3
- package/dist/esm/zonos-collect-cart-items_3.entry.js +2 -2
- package/dist/esm/zonos-collect-finish_6.entry.js +6 -6
- package/dist/esm/zonos-collect.entry.js +4 -4
- package/dist/esm/zonos-controller.entry.js +2 -2
- package/dist/esm/zonos-country-flag.entry.js +1 -1
- package/dist/esm/zonos-country-select_4.entry.js +1 -1
- package/dist/esm/zonos-hello-dialog.entry.js +2 -2
- package/dist/esm/zonos-hello.entry.js +1 -1
- package/dist/esm/zonos-invoice-cart-items_2.entry.js +4 -4
- package/dist/esm/zonos-invoice-finish_5.entry.js +6 -6
- package/dist/esm/zonos-invoice.entry.js +4 -4
- package/dist/esm/zonos-language-select_2.entry.js +1 -1
- package/dist/esm-es5/{cart-66aecbb3.js → cart-d802d953.js} +1 -1
- package/dist/esm-es5/{hasInclusivePrice-2a1bf474.js → hasInclusivePrice-0285118a.js} +1 -1
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/{invoice-c7452847.js → invoice-888ae8c9.js} +1 -1
- package/dist/esm-es5/{isCollectMobileTablet-921002b0.js → isCollectMobileTablet-028f8611.js} +1 -1
- package/dist/esm-es5/{localization-04b05867.js → localization-8f12d460.js} +1 -1
- package/dist/esm-es5/{paypal-56564874.js → paypal-9b9e6231.js} +1 -1
- package/dist/esm-es5/{placeTestOrder-6b9eda9e.js → placeTestOrder-42778584.js} +1 -1
- package/dist/esm-es5/{renderCheckoutCurrency-cb808110.js → renderCheckoutCurrency-db3ce341.js} +1 -1
- package/dist/esm-es5/zonos-address-display_9.entry.js +1 -1
- package/dist/esm-es5/zonos-address_4.entry.js +1 -1
- package/dist/esm-es5/zonos-card_5.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_12.entry.js +1 -1
- package/dist/esm-es5/zonos-checkout.entry.js +1 -1
- package/dist/esm-es5/zonos-collect-cart-items_3.entry.js +1 -1
- package/dist/esm-es5/zonos-collect-finish_6.entry.js +1 -1
- package/dist/esm-es5/zonos-collect.entry.js +1 -1
- package/dist/esm-es5/zonos-controller.entry.js +1 -1
- package/dist/esm-es5/zonos-country-flag.entry.js +1 -1
- package/dist/esm-es5/zonos-country-select_4.entry.js +1 -1
- package/dist/esm-es5/zonos-hello-dialog.entry.js +1 -1
- package/dist/esm-es5/zonos-hello.entry.js +1 -1
- package/dist/esm-es5/zonos-invoice-cart-items_2.entry.js +1 -1
- package/dist/esm-es5/zonos-invoice-finish_5.entry.js +1 -1
- package/dist/esm-es5/zonos-invoice.entry.js +1 -1
- package/dist/esm-es5/zonos-language-select_2.entry.js +1 -1
- package/dist/scripts/index.js +1 -1
- package/dist/scripts/loadZonos.js +1 -1
- package/dist/scripts/zonos.js +1 -1
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/{p-f513b231.entry.js → p-09e3ed0d.entry.js} +1 -1
- package/dist/zonos-elements/{p-82febf70.system.js → p-09f2cbc9.system.js} +1 -1
- package/dist/zonos-elements/p-0abc8161.entry.js +1 -0
- package/dist/zonos-elements/{p-00719e49.entry.js → p-0ce28a83.entry.js} +1 -1
- package/dist/zonos-elements/{p-1a30fe18.system.entry.js → p-0e80d189.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-38913b2f.entry.js → p-1f1bf0c6.entry.js} +1 -1
- package/dist/zonos-elements/{p-10316d4d.system.entry.js → p-20dac9d4.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-836db369.system.entry.js → p-26ce341c.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-7e469c5c.entry.js → p-293d7a79.entry.js} +1 -1
- package/dist/zonos-elements/{p-18bc6c7a.entry.js → p-2e74e090.entry.js} +1 -1
- package/dist/zonos-elements/{p-f64207fa.system.entry.js → p-35a1979e.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-dc94d7eb.js → p-37f46852.js} +1 -1
- package/dist/zonos-elements/{p-a610c24e.system.entry.js → p-387304a0.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-48dc96f9.system.entry.js → p-3913b1e4.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-9479f155.system.js → p-3b598f1d.system.js} +1 -1
- package/dist/zonos-elements/{p-f4e976ae.entry.js → p-3fce3aef.entry.js} +1 -1
- package/dist/zonos-elements/{p-7e17667d.js → p-442f1023.js} +1 -1
- package/dist/zonos-elements/{p-95dc475b.system.js → p-48637bf6.system.js} +1 -1
- package/dist/zonos-elements/{p-9fa32fdf.js → p-48f48767.js} +1 -1
- package/dist/zonos-elements/{p-7f91617c.system.entry.js → p-4f030caf.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-170314a3.js → p-59bc0ca9.js} +1 -1
- package/dist/zonos-elements/{p-f3962950.system.entry.js → p-5fc40d18.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-8d3a62fb.entry.js → p-63a1b931.entry.js} +1 -1
- package/dist/zonos-elements/{p-30c661b3.system.entry.js → p-68991148.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-50f31c12.system.entry.js → p-73718cac.system.entry.js} +1 -1
- package/dist/zonos-elements/p-802a28f5.js +1 -0
- package/dist/zonos-elements/{p-757d4c62.system.entry.js → p-8916f54e.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-44b50260.entry.js → p-8e250c09.entry.js} +1 -1
- package/dist/zonos-elements/{p-f1d9dd4e.entry.js → p-a006320c.entry.js} +1 -1
- package/dist/zonos-elements/{p-83b3f824.system.entry.js → p-a12605f5.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-17a09191.entry.js → p-a5538e61.entry.js} +1 -1
- package/dist/zonos-elements/{p-6688473e.entry.js → p-a5ac9c92.entry.js} +1 -1
- package/dist/zonos-elements/{p-8af188f8.system.js → p-a87b5eaa.system.js} +1 -1
- package/dist/zonos-elements/{p-34bf7bbe.system.js → p-a8b1c81e.system.js} +1 -1
- package/dist/zonos-elements/{p-9b9bfb6d.entry.js → p-b29c5296.entry.js} +1 -1
- package/dist/zonos-elements/{p-4aa86184.system.entry.js → p-b80d40e5.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-18d20206.system.js → p-b9b42171.system.js} +1 -1
- package/dist/zonos-elements/p-bb73eb0f.js +1 -0
- package/dist/zonos-elements/{p-0e82fcea.entry.js → p-bf37c05f.entry.js} +1 -1
- package/dist/zonos-elements/p-c2442878.system.js +1 -1
- package/dist/zonos-elements/{p-976afc17.system.js → p-cca277fb.system.js} +1 -1
- package/dist/zonos-elements/{p-2250e585.entry.js → p-cd8ffc39.entry.js} +1 -1
- package/dist/zonos-elements/{p-4d594c8e.system.js → p-d24dde2c.system.js} +1 -1
- package/dist/zonos-elements/{p-a2a0bf4e.js → p-dadd3f97.js} +1 -1
- package/dist/zonos-elements/{p-0cd5bcb3.entry.js → p-dc08012c.entry.js} +1 -1
- package/dist/zonos-elements/{p-c8cc20d9.system.js → p-dea18dc5.system.js} +1 -1
- package/dist/zonos-elements/{p-73c737aa.js → p-e2e1145c.js} +1 -1
- package/dist/zonos-elements/{p-890bfc42.system.entry.js → p-e8c344c9.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-ed8ae947.system.entry.js → p-ef1edb24.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-248dd596.system.entry.js → p-f0cbecc3.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-851011aa.system.entry.js → p-f7290144.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-f1d4d6da.entry.js → p-f9183b9f.entry.js} +1 -1
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +1 -1
- package/dist/zonos-elements/p-6626d240.entry.js +0 -1
- package/dist/zonos-elements/p-81e3eb5b.js +0 -1
- package/dist/zonos-elements/p-dc5fb21c.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{z as e,c as t}from"./p-b2a0ab4a.js";import{s as o,l as n,e as s,t as r,f as i,b as a}from"./p-170314a3.js";import{f as d,h as l,g as c,a as u,s as m,l as p,j as v}from"./p-41dd1cb8.js";import{l as h,b as y}from"./p-0a377722.js";import{i as w}from"./p-57fa64d7.js";import{g}from"./p-1f894984.js";const f=({firstName:e,lastName:t,name:o})=>{var n;if(!o&&!e&&!t)return{firstName:"",lastName:""};const s=(null==o?void 0:o.split(/\s+/))||[];return{firstName:(null==e?void 0:e.trim())||(null===(n=s[0])||void 0===n?void 0:n.trim())||"",lastName:(null==t?void 0:t.trim())||s.slice(1).join(" ").trim()||""}},b=({currentAddress:e,translatedAddress:t})=>{var o,n,s,r,i,a;const{city:d,country:l,line1:c,line2:u,postal_code:m,state:p}=e.value.address,v=e.value.name||[e.value.firstName,e.value.lastName].join(" ");return{city:(null===(o=t.city)||void 0===o?void 0:o[d])||d,country:l,line1:(null===(n=t.line1)||void 0===n?void 0:n[c])||c,line2:(null===(s=t.line2)||void 0===s?void 0:s[u||""])||u||"",name:(null===(r=t.name)||void 0===r?void 0:r[v])||v,phone:e.value.phone||"",postal_code:(null===(i=t.postal_code)||void 0===i?void 0:i[m])||m,state:(null===(a=t.state)||void 0===a?void 0:a[p])||p}},S=e=>{var t;const r="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),i=D.stripeLinkEventData,a=D.stripeAddressEventData,d=D.stripeShippingSameAsBilling?D.stripeAddressEventData:D.stripeBillingAddressEventData;if(!a||!d)throw new Error("Missing stripe address data");const l=b({currentAddress:a,translatedAddress:D.translatedAddress.address}),{firstName:c,lastName:u}=f({name:l.name}),m=b({currentAddress:d,translatedAddress:D.translatedAddress.address}),{firstName:p,lastName:v}=f({name:m.name}),h=s()||"US";return{billingAddress:{addressLine1:m.line1,addressLine2:m.line2||"",city:m.city,country:m.country,postalCode:m.postal_code,state:m.state},billingContact:{firstName:p,lastName:v,phone:m.phone},cartCurrencyCode:null===(t=se.items[0])||void 0===t?void 0:t.currencyCode,cartId:e,checkoutSessionCountry:h||n.selectedCountryCode||void 0,checkoutSessionId:o.checkoutSessionId||"",contact:{companyName:D.companyName,email:null==i?void 0:i.value.email,firstName:c,lastName:u,phone:l.phone},isTest:!!r,landedCostAdjustments:se.promoCode?[{amount:0,productId:null,promoCode:se.promoCode,sku:null,type:"PROMO_CODE"}]:[],shipToTaxId:D.taxId,shippingAddress:{addressLine1:l.line1,addressLine2:l.line2,city:l.city,country:l.country,postalCode:l.postal_code,state:l.state}}},C=()=>{const e="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),t=D.stripeLinkEventData,n=D.stripeAddressEventData,s=D.stripeShippingSameAsBilling?D.stripeAddressEventData:D.stripeBillingAddressEventData;if(h({stripeAddressData:n,stripeBillingAddressData:s},"info"),!n||!s)throw new Error("Missing stripe address data");const r=b({currentAddress:n,translatedAddress:D.translatedAddress.address}),{firstName:i,lastName:a}=f({name:r.name}),d=b({currentAddress:s,translatedAddress:D.translatedAddress.address}),{firstName:l,lastName:c}=f({name:d.name}),u=se.adjustments.map((e=>({amount:e.amount,name:e.description||null,productId:e.productId,sku:e.sku,type:e.type}))),m=se.promoCode?[{amount:0,productId:null,promoCode:se.promoCode,sku:null,type:"PROMO_CODE"},...u]:u;return{billingAddress:{addressLine1:d.line1,addressLine2:d.line2||"",city:d.city,country:d.country,postalCode:d.postal_code,state:d.state},billingContact:{firstName:l,lastName:c,phone:d.phone},checkoutSessionId:o.checkoutSessionId||"",contact:{companyName:D.companyName,email:null==t?void 0:t.value.email,firstName:i,lastName:a,phone:r.phone},isTest:e,items:se.items,landedCostAdjustments:m,shipToTaxId:D.taxId,shippingAddress:{addressLine1:r.line1,addressLine2:r.line2,city:r.city,country:r.country,postalCode:r.postal_code,state:r.state}}};const O=async t=>{const o=window.Zonos.cartId;if(!o)return await(async t=>{var o;const n=e.checkoutSettings.buildLandedCost;if(n){const e=await(async e=>{var t,o,n,s,r;const i=C(),a=await e({billingAddress:i.billingAddress,billingContact:i.billingContact,checkoutSessionId:i.checkoutSessionId,contact:i.contact,landedCostAdjustments:i.landedCostAdjustments,publicCredential:window.Zonos.zonosApiKey||"",shippingAddress:i.shippingAddress,zonosApiRoute:d.vercel});if(!a||!(null===(t=a.checkoutSessionWorkflow)||void 0===t?void 0:t.length)&&(null===(o=a.errors)||void 0===o?void 0:o.length))throw new Error(`Failed to build landed cost: ${(null===(s=null===(n=null==a?void 0:a.errors)||void 0===n?void 0:n[0])||void 0===s?void 0:s.message)||"Unknown error"}`);const{errors:c,json:u}=await l("/api/zonos-elements/validate-landed-cost",{body:a,headers:{"Content-Type":"application/json"},method:"POST"});if(!u||c.length)throw new Error(`Invalid landed cost object: ${(null===(r=c.find(Boolean))||void 0===r?void 0:r.message)||"Unknown error"}`);return a})(n);return e}const{errors:s,json:r}=await l("/api/zonos-elements/calculate-landed-cost",{body:C(),method:"POST",signal:null==t?void 0:t.signal});if(s.length||!r){if("The user aborted a request."===(null===(o=s[0])||void 0===o?void 0:o.message))throw new Error("The landed cost calculation request was aborted to initiate a new one.");if(s.forEach((e=>{console.warn(`Error calculating landed cost: ${e.message}`)})),!r)throw new Error("Failed to calculate landed cost");return r}return r})(t);const n=await(async({abortController:e,cartId:t})=>{var o,n,s,r,i;const{errors:a,json:d}=await l("/api/zonos-elements/cart-calculate-landed-cost",{body:S(t),method:"POST",signal:null==e?void 0:e.signal});if(a.length||!d){const e="string"==typeof(null===(o=a[0])||void 0===o?void 0:o.message)&&("The user aborted a request."===(null===(n=a[0])||void 0===n?void 0:n.message)||(null===(s=a[0])||void 0===s?void 0:s.message.includes("signal is aborted"))||(null===(r=a[0])||void 0===r?void 0:r.message.includes("The operation was aborted"))||(null===(i=a[0])||void 0===i?void 0:i.message.includes("Fetch is aborted")));throw new Error(e?"The landed cost calculation request was aborted to initiate a new one.":"Failed to calculate landed cost")}return d})({abortController:t,cartId:o}),{cartWorkflow:s}=n,r=function(e,t){var o={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++)t.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(o[n[s]]=e[n[s]])}return o}(n,["cartWorkflow"]);return Object.assign(Object.assign({},r),{itemCreateWorkflow:s.items})},A=async({checkoutSessionId:t,eventName:o,metadata:s})=>{var r,i;const a=Date.now(),d=[...window.Zonos.trackEventLogs];window.Zonos.trackEventLogs.push({checkoutSessionId:t,eventCreated:a,eventName:o});const p=window.location.href.includes("zonos.com")&&!window.location.href.includes("checkout.zonos.com")||!!(null===(r=window.Zonos)||void 0===r?void 0:r.zonosQaUrl)||!!(null===(i=window.Zonos)||void 0===i?void 0:i.debug);if((c()||u()||p)&&!window.Zonos.zonosConversionTest)return;const v=n.selectedCountryCode,h=e.organizationId;if(!t)return void m({endpoint:"trackConversionEventMetric",errors:[`Event "${o}" - No checkout session id found`],metadata:{allLogs:y,checkoutSessionId:t,eventName:o,metadata:s,organizationId:h,trackEventLogs:d}});h||m({endpoint:"trackConversionEventMetric",errors:[`Event "${o}" - No organization id found`],metadata:{allLogs:y,checkoutSessionId:t,eventName:o,metadata:s,organizationId:h,trackEventLogs:d}});const w={checkoutSessionId:t,countryCode:v,eventCreated:a,eventName:o,metadata:Object.assign(Object.assign({},s),{trackEventLogs:d}),organizationId:h};await l("/api/zonos-elements/track-conversion-event",{body:w,method:"POST"})},k=({address:e,invalidAdddressList:t})=>{if(!e)return;if(!t)return;const o={};return t.city&&(o.city=e.city),t.line1&&(o.line1=e.line1),t.line2&&(o.line2=e.line2),t.postal_code&&(o.postal_code=e.postal_code),t.state&&(o.state=e.state),t.name&&(o.name=e.name),Object.keys(o).length?o:void 0},I=e=>e.sort(((e,t)=>e.amount-t.amount)),N=async()=>{var e;const{errors:t,json:n}=await(async()=>{if(!o.checkoutSessionId)return{errors:[{message:"No checkout session id found"}],json:null};const e=new URLSearchParams;e.set("checkoutSessionId",o.checkoutSessionId);const{errors:t,json:n}=await l(`/api/zonos-elements/get-checkout-session?${e.toString()}`);return{errors:t,json:n}})();return t.length||!n?(p("Failed to retrieve checkout session info before confirming payment ",t),m({endpoint:"validateCheckoutSession",errors:t.map((e=>e.message)),metadata:{allLogs:y}}),{errorMessage:r("Unable to retrieve the checkout session at the moment. Please try again or contact our support team."),valid:!1}):(null===(e=n.checkoutSession.landedCost)||void 0===e?void 0:e.id)?{errorMessage:"",valid:!0}:(p("Landed cost is not found in the checkout session before confirming payment."),m({endpoint:"validateCheckoutSession",errors:["No landed cost found before confirming payment"],metadata:{allLogs:y}}),{errorMessage:r('No shipment rating selected. Please go back to the "Shipping" step and select a shipment rating to proceed.'),valid:!1})},j=({theme:t})=>{const o={".AccordionItem":{color:"var(--colorText)"},".AccordionItem--selected":{color:"var(--colorText)"},".Action":{color:"var(--colorText)"},".Input":{boxShadow:"none",fontSize:e.appearance.fontSizeInputValue?`${e.appearance.fontSizeInputValue}px`:void 0,padding:"0",paddingBottom:"8px",paddingLeft:"16px",paddingRight:"8px",paddingTop:"6px"},".Label--resting":{fontSize:e.appearance.fontSizeInputLabel?`${e.appearance.fontSizeInputLabel}px`:void 0},".PickerItem--highlight":{boxShadow:"0 0 0 2px var(--colorBackground)"},".PickerItem--highlight:hover":{backgroundColor:"var(--colorBackground)",boxShadow:"none"},".PickerItem--new":{color:"var(--colorText)"},".Tab--selected":{borderStyle:"solid",borderWidth:"1px"}};return"DARK"===t?Object.assign(Object.assign({},o),{".Action":Object.assign(Object.assign({},o[".Action"]),{color:"white"}),".PickerItem--new":Object.assign(Object.assign({},o[".PickerItem--new"]),{color:"white"})}):o},T=({borderStyle:e,theme:t})=>"DARK"===t?{borderRadius:g({overrideBorderStyle:e}),colorBackground:"#101117",colorBackgroundText:"#C5C6CA",colorText:"#C5C6CA",colorTextPlaceholder:"#C5C6CA"}:{borderRadius:g({overrideBorderStyle:e}),iconMenuColor:"var(--colorText)",iconMenuHoverColor:"var(--colorText)"},{onChange:E,reset:P,state:D}=t((()=>({checkoutSettlementCurrency:"USD",clientSecret:sessionStorage.getItem("zonos--client-secret")||"",companyName:"",companyNameUsedWhenAsyncAddressUpdate:"",customAddressErrors:{city:"",firstName:"",lastName:"",line1:"",phone:"",postalCode:"",showError:!1,state:""},customBillingAddressErrors:{city:"",firstName:"",lastName:"",line1:"",phone:"",postalCode:"",showError:!1,state:""},customErrorMessage:null,customerProfile:null,fetchingLandedCostAbortController:null,hasPaymentError:!1,isFetchingLandedCost:!1,isFetchingSession:!1,partyBillingId:null,partyShippingId:null,shouldInventoryRefund:!1,shouldRenderPayInUsdButton:!1,skipPaymentIntent:"0"!==new URLSearchParams(window.location.search).get("skipPaymentIntent"),stripe:null,stripeAddressElement:null,stripeAddressEventData:null,stripeAddressUsedWhenAsyncAddressUpdate:null,stripeAddressUsedWhenFetchingLC:null,stripeAddressUsedWhenValidatingAddress:null,stripeBillingAddressElement:null,stripeBillingAddressEventData:null,stripeBillingAddressUsedWhenAsyncAddressUpdate:null,stripeBillingAddressUsedWhenFetchingLC:null,stripeBillingAddressUsedWhenValidatingAddress:null,stripeCustomerSessionClientSecret:null,stripeElements:null,stripeElementsForBillingAddress:null,stripeElementsOptions:null,stripeLinkElement:null,stripeLinkEventData:null,stripeLinkUsedWhenFetchingLC:null,stripePaymentElement:null,stripePaymentEventData:null,stripeShippingSameAsBilling:!0,taxId:"",taxIdUsedWhenAsyncAddressUpdate:"",translatedAddress:{address:{},billingAddress:{},firstName:{},lastName:{},name:{}}}))),L=()=>{window.sessionStorage.removeItem("zonos--bigcommerce-domestic-checkout-shipping")},x=e=>{window.sessionStorage.setItem("zonos--bigcommerce-domestic-checkout-shipping",JSON.stringify(e))},R=()=>{const e=window.sessionStorage.getItem("zonos--bigcommerce-domestic-checkout-shipping");return v(e)},U=async t=>{var o,s;const r=D.clientSecret;if(!D.stripe)return void h("Skip. Stripe is not initialized");const i=(({clientSecret:t,overrideBorderRadius:o,overridePrimaryColor:s,overrideSecondaryColor:r,overrideTheme:i,paypalEnabled:a})=>{const d=s||e.appearance.colorPrimary,l=r||e.appearance.colorSecondary,c=(window.Zonos.isCollect||window.Zonos.isInvoice?"DARK"===e.appearance.theme:d&&w(d))?"night":"flat",u="DARK"===i?"night":"flat",m=a?["external_paypal"]:[];return{appearance:{labels:"floating",rules:Object.assign({},j({theme:i||"LIGHT"})),theme:i?u:c,variables:Object.assign(Object.assign({},T({borderStyle:o,theme:"LIGHT"})),{colorPrimary:l})},clientSecret:t||void 0,customerSessionClientSecret:D.stripeCustomerSessionClientSecret||void 0,externalPaymentMethodTypes:[...m],locale:n.selectedLocale}})({clientSecret:r,overrideBorderRadius:null==t?void 0:t.overrideBorderRadius,overridePrimaryColor:null==t?void 0:t.overridePrimaryColor,overrideSecondaryColor:null==t?void 0:t.overrideSecondaryColor,overrideTheme:null==t?void 0:t.overrideTheme,paypalEnabled:null==t?void 0:t.paypalEnabled}),a=JSON.stringify(i)===JSON.stringify(D.stripeElementsOptions);if(!D.stripeElements||!D.stripeElementsForBillingAddress)return D.stripeElementsForBillingAddress=null===(o=D.stripe)||void 0===o?void 0:o.elements(i),h("Stripe elements for billing address initialized"),D.stripeElements=null===(s=D.stripe)||void 0===s?void 0:s.elements(i),D.stripeElementsOptions=i,void h("Stripe elements initialized");a||(D.stripeElements.update(i),D.stripeElementsForBillingAddress.update(i),D.stripeElementsOptions=i,D.stripeElements.fetchUpdates()),h("Stripe elements updated")},_=()=>{sessionStorage.removeItem("zonos--client-secret"),P(),D.stripe=window.Zonos.stripe},z=({address:e,firstName:t,lastName:n,name:s,phone:r})=>{const{firstName:i,lastName:a}=f({firstName:t,lastName:n,name:s});return i&&a||m({endpoint:"PARTY_CREATE_NO_NAME_FOUND",errors:["No name found"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,firstName:t,lastName:n,name:s}}),r||m({endpoint:"PARTY_CREATE_NO_PHONE_FOUND",errors:["No phone found"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,phone:r}}),{city:e.city,country:e.country,firstName:i,lastName:a,line1:e.line1,line2:e.line2,phone:r||"",postal_code:e.postal_code,state:e.state}},B=async()=>{var e,t,n,s;if(!(null===(e=D.stripeAddressEventData)||void 0===e?void 0:e.complete)||!D.stripeShippingSameAsBilling&&!(null===(t=D.stripeBillingAddressEventData)||void 0===t?void 0:t.complete)||!D.stripeBillingAddressEventData)return{partiesCreated:!1};if(!se.landedCostData)return{partiesCreated:!1};const r=null===(n=se.landedCostData.find(Boolean))||void 0===n?void 0:n.landedCost.rootId;if(!r)return m({endpoint:"PF_NO_SELECTED_LANDED_COST",errors:["No selected landed cost"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId}}),{partiesCreated:!1};const i=(()=>{var e,t,o,n,s,r;const i=JSON.stringify(null===(e=D.stripeLinkUsedWhenFetchingLC)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=D.stripeLinkEventData)||void 0===t?void 0:t.value),a=JSON.stringify(null===(o=D.stripeAddressUsedWhenAsyncAddressUpdate)||void 0===o?void 0:o.value)!==JSON.stringify(null===(n=D.stripeAddressEventData)||void 0===n?void 0:n.value),d=!D.stripeShippingSameAsBilling&&JSON.stringify(null===(s=D.stripeBillingAddressUsedWhenAsyncAddressUpdate)||void 0===s?void 0:s.value)!==JSON.stringify(null===(r=D.stripeBillingAddressEventData)||void 0===r?void 0:r.value);return i||a||d||D.taxIdUsedWhenAsyncAddressUpdate!==D.taxId||D.companyNameUsedWhenAsyncAddressUpdate!==D.companyName})();if(!i)return{partiesCreated:!1};const a=z({address:D.stripeAddressEventData.value.address,firstName:D.stripeAddressEventData.value.firstName,lastName:D.stripeAddressEventData.value.lastName,name:D.stripeAddressEventData.value.name,phone:D.stripeAddressEventData.value.phone}),d=D.stripeShippingSameAsBilling?a:z({address:D.stripeBillingAddressEventData.value.address,firstName:D.stripeBillingAddressEventData.value.firstName,lastName:D.stripeBillingAddressEventData.value.lastName,name:D.stripeBillingAddressEventData.value.name,phone:D.stripeBillingAddressEventData.value.phone}),c="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),{errors:u,json:v}=await l("/api/zonos-elements/create-parties",{body:{address:a,billingAddress:d,companyName:D.companyName,email:(null===(s=D.stripeLinkEventData)||void 0===s?void 0:s.value.email)||"",isTest:c,rootId:r,taxId:D.taxId},method:"POST"});return u.length||!v?(p("Error occurs when creating parties",JSON.stringify(u,null,2)),m({endpoint:"PF_PARTY_CREATE_FAILED",errors:["Failed to create parties"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,errors:u,json:v}}),{partiesCreated:!1}):(D.companyNameUsedWhenAsyncAddressUpdate=D.companyName,D.stripeAddressUsedWhenAsyncAddressUpdate=D.stripeAddressEventData,D.stripeBillingAddressUsedWhenAsyncAddressUpdate=D.stripeBillingAddressEventData,D.taxIdUsedWhenAsyncAddressUpdate=D.taxId,D.partyBillingId=v.billToPartyId,D.partyShippingId=v.shipToPartyId,{partiesCreated:!0})},F=e=>({countryCode:e.address.country,postalCode:e.address.postal_code,state:e.address.state}),J=async t=>{var n,s,r,i;const a=(null==t?void 0:t.retries)||0,d=!!(null==t?void 0:t.applyingPromocode),l=(()=>{var e;const t=se.landedCostData&&(null===(e=se.landedCostData.find(Boolean))||void 0===e?void 0:e.subtotals.items)!==se.subtotal,o=(()=>{var e,t;const o=JSON.stringify(null===(e=D.stripeLinkUsedWhenFetchingLC)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=D.stripeLinkEventData)||void 0===t?void 0:t.value),n=D.stripeAddressEventData&&JSON.stringify(F(D.stripeAddressEventData.value))!==JSON.stringify(D.stripeAddressUsedWhenFetchingLC),s=!D.stripeShippingSameAsBilling&&D.stripeBillingAddressEventData&&JSON.stringify(F(D.stripeBillingAddressEventData.value))!==JSON.stringify(D.stripeBillingAddressUsedWhenFetchingLC);return o||n||s})();return h("isPrefetchInfoOutdated","info",{isAddressOutdated:o}),!se.landedCostData&&!D.isFetchingLandedCost||o||t})();if(!(()=>{var t,o,n,s;const r=!!(null===(t=D.stripeLinkEventData)||void 0===t?void 0:t.complete),i=!!(null===(o=D.stripeAddressEventData)||void 0===o?void 0:o.complete),a=D.stripeShippingSameAsBilling?i:!!(null===(n=D.stripeBillingAddressEventData)||void 0===n?void 0:n.complete),d=(t=>{var o,n;const s=null===(o=e.genericSettings)||void 0===o?void 0:o.countryFields,r=null===(n=e.genericSettings)||void 0===n?void 0:n.stripeCountryFieldLabels;return"stripe"===se.addressFormRenderType&&(r&&t in r?r[t]:null)||(s&&t in s?s[t]:null)})((null===(s=D.stripeAddressEventData)||void 0===s?void 0:s.value.address.country)||"US");return!!(i&&a&&r)||(d&&D.stripeAddressEventData?r&&D.stripeAddressEventData.value.firstName&&D.stripeAddressEventData.value.lastName&&D.stripeAddressEventData.value.address.line1.length>0&&(!d.stateRequired||d.stateRequired&&D.stripeAddressEventData.value.address.state.length>0)&&(!d.zipRequired||d.zipRequired&&D.stripeAddressEventData.value.address.postal_code.length>=3)&&D.stripeAddressEventData.value.phone&&D.stripeAddressEventData.value.phone.length>0:i&&a&&r)})())return{isRequestNotReady:!0};if(l&&(null===(n=D.fetchingLandedCostAbortController)||void 0===n||n.abort(),D.fetchingLandedCostAbortController=null),!l&&!d)return{isRequestNotReady:!1};a?(D.isFetchingLandedCost=!1,setTimeout((()=>{D.isFetchingLandedCost=!0}),300)):D.isFetchingLandedCost=!0,D.stripeAddressEventData&&(D.stripeAddressUsedWhenFetchingLC={countryCode:D.stripeAddressEventData.value.address.country,postalCode:D.stripeAddressEventData.value.address.postal_code,state:D.stripeAddressEventData.value.address.state}),D.stripeBillingAddressEventData&&(D.stripeBillingAddressUsedWhenFetchingLC={countryCode:D.stripeBillingAddressEventData.value.address.country,postalCode:D.stripeBillingAddressEventData.value.address.postal_code,state:D.stripeBillingAddressEventData.value.address.state}),D.stripeLinkEventData&&(D.stripeLinkUsedWhenFetchingLC=Object.assign({},D.stripeLinkEventData));try{fe(),await(async()=>{var e;const t=new AbortController;D.fetchingLandedCostAbortController=t,fe();const{checkoutSessionWorkflow:n,errors:s,itemCreateWorkflow:r,landedCostCalculateWorkflow:i,partyCreateWorkflow:a,shipmentRatingCalculateWorkflow:d}=await O(t);se.customQuotingError=(null===(e=null==s?void 0:s.find((e=>{var t;return"CUSTOM"===(null===(t=e.extensions)||void 0===t?void 0:t.ruleMessageType)})))||void 0===e?void 0:e.message)||null,se.shippingData=I((null==d?void 0:d.filter(Boolean))||[]),de(r),D.fetchingLandedCostAbortController=null,se.partiesData=(null==a?void 0:a.filter(Boolean))||[],se.landedCostData=(null==n?void 0:n.map((e=>{const t=null==i?void 0:i.find((t=>(null==t?void 0:t.id)===e.landedCostId));return t?Object.assign(Object.assign({},e),{landedCost:t}):null})).filter(Boolean))||[],(null==n?void 0:n.length)&&A({checkoutSessionId:o.checkoutSessionId,eventName:"checkout_quoteReceived"});const l=se.promoCodeApplied&&!se.landedCostData.find((e=>{var t;return null===(t=e.landedCost.appliedAdjustments)||void 0===t?void 0:t.find((e=>"PROMO_CODE"===e.type))}));se.promoCodeError=l,l||sessionStorage.setItem("zonos--promo-code",se.promoCode)})();const e=null===(s=se.shippingData)||void 0===s?void 0:s.find(Boolean),t=null===(r=se.landedCostData)||void 0===r?void 0:r.find((t=>t.landedCost.shipmentRating.id===(null==e?void 0:e.id))),n=t?t.subtotals:null;n&&ue({method:(null==t?void 0:t.landedCost.method)||"DDP",subtotals:n})}catch(e){if(se.landedCostData=[],se.shippingData=[],e instanceof Error&&e.message&&!["The landed cost calculation request was aborted to initiate a new one."].includes(e.message)){if(a<1)return await J(Object.assign(Object.assign({},t),{retries:(a||0)+1})),{isRequestNotReady:!1};const o=null===(i=D.stripeAddressEventData)||void 0===i?void 0:i.value;m({endpoint:`Failed to fetch landed cost (${a} retries)`,errors:[e.message],metadata:{cartId:window.Zonos.cartId,shipToAddress:o}})}p(e)}return D.isFetchingLandedCost=!1,{isRequestNotReady:!1}},M=async()=>{var e,t;await J({applyingPromocode:!0}),"payment"===se.step&&Se(),await B();const o=null===(e=se.shippingData)||void 0===e?void 0:e.find(Boolean),n=null===(t=se.landedCostData)||void 0===t?void 0:t.find((e=>e.landedCost.id===(null==o?void 0:o.id)));o&&n&&await ye({applySubtotalsOnly:!1,landedCostId:n.landedCostId,selectedShippingOption:o})},W=()=>{se.promoCode="",sessionStorage.removeItem("zonos--promo-code"),se.promoCodeError=!1,se.promoCodeApplied=!1},$=async()=>{"payment"===se.step&&Se(),W(),await M()},q=e=>{let t=[],o=!0;const n=window.Zonos.isCollect,s=window.Zonos.isInvoice;switch(e){case"succeeded":t=[r("Your payment went through successfully! Thank you for shopping with us! We hope you had an enjoyable experience and your support means the world to us."),"",r("We've sent an email confirmation of the order details for your review. And our team is carefully preparing your order so it arrives on time.")],(n||s)&&(t=[r("Thank you for submitting your payment. We appreciate your prompt attention."),"",r("A confirmation email with your payment details has been sent for your records. If you have any questions or need support, our team is here to help.")]),o=!1;break;case"requires_capture":case"processing":t=[r("Payment processing. We'll update you when payment is received.")],o=!1;break;case"requires_payment_method":t=[r("Payment failed. Please try another payment method.")],n&&(t=[r("Payment failed. Please reload the page and try another payment method.")]);break;case"requires_action":o=!1,t=[r("Your selected payment method requires additional verification. Please follow the instructions provided by your payment provider to complete the transaction.")];default:t=[r("Something went wrong.")]}return{isError:o,messages:t}},Y=async()=>{var t,o;const{onInventoryCheck:n}=e.checkoutSettings,s=!!(null===(o=null===(t=window.Zonos.cartData)||void 0===t?void 0:t.metadata.find((e=>"referenceId"===e.key)))||void 0===o?void 0:o.value);if(window.Zonos.isLegacyCheckout&&window.Zonos.cartData&&s){const{errors:e,json:t}=await l("/api/zonos-elements/legacy/inventory-check",{body:{cartData:window.Zonos.cartData},method:"POST"});return e.length||!t?(p("Error occurs when handling inventory refund","warn",JSON.stringify(e)),null):t.available&&204!==t.status?t.available||200===t.status?(D.shouldInventoryRefund=!0,null):null:r("The item you're looking for is currently unavailable in our inventory. Please check back later or contact support for assistance with availability.")}if("function"!=typeof n)return null;try{return await n({items:se.items})}catch(e){const t=e instanceof Error?e.message:"Unknown error";throw m({endpoint:"onInventoryCheck",errors:[`cartId: ${window.Zonos.cartId} - ${t}`],metadata:{cartId:window.Zonos.cartId,href:window.location.href,items:se.items}}),e}},H=async()=>{var e,t;const o=!!(null===(t=null===(e=window.Zonos.cartData)||void 0===e?void 0:e.metadata.find((e=>"referenceId"===e.key)))||void 0===t?void 0:t.value);window.Zonos.isLegacyCheckout&&window.Zonos.cartData&&o&&await l("/api/zonos-elements/legacy/inventory-refund",{body:{cartData:window.Zonos.cartData},method:"POST"})},K=async({clientSecret:e,storybookForceStatus:t})=>{if(t){const{isError:e,messages:o}=q(t);return{error:e,messages:o}}const o=e||D.clientSecret;if(!D.stripe||!o)return p("Failed to retrieve payment intent. Stripe is not initialized"),{error:!0,message:[r("Something went wrong.")]};const{paymentIntent:n}=await D.stripe.retrievePaymentIntent(o),s=null==n?void 0:n.status,{isError:i,messages:a}=q(s);return{error:i,messages:a,paymentIntentId:null==n?void 0:n.id,paymentMethod:null==n?void 0:n.payment_method,status:s}},G=async e=>{var t,n;const s=!!(null===(t=D.stripePaymentEventData)||void 0===t?void 0:t.complete),i=D.stripeElements,a=D.stripe,d=D.clientSecret;if(D.customErrorMessage=null,!(null===(n=se.selectedLandedCost)||void 0===n?void 0:n.landedCost.id)&&!(null==e?void 0:e.noLandedCostCheck))throw new Error("Attempted to confirm the payment when no landed cost is found in store");const l=await N();if(!l.valid)throw D.customErrorMessage=l.errorMessage,new Error(l.errorMessage);const c=o.checkoutSessionId;if(a&&i&&s&&d&&c){const e=new URL(window.location.href);e.searchParams.set("payment_intent_client_secret",d),e.searchParams.set("zonosCheckoutSessionId",c),A({checkoutSessionId:c,eventName:"checkout_paymentInfoCompleted"});const{error:t,paymentIntent:o}=await a.confirmPayment({confirmParams:{return_url:e.toString()},elements:i,redirect:"if_required"});if(h("Payment intent confirmed","info",{error:t,paymentIntent:o}),"requires_action"===(null==o?void 0:o.status))throw new Error(r("Your selected payment method requires additional verification. Please follow the instructions provided by your payment provider to complete the transaction."));if(t){if("card_error"===t.type||"validation_error"===t.type)throw new Error(t.message);if("invalid_request_error"===t.type&&"payment_intent_unexpected_state"===t.code)return;throw new Error("An unexpected error occurred.")}if("requires_payment_method"===o.status)throw new Error(r("Payment failed. Please try another payment method."))}},V=()=>{var e;const t=se.items.reduce(((e,t)=>e+t.amount*t.quantity),0),s=o.enabledVariantTestKeys||[];return{adjustmentsAmount:se.adjustments.reduce(((e,t)=>e+t.amount),0),cartId:window.Zonos.cartId,currency:(null===(e=se.items.find(Boolean))||void 0===e?void 0:e.currencyCode)||"",customerAuthenticationToken:se.customerAuthenticationToken||void 0,isCollect:!!window.Zonos.isCollect,isInvoice:!!window.Zonos.isInvoice,itemsAmount:t,metadata:[{key:"language",value:n.selectedLocale}],presentmentCountryCode:n.selectedCountryCode,skipPaymentIntent:D.skipPaymentIntent,varianceTestInput:s}},Z=async()=>{var e;if(!o.checkoutSessionId)return m({endpoint:"Error creating payment intent",errors:["No checkout session id found when retrieving payment intent"],metadata:{allLogs:y,cartId:window.Zonos.cartId}}),void ce({messages:[r("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:r("Error creating Checkout")});const{errors:t,json:n}=await l("/api/zonos-elements/create-payment-intent",{body:{checkoutSessionId:o.checkoutSessionId},method:"POST"}),s=null===(e=null==n?void 0:n.checkoutSessionPaymentIntentCreate)||void 0===e?void 0:e.clientSecret;if(t.length||!s)return p("Error occurs when getting payment intent",JSON.stringify(t,null,2)),m({endpoint:"Error creating payment intent",errors:t.map((e=>e.message)),metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,clientSecret:s}}),void ce({messages:[r("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:r("Error creating Checkout")});pe(n.checkoutSessionPaymentIntentCreate)},Q=async()=>{var e,t;if(!n.targetCurrency)return p("Failed to create checkout session - missing localizationStore.targetCurrency"),!1;D.isFetchingSession=!0;const o=V();h("Checkout session body","info",o);const{errors:s,json:r}=await l("/api/zonos-elements/create-checkout-session",{body:o,method:"POST"});if(D.isFetchingSession=!1,s.length||!r){const t=null===(e=s.find((e=>e.message)))||void 0===e?void 0:e.message;if(Array.isArray(t)&&t.some((e=>"Cart is expired."===e.message)))throw new Error("Cart is expired.");return p("Error occurred when creating checkout session",JSON.stringify(s,null,2)),!1}const i=r.checkoutSessionCreate;return pe(i),ue({method:(null===(t=i.landedCost)||void 0===t?void 0:t.method)||"DDP",subtotals:i.subtotals}),h("Exchange rate updated for cart items (checkout session create)","info",se.exchangeRate),h("done-init-checkout-session"),!0},X=async()=>{const t=o.checkoutSessionId;if(!t)return p("Failed to update checkout session base currency"),!1;if("LOCAL"===e.checkoutSettings.allowedSettlementCurrencies)return h('allowedSettlementCurrencies: "LOCAL". Skip updating checkout session base currency'),!0;const{json:n}=await l("/api/zonos-elements/update-checkout-session-base-currency",{body:{checkoutSessionId:t,currencyCode:D.checkoutSettlementCurrency},method:"POST"}),s=null==n?void 0:n.checkoutSessionBaseCurrencyUpdate.subtotals.presentmentCurrencyCode;return n&&s===D.checkoutSettlementCurrency?(h(`Updated checkout session to settlement currency "${s}".`),!0):(p("Failed to update checkout session base currency"),!1)},ee=({currentAddress:e,translatedAddressResult:t})=>{const o={};if(!t)return o;const{city:n,line1:s,line2:r,name:i,postal_code:a,state:d}=t;return e.city&&n&&(o.city={[e.city]:n}),e.line1&&s&&(o.line1={[e.line1]:s}),e.line2&&r&&(o.line2={[e.line2]:r}),e.postal_code&&a&&(o.postal_code={[e.postal_code]:a}),e.state&&d&&(o.state={[e.state]:d}),e.name&&i&&(o.name={[e.name]:i}),o},te=async({addressInvalidCharactersList:e,billingAddressInvalidCharactersList:t})=>{var o,n,s,r;const i=(({addressInvalidCharactersList:e,billingAddressInvalidCharactersList:t,stripeAddressEventData:o,stripeBillingAddressEventData:n,stripeShippingSameAsBilling:s})=>{const r=!!(null==o?void 0:o.complete);if(!r||!(s?r:null==n?void 0:n.complete))return null;if(!e&&!t)return null;const i=o.value,a=(null==n?void 0:n.value)||null,{firstName:d,lastName:l}=f({firstName:i.firstName,lastName:i.lastName,name:i.name}),c=`${d} ${l}`,{firstName:u,lastName:m}=f({firstName:null==a?void 0:a.firstName,lastName:null==a?void 0:a.lastName,name:(null==a?void 0:a.name)||""}),p=u&&m?`${u} ${m}`:"",v=i.address,h=null==a?void 0:a.address;return{address:k({address:Object.assign(Object.assign({},v),{name:c}),invalidAdddressList:e}),billingAddress:s?void 0:k({address:h?Object.assign(Object.assign({},h),{name:p}):null,invalidAdddressList:t}),destinationCountry:v.country}})({addressInvalidCharactersList:e,billingAddressInvalidCharactersList:t,stripeAddressEventData:D.stripeAddressEventData,stripeBillingAddressEventData:D.stripeBillingAddressEventData,stripeShippingSameAsBilling:D.stripeShippingSameAsBilling});if(!i)return void(D.translatedAddress={address:{},billingAddress:{}});const a=(()=>{var e,t,o,n;const s=JSON.stringify(null===(e=D.stripeAddressUsedWhenValidatingAddress)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=D.stripeAddressEventData)||void 0===t?void 0:t.value),r=!D.stripeShippingSameAsBilling&&JSON.stringify(null===(o=D.stripeBillingAddressEventData)||void 0===o?void 0:o.value)!==JSON.stringify(null===(n=D.stripeBillingAddressUsedWhenValidatingAddress)||void 0===n?void 0:n.value);return s||r})();if(!a)return;const{errors:d,json:c}=await l("/api/zonos-elements/validate-address",{body:i,method:"POST"});if(d.length||!c)return p("Error occurs when translating address to latin",JSON.stringify(d,null,2)),void(D.translatedAddress={address:{},billingAddress:{}});D.stripeAddressUsedWhenValidatingAddress=D.stripeAddressEventData,D.stripeBillingAddressUsedWhenValidatingAddress=D.stripeBillingAddressEventData;const u=null===(o=D.stripeAddressEventData)||void 0===o?void 0:o.value.address,m=null===(n=D.stripeBillingAddressEventData)||void 0===n?void 0:n.value.address;D.translatedAddress={address:u?ee({currentAddress:Object.assign(Object.assign({},u),{name:null===(s=D.stripeAddressEventData)||void 0===s?void 0:s.value.name}),translatedAddressResult:c.address||null}):{},billingAddress:D.stripeShippingSameAsBilling?{}:ee({currentAddress:Object.assign(Object.assign({},m),{name:null===(r=D.stripeBillingAddressEventData)||void 0===r?void 0:r.value.name}),translatedAddressResult:c.billingAddress||null})}};E("clientSecret",(e=>{e&&D.stripe&&sessionStorage.setItem("zonos--client-secret",e),e||sessionStorage.removeItem("zonos--client-secret")}));const{onChange:oe,reset:ne,state:se}=t((()=>({addressFormRenderType:"stripe",adjustmentTotal:0,adjustments:[],checkoutSession:null,checkoutSessionTimeoutShow:!1,checkoutTimeoutInterval:null,currency:"USD",customQuotingError:null,customerAuthenticationToken:null,displayBaseCurrency:!1,dutiesTaxesFees:null,dutiesTaxesFeesEstimate:null,error:null,exchangeRate:null,externalConfirmationPageURL:null,inventoryCheckErrorMessage:null,isSelectedShippingAboveDeminimis:!1,isSelectedShippingGuarantee:!1,isStagingMode:u(),items:[],landedCostData:null,landedCostMethod:"DDP",partiesData:[],promoCode:sessionStorage.getItem("zonos--promo-code")||"",promoCodeApplied:!!sessionStorage.getItem("zonos--promo-code"),promoCodeError:!1,restrictedItems:[],selectedLandedCost:null,selectedShippingOption:null,selectedShippingOptionExpectedDate:"",selectedShippingOptionTransitTime:"",shipping:0,shippingData:null,shouldHideDiscountInput:!1,step:"customer-info",subtotal:0,tabItems:{"customer-info":{index:1,isDone:!1,label:"Customer",value:"customer-info"},shipping:{index:2,isDone:!1,label:"Shipping",value:"shipping"},payment:{index:3,isDone:!1,label:"Payment",value:"payment"}},total:0}))),re=e=>{switch(e){case"DAYS":return r("days");case"WEEKS":return r("weeks");default:return r("business days")}},ie=e=>{var t;const o=null===(t=e.shippingProfile)||void 0===t?void 0:t.transitTime;return(null==o?void 0:o.min)&&(null==o?void 0:o.max)&&(null==o?void 0:o.type)?{maxTransit:o.max,minTransit:o.min,unit:re(o.type)}:null},ae=({item1:e,item2:t})=>!(!e||!t)&&(t.sku&&e.sku&&e.sku===t.sku||t.description&&e.description&&e.description===t.description||e.name&&t.name&&e.name===t.name),de=e=>{h("Checking item restrictions");const t=e.map((e=>{if(!e.restriction)return null;const{restriction:t}=e,o=se.items.find((t=>ae({item1:t,item2:e})));return Object.assign(Object.assign({matchedItem:o},e),{restriction:t})})).filter(Boolean);return se.restrictedItems=t,se.items=se.items.map((e=>Object.assign(Object.assign({},e),{isRestricted:!!t.find((t=>ae({item1:t,item2:e})))}))),{cartItems:se.items,restrictedItems:t}},le=()=>{o.checkoutSessionId=null,ne()},ce=({messages:e,title:t})=>{le(),_(),se.step="error",se.error={messages:e,title:t}},ue=({dutiesTaxesFeesEstimate:e,method:t,subtotals:o})=>{se.exchangeRate=o.exchangeRate,se.adjustmentTotal=o.adjustments,se.dutiesTaxesFees="DAP"===t?null:o.landedCostTotal,se.subtotal=o.items,se.total=o.total,se.currency=o.presentmentCurrencyCode,se.dutiesTaxesFeesEstimate=e||null},me=()=>!!se.items.filter((e=>e.amount>0)).find((e=>!e.isRestricted)),pe=e=>{var t,n,s,r,d;D.clientSecret=e.clientSecret,D.stripeCustomerSessionClientSecret=e.customerSessionClientSecret,D.customerProfile=e.customerProfile,se.checkoutSession=e,e.id||m({endpoint:"cartStoreSetCheckoutSession",errors:["Missing checkout session id in checkout session"],metadata:{allLogs:y,checkoutSession:e}}),e.id&&(o.checkoutSessionId=e.id);const l=i(e.varianceTestResults||[]);a(l);const c=(null===(s=null===(n=null===(t=se.checkoutSession)||void 0===t?void 0:t.metadata)||void 0===n?void 0:n.find((e=>"externalConfirmationPageURL"===(null==e?void 0:e.key))))||void 0===s?void 0:s.value)||(null===(d=null===(r=window.Zonos.cartData)||void 0===r?void 0:r.metadata.find((e=>"externalConfirmationPageURL"===(null==e?void 0:e.key))))||void 0===d?void 0:d.value)||null;c&&(h(`Found externalConfirmationPageURL: ${c}`),se.externalConfirmationPageURL=c)},ve=async({adjustmentsAmount:e,cartId:t,currency:s,dutiesTaxesFeesEstimate:i,itemsAmount:a,landedCostId:d,shouldInitSessionOnFailure:c})=>{var u;if(d&&se.selectedLandedCost&&(ue({dutiesTaxesFeesEstimate:i,method:se.landedCostMethod,subtotals:se.selectedLandedCost.subtotals}),h("Exchange rate updated for cart items (landed cost subtotal)","info",se.exchangeRate)),!o.checkoutSessionId)return h("Could not update cart total without checkout session id","info"),!1;const{errors:m,json:v}=await(async({adjustmentsAmount:e,cartId:t,currency:s,id:r,itemsAmount:i,landedCostId:a,presentmentCountryCode:d})=>{const c=o.enabledVariantTestKeys||[],{errors:u,json:m}=await l("/api/zonos-elements/update-checkout-session",{body:{adjustmentsAmount:e,billToPartyId:D.partyBillingId,cartId:t,currency:s,customerAuthenticationToken:se.customerAuthenticationToken||void 0,id:r,itemsAmount:i,landedCostId:a,metadata:[{key:"language",value:n.selectedLocale}],presentmentCountryCode:d,shipToPartyId:D.partyShippingId,skipPaymentIntent:D.skipPaymentIntent,varianceTestInput:c},method:"POST"});return u.length||!m?(p("Error occurs when updating checkout session",JSON.stringify(u,null,2)),{errors:u,json:m}):{errors:[],json:m}})({adjustmentsAmount:e,billToPartyId:D.partyBillingId,cartId:t,currency:s,id:o.checkoutSessionId,itemsAmount:a,landedCostId:d,presentmentCountryCode:n.selectedCountryCode,shipToPartyId:D.partyShippingId,varianceTestInput:o.enabledVariantTestKeys||[]});if(m.length>0||!v){if(p("Error occurs when updating checkout session."),c){h("Initiating checkout session on failure","info");const e=await Q();return h(`stripeStoreInitCheckoutSession: ${e}`),!!e||(ce({messages:[r("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:r("Error creating Checkout")}),!1)}return!1}return d||(ue({method:(null===(u=v.checkoutSessionUpdate.landedCost)||void 0===u?void 0:u.method)||"DDP",subtotals:v.checkoutSessionUpdate.subtotals}),h("Exchange rate updated for cart items (checkout session update)","info",se.exchangeRate)),pe(v.checkoutSessionUpdate),!0},he=t=>{var o,n,s;return"DAP"===t.method&&(null===(n=null===(o=e.genericSettings)||void 0===o?void 0:o.domesticCountries)||void 0===n?void 0:n.includes((null===(s=D.stripeAddressEventData)||void 0===s?void 0:s.value.address.country)||"US"))||"DAP"===t.method&&t.remittance.length&&"ZONOS"===t.landedCostGuaranteeCode?"DDP":t.method},ye=async({applySubtotalsOnly:t,landedCostId:n,selectedShippingOption:s})=>{var r,i,a,d,l,c,u,m,p,v,y;h("Updating selected shipping option","info",{landedCostId:n,selectedShippingOption:s}),se.selectedShippingOption=s;const w=ie(se.selectedShippingOption);if(w){const{maxTransit:e,minTransit:t,unit:o}=w;se.selectedShippingOptionTransitTime=`${t}-${e} ${o}`}else se.selectedShippingOptionTransitTime="";const g=null===(r=se.landedCostData)||void 0===r?void 0:r.find((e=>e.landedCostId===n));if(se.selectedLandedCost=g||null,!g)return!1;const f=((null===(i=g.landedCost.amountSubtotals)||void 0===i?void 0:i.landedCostTotal)||0)*g.subtotals.exchangeRate.rate;f&&h(`DAP quote, using estimate: ${f}`,"info"),se.landedCostMethod=he(g.landedCost),se.shipping=g.subtotals.shipping;const b="ZONOS"===(null===(a=null==g?void 0:g.landedCost)||void 0===a?void 0:a.landedCostGuaranteeCode),S=!!(null===(l=null===(d=null==g?void 0:g.landedCost)||void 0===d?void 0:d.deMinimis)||void 0===l?void 0:l.find((e=>["DUTY","TAX"].includes(e.type)&&"ABOVE"===e.threshold)));se.isSelectedShippingAboveDeminimis=S,se.isSelectedShippingGuarantee=b;let C=!1;t?(ue({dutiesTaxesFeesEstimate:f,method:se.landedCostMethod,subtotals:g.subtotals}),h("Exchange rate updated for cart items (landed cost subtotal)","info",se.exchangeRate),C=!0):C=await ve({adjustmentsAmount:se.adjustmentTotal,billToPartyId:D.partyBillingId,cartId:window.Zonos.cartId,dutiesTaxesFeesEstimate:f,landedCostId:null===(c=g.landedCost)||void 0===c?void 0:c.id,shipToPartyId:D.partyShippingId,varianceTestInput:o.enabledVariantTestKeys||[]});const O=null===(u=se.items.find(Boolean))||void 0===u?void 0:u.currencyCode,A=(null===(m=D.stripeAddressEventData)||void 0===m?void 0:m.value.address.country)||"US";return D.shouldRenderPayInUsdButton="USD"===O&&"LOCAL_AND_USD"===e.checkoutSettings.allowedSettlementCurrencies&&"USD"!==(null===(p=se.checkoutSession)||void 0===p?void 0:p.subtotals.presentmentCurrencyCode)&&!!(null===(y=null===(v=e.genericSettings)||void 0===v?void 0:v.usdSettlementCountryEnabled)||void 0===y?void 0:y.includes(A)),C},we=({isPreview:e,sessionTimeout:t})=>{if(e)return;const o=new URLSearchParams(window.location.search).get("zonosCheckoutTimeout"),n=o&&!isNaN(parseInt(o,10))?parseInt(o,10):t;h(`==START CHECKOUT TIMEOUT - ${n}==`),se.checkoutTimeoutInterval=setTimeout((()=>{se.checkoutSessionTimeoutShow=!0}),n)},ge=()=>{se.checkoutTimeoutInterval&&(clearTimeout(se.checkoutTimeoutInterval),se.checkoutTimeoutInterval=null)},fe=()=>{se.items=se.items.map((e=>Object.assign(Object.assign({},e),{isRestricted:!1}))),se.restrictedItems=[]},be=async({adjustments:e,cartItems:t,landedCostId:n,shouldInitSessionOnFailure:s=!0})=>{var r;se.adjustments=e,se.items=t.map((e=>Object.assign(Object.assign({},e),{isRestricted:!1})));const i=null===(r=t.find(Boolean))||void 0===r?void 0:r.currencyCode,a=t.reduce(((e,t)=>e+t.amount*t.quantity),0),d=e.reduce(((e,t)=>e+t.amount),0);i&&a&&(se.currency=i,D.isFetchingSession=!0,await ve({adjustmentsAmount:d,billToPartyId:D.partyBillingId,cartId:window.Zonos.cartId,currency:i,dutiesTaxesFeesEstimate:0,itemsAmount:a,landedCostId:n,shipToPartyId:D.partyShippingId,shouldInitSessionOnFailure:s,varianceTestInput:o.enabledVariantTestKeys||[]}),D.isFetchingSession=!1)},Se=()=>{"shipping"===se.step?(se.step="customer-info",se.tabItems=Object.assign(Object.assign({},se.tabItems),{"customer-info":Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!1})})):"payment"===se.step?(se.step="shipping",se.tabItems=Object.assign(Object.assign({},se.tabItems),{shipping:Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!1})})):"finish"===se.step&&(se.step="payment",se.tabItems=Object.assign(Object.assign({},se.tabItems),{payment:Object.assign(Object.assign({},se.tabItems.payment),{isDone:!1})}))},Ce=()=>{"customer-info"===se.step?(se.step="shipping",se.tabItems=Object.assign(Object.assign({},se.tabItems),{"customer-info":Object.assign(Object.assign({},se.tabItems["customer-info"]),{isDone:!0})})):"shipping"===se.step?(se.step="payment",se.tabItems=Object.assign(Object.assign({},se.tabItems),{shipping:Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!0})})):"payment"===se.step&&(se.step="finish")},Oe=()=>{se.step="customer-info",se.tabItems=Object.assign(Object.assign({},se.tabItems),{"customer-info":Object.assign(Object.assign({},se.tabItems["customer-info"]),{isDone:!1}),payment:Object.assign(Object.assign({},se.tabItems.payment),{isDone:!1}),shipping:Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!1})}),se.selectedShippingOption=null,se.isSelectedShippingAboveDeminimis=!1,se.isSelectedShippingGuarantee=!1,se.selectedShippingOptionTransitTime="",se.dutiesTaxesFees=0,se.dutiesTaxesFeesEstimate=0,se.shipping=0,se.total=se.subtotal};export{N as A,E as B,z as C,ye as D,me as E,M as F,$ as G,W as H,q as I,te as J,f as K,B as L,ie as M,he as N,I as O,L as a,x as b,D as c,K as d,se as e,be as f,le as g,Oe as h,U as i,ge as j,Q as k,Z as l,we as m,V as n,ce as o,pe as p,J as q,Ce as r,R as s,A as t,X as u,Y as v,G as w,H as x,_ as y,oe as z}
|
|
1
|
+
import{z as e,c as t}from"./p-b2a0ab4a.js";import{s as o,l as n,e as s,t as r,f as i,b as a}from"./p-59bc0ca9.js";import{f as d,h as l,g as c,a as u,s as m,l as p,j as v}from"./p-41dd1cb8.js";import{l as h,b as y}from"./p-0a377722.js";import{i as w}from"./p-57fa64d7.js";import{g}from"./p-1f894984.js";const f=({firstName:e,lastName:t,name:o})=>{var n;if(!o&&!e&&!t)return{firstName:"",lastName:""};const s=(null==o?void 0:o.split(/\s+/))||[];return{firstName:(null==e?void 0:e.trim())||(null===(n=s[0])||void 0===n?void 0:n.trim())||"",lastName:(null==t?void 0:t.trim())||s.slice(1).join(" ").trim()||""}},b=({currentAddress:e,translatedAddress:t})=>{var o,n,s,r,i,a;const{city:d,country:l,line1:c,line2:u,postal_code:m,state:p}=e.value.address,v=e.value.name||[e.value.firstName,e.value.lastName].join(" ");return{city:(null===(o=t.city)||void 0===o?void 0:o[d])||d,country:l,line1:(null===(n=t.line1)||void 0===n?void 0:n[c])||c,line2:(null===(s=t.line2)||void 0===s?void 0:s[u||""])||u||"",name:(null===(r=t.name)||void 0===r?void 0:r[v])||v,phone:e.value.phone||"",postal_code:(null===(i=t.postal_code)||void 0===i?void 0:i[m])||m,state:(null===(a=t.state)||void 0===a?void 0:a[p])||p}},S=e=>{var t;const r="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),i=D.stripeLinkEventData,a=D.stripeAddressEventData,d=D.stripeShippingSameAsBilling?D.stripeAddressEventData:D.stripeBillingAddressEventData;if(!a||!d)throw new Error("Missing stripe address data");const l=b({currentAddress:a,translatedAddress:D.translatedAddress.address}),{firstName:c,lastName:u}=f({name:l.name}),m=b({currentAddress:d,translatedAddress:D.translatedAddress.address}),{firstName:p,lastName:v}=f({name:m.name}),h=s()||"US";return{billingAddress:{addressLine1:m.line1,addressLine2:m.line2||"",city:m.city,country:m.country,postalCode:m.postal_code,state:m.state},billingContact:{firstName:p,lastName:v,phone:m.phone},cartCurrencyCode:null===(t=se.items[0])||void 0===t?void 0:t.currencyCode,cartId:e,checkoutSessionCountry:h||n.selectedCountryCode||void 0,checkoutSessionId:o.checkoutSessionId||"",contact:{companyName:D.companyName,email:null==i?void 0:i.value.email,firstName:c,lastName:u,phone:l.phone},isTest:!!r,landedCostAdjustments:se.promoCode?[{amount:0,productId:null,promoCode:se.promoCode,sku:null,type:"PROMO_CODE"}]:[],shipToTaxId:D.taxId,shippingAddress:{addressLine1:l.line1,addressLine2:l.line2,city:l.city,country:l.country,postalCode:l.postal_code,state:l.state}}},C=()=>{const e="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),t=D.stripeLinkEventData,n=D.stripeAddressEventData,s=D.stripeShippingSameAsBilling?D.stripeAddressEventData:D.stripeBillingAddressEventData;if(h({stripeAddressData:n,stripeBillingAddressData:s},"info"),!n||!s)throw new Error("Missing stripe address data");const r=b({currentAddress:n,translatedAddress:D.translatedAddress.address}),{firstName:i,lastName:a}=f({name:r.name}),d=b({currentAddress:s,translatedAddress:D.translatedAddress.address}),{firstName:l,lastName:c}=f({name:d.name}),u=se.adjustments.map((e=>({amount:e.amount,name:e.description||null,productId:e.productId,sku:e.sku,type:e.type}))),m=se.promoCode?[{amount:0,productId:null,promoCode:se.promoCode,sku:null,type:"PROMO_CODE"},...u]:u;return{billingAddress:{addressLine1:d.line1,addressLine2:d.line2||"",city:d.city,country:d.country,postalCode:d.postal_code,state:d.state},billingContact:{firstName:l,lastName:c,phone:d.phone},checkoutSessionId:o.checkoutSessionId||"",contact:{companyName:D.companyName,email:null==t?void 0:t.value.email,firstName:i,lastName:a,phone:r.phone},isTest:e,items:se.items,landedCostAdjustments:m,shipToTaxId:D.taxId,shippingAddress:{addressLine1:r.line1,addressLine2:r.line2,city:r.city,country:r.country,postalCode:r.postal_code,state:r.state}}};const O=async t=>{const o=window.Zonos.cartId;if(!o)return await(async t=>{var o;const n=e.checkoutSettings.buildLandedCost;if(n){const e=await(async e=>{var t,o,n,s,r;const i=C(),a=await e({billingAddress:i.billingAddress,billingContact:i.billingContact,checkoutSessionId:i.checkoutSessionId,contact:i.contact,landedCostAdjustments:i.landedCostAdjustments,publicCredential:window.Zonos.zonosApiKey||"",shippingAddress:i.shippingAddress,zonosApiRoute:d.vercel});if(!a||!(null===(t=a.checkoutSessionWorkflow)||void 0===t?void 0:t.length)&&(null===(o=a.errors)||void 0===o?void 0:o.length))throw new Error(`Failed to build landed cost: ${(null===(s=null===(n=null==a?void 0:a.errors)||void 0===n?void 0:n[0])||void 0===s?void 0:s.message)||"Unknown error"}`);const{errors:c,json:u}=await l("/api/zonos-elements/validate-landed-cost",{body:a,headers:{"Content-Type":"application/json"},method:"POST"});if(!u||c.length)throw new Error(`Invalid landed cost object: ${(null===(r=c.find(Boolean))||void 0===r?void 0:r.message)||"Unknown error"}`);return a})(n);return e}const{errors:s,json:r}=await l("/api/zonos-elements/calculate-landed-cost",{body:C(),method:"POST",signal:null==t?void 0:t.signal});if(s.length||!r){if("The user aborted a request."===(null===(o=s[0])||void 0===o?void 0:o.message))throw new Error("The landed cost calculation request was aborted to initiate a new one.");if(s.forEach((e=>{console.warn(`Error calculating landed cost: ${e.message}`)})),!r)throw new Error("Failed to calculate landed cost");return r}return r})(t);const n=await(async({abortController:e,cartId:t})=>{var o,n,s,r,i;const{errors:a,json:d}=await l("/api/zonos-elements/cart-calculate-landed-cost",{body:S(t),method:"POST",signal:null==e?void 0:e.signal});if(a.length||!d){const e="string"==typeof(null===(o=a[0])||void 0===o?void 0:o.message)&&("The user aborted a request."===(null===(n=a[0])||void 0===n?void 0:n.message)||(null===(s=a[0])||void 0===s?void 0:s.message.includes("signal is aborted"))||(null===(r=a[0])||void 0===r?void 0:r.message.includes("The operation was aborted"))||(null===(i=a[0])||void 0===i?void 0:i.message.includes("Fetch is aborted")));throw new Error(e?"The landed cost calculation request was aborted to initiate a new one.":"Failed to calculate landed cost")}return d})({abortController:t,cartId:o}),{cartWorkflow:s}=n,r=function(e,t){var o={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++)t.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(o[n[s]]=e[n[s]])}return o}(n,["cartWorkflow"]);return Object.assign(Object.assign({},r),{itemCreateWorkflow:s.items})},A=async({checkoutSessionId:t,eventName:o,metadata:s})=>{var r,i;const a=Date.now(),d=[...window.Zonos.trackEventLogs];window.Zonos.trackEventLogs.push({checkoutSessionId:t,eventCreated:a,eventName:o});const p=window.location.href.includes("zonos.com")&&!window.location.href.includes("checkout.zonos.com")||!!(null===(r=window.Zonos)||void 0===r?void 0:r.zonosQaUrl)||!!(null===(i=window.Zonos)||void 0===i?void 0:i.debug);if((c()||u()||p)&&!window.Zonos.zonosConversionTest)return;const v=n.selectedCountryCode,h=e.organizationId;if(!t)return void m({endpoint:"trackConversionEventMetric",errors:[`Event "${o}" - No checkout session id found`],metadata:{allLogs:y,checkoutSessionId:t,eventName:o,metadata:s,organizationId:h,trackEventLogs:d}});h||m({endpoint:"trackConversionEventMetric",errors:[`Event "${o}" - No organization id found`],metadata:{allLogs:y,checkoutSessionId:t,eventName:o,metadata:s,organizationId:h,trackEventLogs:d}});const w={checkoutSessionId:t,countryCode:v,eventCreated:a,eventName:o,metadata:Object.assign(Object.assign({},s),{trackEventLogs:d}),organizationId:h};await l("/api/zonos-elements/track-conversion-event",{body:w,method:"POST"})},k=({address:e,invalidAdddressList:t})=>{if(!e)return;if(!t)return;const o={};return t.city&&(o.city=e.city),t.line1&&(o.line1=e.line1),t.line2&&(o.line2=e.line2),t.postal_code&&(o.postal_code=e.postal_code),t.state&&(o.state=e.state),t.name&&(o.name=e.name),Object.keys(o).length?o:void 0},I=e=>e.sort(((e,t)=>e.amount-t.amount)),N=async()=>{var e;const{errors:t,json:n}=await(async()=>{if(!o.checkoutSessionId)return{errors:[{message:"No checkout session id found"}],json:null};const e=new URLSearchParams;e.set("checkoutSessionId",o.checkoutSessionId);const{errors:t,json:n}=await l(`/api/zonos-elements/get-checkout-session?${e.toString()}`);return{errors:t,json:n}})();return t.length||!n?(p("Failed to retrieve checkout session info before confirming payment ",t),m({endpoint:"validateCheckoutSession",errors:t.map((e=>e.message)),metadata:{allLogs:y}}),{errorMessage:r("Unable to retrieve the checkout session at the moment. Please try again or contact our support team."),valid:!1}):(null===(e=n.checkoutSession.landedCost)||void 0===e?void 0:e.id)?{errorMessage:"",valid:!0}:(p("Landed cost is not found in the checkout session before confirming payment."),m({endpoint:"validateCheckoutSession",errors:["No landed cost found before confirming payment"],metadata:{allLogs:y}}),{errorMessage:r('No shipment rating selected. Please go back to the "Shipping" step and select a shipment rating to proceed.'),valid:!1})},j=({theme:t})=>{const o={".AccordionItem":{color:"var(--colorText)"},".AccordionItem--selected":{color:"var(--colorText)"},".Action":{color:"var(--colorText)"},".Input":{boxShadow:"none",fontSize:e.appearance.fontSizeInputValue?`${e.appearance.fontSizeInputValue}px`:void 0,padding:"0",paddingBottom:"8px",paddingLeft:"16px",paddingRight:"8px",paddingTop:"6px"},".Label--resting":{fontSize:e.appearance.fontSizeInputLabel?`${e.appearance.fontSizeInputLabel}px`:void 0},".PickerItem--highlight":{boxShadow:"0 0 0 2px var(--colorBackground)"},".PickerItem--highlight:hover":{backgroundColor:"var(--colorBackground)",boxShadow:"none"},".PickerItem--new":{color:"var(--colorText)"},".Tab--selected":{borderStyle:"solid",borderWidth:"1px"}};return"DARK"===t?Object.assign(Object.assign({},o),{".Action":Object.assign(Object.assign({},o[".Action"]),{color:"white"}),".PickerItem--new":Object.assign(Object.assign({},o[".PickerItem--new"]),{color:"white"})}):o},T=({borderStyle:e,theme:t})=>"DARK"===t?{borderRadius:g({overrideBorderStyle:e}),colorBackground:"#101117",colorBackgroundText:"#C5C6CA",colorText:"#C5C6CA",colorTextPlaceholder:"#C5C6CA"}:{borderRadius:g({overrideBorderStyle:e}),iconMenuColor:"var(--colorText)",iconMenuHoverColor:"var(--colorText)"},{onChange:E,reset:P,state:D}=t((()=>({checkoutSettlementCurrency:"USD",clientSecret:sessionStorage.getItem("zonos--client-secret")||"",companyName:"",companyNameUsedWhenAsyncAddressUpdate:"",customAddressErrors:{city:"",firstName:"",lastName:"",line1:"",phone:"",postalCode:"",showError:!1,state:""},customBillingAddressErrors:{city:"",firstName:"",lastName:"",line1:"",phone:"",postalCode:"",showError:!1,state:""},customErrorMessage:null,customerProfile:null,fetchingLandedCostAbortController:null,hasPaymentError:!1,isFetchingLandedCost:!1,isFetchingSession:!1,partyBillingId:null,partyShippingId:null,shouldInventoryRefund:!1,shouldRenderPayInUsdButton:!1,skipPaymentIntent:"0"!==new URLSearchParams(window.location.search).get("skipPaymentIntent"),stripe:null,stripeAddressElement:null,stripeAddressEventData:null,stripeAddressUsedWhenAsyncAddressUpdate:null,stripeAddressUsedWhenFetchingLC:null,stripeAddressUsedWhenValidatingAddress:null,stripeBillingAddressElement:null,stripeBillingAddressEventData:null,stripeBillingAddressUsedWhenAsyncAddressUpdate:null,stripeBillingAddressUsedWhenFetchingLC:null,stripeBillingAddressUsedWhenValidatingAddress:null,stripeCustomerSessionClientSecret:null,stripeElements:null,stripeElementsForBillingAddress:null,stripeElementsOptions:null,stripeLinkElement:null,stripeLinkEventData:null,stripeLinkUsedWhenFetchingLC:null,stripePaymentElement:null,stripePaymentEventData:null,stripeShippingSameAsBilling:!0,taxId:"",taxIdUsedWhenAsyncAddressUpdate:"",translatedAddress:{address:{},billingAddress:{},firstName:{},lastName:{},name:{}}}))),L=()=>{window.sessionStorage.removeItem("zonos--bigcommerce-domestic-checkout-shipping")},x=e=>{window.sessionStorage.setItem("zonos--bigcommerce-domestic-checkout-shipping",JSON.stringify(e))},R=()=>{const e=window.sessionStorage.getItem("zonos--bigcommerce-domestic-checkout-shipping");return v(e)},U=async t=>{var o,s;const r=D.clientSecret;if(!D.stripe)return void h("Skip. Stripe is not initialized");const i=(({clientSecret:t,overrideBorderRadius:o,overridePrimaryColor:s,overrideSecondaryColor:r,overrideTheme:i,paypalEnabled:a})=>{const d=s||e.appearance.colorPrimary,l=r||e.appearance.colorSecondary,c=(window.Zonos.isCollect||window.Zonos.isInvoice?"DARK"===e.appearance.theme:d&&w(d))?"night":"flat",u="DARK"===i?"night":"flat",m=a?["external_paypal"]:[];return{appearance:{labels:"floating",rules:Object.assign({},j({theme:i||"LIGHT"})),theme:i?u:c,variables:Object.assign(Object.assign({},T({borderStyle:o,theme:"LIGHT"})),{colorPrimary:l})},clientSecret:t||void 0,customerSessionClientSecret:D.stripeCustomerSessionClientSecret||void 0,externalPaymentMethodTypes:[...m],locale:n.selectedLocale}})({clientSecret:r,overrideBorderRadius:null==t?void 0:t.overrideBorderRadius,overridePrimaryColor:null==t?void 0:t.overridePrimaryColor,overrideSecondaryColor:null==t?void 0:t.overrideSecondaryColor,overrideTheme:null==t?void 0:t.overrideTheme,paypalEnabled:null==t?void 0:t.paypalEnabled}),a=JSON.stringify(i)===JSON.stringify(D.stripeElementsOptions);if(!D.stripeElements||!D.stripeElementsForBillingAddress)return D.stripeElementsForBillingAddress=null===(o=D.stripe)||void 0===o?void 0:o.elements(i),h("Stripe elements for billing address initialized"),D.stripeElements=null===(s=D.stripe)||void 0===s?void 0:s.elements(i),D.stripeElementsOptions=i,void h("Stripe elements initialized");a||(D.stripeElements.update(i),D.stripeElementsForBillingAddress.update(i),D.stripeElementsOptions=i,D.stripeElements.fetchUpdates()),h("Stripe elements updated")},_=()=>{sessionStorage.removeItem("zonos--client-secret"),P(),D.stripe=window.Zonos.stripe},z=({address:e,firstName:t,lastName:n,name:s,phone:r})=>{const{firstName:i,lastName:a}=f({firstName:t,lastName:n,name:s});return i&&a||m({endpoint:"PARTY_CREATE_NO_NAME_FOUND",errors:["No name found"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,firstName:t,lastName:n,name:s}}),r||m({endpoint:"PARTY_CREATE_NO_PHONE_FOUND",errors:["No phone found"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,phone:r}}),{city:e.city,country:e.country,firstName:i,lastName:a,line1:e.line1,line2:e.line2,phone:r||"",postal_code:e.postal_code,state:e.state}},B=async()=>{var e,t,n,s;if(!(null===(e=D.stripeAddressEventData)||void 0===e?void 0:e.complete)||!D.stripeShippingSameAsBilling&&!(null===(t=D.stripeBillingAddressEventData)||void 0===t?void 0:t.complete)||!D.stripeBillingAddressEventData)return{partiesCreated:!1};if(!se.landedCostData)return{partiesCreated:!1};const r=null===(n=se.landedCostData.find(Boolean))||void 0===n?void 0:n.landedCost.rootId;if(!r)return m({endpoint:"PF_NO_SELECTED_LANDED_COST",errors:["No selected landed cost"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId}}),{partiesCreated:!1};const i=(()=>{var e,t,o,n,s,r;const i=JSON.stringify(null===(e=D.stripeLinkUsedWhenFetchingLC)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=D.stripeLinkEventData)||void 0===t?void 0:t.value),a=JSON.stringify(null===(o=D.stripeAddressUsedWhenAsyncAddressUpdate)||void 0===o?void 0:o.value)!==JSON.stringify(null===(n=D.stripeAddressEventData)||void 0===n?void 0:n.value),d=!D.stripeShippingSameAsBilling&&JSON.stringify(null===(s=D.stripeBillingAddressUsedWhenAsyncAddressUpdate)||void 0===s?void 0:s.value)!==JSON.stringify(null===(r=D.stripeBillingAddressEventData)||void 0===r?void 0:r.value);return i||a||d||D.taxIdUsedWhenAsyncAddressUpdate!==D.taxId||D.companyNameUsedWhenAsyncAddressUpdate!==D.companyName})();if(!i)return{partiesCreated:!1};const a=z({address:D.stripeAddressEventData.value.address,firstName:D.stripeAddressEventData.value.firstName,lastName:D.stripeAddressEventData.value.lastName,name:D.stripeAddressEventData.value.name,phone:D.stripeAddressEventData.value.phone}),d=D.stripeShippingSameAsBilling?a:z({address:D.stripeBillingAddressEventData.value.address,firstName:D.stripeBillingAddressEventData.value.firstName,lastName:D.stripeBillingAddressEventData.value.lastName,name:D.stripeBillingAddressEventData.value.name,phone:D.stripeBillingAddressEventData.value.phone}),c="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),{errors:u,json:v}=await l("/api/zonos-elements/create-parties",{body:{address:a,billingAddress:d,companyName:D.companyName,email:(null===(s=D.stripeLinkEventData)||void 0===s?void 0:s.value.email)||"",isTest:c,rootId:r,taxId:D.taxId},method:"POST"});return u.length||!v?(p("Error occurs when creating parties",JSON.stringify(u,null,2)),m({endpoint:"PF_PARTY_CREATE_FAILED",errors:["Failed to create parties"],metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,errors:u,json:v}}),{partiesCreated:!1}):(D.companyNameUsedWhenAsyncAddressUpdate=D.companyName,D.stripeAddressUsedWhenAsyncAddressUpdate=D.stripeAddressEventData,D.stripeBillingAddressUsedWhenAsyncAddressUpdate=D.stripeBillingAddressEventData,D.taxIdUsedWhenAsyncAddressUpdate=D.taxId,D.partyBillingId=v.billToPartyId,D.partyShippingId=v.shipToPartyId,{partiesCreated:!0})},F=e=>({countryCode:e.address.country,postalCode:e.address.postal_code,state:e.address.state}),J=async t=>{var n,s,r,i;const a=(null==t?void 0:t.retries)||0,d=!!(null==t?void 0:t.applyingPromocode),l=(()=>{var e;const t=se.landedCostData&&(null===(e=se.landedCostData.find(Boolean))||void 0===e?void 0:e.subtotals.items)!==se.subtotal,o=(()=>{var e,t;const o=JSON.stringify(null===(e=D.stripeLinkUsedWhenFetchingLC)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=D.stripeLinkEventData)||void 0===t?void 0:t.value),n=D.stripeAddressEventData&&JSON.stringify(F(D.stripeAddressEventData.value))!==JSON.stringify(D.stripeAddressUsedWhenFetchingLC),s=!D.stripeShippingSameAsBilling&&D.stripeBillingAddressEventData&&JSON.stringify(F(D.stripeBillingAddressEventData.value))!==JSON.stringify(D.stripeBillingAddressUsedWhenFetchingLC);return o||n||s})();return h("isPrefetchInfoOutdated","info",{isAddressOutdated:o}),!se.landedCostData&&!D.isFetchingLandedCost||o||t})();if(!(()=>{var t,o,n,s;const r=!!(null===(t=D.stripeLinkEventData)||void 0===t?void 0:t.complete),i=!!(null===(o=D.stripeAddressEventData)||void 0===o?void 0:o.complete),a=D.stripeShippingSameAsBilling?i:!!(null===(n=D.stripeBillingAddressEventData)||void 0===n?void 0:n.complete),d=(t=>{var o,n;const s=null===(o=e.genericSettings)||void 0===o?void 0:o.countryFields,r=null===(n=e.genericSettings)||void 0===n?void 0:n.stripeCountryFieldLabels;return"stripe"===se.addressFormRenderType&&(r&&t in r?r[t]:null)||(s&&t in s?s[t]:null)})((null===(s=D.stripeAddressEventData)||void 0===s?void 0:s.value.address.country)||"US");return!!(i&&a&&r)||(d&&D.stripeAddressEventData?r&&D.stripeAddressEventData.value.firstName&&D.stripeAddressEventData.value.lastName&&D.stripeAddressEventData.value.address.line1.length>0&&(!d.stateRequired||d.stateRequired&&D.stripeAddressEventData.value.address.state.length>0)&&(!d.zipRequired||d.zipRequired&&D.stripeAddressEventData.value.address.postal_code.length>=3)&&D.stripeAddressEventData.value.phone&&D.stripeAddressEventData.value.phone.length>0:i&&a&&r)})())return{isRequestNotReady:!0};if(l&&(null===(n=D.fetchingLandedCostAbortController)||void 0===n||n.abort(),D.fetchingLandedCostAbortController=null),!l&&!d)return{isRequestNotReady:!1};a?(D.isFetchingLandedCost=!1,setTimeout((()=>{D.isFetchingLandedCost=!0}),300)):D.isFetchingLandedCost=!0,D.stripeAddressEventData&&(D.stripeAddressUsedWhenFetchingLC={countryCode:D.stripeAddressEventData.value.address.country,postalCode:D.stripeAddressEventData.value.address.postal_code,state:D.stripeAddressEventData.value.address.state}),D.stripeBillingAddressEventData&&(D.stripeBillingAddressUsedWhenFetchingLC={countryCode:D.stripeBillingAddressEventData.value.address.country,postalCode:D.stripeBillingAddressEventData.value.address.postal_code,state:D.stripeBillingAddressEventData.value.address.state}),D.stripeLinkEventData&&(D.stripeLinkUsedWhenFetchingLC=Object.assign({},D.stripeLinkEventData));try{fe(),await(async()=>{var e;const t=new AbortController;D.fetchingLandedCostAbortController=t,fe();const{checkoutSessionWorkflow:n,errors:s,itemCreateWorkflow:r,landedCostCalculateWorkflow:i,partyCreateWorkflow:a,shipmentRatingCalculateWorkflow:d}=await O(t);se.customQuotingError=(null===(e=null==s?void 0:s.find((e=>{var t;return"CUSTOM"===(null===(t=e.extensions)||void 0===t?void 0:t.ruleMessageType)})))||void 0===e?void 0:e.message)||null,se.shippingData=I((null==d?void 0:d.filter(Boolean))||[]),de(r),D.fetchingLandedCostAbortController=null,se.partiesData=(null==a?void 0:a.filter(Boolean))||[],se.landedCostData=(null==n?void 0:n.map((e=>{const t=null==i?void 0:i.find((t=>(null==t?void 0:t.id)===e.landedCostId));return t?Object.assign(Object.assign({},e),{landedCost:t}):null})).filter(Boolean))||[],(null==n?void 0:n.length)&&A({checkoutSessionId:o.checkoutSessionId,eventName:"checkout_quoteReceived"});const l=se.promoCodeApplied&&!se.landedCostData.find((e=>{var t;return null===(t=e.landedCost.appliedAdjustments)||void 0===t?void 0:t.find((e=>"PROMO_CODE"===e.type))}));se.promoCodeError=l,l||sessionStorage.setItem("zonos--promo-code",se.promoCode)})();const e=null===(s=se.shippingData)||void 0===s?void 0:s.find(Boolean),t=null===(r=se.landedCostData)||void 0===r?void 0:r.find((t=>t.landedCost.shipmentRating.id===(null==e?void 0:e.id))),n=t?t.subtotals:null;n&&ue({method:(null==t?void 0:t.landedCost.method)||"DDP",subtotals:n})}catch(e){if(se.landedCostData=[],se.shippingData=[],e instanceof Error&&e.message&&!["The landed cost calculation request was aborted to initiate a new one."].includes(e.message)){if(a<1)return await J(Object.assign(Object.assign({},t),{retries:(a||0)+1})),{isRequestNotReady:!1};const o=null===(i=D.stripeAddressEventData)||void 0===i?void 0:i.value;m({endpoint:`Failed to fetch landed cost (${a} retries)`,errors:[e.message],metadata:{cartId:window.Zonos.cartId,shipToAddress:o}})}p(e)}return D.isFetchingLandedCost=!1,{isRequestNotReady:!1}},M=async()=>{var e,t;await J({applyingPromocode:!0}),"payment"===se.step&&Se(),await B();const o=null===(e=se.shippingData)||void 0===e?void 0:e.find(Boolean),n=null===(t=se.landedCostData)||void 0===t?void 0:t.find((e=>e.landedCost.id===(null==o?void 0:o.id)));o&&n&&await ye({applySubtotalsOnly:!1,landedCostId:n.landedCostId,selectedShippingOption:o})},W=()=>{se.promoCode="",sessionStorage.removeItem("zonos--promo-code"),se.promoCodeError=!1,se.promoCodeApplied=!1},$=async()=>{"payment"===se.step&&Se(),W(),await M()},q=e=>{let t=[],o=!0;const n=window.Zonos.isCollect,s=window.Zonos.isInvoice;switch(e){case"succeeded":t=[r("Your payment went through successfully! Thank you for shopping with us! We hope you had an enjoyable experience and your support means the world to us."),"",r("We've sent an email confirmation of the order details for your review. And our team is carefully preparing your order so it arrives on time.")],(n||s)&&(t=[r("Thank you for submitting your payment. We appreciate your prompt attention."),"",r("A confirmation email with your payment details has been sent for your records. If you have any questions or need support, our team is here to help.")]),o=!1;break;case"requires_capture":case"processing":t=[r("Payment processing. We'll update you when payment is received.")],o=!1;break;case"requires_payment_method":t=[r("Payment failed. Please try another payment method.")],n&&(t=[r("Payment failed. Please reload the page and try another payment method.")]);break;case"requires_action":o=!1,t=[r("Your selected payment method requires additional verification. Please follow the instructions provided by your payment provider to complete the transaction.")];default:t=[r("Something went wrong.")]}return{isError:o,messages:t}},Y=async()=>{var t,o;const{onInventoryCheck:n}=e.checkoutSettings,s=!!(null===(o=null===(t=window.Zonos.cartData)||void 0===t?void 0:t.metadata.find((e=>"referenceId"===e.key)))||void 0===o?void 0:o.value);if(window.Zonos.isLegacyCheckout&&window.Zonos.cartData&&s){const{errors:e,json:t}=await l("/api/zonos-elements/legacy/inventory-check",{body:{cartData:window.Zonos.cartData},method:"POST"});return e.length||!t?(p("Error occurs when handling inventory refund","warn",JSON.stringify(e)),null):t.available&&204!==t.status?t.available||200===t.status?(D.shouldInventoryRefund=!0,null):null:r("The item you're looking for is currently unavailable in our inventory. Please check back later or contact support for assistance with availability.")}if("function"!=typeof n)return null;try{return await n({items:se.items})}catch(e){const t=e instanceof Error?e.message:"Unknown error";throw m({endpoint:"onInventoryCheck",errors:[`cartId: ${window.Zonos.cartId} - ${t}`],metadata:{cartId:window.Zonos.cartId,href:window.location.href,items:se.items}}),e}},H=async()=>{var e,t;const o=!!(null===(t=null===(e=window.Zonos.cartData)||void 0===e?void 0:e.metadata.find((e=>"referenceId"===e.key)))||void 0===t?void 0:t.value);window.Zonos.isLegacyCheckout&&window.Zonos.cartData&&o&&await l("/api/zonos-elements/legacy/inventory-refund",{body:{cartData:window.Zonos.cartData},method:"POST"})},K=async({clientSecret:e,storybookForceStatus:t})=>{if(t){const{isError:e,messages:o}=q(t);return{error:e,messages:o}}const o=e||D.clientSecret;if(!D.stripe||!o)return p("Failed to retrieve payment intent. Stripe is not initialized"),{error:!0,message:[r("Something went wrong.")]};const{paymentIntent:n}=await D.stripe.retrievePaymentIntent(o),s=null==n?void 0:n.status,{isError:i,messages:a}=q(s);return{error:i,messages:a,paymentIntentId:null==n?void 0:n.id,paymentMethod:null==n?void 0:n.payment_method,status:s}},G=async e=>{var t,n;const s=!!(null===(t=D.stripePaymentEventData)||void 0===t?void 0:t.complete),i=D.stripeElements,a=D.stripe,d=D.clientSecret;if(D.customErrorMessage=null,!(null===(n=se.selectedLandedCost)||void 0===n?void 0:n.landedCost.id)&&!(null==e?void 0:e.noLandedCostCheck))throw new Error("Attempted to confirm the payment when no landed cost is found in store");const l=await N();if(!l.valid)throw D.customErrorMessage=l.errorMessage,new Error(l.errorMessage);const c=o.checkoutSessionId;if(a&&i&&s&&d&&c){const e=new URL(window.location.href);e.searchParams.set("payment_intent_client_secret",d),e.searchParams.set("zonosCheckoutSessionId",c),A({checkoutSessionId:c,eventName:"checkout_paymentInfoCompleted"});const{error:t,paymentIntent:o}=await a.confirmPayment({confirmParams:{return_url:e.toString()},elements:i,redirect:"if_required"});if(h("Payment intent confirmed","info",{error:t,paymentIntent:o}),"requires_action"===(null==o?void 0:o.status))throw new Error(r("Your selected payment method requires additional verification. Please follow the instructions provided by your payment provider to complete the transaction."));if(t){if("card_error"===t.type||"validation_error"===t.type)throw new Error(t.message);if("invalid_request_error"===t.type&&"payment_intent_unexpected_state"===t.code)return;throw new Error("An unexpected error occurred.")}if("requires_payment_method"===o.status)throw new Error(r("Payment failed. Please try another payment method."))}},V=()=>{var e;const t=se.items.reduce(((e,t)=>e+t.amount*t.quantity),0),s=o.enabledVariantTestKeys||[];return{adjustmentsAmount:se.adjustments.reduce(((e,t)=>e+t.amount),0),cartId:window.Zonos.cartId,currency:(null===(e=se.items.find(Boolean))||void 0===e?void 0:e.currencyCode)||"",customerAuthenticationToken:se.customerAuthenticationToken||void 0,isCollect:!!window.Zonos.isCollect,isInvoice:!!window.Zonos.isInvoice,itemsAmount:t,metadata:[{key:"language",value:n.selectedLocale}],presentmentCountryCode:n.selectedCountryCode,skipPaymentIntent:D.skipPaymentIntent,varianceTestInput:s}},Z=async()=>{var e;if(!o.checkoutSessionId)return m({endpoint:"Error creating payment intent",errors:["No checkout session id found when retrieving payment intent"],metadata:{allLogs:y,cartId:window.Zonos.cartId}}),void ce({messages:[r("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:r("Error creating Checkout")});const{errors:t,json:n}=await l("/api/zonos-elements/create-payment-intent",{body:{checkoutSessionId:o.checkoutSessionId},method:"POST"}),s=null===(e=null==n?void 0:n.checkoutSessionPaymentIntentCreate)||void 0===e?void 0:e.clientSecret;if(t.length||!s)return p("Error occurs when getting payment intent",JSON.stringify(t,null,2)),m({endpoint:"Error creating payment intent",errors:t.map((e=>e.message)),metadata:{allLogs:y,cartId:window.Zonos.cartId,checkoutSessionId:o.checkoutSessionId,clientSecret:s}}),void ce({messages:[r("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:r("Error creating Checkout")});pe(n.checkoutSessionPaymentIntentCreate)},Q=async()=>{var e,t;if(!n.targetCurrency)return p("Failed to create checkout session - missing localizationStore.targetCurrency"),!1;D.isFetchingSession=!0;const o=V();h("Checkout session body","info",o);const{errors:s,json:r}=await l("/api/zonos-elements/create-checkout-session",{body:o,method:"POST"});if(D.isFetchingSession=!1,s.length||!r){const t=null===(e=s.find((e=>e.message)))||void 0===e?void 0:e.message;if(Array.isArray(t)&&t.some((e=>"Cart is expired."===e.message)))throw new Error("Cart is expired.");return p("Error occurred when creating checkout session",JSON.stringify(s,null,2)),!1}const i=r.checkoutSessionCreate;return pe(i),ue({method:(null===(t=i.landedCost)||void 0===t?void 0:t.method)||"DDP",subtotals:i.subtotals}),h("Exchange rate updated for cart items (checkout session create)","info",se.exchangeRate),h("done-init-checkout-session"),!0},X=async()=>{const t=o.checkoutSessionId;if(!t)return p("Failed to update checkout session base currency"),!1;if("LOCAL"===e.checkoutSettings.allowedSettlementCurrencies)return h('allowedSettlementCurrencies: "LOCAL". Skip updating checkout session base currency'),!0;const{json:n}=await l("/api/zonos-elements/update-checkout-session-base-currency",{body:{checkoutSessionId:t,currencyCode:D.checkoutSettlementCurrency},method:"POST"}),s=null==n?void 0:n.checkoutSessionBaseCurrencyUpdate.subtotals.presentmentCurrencyCode;return n&&s===D.checkoutSettlementCurrency?(h(`Updated checkout session to settlement currency "${s}".`),!0):(p("Failed to update checkout session base currency"),!1)},ee=({currentAddress:e,translatedAddressResult:t})=>{const o={};if(!t)return o;const{city:n,line1:s,line2:r,name:i,postal_code:a,state:d}=t;return e.city&&n&&(o.city={[e.city]:n}),e.line1&&s&&(o.line1={[e.line1]:s}),e.line2&&r&&(o.line2={[e.line2]:r}),e.postal_code&&a&&(o.postal_code={[e.postal_code]:a}),e.state&&d&&(o.state={[e.state]:d}),e.name&&i&&(o.name={[e.name]:i}),o},te=async({addressInvalidCharactersList:e,billingAddressInvalidCharactersList:t})=>{var o,n,s,r;const i=(({addressInvalidCharactersList:e,billingAddressInvalidCharactersList:t,stripeAddressEventData:o,stripeBillingAddressEventData:n,stripeShippingSameAsBilling:s})=>{const r=!!(null==o?void 0:o.complete);if(!r||!(s?r:null==n?void 0:n.complete))return null;if(!e&&!t)return null;const i=o.value,a=(null==n?void 0:n.value)||null,{firstName:d,lastName:l}=f({firstName:i.firstName,lastName:i.lastName,name:i.name}),c=`${d} ${l}`,{firstName:u,lastName:m}=f({firstName:null==a?void 0:a.firstName,lastName:null==a?void 0:a.lastName,name:(null==a?void 0:a.name)||""}),p=u&&m?`${u} ${m}`:"",v=i.address,h=null==a?void 0:a.address;return{address:k({address:Object.assign(Object.assign({},v),{name:c}),invalidAdddressList:e}),billingAddress:s?void 0:k({address:h?Object.assign(Object.assign({},h),{name:p}):null,invalidAdddressList:t}),destinationCountry:v.country}})({addressInvalidCharactersList:e,billingAddressInvalidCharactersList:t,stripeAddressEventData:D.stripeAddressEventData,stripeBillingAddressEventData:D.stripeBillingAddressEventData,stripeShippingSameAsBilling:D.stripeShippingSameAsBilling});if(!i)return void(D.translatedAddress={address:{},billingAddress:{}});const a=(()=>{var e,t,o,n;const s=JSON.stringify(null===(e=D.stripeAddressUsedWhenValidatingAddress)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=D.stripeAddressEventData)||void 0===t?void 0:t.value),r=!D.stripeShippingSameAsBilling&&JSON.stringify(null===(o=D.stripeBillingAddressEventData)||void 0===o?void 0:o.value)!==JSON.stringify(null===(n=D.stripeBillingAddressUsedWhenValidatingAddress)||void 0===n?void 0:n.value);return s||r})();if(!a)return;const{errors:d,json:c}=await l("/api/zonos-elements/validate-address",{body:i,method:"POST"});if(d.length||!c)return p("Error occurs when translating address to latin",JSON.stringify(d,null,2)),void(D.translatedAddress={address:{},billingAddress:{}});D.stripeAddressUsedWhenValidatingAddress=D.stripeAddressEventData,D.stripeBillingAddressUsedWhenValidatingAddress=D.stripeBillingAddressEventData;const u=null===(o=D.stripeAddressEventData)||void 0===o?void 0:o.value.address,m=null===(n=D.stripeBillingAddressEventData)||void 0===n?void 0:n.value.address;D.translatedAddress={address:u?ee({currentAddress:Object.assign(Object.assign({},u),{name:null===(s=D.stripeAddressEventData)||void 0===s?void 0:s.value.name}),translatedAddressResult:c.address||null}):{},billingAddress:D.stripeShippingSameAsBilling?{}:ee({currentAddress:Object.assign(Object.assign({},m),{name:null===(r=D.stripeBillingAddressEventData)||void 0===r?void 0:r.value.name}),translatedAddressResult:c.billingAddress||null})}};E("clientSecret",(e=>{e&&D.stripe&&sessionStorage.setItem("zonos--client-secret",e),e||sessionStorage.removeItem("zonos--client-secret")}));const{onChange:oe,reset:ne,state:se}=t((()=>({addressFormRenderType:"stripe",adjustmentTotal:0,adjustments:[],checkoutSession:null,checkoutSessionTimeoutShow:!1,checkoutTimeoutInterval:null,currency:"USD",customQuotingError:null,customerAuthenticationToken:null,displayBaseCurrency:!1,dutiesTaxesFees:null,dutiesTaxesFeesEstimate:null,error:null,exchangeRate:null,externalConfirmationPageURL:null,inventoryCheckErrorMessage:null,isSelectedShippingAboveDeminimis:!1,isSelectedShippingGuarantee:!1,isStagingMode:u(),items:[],landedCostData:null,landedCostMethod:"DDP",partiesData:[],promoCode:sessionStorage.getItem("zonos--promo-code")||"",promoCodeApplied:!!sessionStorage.getItem("zonos--promo-code"),promoCodeError:!1,restrictedItems:[],selectedLandedCost:null,selectedShippingOption:null,selectedShippingOptionExpectedDate:"",selectedShippingOptionTransitTime:"",shipping:0,shippingData:null,shouldHideDiscountInput:!1,step:"customer-info",subtotal:0,tabItems:{"customer-info":{index:1,isDone:!1,label:"Customer",value:"customer-info"},shipping:{index:2,isDone:!1,label:"Shipping",value:"shipping"},payment:{index:3,isDone:!1,label:"Payment",value:"payment"}},total:0}))),re=e=>{switch(e){case"DAYS":return r("days");case"WEEKS":return r("weeks");default:return r("business days")}},ie=e=>{var t;const o=null===(t=e.shippingProfile)||void 0===t?void 0:t.transitTime;return(null==o?void 0:o.min)&&(null==o?void 0:o.max)&&(null==o?void 0:o.type)?{maxTransit:o.max,minTransit:o.min,unit:re(o.type)}:null},ae=({item1:e,item2:t})=>!(!e||!t)&&(t.sku&&e.sku&&e.sku===t.sku||t.description&&e.description&&e.description===t.description||e.name&&t.name&&e.name===t.name),de=e=>{h("Checking item restrictions");const t=e.map((e=>{if(!e.restriction)return null;const{restriction:t}=e,o=se.items.find((t=>ae({item1:t,item2:e})));return Object.assign(Object.assign({matchedItem:o},e),{restriction:t})})).filter(Boolean);return se.restrictedItems=t,se.items=se.items.map((e=>Object.assign(Object.assign({},e),{isRestricted:!!t.find((t=>ae({item1:t,item2:e})))}))),{cartItems:se.items,restrictedItems:t}},le=()=>{o.checkoutSessionId=null,ne()},ce=({messages:e,title:t})=>{le(),_(),se.step="error",se.error={messages:e,title:t}},ue=({dutiesTaxesFeesEstimate:e,method:t,subtotals:o})=>{se.exchangeRate=o.exchangeRate,se.adjustmentTotal=o.adjustments,se.dutiesTaxesFees="DAP"===t?null:o.landedCostTotal,se.subtotal=o.items,se.total=o.total,se.currency=o.presentmentCurrencyCode,se.dutiesTaxesFeesEstimate=e||null},me=()=>!!se.items.filter((e=>e.amount>0)).find((e=>!e.isRestricted)),pe=e=>{var t,n,s,r,d;D.clientSecret=e.clientSecret,D.stripeCustomerSessionClientSecret=e.customerSessionClientSecret,D.customerProfile=e.customerProfile,se.checkoutSession=e,e.id||m({endpoint:"cartStoreSetCheckoutSession",errors:["Missing checkout session id in checkout session"],metadata:{allLogs:y,checkoutSession:e}}),e.id&&(o.checkoutSessionId=e.id);const l=i(e.varianceTestResults||[]);a(l);const c=(null===(s=null===(n=null===(t=se.checkoutSession)||void 0===t?void 0:t.metadata)||void 0===n?void 0:n.find((e=>"externalConfirmationPageURL"===(null==e?void 0:e.key))))||void 0===s?void 0:s.value)||(null===(d=null===(r=window.Zonos.cartData)||void 0===r?void 0:r.metadata.find((e=>"externalConfirmationPageURL"===(null==e?void 0:e.key))))||void 0===d?void 0:d.value)||null;c&&(h(`Found externalConfirmationPageURL: ${c}`),se.externalConfirmationPageURL=c)},ve=async({adjustmentsAmount:e,cartId:t,currency:s,dutiesTaxesFeesEstimate:i,itemsAmount:a,landedCostId:d,shouldInitSessionOnFailure:c})=>{var u;if(d&&se.selectedLandedCost&&(ue({dutiesTaxesFeesEstimate:i,method:se.landedCostMethod,subtotals:se.selectedLandedCost.subtotals}),h("Exchange rate updated for cart items (landed cost subtotal)","info",se.exchangeRate)),!o.checkoutSessionId)return h("Could not update cart total without checkout session id","info"),!1;const{errors:m,json:v}=await(async({adjustmentsAmount:e,cartId:t,currency:s,id:r,itemsAmount:i,landedCostId:a,presentmentCountryCode:d})=>{const c=o.enabledVariantTestKeys||[],{errors:u,json:m}=await l("/api/zonos-elements/update-checkout-session",{body:{adjustmentsAmount:e,billToPartyId:D.partyBillingId,cartId:t,currency:s,customerAuthenticationToken:se.customerAuthenticationToken||void 0,id:r,itemsAmount:i,landedCostId:a,metadata:[{key:"language",value:n.selectedLocale}],presentmentCountryCode:d,shipToPartyId:D.partyShippingId,skipPaymentIntent:D.skipPaymentIntent,varianceTestInput:c},method:"POST"});return u.length||!m?(p("Error occurs when updating checkout session",JSON.stringify(u,null,2)),{errors:u,json:m}):{errors:[],json:m}})({adjustmentsAmount:e,billToPartyId:D.partyBillingId,cartId:t,currency:s,id:o.checkoutSessionId,itemsAmount:a,landedCostId:d,presentmentCountryCode:n.selectedCountryCode,shipToPartyId:D.partyShippingId,varianceTestInput:o.enabledVariantTestKeys||[]});if(m.length>0||!v){if(p("Error occurs when updating checkout session."),c){h("Initiating checkout session on failure","info");const e=await Q();return h(`stripeStoreInitCheckoutSession: ${e}`),!!e||(ce({messages:[r("There's been an error creating your checkout session. Please reload and try again or contact support if the error persists")],title:r("Error creating Checkout")}),!1)}return!1}return d||(ue({method:(null===(u=v.checkoutSessionUpdate.landedCost)||void 0===u?void 0:u.method)||"DDP",subtotals:v.checkoutSessionUpdate.subtotals}),h("Exchange rate updated for cart items (checkout session update)","info",se.exchangeRate)),pe(v.checkoutSessionUpdate),!0},he=t=>{var o,n,s;return"DAP"===t.method&&(null===(n=null===(o=e.genericSettings)||void 0===o?void 0:o.domesticCountries)||void 0===n?void 0:n.includes((null===(s=D.stripeAddressEventData)||void 0===s?void 0:s.value.address.country)||"US"))||"DAP"===t.method&&t.remittance.length&&"ZONOS"===t.landedCostGuaranteeCode?"DDP":t.method},ye=async({applySubtotalsOnly:t,landedCostId:n,selectedShippingOption:s})=>{var r,i,a,d,l,c,u,m,p,v,y;h("Updating selected shipping option","info",{landedCostId:n,selectedShippingOption:s}),se.selectedShippingOption=s;const w=ie(se.selectedShippingOption);if(w){const{maxTransit:e,minTransit:t,unit:o}=w;se.selectedShippingOptionTransitTime=`${t}-${e} ${o}`}else se.selectedShippingOptionTransitTime="";const g=null===(r=se.landedCostData)||void 0===r?void 0:r.find((e=>e.landedCostId===n));if(se.selectedLandedCost=g||null,!g)return!1;const f=((null===(i=g.landedCost.amountSubtotals)||void 0===i?void 0:i.landedCostTotal)||0)*g.subtotals.exchangeRate.rate;f&&h(`DAP quote, using estimate: ${f}`,"info"),se.landedCostMethod=he(g.landedCost),se.shipping=g.subtotals.shipping;const b="ZONOS"===(null===(a=null==g?void 0:g.landedCost)||void 0===a?void 0:a.landedCostGuaranteeCode),S=!!(null===(l=null===(d=null==g?void 0:g.landedCost)||void 0===d?void 0:d.deMinimis)||void 0===l?void 0:l.find((e=>["DUTY","TAX"].includes(e.type)&&"ABOVE"===e.threshold)));se.isSelectedShippingAboveDeminimis=S,se.isSelectedShippingGuarantee=b;let C=!1;t?(ue({dutiesTaxesFeesEstimate:f,method:se.landedCostMethod,subtotals:g.subtotals}),h("Exchange rate updated for cart items (landed cost subtotal)","info",se.exchangeRate),C=!0):C=await ve({adjustmentsAmount:se.adjustmentTotal,billToPartyId:D.partyBillingId,cartId:window.Zonos.cartId,dutiesTaxesFeesEstimate:f,landedCostId:null===(c=g.landedCost)||void 0===c?void 0:c.id,shipToPartyId:D.partyShippingId,varianceTestInput:o.enabledVariantTestKeys||[]});const O=null===(u=se.items.find(Boolean))||void 0===u?void 0:u.currencyCode,A=(null===(m=D.stripeAddressEventData)||void 0===m?void 0:m.value.address.country)||"US";return D.shouldRenderPayInUsdButton="USD"===O&&"LOCAL_AND_USD"===e.checkoutSettings.allowedSettlementCurrencies&&"USD"!==(null===(p=se.checkoutSession)||void 0===p?void 0:p.subtotals.presentmentCurrencyCode)&&!!(null===(y=null===(v=e.genericSettings)||void 0===v?void 0:v.usdSettlementCountryEnabled)||void 0===y?void 0:y.includes(A)),C},we=({isPreview:e,sessionTimeout:t})=>{if(e)return;const o=new URLSearchParams(window.location.search).get("zonosCheckoutTimeout"),n=o&&!isNaN(parseInt(o,10))?parseInt(o,10):t;h(`==START CHECKOUT TIMEOUT - ${n}==`),se.checkoutTimeoutInterval=setTimeout((()=>{se.checkoutSessionTimeoutShow=!0}),n)},ge=()=>{se.checkoutTimeoutInterval&&(clearTimeout(se.checkoutTimeoutInterval),se.checkoutTimeoutInterval=null)},fe=()=>{se.items=se.items.map((e=>Object.assign(Object.assign({},e),{isRestricted:!1}))),se.restrictedItems=[]},be=async({adjustments:e,cartItems:t,landedCostId:n,shouldInitSessionOnFailure:s=!0})=>{var r;se.adjustments=e,se.items=t.map((e=>Object.assign(Object.assign({},e),{isRestricted:!1})));const i=null===(r=t.find(Boolean))||void 0===r?void 0:r.currencyCode,a=t.reduce(((e,t)=>e+t.amount*t.quantity),0),d=e.reduce(((e,t)=>e+t.amount),0);i&&a&&(se.currency=i,D.isFetchingSession=!0,await ve({adjustmentsAmount:d,billToPartyId:D.partyBillingId,cartId:window.Zonos.cartId,currency:i,dutiesTaxesFeesEstimate:0,itemsAmount:a,landedCostId:n,shipToPartyId:D.partyShippingId,shouldInitSessionOnFailure:s,varianceTestInput:o.enabledVariantTestKeys||[]}),D.isFetchingSession=!1)},Se=()=>{"shipping"===se.step?(se.step="customer-info",se.tabItems=Object.assign(Object.assign({},se.tabItems),{"customer-info":Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!1})})):"payment"===se.step?(se.step="shipping",se.tabItems=Object.assign(Object.assign({},se.tabItems),{shipping:Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!1})})):"finish"===se.step&&(se.step="payment",se.tabItems=Object.assign(Object.assign({},se.tabItems),{payment:Object.assign(Object.assign({},se.tabItems.payment),{isDone:!1})}))},Ce=()=>{"customer-info"===se.step?(se.step="shipping",se.tabItems=Object.assign(Object.assign({},se.tabItems),{"customer-info":Object.assign(Object.assign({},se.tabItems["customer-info"]),{isDone:!0})})):"shipping"===se.step?(se.step="payment",se.tabItems=Object.assign(Object.assign({},se.tabItems),{shipping:Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!0})})):"payment"===se.step&&(se.step="finish")},Oe=()=>{se.step="customer-info",se.tabItems=Object.assign(Object.assign({},se.tabItems),{"customer-info":Object.assign(Object.assign({},se.tabItems["customer-info"]),{isDone:!1}),payment:Object.assign(Object.assign({},se.tabItems.payment),{isDone:!1}),shipping:Object.assign(Object.assign({},se.tabItems.shipping),{isDone:!1})}),se.selectedShippingOption=null,se.isSelectedShippingAboveDeminimis=!1,se.isSelectedShippingGuarantee=!1,se.selectedShippingOptionTransitTime="",se.dutiesTaxesFees=0,se.dutiesTaxesFeesEstimate=0,se.shipping=0,se.total=se.subtotal};export{N as A,E as B,z as C,ye as D,me as E,M as F,$ as G,W as H,q as I,te as J,f as K,B as L,ie as M,he as N,I as O,L as a,x as b,D as c,K as d,se as e,be as f,le as g,Oe as h,U as i,ge as j,Q as k,Z as l,we as m,V as n,ce as o,pe as p,J as q,Ce as r,R as s,A as t,X as u,Y as v,G as w,H as x,_ as y,oe as z}
|