@zonos/elements 1.0.16 → 1.1.1

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.
Files changed (85) hide show
  1. package/dist/cjs/{cart-e27fd17c.js → cart-108bc407.js} +8 -1
  2. package/dist/cjs/cart-108bc407.js.map +1 -0
  3. package/dist/cjs/zonos-address_2.cjs.entry.js +1 -1
  4. package/dist/cjs/zonos-banner_2.cjs.entry.js +1 -1
  5. package/dist/cjs/zonos-cart-items_10.cjs.entry.js +5 -3
  6. package/dist/cjs/zonos-cart-items_10.cjs.entry.js.map +1 -1
  7. package/dist/cjs/zonos-checkout.cjs.entry.js +6 -2
  8. package/dist/cjs/zonos-checkout.cjs.entry.js.map +1 -1
  9. package/dist/cjs/zonos-controller.cjs.entry.js +1 -1
  10. package/dist/collection/components/checkout/zonos-checkout/zonos-cart-items/zonos-cart-items.js +3 -1
  11. package/dist/collection/components/checkout/zonos-checkout/zonos-cart-items/zonos-cart-items.js.map +1 -1
  12. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js +1 -1
  13. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js.map +1 -1
  14. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +5 -1
  15. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js.map +1 -1
  16. package/dist/collection/components/store/checkout/cart.js +6 -0
  17. package/dist/collection/components/store/checkout/cart.js.map +1 -1
  18. package/dist/collection/components/store/checkout/stripe.js +2 -0
  19. package/dist/collection/components/store/checkout/stripe.js.map +1 -1
  20. package/dist/collection/environment.js +9 -1
  21. package/dist/collection/environment.js.map +1 -1
  22. package/dist/collection/scripts/stripe.js +3 -3
  23. package/dist/collection/scripts/stripe.js.map +1 -1
  24. package/dist/collection/types/generated/graphql.customer.types.js +5 -0
  25. package/dist/collection/types/generated/graphql.customer.types.js.map +1 -1
  26. package/dist/components/stripe.js +8 -1
  27. package/dist/components/stripe.js.map +1 -1
  28. package/dist/components/zonos-cart-items2.js +3 -1
  29. package/dist/components/zonos-cart-items2.js.map +1 -1
  30. package/dist/components/zonos-checkout-finish2.js +1 -1
  31. package/dist/components/zonos-checkout-finish2.js.map +1 -1
  32. package/dist/components/zonos-checkout.js +5 -1
  33. package/dist/components/zonos-checkout.js.map +1 -1
  34. package/dist/esm/{cart-36c33342.js → cart-2f83e048.js} +8 -1
  35. package/dist/esm/cart-2f83e048.js.map +1 -0
  36. package/dist/esm/zonos-address_2.entry.js +1 -1
  37. package/dist/esm/zonos-banner_2.entry.js +1 -1
  38. package/dist/esm/zonos-cart-items_10.entry.js +5 -3
  39. package/dist/esm/zonos-cart-items_10.entry.js.map +1 -1
  40. package/dist/esm/zonos-checkout.entry.js +6 -2
  41. package/dist/esm/zonos-checkout.entry.js.map +1 -1
  42. package/dist/esm/zonos-controller.entry.js +1 -1
  43. package/dist/esm-es5/cart-2f83e048.js +2 -0
  44. package/dist/esm-es5/cart-2f83e048.js.map +1 -0
  45. package/dist/esm-es5/zonos-address_2.entry.js +1 -1
  46. package/dist/esm-es5/zonos-banner_2.entry.js +1 -1
  47. package/dist/esm-es5/zonos-cart-items_10.entry.js +1 -1
  48. package/dist/esm-es5/zonos-cart-items_10.entry.js.map +1 -1
  49. package/dist/esm-es5/zonos-checkout.entry.js +1 -1
  50. package/dist/esm-es5/zonos-checkout.entry.js.map +1 -1
  51. package/dist/esm-es5/zonos-controller.entry.js +1 -1
  52. package/dist/scripts/loadStripe.js +118 -0
  53. package/dist/scripts/loadZonos.js +300 -0
  54. package/dist/scripts/stripe.js +126 -0
  55. package/dist/scripts/zonos.js +300 -0
  56. package/dist/types/components/store/checkout/cart.d.ts +14 -0
  57. package/dist/types/components/store/checkout/stripe.d.ts +1 -1
  58. package/dist/types/types/generated/graphql.customer.types.d.ts +48 -0
  59. package/dist/types/types/generated/graphql.customer.types.ts +50 -0
  60. package/dist/zonos-elements/{cart-36c33342.js → cart-2f83e048.js} +8 -1
  61. package/dist/zonos-elements/cart-2f83e048.js.map +1 -0
  62. package/dist/zonos-elements/cart-9780fa28.system.js +2 -0
  63. package/dist/zonos-elements/cart-9780fa28.system.js.map +1 -0
  64. package/dist/zonos-elements/zonos-address_2.entry.js +1 -1
  65. package/dist/zonos-elements/zonos-address_2.system.entry.js +1 -1
  66. package/dist/zonos-elements/zonos-banner_2.entry.js +1 -1
  67. package/dist/zonos-elements/zonos-banner_2.system.entry.js +1 -1
  68. package/dist/zonos-elements/zonos-cart-items_10.entry.js +5 -3
  69. package/dist/zonos-elements/zonos-cart-items_10.entry.js.map +1 -1
  70. package/dist/zonos-elements/zonos-cart-items_10.system.entry.js +1 -1
  71. package/dist/zonos-elements/zonos-cart-items_10.system.entry.js.map +1 -1
  72. package/dist/zonos-elements/zonos-checkout.entry.js +6 -2
  73. package/dist/zonos-elements/zonos-checkout.entry.js.map +1 -1
  74. package/dist/zonos-elements/zonos-checkout.system.entry.js +1 -1
  75. package/dist/zonos-elements/zonos-checkout.system.entry.js.map +1 -1
  76. package/dist/zonos-elements/zonos-controller.entry.js +1 -1
  77. package/dist/zonos-elements/zonos-controller.system.entry.js +1 -1
  78. package/package.json +2 -2
  79. package/dist/cjs/cart-e27fd17c.js.map +0 -1
  80. package/dist/esm/cart-36c33342.js.map +0 -1
  81. package/dist/esm-es5/cart-36c33342.js +0 -2
  82. package/dist/esm-es5/cart-36c33342.js.map +0 -1
  83. package/dist/zonos-elements/cart-36c33342.js.map +0 -1
  84. package/dist/zonos-elements/cart-ecd9011b.system.js +0 -2
  85. package/dist/zonos-elements/cart-ecd9011b.system.js.map +0 -1
@@ -1,2 +0,0 @@
1
- var __awaiter=this&&this.__awaiter||function(e,t,r,n){function o(e){return e instanceof r?e:new r((function(t){t(e)}))}return new(r||(r=Promise))((function(r,i){function a(e){try{c(n.next(e))}catch(e){i(e)}}function s(e){try{c(n["throw"](e))}catch(e){i(e)}}function c(e){e.done?r(e.value):o(e.value).then(a,s)}c((n=n.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,a;return a={next:s(0),throw:s(1),return:s(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function s(e){return function(t){return c([e,t])}}function c(s){if(n)throw new TypeError("Generator is already executing.");while(a&&(a=0,s[0]&&(r=0)),r)try{if(n=1,o&&(i=s[0]&2?o["return"]:s[0]?o["throw"]||((i=o["return"])&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;if(o=0,i)s=[s[0]&2,i.value];switch(s[0]){case 0:case 1:i=s;break;case 4:r.label++;return{value:s[1],done:false};case 5:r.label++;o=s[1];s=[0];continue;case 7:s=r.ops.pop();r.trys.pop();continue;default:if(!(i=r.trys,i=i.length>0&&i[i.length-1])&&(s[0]===6||s[0]===2)){r=0;continue}if(s[0]===3&&(!i||s[1]>i[0]&&s[1]<i[3])){r.label=s[1];break}if(s[0]===6&&r.label<i[1]){r.label=i[1];i=s;break}if(i&&r.label<i[2]){r.label=i[2];r.ops.push(s);break}if(i[2])r.ops.pop();r.trys.pop();continue}s=t.call(e,r)}catch(e){s=[6,e];o=0}finally{n=i=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};import{c as createStore,z as zonosStore}from"./zonosStore-13a7b534.js";import{h as handleFetch,l as log,a as localizationStore,b as logError,t as translate}from"./localization-4a424f49.js";import{i as isDarkColor}from"./isDarkColor-b21326ae.js";import{g as getBorderRadius}from"./getBorderRadius-82fbaf25.js";var prepCalculateLandedCost=function(){var e=stripeStore.stripeLinkEventData;var t=stripeStore.stripeAddressEventData;if(!t||!t.complete){throw new Error("Missing stripe address data")}return{checkoutSessionId:cartStore.checkoutSessionId||"",contact:{email:(e===null||e===void 0?void 0:e.value.email)||"",firstName:t.value.firstName||"",lastName:t.value.lastName||"",phone:t.value.phone||""},items:cartStore.items.map((function(e){return{amount:e.amount,countryOfOrigin:e.countryOfOrigin,currencyCode:e.currencyCode,imageUrl:e.imageUrl,name:e.name,productId:e.productId,quantity:e.quantity}})),shippingAddress:{addressLine1:t.value.address.line1,addressLine2:t.value.address.line2||"",city:t.value.address.city,country:t.value.address.country,postalCode:t.value.address.postal_code,state:t.value.address.state}}};var calculateLandedCost=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t,r,n,o;return __generator(this,(function(i){switch(i.label){case 0:t="".concat("https://route.js.zonos.com","/api/calculate-landed-cost");return[4,handleFetch(t,{body:prepCalculateLandedCost(),method:"POST",signal:e===null||e===void 0?void 0:e.signal})];case 1:r=i.sent(),n=r.errors,o=r.json;if(n.length||!o){throw new Error("Failed to calculate landed cost")}return[2,o]}}))}))};var addressRuleStyle=function(e){var t=e.theme;switch(t){default:return{".Input":{padding:"0",paddingBottom:"8px",paddingLeft:"16px",paddingRight:"8px",paddingTop:"6px"}}}};var defaultVariable=function(e){var t=e.borderStyle,r=e.theme;switch(r){case"DARK":return{borderRadius:getBorderRadius(t),colorBackground:"#101117",colorBackgroundText:"#C5C6CA",colorText:"#C5C6CA",colorTextPlaceholder:"#C5C6CA"};default:return{borderRadius:getBorderRadius(t)}}};var _f=createStore((function(){return{clientSecret:sessionStorage.getItem("zonos--client-secret")||null,fetchingLandedCostAbordController:null,isFetchingLandedCost:false,isFetchingSession:false,stripe:null,stripeAddressElement:null,stripeAddressEventData:null,stripeAddressUsedWhenFetchingLC:null,stripeElements:null,stripeLinkElement:null,stripeLinkEventData:null,stripeLinkUsedWhenFetchingLC:null,stripePaymentElement:null,stripePaymentEventData:null}})),onChange$1=_f.onChange,reset$1=_f.reset,stripeStore=_f.state;var getStripeOptions=function(e){var t=e.clientSecret,r=e.overrideBorderRaidus,n=e.overridePrimaryColor,o=e.overrideTheme;var i=n||zonosStore.appearance.colorPrimary;var a=i&&isDarkColor(i)?"night":"flat";var s=o==="DARK"?"night":"flat";return{appearance:{labels:"floating",rules:Object.assign({},addressRuleStyle({theme:"LIGHT"})),theme:o?s:a,variables:Object.assign({},defaultVariable({borderStyle:r,theme:"LIGHT"}))},clientSecret:t,locale:localizationStore.selectedLocale}};var initStripeElements=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t,r,n;return __generator(this,(function(o){r=stripeStore.clientSecret;if(!stripeStore.stripe){log("Skip. Stripe is not initialized");return[2]}if(r){n=getStripeOptions({clientSecret:r,overrideBorderRaidus:e===null||e===void 0?void 0:e.overrideBorderRaidus,overridePrimaryColor:e===null||e===void 0?void 0:e.overridePrimaryColor,overrideTheme:e===null||e===void 0?void 0:e.overrideTheme});if(!stripeStore.stripeElements){stripeStore.stripeElements=(t=stripeStore.stripe)===null||t===void 0?void 0:t.elements(n)}else{stripeStore.stripeElements.update(n)}log("Stripe elements initialized")}return[2]}))}))};var stripeStoreReset=function(){sessionStorage.removeItem("zonos--client-secret");reset$1();stripeStore.stripe=window.Zonos.stripe};var isPrefetchInfoOutdated=function(){var e,t,r,n;var o=stripeStore.fetchingLandedCostAbordController;if(!o){return false}var i=JSON.stringify((e=stripeStore.stripeLinkUsedWhenFetchingLC)===null||e===void 0?void 0:e.value)!==JSON.stringify((t=stripeStore.stripeLinkEventData)===null||t===void 0?void 0:t.value);var a=JSON.stringify((r=stripeStore.stripeAddressUsedWhenFetchingLC)===null||r===void 0?void 0:r.value)!==JSON.stringify((n=stripeStore.stripeAddressEventData)===null||n===void 0?void 0:n.value);return i||a};var stripeStorePrefetchLandedCost=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,t,r,n,o,i,a,s,c,l,d,u,p,S;return __generator(this,(function(v){switch(v.label){case 0:o=!!((e=stripeStore.stripeAddressEventData)===null||e===void 0?void 0:e.complete);i=!!((t=stripeStore.stripeLinkEventData)===null||t===void 0?void 0:t.complete);a=isPrefetchInfoOutdated();if(a){(r=stripeStore.fetchingLandedCostAbordController)===null||r===void 0?void 0:r.abort();stripeStore.fetchingLandedCostAbordController=null}if(!(o&&i&&(a||!stripeStore.isFetchingLandedCost)))return[3,5];stripeStore.isFetchingLandedCost=true;if(stripeStore.stripeAddressEventData){stripeStore.stripeAddressUsedWhenFetchingLC=Object.assign({},stripeStore.stripeAddressEventData)}if(stripeStore.stripeLinkEventData){stripeStore.stripeLinkUsedWhenFetchingLC=Object.assign({},stripeStore.stripeLinkEventData)}v.label=1;case 1:v.trys.push([1,3,,4]);s=new AbortController;stripeStore.fetchingLandedCostAbordController=s;return[4,calculateLandedCost(s)];case 2:c=v.sent(),l=c.checkoutSessionWorkflow,d=c.shipmentRatingCalculateWorkflow;stripeStore.fetchingLandedCostAbordController=null;cartStore.landedCostData=(l===null||l===void 0?void 0:l.filter(Boolean))||null;cartStore.shippingData=(d===null||d===void 0?void 0:d.filter(Boolean))||null;u=(n=cartStore.landedCostData)===null||n===void 0?void 0:n.find(Boolean);p=!!u?u.subtotals:null;if(p){cartStoreApplySubtotals({items:p.items,landedCostTotal:0,presentmentCurrencyCode:p.presentmentCurrencyCode,shipping:0,total:p.items})}return[3,4];case 3:S=v.sent();logError(S);return[3,4];case 4:stripeStore.isFetchingLandedCost=false;v.label=5;case 5:return[2]}}))}))};var getStripeMessageBasedOnStatus=function(e){var t=[];var r=true;switch(e){case"succeeded":{t=[translate("Your payment went through successfully! Thank you for shopping with us! We hope you had an enjoyable experience and your support means the world to us."),"","",translate("We've sent an email confirmation of the order details for your review. And our team is carefully preparing your order so it arrives on time.")];r=false;break}case"requires_capture":case"processing":{t=[translate("Payment processing. We'll update you when payment is received.")];r=false;break}case"requires_payment_method":{t=[translate("Payment failed. Please try another payment method.")];break}default:{t=[translate("Something went wrong.")];break}}return{isError:r,messages:t}};var stripeStoreRetrievePayment=function(e){var t=e.clientSecret,r=e.storybookForceStatus;return __awaiter(void 0,void 0,void 0,(function(){var e,n,o,i,a,s,c,l,d;return __generator(this,(function(u){switch(u.label){case 0:if(r){e=getStripeMessageBasedOnStatus(r),n=e.isError,o=e.messages;return[2,{error:n,messages:o}]}i=t||stripeStore.clientSecret;if(!stripeStore.stripe||!i){logError("Failed to retrieve payment intent. Stripe is not initialized");return[2,{error:true,message:[translate("Something went wrong.")]}]}return[4,stripeStore.stripe.retrievePaymentIntent(i)];case 1:a=u.sent().paymentIntent;s=a===null||a===void 0?void 0:a.status;c=getStripeMessageBasedOnStatus(s),l=c.isError,d=c.messages;return[2,{error:l,messages:d}]}}))}))};var stripeStoreConfirmPayment=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,t,r,n,o,i,a,s;return __generator(this,(function(c){switch(c.label){case 0:n=!!((e=stripeStore.stripePaymentEventData)===null||e===void 0?void 0:e.complete);o=stripeStore.stripeElements;i=stripeStore.stripe;a=stripeStore.clientSecret;if(!(i&&o&&n&&a))return[3,2];return[4,i.confirmPayment({confirmParams:{receipt_email:(r=(t=stripeStore.stripeLinkEventData)===null||t===void 0?void 0:t.value)===null||r===void 0?void 0:r.email,return_url:window.location.href},elements:o,redirect:"if_required"})];case 1:s=c.sent().error;if(s){if(s.type==="card_error"||s.type==="validation_error"){throw new Error(s.message)}if(s.type==="invalid_request_error"){if(s.code==="payment_intent_unexpected_state"){return[2]}}throw new Error("An unexpected error occurred.")}c.label=2;case 2:return[2]}}))}))};var stripeStoreInitCheckoutSession=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,t,r,n,o,i;return __generator(this,(function(a){switch(a.label){case 0:t=cartStore.items.reduce((function(e,t){return e+t.amount*t.quantity}),0);if(!t||!localizationStore.targetCurrency){logError("Fail to create checkout session - invalid total or currency");return[2,false]}stripeStore.isFetchingSession=true;return[4,handleFetch("".concat("https://route.js.zonos.com","/api/create-checkout-session"),{body:{currency:((e=cartStore.items.find(Boolean))===null||e===void 0?void 0:e.currencyCode)||"",itemsAmount:t,presentmentCountryCode:localizationStore.selectedCountryCode||null},method:"POST"})];case 1:r=a.sent(),n=r.errors,o=r.json;stripeStore.isFetchingSession=false;if(n.length||!o){logError("Error occurs when creating checkout session",JSON.stringify(n,null,2));return[2,false]}i=o.checkoutSessionCreate;stripeStore.clientSecret=i.clientSecret;cartStore.checkoutSessionId=i.id;cartStoreApplySubtotals(Object.assign(Object.assign({},i.subtotals),{landedCostTotal:0,shipping:0,total:i.subtotals.items}));log("done-init-checkout-session");return[2,true]}}))}))};var stripeStoreUpdateCheckoutSession=function(e){var t=e.currency,r=e.id,n=e.itemsAmount,o=e.landedCostId,i=e.presentmentCountryCode;return __awaiter(void 0,void 0,void 0,(function(){var e,a,s;return __generator(this,(function(c){switch(c.label){case 0:return[4,handleFetch("".concat("https://route.js.zonos.com","/api/update-checkout-session"),{body:{currency:t,id:r,itemsAmount:n,landedCostId:o,presentmentCountryCode:i},method:"POST"})];case 1:e=c.sent(),a=e.errors,s=e.json;if(a.length||!s){logError("Error occurs when updating checkout session",JSON.stringify(a,null,2));return[2,{errors:a,json:s}]}return[2,{errors:[],json:s}]}}))}))};onChange$1("clientSecret",(function(e){if(e&&stripeStore.stripe){sessionStorage.setItem("zonos--client-secret",e)}if(!e){sessionStorage.removeItem("zonos--client-secret")}}));var formatDate=function(e){var t=e.date,r=e.formatOptions,n=r===void 0?{day:"numeric",weekday:"long",year:"numeric"}:r;return new Intl.DateTimeFormat("en-US",n).format(t)};var getDaysDifference=function(e){var t=new Date;var r=e.getTime()-t.getTime();var n=Math.floor(r/(1e3*60*60*24));return n};var _g=createStore((function(){return{checkoutSessionId:sessionStorage.getItem("zonos--checkout-session-id")||null,currency:"USD",dutiesTaxFees:0,error:null,isSelectedShippingAboveDeminimis:false,isSelectedShippingGuarantee:false,items:[],landedCostData:null,selectedLandedCost:null,selectedShippingOption:null,selectedShippingOptionExpectedDate:"",selectedShippingOptionTransitTime:"",shipping:0,shippingData:null,step:"customer-info",subtotal:0,total:0}})),onChange=_g.onChange,reset=_g.reset,cartStore=_g.state;var cartStoreGetShippingTransitInfo=function(e){var t=e.minTransitAt?getDaysDifference(new Date(e.minTransitAt)):"";var r=e.maxTransitAt?getDaysDifference(new Date(e.maxTransitAt)):"";var n=e.minTransitAt?formatDate({date:new Date(e.minTransitAt)}):"";return{expectedDate:n,maxTransit:r,minTransit:t}};var cartStoreReset=function(){sessionStorage.removeItem("zonos--checkout-session-id");reset()};var cartStoreUpdateToErrorState=function(e){var t=e.messages,r=e.title;cartStore.step="error";cartStore.error={messages:t,title:r}};var cartStoreApplySubtotals=function(e){cartStore.dutiesTaxFees=e.landedCostTotal;cartStore.subtotal=e.items;cartStore.total=e.total;cartStore.currency=e.presentmentCurrencyCode};var cartStoreReCalculateTotal=function(e){var t=e.currency,r=e.itemsAmount,n=e.landedCostId;return __awaiter(void 0,void 0,void 0,(function(){var e,o;return __generator(this,(function(i){switch(i.label){case 0:if(n&&cartStore.selectedLandedCost){e=cartStore.selectedLandedCost.subtotals;cartStoreApplySubtotals(e)}if(!cartStore.checkoutSessionId){logError("Could update cart total without checkout session id");return[2,false]}return[4,stripeStoreUpdateCheckoutSession({currency:t,id:cartStore.checkoutSessionId,itemsAmount:r,landedCostId:n,presentmentCountryCode:localizationStore.selectedCountryCode})];case 1:o=i.sent().json;if(!o){logError("Error occurs when updating checkout session");cartStoreUpdateToErrorState({messages:[translate("There's been an error updating your checkout session. Please reload and try again or contact support if the error persists")],title:translate("Error updating Checkout")});return[2,false]}if(!n){cartStoreApplySubtotals(o.checkoutSessionUpdate.subtotals)}return[2,true]}}))}))};var cartStoreUpdateSelectedShippingOption=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t,r,n,o,i,a,s,c,l,d,u,p,S;return __generator(this,(function(v){switch(v.label){case 0:cartStore.selectedShippingOption=e;a=cartStoreGetShippingTransitInfo(cartStore.selectedShippingOption),s=a.expectedDate,c=a.maxTransit,l=a.minTransit;cartStore.selectedShippingOptionExpectedDate=s;cartStore.selectedShippingOptionTransitTime=l&&c?"".concat(l,"-").concat(c):"".concat(l||c);d=(t=cartStore.landedCostData)===null||t===void 0?void 0:t.find((function(e){var t,r,n;return((r=(t=e.landedCost)===null||t===void 0?void 0:t.shipmentRating)===null||r===void 0?void 0:r.id)===((n=cartStore.selectedShippingOption)===null||n===void 0?void 0:n.id)}));cartStore.selectedLandedCost=d||null;if(!d){return[2,false]}cartStore.shipping=d.subtotals.shipping;u=((r=d===null||d===void 0?void 0:d.landedCost)===null||r===void 0?void 0:r.landedCostGuaranteeCode)==="ZONOS";p=!!((o=(n=d===null||d===void 0?void 0:d.landedCost)===null||n===void 0?void 0:n.deMinimis)===null||o===void 0?void 0:o.find((function(e){return["DUTY","TAX"].includes(e.type)&&e.threshold==="ABOVE"})));cartStore.isSelectedShippingAboveDeminimis=p;cartStore.isSelectedShippingGuarantee=u;return[4,cartStoreReCalculateTotal({landedCostId:(i=d.landedCost)===null||i===void 0?void 0:i.id})];case 1:S=v.sent();return[2,S]}}))}))};onChange("checkoutSessionId",(function(){if(!cartStore.checkoutSessionId){sessionStorage.removeItem("zonos--checkout-session-id");return}sessionStorage.setItem("zonos--checkout-session-id",cartStore.checkoutSessionId)}));var cartStoreUpdateItems=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t,r,n;return __generator(this,(function(o){switch(o.label){case 0:cartStore.items=e;r=(t=e.find(Boolean))===null||t===void 0?void 0:t.currencyCode;n=e.reduce((function(e,t){return e+t.amount*t.quantity}),0);if(!r||!n){return[2]}cartStore.currency=r;stripeStore.isFetchingSession=true;return[4,cartStoreReCalculateTotal({currency:r,itemsAmount:n})];case 1:o.sent();stripeStore.isFetchingSession=false;return[2]}}))}))};var cartStoreResetSelectedShippingOption=function(){cartStore.selectedShippingOption=null;cartStore.isSelectedShippingAboveDeminimis=false;cartStore.isSelectedShippingGuarantee=false;cartStore.selectedShippingOptionExpectedDate="";cartStore.selectedShippingOptionTransitTime="";cartStore.shipping=0};var cartStoreNextStep=function(){if(cartStore.step==="customer-info"){cartStore.step="shipping"}else if(cartStore.step==="shipping"){cartStore.step="payment"}else if(cartStore.step==="payment"){cartStore.step="finish"}};var cartStorePreviousStep=function(){if(cartStore.step==="payment"){cartStore.step="shipping"}else if(cartStore.step==="shipping"){cartStore.step="customer-info";cartStoreResetSelectedShippingOption()}};export{cartStoreUpdateItems as a,cartStoreReset as b,cartStore as c,stripeStoreInitCheckoutSession as d,cartStoreUpdateToErrorState as e,stripeStorePrefetchLandedCost as f,cartStoreNextStep as g,stripeStoreConfirmPayment as h,initStripeElements as i,stripeStoreReset as j,cartStorePreviousStep as k,stripeStoreRetrievePayment as l,cartStoreUpdateSelectedShippingOption as m,cartStoreGetShippingTransitInfo as n,stripeStore as s};
2
- //# sourceMappingURL=cart-36c33342.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["prepCalculateLandedCost","stripeLinkData","stripeStore","stripeLinkEventData","stripeAddressData","stripeAddressEventData","complete","Error","checkoutSessionId","cartStore","contact","email","value","firstName","lastName","phone","items","map","item","amount","countryOfOrigin","currencyCode","imageUrl","name","productId","quantity","shippingAddress","addressLine1","address","line1","addressLine2","line2","city","country","postalCode","postal_code","state","calculateLandedCost","abortController","__awaiter","url","concat","handleFetch","body","method","signal","_f","_g","sent","errors","json","length","addressRuleStyle","theme","padding","paddingBottom","paddingLeft","paddingRight","paddingTop","defaultVariable","borderStyle","borderRadius","getBorderRadius","colorBackground","colorBackgroundText","colorText","colorTextPlaceholder","createStore","clientSecret","sessionStorage","getItem","fetchingLandedCostAbordController","isFetchingLandedCost","isFetchingSession","stripe","stripeAddressElement","stripeAddressUsedWhenFetchingLC","stripeElements","stripeLinkElement","stripeLinkUsedWhenFetchingLC","stripePaymentElement","stripePaymentEventData","onChange","reset","getStripeOptions","overrideBorderRaidus","overridePrimaryColor","overrideTheme","primaryColor","zonosStore","appearance","colorPrimary","themeBasedColor","isDarkColor","labels","rules","Object","assign","variables","locale","localizationStore","selectedLocale","initStripeElements","props","log","stripeOptions","_a","elements","update","stripeStoreReset","removeItem","window","Zonos","isPrefetchInfoOutdated","hasAbortController","isLinkDataDirty","JSON","stringify","_b","isAddressDataDirty","_c","_d","stripeStorePrefetchLandedCost","stripeAddressReady","stripeLinkReady","shouldRefetch","abort","AbortController","checkoutSessionWorkflow","shipmentRatingCalculateWorkflow","landedCostData","filter","Boolean","shippingData","firstLandedCostData","find","subtotals","cartStoreApplySubtotals","landedCostTotal","presentmentCurrencyCode","shipping","total","logError","err_1","getStripeMessageBasedOnStatus","status","messages","isError","translate","stripeStoreRetrievePayment","_clientSecret","storybookForceStatus","isError_1","messages_1","error","message","retrievePaymentIntent","paymentIntent","_j","_h","stripeStoreConfirmPayment","stripePaymentReady","stripeClientSecret","confirmPayment","confirmParams","receipt_email","return_url","location","href","redirect","type","code","stripeStoreInitCheckoutSession","reduce","targetCurrency","currency","itemsAmount","presentmentCountryCode","selectedCountryCode","result","checkoutSessionCreate","id","stripeStoreUpdateCheckoutSession","landedCostId","setItem","formatDate","date","formatOptions","day","weekday","year","Intl","DateTimeFormat","format","getDaysDifference","targetDate","currentDate","Date","timeDifference","getTime","daysDifference","Math","floor","dutiesTaxFees","isSelectedShippingAboveDeminimis","isSelectedShippingGuarantee","selectedLandedCost","selectedShippingOption","selectedShippingOptionExpectedDate","selectedShippingOptionTransitTime","step","subtotal","cartStoreGetShippingTransitInfo","minTransit","minTransitAt","maxTransit","maxTransitAt","expectedDate","cartStoreReset","cartStoreUpdateToErrorState","title","cartStoreReCalculateTotal","checkoutSessionUpdate","cartStoreUpdateSelectedShippingOption","checkoutSessionPresentment","landedCost","shipmentRating","isGuarantee","landedCostGuaranteeCode","isAboveDeminimis","deMinimis","includes","threshold","_e","updateCalulateStatus","cartStoreUpdateItems","amt","cartStoreResetSelectedShippingOption","cartStoreNextStep","cartStorePreviousStep"],"sources":["src/components/utils/api/prepCalculateLandedCost.ts","src/components/utils/api/calculateLandedCost.ts","src/styles/stripe/addressRuleStyle.ts","src/styles/stripe/defaultVariable.ts","src/components/store/checkout/stripe.ts","src/components/utils/formatDate.ts","src/components/utils/getDaysDifference.ts","src/components/store/checkout/cart.ts"],"sourcesContent":["import { cartStore } from 'src/components/store/checkout/cart';\nimport { stripeStore } from 'src/components/store/checkout/stripe';\nimport type { CalculateLandedCostRequest } from 'src/types/checkout/api/CalculateLandedCostRequest';\n\nexport const prepCalculateLandedCost = (): CalculateLandedCostRequest => {\n // maybe we don't need email now for prefetch the landed cost\n const stripeLinkData = stripeStore.stripeLinkEventData;\n\n const stripeAddressData = stripeStore.stripeAddressEventData;\n if (!stripeAddressData || !stripeAddressData.complete) {\n throw new Error('Missing stripe address data');\n }\n\n return {\n checkoutSessionId: cartStore.checkoutSessionId || '',\n contact: {\n email: stripeLinkData?.value.email || '',\n // firstName and lastName should be valid now since stripe only mark\n // the address as complete when both fields are filled.\n firstName: stripeAddressData.value.firstName || '',\n lastName: stripeAddressData.value.lastName || '',\n phone: stripeAddressData.value.phone || '',\n },\n items: cartStore.items.map(item => ({\n amount: item.amount,\n countryOfOrigin: item.countryOfOrigin,\n currencyCode: item.currencyCode,\n imageUrl: item.imageUrl,\n name: item.name,\n productId: item.productId,\n quantity: item.quantity,\n })),\n shippingAddress: {\n addressLine1: stripeAddressData.value.address.line1,\n addressLine2: stripeAddressData.value.address.line2 || '',\n city: stripeAddressData.value.address.city,\n country: stripeAddressData.value.address.country,\n postalCode: stripeAddressData.value.address.postal_code,\n state: stripeAddressData.value.address.state,\n },\n };\n};\n","import { prepCalculateLandedCost } from 'src/components/utils/api/prepCalculateLandedCost';\nimport { handleFetch } from 'src/components/utils/handleFetch';\nimport type { CalculateLandedCostRequest } from 'src/types/checkout/api/CalculateLandedCostRequest';\nimport type { CalculateLandedCostMutation } from 'src/types/generated/graphql.customer.types';\n\nexport const calculateLandedCost = async (\n abortController?: AbortController,\n) => {\n // request to get landed cost info\n const url = `${process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL}/api/calculate-landed-cost`;\n const { errors, json } = await handleFetch<\n CalculateLandedCostMutation,\n CalculateLandedCostRequest\n >(url, {\n body: prepCalculateLandedCost(),\n method: 'POST',\n signal: abortController?.signal,\n });\n if (errors.length || !json) {\n throw new Error('Failed to calculate landed cost');\n }\n\n return json;\n};\n","import type { ElementsUiTheme, StripeRuleType } from 'src/types';\n\nexport const addressRuleStyle = ({\n theme,\n}: {\n theme: ElementsUiTheme;\n}): StripeRuleType => {\n switch (theme) {\n default:\n return {\n '.Input': {\n // need to reset everything and the paddingTop to default, otherwise the paddingTop will not be updated.\n padding: '0',\n paddingBottom: '8px',\n paddingLeft: '16px',\n paddingRight: '8px',\n // any value here will be add up to the default paddingTop (20px).\n paddingTop: '6px',\n },\n };\n }\n};\n","import type { Appearance } from '@stripe/stripe-js';\n\nimport { getBorderRadius } from 'src/components/utils/getBorderRadius';\nimport type {\n ElementsUiStyle,\n ElementsUiTheme,\n} from 'src/types/generated/graphql.customer.types';\n\nexport const defaultVariable = ({\n borderStyle,\n theme,\n}: {\n borderStyle?: ElementsUiStyle;\n theme: ElementsUiTheme;\n}): Appearance['variables'] => {\n switch (theme) {\n case 'DARK':\n return {\n borderRadius: getBorderRadius(borderStyle),\n colorBackground: '#101117',\n colorBackgroundText: '#C5C6CA',\n colorText: '#C5C6CA',\n colorTextPlaceholder: '#C5C6CA',\n };\n default:\n return {\n borderRadius: getBorderRadius(borderStyle),\n };\n }\n};\n","import { createStore } from '@stencil/store';\nimport type {\n PaymentIntent,\n Stripe,\n StripeAddressElement,\n StripeAddressElementChangeEvent,\n StripeElements,\n StripeElementsOptionsClientSecret,\n StripeLinkAuthenticationElement,\n StripeLinkAuthenticationElementChangeEvent,\n StripePaymentElement,\n StripePaymentElementChangeEvent,\n} from '@stripe/stripe-js';\n\nimport {\n cartStore,\n cartStoreApplySubtotals,\n} from 'src/components/store/checkout/cart';\nimport { localizationStore } from 'src/components/store/hello/localization';\nimport { translate } from 'src/components/store/translationStore';\nimport { zonosStore } from 'src/components/store/zonosStore';\nimport { calculateLandedCost } from 'src/components/utils/api/calculateLandedCost';\nimport { handleFetch } from 'src/components/utils/handleFetch';\nimport { isDarkColor } from 'src/components/utils/isDarkColor';\nimport { log } from 'src/components/utils/logging/log';\nimport { logError } from 'src/components/utils/logging/logError';\nimport { addressRuleStyle } from 'src/styles/stripe/addressRuleStyle';\nimport { defaultVariable } from 'src/styles/stripe/defaultVariable';\nimport type {\n CheckoutSessionCreateMutation,\n CheckoutSessionUpdateMutation,\n CountryCode,\n ElementsUiStyle,\n ElementsUiTheme,\n} from 'src/types/generated/graphql.customer.types';\n\nexport type ContactOption = {\n address: {\n city: string;\n country: string;\n line1: string;\n line2?: string;\n postal_code: string;\n state: string;\n };\n name: string;\n phone?: string;\n};\n\ntype StripeStore = {\n // client secret is used to render link and payment elements\n clientSecret: string | null;\n fetchingLandedCostAbordController: AbortController | null;\n // toggle to indicate if we are pre-fetching/fetching landed cost\n isFetchingLandedCost: boolean;\n // toggle to indicate if we are fetching checkout session\n isFetchingSession: boolean;\n stripe: Stripe | null;\n stripeAddressElement: StripeAddressElement | null;\n stripeAddressEventData: StripeAddressElementChangeEvent | null;\n stripeAddressUsedWhenFetchingLC: StripeAddressElementChangeEvent | null;\n stripeElements: StripeElements | null;\n stripeLinkElement: StripeLinkAuthenticationElement | null;\n stripeLinkEventData: StripeLinkAuthenticationElementChangeEvent | null;\n stripeLinkUsedWhenFetchingLC: StripeLinkAuthenticationElementChangeEvent | null;\n stripePaymentElement: StripePaymentElement | null;\n stripePaymentEventData: StripePaymentElementChangeEvent | null;\n};\n\nconst {\n onChange,\n reset,\n state: stripeStore,\n} = createStore<StripeStore>(() => ({\n clientSecret: sessionStorage.getItem('zonos--client-secret') || null,\n fetchingLandedCostAbordController: null,\n isFetchingLandedCost: false,\n isFetchingSession: false,\n stripe: null,\n stripeAddressElement: null,\n stripeAddressEventData: null,\n stripeAddressUsedWhenFetchingLC: null,\n stripeElements: null,\n stripeLinkElement: null,\n stripeLinkEventData: null,\n stripeLinkUsedWhenFetchingLC: null,\n stripePaymentElement: null,\n stripePaymentEventData: null,\n}));\n\nconst getStripeOptions = ({\n clientSecret,\n overrideBorderRaidus,\n overridePrimaryColor,\n overrideTheme,\n}: {\n clientSecret?: string;\n overrideBorderRaidus?: ElementsUiStyle;\n overridePrimaryColor?: string;\n overrideTheme?: ElementsUiTheme;\n}): StripeElementsOptionsClientSecret => {\n const primaryColor =\n overridePrimaryColor || zonosStore.appearance.colorPrimary;\n const themeBasedColor =\n primaryColor && isDarkColor(primaryColor) ? 'night' : 'flat';\n // if overrideTheme is provided, use it. Otherwise, use theme based on primary color\n const theme = overrideTheme === 'DARK' ? 'night' : 'flat';\n return {\n appearance: {\n labels: 'floating',\n rules: {\n ...addressRuleStyle({ theme: 'LIGHT' }),\n },\n // get contrast theme color base on primary color\n theme: overrideTheme ? theme : themeBasedColor,\n variables: {\n ...defaultVariable({\n borderStyle: overrideBorderRaidus,\n theme: 'LIGHT',\n }),\n },\n },\n clientSecret,\n locale: localizationStore.selectedLocale,\n };\n};\n\nconst initStripeElements = async (props?: {\n overrideBorderRaidus?: ElementsUiStyle;\n overridePrimaryColor?: string;\n overrideTheme?: ElementsUiTheme;\n}) => {\n const clientSecret = stripeStore.clientSecret;\n\n if (!stripeStore.stripe) {\n log('Skip. Stripe is not initialized');\n return;\n }\n if (clientSecret) {\n const stripeOptions = getStripeOptions({\n clientSecret,\n overrideBorderRaidus: props?.overrideBorderRaidus,\n overridePrimaryColor: props?.overridePrimaryColor,\n overrideTheme: props?.overrideTheme,\n });\n\n if (!stripeStore.stripeElements) {\n // init stripe elements if it doesn't exist\n stripeStore.stripeElements = stripeStore.stripe?.elements(stripeOptions);\n } else {\n // update elements with new option if it already exists\n stripeStore.stripeElements.update(stripeOptions);\n }\n log('Stripe elements initialized');\n }\n};\n\nconst stripeStoreReset = () => {\n // clean clientSecret so that we can start the new one.\n sessionStorage.removeItem('zonos--client-secret');\n\n // cleanup stripe elements\n reset();\n // set stripe back to window.Zonos.stripe\n stripeStore.stripe = window.Zonos.stripe;\n};\n\n/**\n * Check if the address and email info used when fetching landed cost with the current email and address info are different\n * Purpose is to resend the request if the info used when fetching landed cost is different from the current info\n */\nconst isPrefetchInfoOutdated = () => {\n const hasAbortController = stripeStore.fetchingLandedCostAbordController;\n if (!hasAbortController) {\n // if there is no abort controller, this is a new request\n return false;\n }\n\n const isLinkDataDirty =\n JSON.stringify(stripeStore.stripeLinkUsedWhenFetchingLC?.value) !==\n JSON.stringify(stripeStore.stripeLinkEventData?.value);\n const isAddressDataDirty =\n JSON.stringify(stripeStore.stripeAddressUsedWhenFetchingLC?.value) !==\n JSON.stringify(stripeStore.stripeAddressEventData?.value);\n\n return isLinkDataDirty || isAddressDataDirty;\n};\n\nconst stripeStorePrefetchLandedCost = async () => {\n const stripeAddressReady = !!stripeStore.stripeAddressEventData?.complete;\n const stripeLinkReady = !!stripeStore.stripeLinkEventData?.complete;\n const shouldRefetch = isPrefetchInfoOutdated();\n\n if (shouldRefetch) {\n // if the info used when fetching landed cost is different from the current info, abort the previous request\n stripeStore.fetchingLandedCostAbordController?.abort();\n stripeStore.fetchingLandedCostAbordController = null;\n }\n\n // only fetch if we are not fetching or we need to refetch\n if (\n stripeAddressReady &&\n stripeLinkReady &&\n (shouldRefetch || !stripeStore.isFetchingLandedCost)\n ) {\n stripeStore.isFetchingLandedCost = true;\n if (stripeStore.stripeAddressEventData) {\n stripeStore.stripeAddressUsedWhenFetchingLC = {\n ...stripeStore.stripeAddressEventData,\n };\n }\n if (stripeStore.stripeLinkEventData) {\n stripeStore.stripeLinkUsedWhenFetchingLC = {\n ...stripeStore.stripeLinkEventData,\n };\n }\n try {\n const abortController = new AbortController();\n stripeStore.fetchingLandedCostAbordController = abortController;\n const { checkoutSessionWorkflow, shipmentRatingCalculateWorkflow } =\n await calculateLandedCost(abortController);\n\n // reset abort controller after we are done\n stripeStore.fetchingLandedCostAbordController = null;\n\n // update cart store with landed cost info\n cartStore.landedCostData =\n checkoutSessionWorkflow?.filter(Boolean) || null;\n\n cartStore.shippingData =\n shipmentRatingCalculateWorkflow?.filter(Boolean) || null;\n // apply new subtotal and total, this is mainly to show items in the presentment currency\n const firstLandedCostData = cartStore.landedCostData?.find(Boolean);\n const subtotals = !!firstLandedCostData\n ? firstLandedCostData.subtotals\n : null;\n if (subtotals) {\n // prefetch landed cost will not update shipping and taxes since we haven't selected shipping method yet\n cartStoreApplySubtotals({\n items: subtotals.items,\n landedCostTotal: 0,\n presentmentCurrencyCode: subtotals.presentmentCurrencyCode,\n shipping: 0,\n total: subtotals.items,\n });\n }\n } catch (err) {\n logError(err);\n }\n stripeStore.isFetchingLandedCost = false;\n }\n};\n\nconst getStripeMessageBasedOnStatus = (status?: PaymentIntent['status']) => {\n let messages: string[] = [];\n let isError = true;\n // Inspect the PaymentIntent `status` to indicate the status of the payment\n // to your customer.\n //\n // Some payment methods will [immediately succeed or fail][0] upon\n // confirmation, while others will first enter a `processing` state.\n //\n // [0]: https://stripe.com/docs/payments/payment-methods#payment-notification\n switch (status) {\n case 'succeeded': {\n messages = [\n translate(\n '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.',\n ),\n '',\n '',\n translate(\n \"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 ),\n ];\n isError = false;\n break;\n }\n case 'requires_capture':\n case 'processing': {\n messages = [\n translate(\n \"Payment processing. We'll update you when payment is received.\",\n ),\n ];\n isError = false;\n break;\n }\n\n case 'requires_payment_method': {\n messages = [\n translate('Payment failed. Please try another payment method.'),\n ];\n break;\n }\n\n default: {\n messages = [translate('Something went wrong.')];\n break;\n }\n }\n return {\n isError,\n messages,\n };\n};\n\nconst stripeStoreRetrievePayment = async ({\n clientSecret: _clientSecret,\n storybookForceStatus,\n}: {\n clientSecret?: string;\n storybookForceStatus?: PaymentIntent['status'];\n}) => {\n if (storybookForceStatus) {\n // return status right away if we are in storybook mode\n const { isError, messages } =\n getStripeMessageBasedOnStatus(storybookForceStatus);\n\n return { error: isError, messages };\n }\n const clientSecret = _clientSecret || stripeStore.clientSecret;\n if (!stripeStore.stripe || !clientSecret) {\n logError('Failed to retrieve payment intent. Stripe is not initialized');\n return { error: true, message: [translate('Something went wrong.')] };\n }\n const { paymentIntent } = await stripeStore.stripe.retrievePaymentIntent(\n clientSecret,\n );\n\n const status = paymentIntent?.status;\n\n const { isError, messages } = getStripeMessageBasedOnStatus(status);\n\n return { error: isError, messages };\n};\n\nconst stripeStoreConfirmPayment = async () => {\n const stripePaymentReady = !!stripeStore.stripePaymentEventData?.complete;\n const stripeElements = stripeStore.stripeElements;\n const stripe = stripeStore.stripe;\n const stripeClientSecret = stripeStore.clientSecret;\n if (stripe && stripeElements && stripePaymentReady && stripeClientSecret) {\n const { error } = await stripe.confirmPayment({\n confirmParams: {\n receipt_email: stripeStore.stripeLinkEventData?.value?.email,\n return_url: window.location.href,\n },\n elements: stripeElements,\n redirect: 'if_required',\n });\n\n if (error) {\n if (error.type === 'card_error' || error.type === 'validation_error') {\n throw new Error(error.message);\n }\n if (error.type === 'invalid_request_error') {\n if (error.code === 'payment_intent_unexpected_state') {\n // PaymentIntent was canceled or expired, or status is `require_capture`.\n // don't throw error here because we will reset the checkout session last step\n return;\n }\n }\n throw new Error('An unexpected error occurred.');\n }\n }\n};\n\ntype CheckoutSessionCreateRequest = {\n currency: string;\n itemsAmount: number;\n presentmentCountryCode: CountryCode | null;\n};\n\n/**\n * Init checkout session\n * @returns {boolean} whether or not the checkout session is successfully created\n */\nconst stripeStoreInitCheckoutSession = async () => {\n const total = cartStore.items.reduce(\n (amount, item) => amount + item.amount * item.quantity,\n 0,\n );\n\n if (!total || !localizationStore.targetCurrency) {\n logError('Fail to create checkout session - invalid total or currency');\n return false;\n }\n\n stripeStore.isFetchingSession = true;\n\n const { errors, json } = await handleFetch<\n CheckoutSessionCreateMutation,\n CheckoutSessionCreateRequest\n >(`${process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL}/api/create-checkout-session`, {\n body: {\n currency: cartStore.items.find(Boolean)?.currencyCode || '',\n itemsAmount: total,\n presentmentCountryCode: localizationStore.selectedCountryCode || null,\n },\n method: 'POST',\n });\n\n stripeStore.isFetchingSession = false;\n\n if (errors.length || !json) {\n logError(\n 'Error occurs when creating checkout session',\n JSON.stringify(errors, null, 2),\n );\n\n return false;\n }\n const result = json.checkoutSessionCreate;\n\n stripeStore.clientSecret = result.clientSecret;\n // update cart store with updated informations\n cartStore.checkoutSessionId = result.id;\n cartStoreApplySubtotals({\n ...result.subtotals,\n landedCostTotal: 0,\n shipping: 0,\n total: result.subtotals.items,\n });\n\n log('done-init-checkout-session');\n return true;\n};\n\ntype CheckoutSessionUpdateRequest = {\n currency?: string;\n id: string;\n itemsAmount?: number;\n landedCostId?: string;\n presentmentCountryCode: CountryCode | null;\n};\n/**\n * Update checkout session. Use for updating amount with landed cost id, or update session when cart items change\n */\nconst stripeStoreUpdateCheckoutSession = async ({\n currency,\n id,\n itemsAmount,\n landedCostId,\n presentmentCountryCode,\n}: CheckoutSessionUpdateRequest) => {\n // No need to set loading state here because this function will be called under the hood to update\n // landed cost id for the section.\n const { errors, json } = await handleFetch<\n CheckoutSessionUpdateMutation,\n CheckoutSessionUpdateRequest\n >(`${process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL}/api/update-checkout-session`, {\n body: {\n currency,\n id,\n itemsAmount,\n landedCostId,\n presentmentCountryCode,\n },\n method: 'POST',\n });\n\n if (errors.length || !json) {\n logError(\n 'Error occurs when updating checkout session',\n JSON.stringify(errors, null, 2),\n );\n return { errors, json };\n }\n\n return { errors: [], json };\n};\n\nonChange('clientSecret', clientSecret => {\n // update stripe elements when client secret changes\n if (clientSecret && stripeStore.stripe) {\n sessionStorage.setItem('zonos--client-secret', clientSecret);\n }\n\n if (!clientSecret) {\n sessionStorage.removeItem('zonos--client-secret');\n }\n});\n\nexport {\n initStripeElements,\n stripeStore,\n stripeStoreConfirmPayment,\n stripeStoreInitCheckoutSession,\n stripeStorePrefetchLandedCost,\n stripeStoreReset,\n stripeStoreRetrievePayment,\n stripeStoreUpdateCheckoutSession,\n};\n","type Params = {\n date: Date;\n /**\n * Format options for Intl.DateTimeFormat\n * @default {day:'numeric',weekday:'long',year:'numeric'} Thursday 3, 2023\n */\n formatOptions?: Intl.DateTimeFormatOptions;\n};\n\nexport const formatDate = ({\n date,\n formatOptions = { day: 'numeric', weekday: 'long', year: 'numeric' },\n}: Params): string => {\n // format date to Thursday 3, 2023\n return new Intl.DateTimeFormat('en-US', formatOptions).format(date);\n};\n","export const getDaysDifference = (targetDate: Date) => {\n const currentDate = new Date();\n const timeDifference = targetDate.getTime() - currentDate.getTime();\n const daysDifference = Math.floor(timeDifference / (1000 * 60 * 60 * 24)); // Convert milliseconds to days\n return daysDifference;\n};\n","import { createStore } from '@stencil/store';\n\nimport {\n stripeStore,\n stripeStoreUpdateCheckoutSession,\n} from 'src/components/store/checkout/stripe';\nimport { localizationStore } from 'src/components/store/hello/localization';\nimport { translate } from 'src/components/store/translationStore';\nimport { formatDate } from 'src/components/utils/formatDate';\nimport { getDaysDifference } from 'src/components/utils/getDaysDifference';\nimport { logError } from 'src/components/utils/logging/logError';\nimport type {\n CheckoutPresentmentFragment,\n CurrencyCode,\n ShipmentRatingFragment,\n} from 'src/types/generated/graphql.customer.types';\n\nexport type CartItem = {\n amount: number;\n countryOfOrigin?: string;\n currencyCode: string;\n description?: string;\n hsCode?: string;\n imageUrl?: string;\n name: string;\n productId?: string;\n quantity: number;\n};\n\ntype CartStore = {\n checkoutSessionId: string | null;\n currency: CurrencyCode;\n dutiesTaxFees: number;\n error: {\n messages: string[];\n title: string;\n } | null;\n isSelectedShippingAboveDeminimis: boolean;\n isSelectedShippingGuarantee: boolean;\n items: CartItem[];\n landedCostData: CheckoutPresentmentFragment[] | null;\n selectedLandedCost: CheckoutPresentmentFragment | null;\n selectedShippingOption: ShipmentRatingFragment | null;\n selectedShippingOptionExpectedDate: string;\n selectedShippingOptionTransitTime: string;\n shipping: number;\n shippingData: ShipmentRatingFragment[] | null;\n step: 'customer-info' | 'shipping' | 'payment' | 'finish' | 'error';\n subtotal: number;\n total: number;\n};\n\nconst {\n onChange,\n reset,\n state: cartStore,\n} = createStore<CartStore>(() => ({\n checkoutSessionId:\n sessionStorage.getItem('zonos--checkout-session-id') || null,\n currency: 'USD',\n dutiesTaxFees: 0,\n error: null,\n isSelectedShippingAboveDeminimis: false,\n isSelectedShippingGuarantee: false,\n items: [],\n landedCostData: null,\n selectedLandedCost: null,\n selectedShippingOption: null,\n selectedShippingOptionExpectedDate: '',\n selectedShippingOptionTransitTime: '',\n shipping: 0,\n shippingData: null,\n step: 'customer-info',\n subtotal: 0,\n total: 0,\n}));\n\n/**\n * Format shipping transit info to be displayed on UI\n * @returns\n * - expectedDate: Thursday, Aug 12\n * - maxTransit: 5\n * - minTransit: 3\n */\nconst cartStoreGetShippingTransitInfo = (item: ShipmentRatingFragment) => {\n const minTransit = item.minTransitAt\n ? getDaysDifference(new Date(item.minTransitAt))\n : '';\n const maxTransit = item.maxTransitAt\n ? getDaysDifference(new Date(item.maxTransitAt))\n : '';\n const expectedDate = item.minTransitAt\n ? formatDate({\n date: new Date(item.minTransitAt),\n })\n : '';\n return {\n expectedDate,\n maxTransit,\n minTransit,\n };\n};\n\nconst cartStoreReset = () => {\n sessionStorage.removeItem('zonos--checkout-session-id');\n\n // reset cart store\n reset();\n};\n\nconst cartStoreUpdateToErrorState = ({\n messages,\n title,\n}: {\n messages: string[];\n title: string;\n}) => {\n cartStore.step = 'error';\n cartStore.error = {\n messages,\n title,\n };\n};\n\ntype CartSubtotals = {\n items: number;\n landedCostTotal: number;\n presentmentCurrencyCode: CurrencyCode;\n shipping: number;\n total: number;\n};\n\nconst cartStoreApplySubtotals = (subtotals: CartSubtotals) => {\n cartStore.dutiesTaxFees = subtotals.landedCostTotal;\n cartStore.subtotal = subtotals.items;\n cartStore.total = subtotals.total;\n cartStore.currency = subtotals.presentmentCurrencyCode;\n};\n\ntype CartStoreRecalculateTotalParams = Omit<\n Parameters<typeof stripeStoreUpdateCheckoutSession>[0],\n 'id' | 'presentmentCountryCode'\n>;\n\nconst cartStoreReCalculateTotal = async ({\n currency,\n itemsAmount,\n landedCostId,\n}: CartStoreRecalculateTotalParams) => {\n if (landedCostId && cartStore.selectedLandedCost) {\n // update cart total right away if we have landed cost id to avoid order total flickering\n const subtotals = cartStore.selectedLandedCost.subtotals;\n cartStoreApplySubtotals(subtotals);\n }\n // update checkout session\n if (!cartStore.checkoutSessionId) {\n logError('Could update cart total without checkout session id');\n return false;\n }\n const { json } = await stripeStoreUpdateCheckoutSession({\n currency,\n id: cartStore.checkoutSessionId,\n itemsAmount,\n landedCostId,\n presentmentCountryCode: localizationStore.selectedCountryCode,\n });\n if (!json) {\n // do nothing if we can't get checkout session\n logError('Error occurs when updating checkout session');\n cartStoreUpdateToErrorState({\n messages: [\n translate(\n \"There's been an error updating your checkout session. Please reload and try again or contact support if the error persists\",\n ),\n ],\n title: translate('Error updating Checkout'),\n });\n return false;\n }\n if (!landedCostId) {\n // This is when first open the checkout modal and we just want to get info from the old cart session.\n // use subtotals from checkout session to update cart total\n cartStoreApplySubtotals(json.checkoutSessionUpdate.subtotals);\n }\n return true;\n};\n\nconst cartStoreUpdateSelectedShippingOption = async (\n selectedShippingOption: ShipmentRatingFragment,\n) => {\n cartStore.selectedShippingOption = selectedShippingOption;\n\n // update shipping transit info\n const { expectedDate, maxTransit, minTransit } =\n cartStoreGetShippingTransitInfo(cartStore.selectedShippingOption);\n cartStore.selectedShippingOptionExpectedDate = expectedDate;\n cartStore.selectedShippingOptionTransitTime =\n minTransit && maxTransit\n ? `${minTransit}-${maxTransit}`\n : `${minTransit || maxTransit}`;\n\n const selectedLandedCost = cartStore.landedCostData?.find(\n checkoutSessionPresentment =>\n checkoutSessionPresentment.landedCost?.shipmentRating?.id ===\n cartStore.selectedShippingOption?.id,\n );\n // save selected landed cost for later use\n cartStore.selectedLandedCost = selectedLandedCost || null;\n\n if (!selectedLandedCost) {\n // do nothing if we can't find landed cost for selected shipping option\n return false;\n }\n\n // update shipping value and dutiesTaxFees on selectedShippingOption change\n cartStore.shipping = selectedLandedCost.subtotals.shipping;\n\n // update deminimis status\n const isGuarantee =\n selectedLandedCost?.landedCost?.landedCostGuaranteeCode === 'ZONOS';\n // one item in deminimis with type of duty and tax has threshold value is \"ABOVE\"\n const isAboveDeminimis = !!selectedLandedCost?.landedCost?.deMinimis?.find(\n item => ['DUTY', 'TAX'].includes(item.type) && item.threshold === 'ABOVE',\n );\n cartStore.isSelectedShippingAboveDeminimis = isAboveDeminimis;\n cartStore.isSelectedShippingGuarantee = isGuarantee;\n // update session with selected landed cost\n const updateCalulateStatus = await cartStoreReCalculateTotal({\n landedCostId: selectedLandedCost.landedCost?.id,\n });\n return updateCalulateStatus;\n};\n\nonChange('checkoutSessionId', () => {\n if (!cartStore.checkoutSessionId) {\n sessionStorage.removeItem('zonos--checkout-session-id');\n return;\n }\n sessionStorage.setItem(\n 'zonos--checkout-session-id',\n cartStore.checkoutSessionId,\n );\n});\n\nconst cartStoreUpdateItems = async (items: CartItem[]) => {\n cartStore.items = items;\n const currency = items.find(Boolean)?.currencyCode as CurrencyCode;\n const total = items.reduce((amt, item) => {\n return amt + item.amount * item.quantity;\n }, 0);\n if (!currency || !total) {\n // do nothing if we can't get currency or total\n return;\n }\n cartStore.currency = currency;\n // set loading state here because this is first load checkout session when we already have checkout session id stored\n stripeStore.isFetchingSession = true;\n await cartStoreReCalculateTotal({\n currency: currency,\n itemsAmount: total,\n });\n stripeStore.isFetchingSession = false;\n};\n\nconst cartStoreResetSelectedShippingOption = () => {\n cartStore.selectedShippingOption = null;\n cartStore.isSelectedShippingAboveDeminimis = false;\n cartStore.isSelectedShippingGuarantee = false;\n cartStore.selectedShippingOptionExpectedDate = '';\n cartStore.selectedShippingOptionTransitTime = '';\n cartStore.shipping = 0;\n};\n\nconst cartStoreNextStep = () => {\n if (cartStore.step === 'customer-info') {\n cartStore.step = 'shipping';\n } else if (cartStore.step === 'shipping') {\n cartStore.step = 'payment';\n } else if (cartStore.step === 'payment') {\n cartStore.step = 'finish';\n }\n};\n\nconst cartStorePreviousStep = () => {\n if (cartStore.step === 'payment') {\n cartStore.step = 'shipping';\n } else if (cartStore.step === 'shipping') {\n cartStore.step = 'customer-info';\n // reset selected shipping option\n cartStoreResetSelectedShippingOption();\n }\n};\n\nexport {\n cartStore,\n cartStoreApplySubtotals,\n cartStoreGetShippingTransitInfo,\n cartStoreNextStep,\n cartStorePreviousStep,\n cartStoreReCalculateTotal,\n cartStoreReset,\n cartStoreUpdateItems,\n cartStoreUpdateSelectedShippingOption,\n cartStoreUpdateToErrorState,\n};\n"],"mappings":"mwDAIO,IAAMA,wBAA0B,WAErC,IAAMC,EAAiBC,YAAYC,oBAEnC,IAAMC,EAAoBF,YAAYG,uBACtC,IAAKD,IAAsBA,EAAkBE,SAAU,CACrD,MAAM,IAAIC,MAAM,8B,CAGlB,MAAO,CACLC,kBAAmBC,UAAUD,mBAAqB,GAClDE,QAAS,CACPC,OAAOV,IAAc,MAAdA,SAAc,SAAdA,EAAgBW,MAAMD,QAAS,GAGtCE,UAAWT,EAAkBQ,MAAMC,WAAa,GAChDC,SAAUV,EAAkBQ,MAAME,UAAY,GAC9CC,MAAOX,EAAkBQ,MAAMG,OAAS,IAE1CC,MAAOP,UAAUO,MAAMC,KAAI,SAAAC,GAAI,OAC7BC,OAAQD,EAAKC,OACbC,gBAAiBF,EAAKE,gBACtBC,aAAcH,EAAKG,aACnBC,SAAUJ,EAAKI,SACfC,KAAML,EAAKK,KACXC,UAAWN,EAAKM,UAChBC,SAAUP,EAAKO,SAPc,IAS/BC,gBAAiB,CACfC,aAAcvB,EAAkBQ,MAAMgB,QAAQC,MAC9CC,aAAc1B,EAAkBQ,MAAMgB,QAAQG,OAAS,GACvDC,KAAM5B,EAAkBQ,MAAMgB,QAAQI,KACtCC,QAAS7B,EAAkBQ,MAAMgB,QAAQK,QACzCC,WAAY9B,EAAkBQ,MAAMgB,QAAQO,YAC5CC,MAAOhC,EAAkBQ,MAAMgB,QAAQQ,OAG7C,ECpCO,IAAMC,oBAAsB,SACjCC,GAAiC,OAAAC,eAAA,4B,wEAG3BC,EAAM,GAAAC,OAAG,6BAAuC,8BAC7B,SAAMC,YAG7BF,EAAK,CAC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3B;AACH,EAAE;MAEI,qBAAqB,GAAG;EAC5B,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,EAAE;IAChC,SAAS,CAAC,IAAI,GAAG,UAAU,CAAC;GAC7B;OAAM,IAAI,SAAS,CAAC,IAAI,KAAK,UAAU,EAAE;IACxC,SAAS,CAAC,IAAI,GAAG,eAAe,CAAC;;IAEjC,oCAAoC,EAAE,CAAC;GACxC;AACH;;;;","names":["onChange","reset"],"sources":["src/components/utils/api/prepCalculateLandedCost.ts","src/components/utils/api/calculateLandedCost.ts","src/styles/stripe/addressRuleStyle.ts","src/styles/stripe/defaultVariable.ts","src/components/store/checkout/stripe.ts","src/components/utils/formatDate.ts","src/components/utils/getDaysDifference.ts","src/components/store/checkout/cart.ts"],"sourcesContent":["import { cartStore } from 'src/components/store/checkout/cart';\nimport { stripeStore } from 'src/components/store/checkout/stripe';\nimport type { CalculateLandedCostRequest } from 'src/types/checkout/api/CalculateLandedCostRequest';\n\nexport const prepCalculateLandedCost = (): CalculateLandedCostRequest => {\n // maybe we don't need email now for prefetch the landed cost\n const stripeLinkData = stripeStore.stripeLinkEventData;\n\n const stripeAddressData = stripeStore.stripeAddressEventData;\n if (!stripeAddressData || !stripeAddressData.complete) {\n throw new Error('Missing stripe address data');\n }\n\n return {\n checkoutSessionId: cartStore.checkoutSessionId || '',\n contact: {\n email: stripeLinkData?.value.email || '',\n // firstName and lastName should be valid now since stripe only mark\n // the address as complete when both fields are filled.\n firstName: stripeAddressData.value.firstName || '',\n lastName: stripeAddressData.value.lastName || '',\n phone: stripeAddressData.value.phone || '',\n },\n items: cartStore.items.map(item => ({\n amount: item.amount,\n countryOfOrigin: item.countryOfOrigin,\n currencyCode: item.currencyCode,\n imageUrl: item.imageUrl,\n name: item.name,\n productId: item.productId,\n quantity: item.quantity,\n })),\n shippingAddress: {\n addressLine1: stripeAddressData.value.address.line1,\n addressLine2: stripeAddressData.value.address.line2 || '',\n city: stripeAddressData.value.address.city,\n country: stripeAddressData.value.address.country,\n postalCode: stripeAddressData.value.address.postal_code,\n state: stripeAddressData.value.address.state,\n },\n };\n};\n","import { prepCalculateLandedCost } from 'src/components/utils/api/prepCalculateLandedCost';\nimport { handleFetch } from 'src/components/utils/handleFetch';\nimport type { CalculateLandedCostRequest } from 'src/types/checkout/api/CalculateLandedCostRequest';\nimport type { CalculateLandedCostMutation } from 'src/types/generated/graphql.customer.types';\n\nexport const calculateLandedCost = async (\n abortController?: AbortController,\n) => {\n // request to get landed cost info\n const url = `${process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL}/api/calculate-landed-cost`;\n const { errors, json } = await handleFetch<\n CalculateLandedCostMutation,\n CalculateLandedCostRequest\n >(url, {\n body: prepCalculateLandedCost(),\n method: 'POST',\n signal: abortController?.signal,\n });\n if (errors.length || !json) {\n throw new Error('Failed to calculate landed cost');\n }\n\n return json;\n};\n","import type { ElementsUiTheme, StripeRuleType } from 'src/types';\n\nexport const addressRuleStyle = ({\n theme,\n}: {\n theme: ElementsUiTheme;\n}): StripeRuleType => {\n switch (theme) {\n default:\n return {\n '.Input': {\n // need to reset everything and the paddingTop to default, otherwise the paddingTop will not be updated.\n padding: '0',\n paddingBottom: '8px',\n paddingLeft: '16px',\n paddingRight: '8px',\n // any value here will be add up to the default paddingTop (20px).\n paddingTop: '6px',\n },\n };\n }\n};\n","import type { Appearance } from '@stripe/stripe-js';\n\nimport { getBorderRadius } from 'src/components/utils/getBorderRadius';\nimport type {\n ElementsUiStyle,\n ElementsUiTheme,\n} from 'src/types/generated/graphql.customer.types';\n\nexport const defaultVariable = ({\n borderStyle,\n theme,\n}: {\n borderStyle?: ElementsUiStyle;\n theme: ElementsUiTheme;\n}): Appearance['variables'] => {\n switch (theme) {\n case 'DARK':\n return {\n borderRadius: getBorderRadius(borderStyle),\n colorBackground: '#101117',\n colorBackgroundText: '#C5C6CA',\n colorText: '#C5C6CA',\n colorTextPlaceholder: '#C5C6CA',\n };\n default:\n return {\n borderRadius: getBorderRadius(borderStyle),\n };\n }\n};\n","import { createStore } from '@stencil/store';\nimport type {\n PaymentIntent,\n Stripe,\n StripeAddressElement,\n StripeAddressElementChangeEvent,\n StripeElements,\n StripeElementsOptionsClientSecret,\n StripeLinkAuthenticationElement,\n StripeLinkAuthenticationElementChangeEvent,\n StripePaymentElement,\n StripePaymentElementChangeEvent,\n} from '@stripe/stripe-js';\n\nimport {\n cartStore,\n cartStoreApplySubtotals,\n} from 'src/components/store/checkout/cart';\nimport { localizationStore } from 'src/components/store/hello/localization';\nimport { translate } from 'src/components/store/translationStore';\nimport { zonosStore } from 'src/components/store/zonosStore';\nimport { calculateLandedCost } from 'src/components/utils/api/calculateLandedCost';\nimport { handleFetch } from 'src/components/utils/handleFetch';\nimport { isDarkColor } from 'src/components/utils/isDarkColor';\nimport { log } from 'src/components/utils/logging/log';\nimport { logError } from 'src/components/utils/logging/logError';\nimport { addressRuleStyle } from 'src/styles/stripe/addressRuleStyle';\nimport { defaultVariable } from 'src/styles/stripe/defaultVariable';\nimport type {\n CheckoutSessionCreateMutation,\n CheckoutSessionUpdateMutation,\n CountryCode,\n ElementsUiStyle,\n ElementsUiTheme,\n} from 'src/types/generated/graphql.customer.types';\n\nexport type ContactOption = {\n address: {\n city: string;\n country: string;\n line1: string;\n line2?: string;\n postal_code: string;\n state: string;\n };\n name: string;\n phone?: string;\n};\n\ntype StripeStore = {\n // client secret is used to render link and payment elements\n clientSecret: string | null;\n fetchingLandedCostAbordController: AbortController | null;\n // toggle to indicate if we are pre-fetching/fetching landed cost\n isFetchingLandedCost: boolean;\n // toggle to indicate if we are fetching checkout session\n isFetchingSession: boolean;\n stripe: Stripe | null;\n stripeAddressElement: StripeAddressElement | null;\n stripeAddressEventData: StripeAddressElementChangeEvent | null;\n stripeAddressUsedWhenFetchingLC: StripeAddressElementChangeEvent | null;\n stripeElements: StripeElements | null;\n stripeLinkElement: StripeLinkAuthenticationElement | null;\n stripeLinkEventData: StripeLinkAuthenticationElementChangeEvent | null;\n stripeLinkUsedWhenFetchingLC: StripeLinkAuthenticationElementChangeEvent | null;\n stripePaymentElement: StripePaymentElement | null;\n stripePaymentEventData: StripePaymentElementChangeEvent | null;\n};\n\nconst {\n onChange,\n reset,\n state: stripeStore,\n} = createStore<StripeStore>(() => ({\n clientSecret: sessionStorage.getItem('zonos--client-secret') || null,\n fetchingLandedCostAbordController: null,\n isFetchingLandedCost: false,\n isFetchingSession: false,\n stripe: null,\n stripeAddressElement: null,\n stripeAddressEventData: null,\n stripeAddressUsedWhenFetchingLC: null,\n stripeElements: null,\n stripeLinkElement: null,\n stripeLinkEventData: null,\n stripeLinkUsedWhenFetchingLC: null,\n stripePaymentElement: null,\n stripePaymentEventData: null,\n}));\n\nconst getStripeOptions = ({\n clientSecret,\n overrideBorderRaidus,\n overridePrimaryColor,\n overrideTheme,\n}: {\n clientSecret?: string;\n overrideBorderRaidus?: ElementsUiStyle;\n overridePrimaryColor?: string;\n overrideTheme?: ElementsUiTheme;\n}): StripeElementsOptionsClientSecret => {\n const primaryColor =\n overridePrimaryColor || zonosStore.appearance.colorPrimary;\n const themeBasedColor =\n primaryColor && isDarkColor(primaryColor) ? 'night' : 'flat';\n // if overrideTheme is provided, use it. Otherwise, use theme based on primary color\n const theme = overrideTheme === 'DARK' ? 'night' : 'flat';\n return {\n appearance: {\n labels: 'floating',\n rules: {\n ...addressRuleStyle({ theme: 'LIGHT' }),\n },\n // get contrast theme color base on primary color\n theme: overrideTheme ? theme : themeBasedColor,\n variables: {\n ...defaultVariable({\n borderStyle: overrideBorderRaidus,\n theme: 'LIGHT',\n }),\n },\n },\n clientSecret,\n locale: localizationStore.selectedLocale,\n };\n};\n\nconst initStripeElements = async (props?: {\n overrideBorderRaidus?: ElementsUiStyle;\n overridePrimaryColor?: string;\n overrideTheme?: ElementsUiTheme;\n}) => {\n const clientSecret = stripeStore.clientSecret;\n\n if (!stripeStore.stripe) {\n log('Skip. Stripe is not initialized');\n return;\n }\n if (clientSecret) {\n const stripeOptions = getStripeOptions({\n clientSecret,\n overrideBorderRaidus: props?.overrideBorderRaidus,\n overridePrimaryColor: props?.overridePrimaryColor,\n overrideTheme: props?.overrideTheme,\n });\n\n if (!stripeStore.stripeElements) {\n // init stripe elements if it doesn't exist\n stripeStore.stripeElements = stripeStore.stripe?.elements(stripeOptions);\n } else {\n // update elements with new option if it already exists\n stripeStore.stripeElements.update(stripeOptions);\n }\n log('Stripe elements initialized');\n }\n};\n\nconst stripeStoreReset = () => {\n // clean clientSecret so that we can start the new one.\n sessionStorage.removeItem('zonos--client-secret');\n\n // cleanup stripe elements\n reset();\n // set stripe back to window.Zonos.stripe\n stripeStore.stripe = window.Zonos.stripe;\n};\n\n/**\n * Check if the address and email info used when fetching landed cost with the current email and address info are different\n * Purpose is to resend the request if the info used when fetching landed cost is different from the current info\n */\nconst isPrefetchInfoOutdated = () => {\n const hasAbortController = stripeStore.fetchingLandedCostAbordController;\n if (!hasAbortController) {\n // if there is no abort controller, this is a new request\n return false;\n }\n\n const isLinkDataDirty =\n JSON.stringify(stripeStore.stripeLinkUsedWhenFetchingLC?.value) !==\n JSON.stringify(stripeStore.stripeLinkEventData?.value);\n const isAddressDataDirty =\n JSON.stringify(stripeStore.stripeAddressUsedWhenFetchingLC?.value) !==\n JSON.stringify(stripeStore.stripeAddressEventData?.value);\n\n return isLinkDataDirty || isAddressDataDirty;\n};\n\nconst stripeStorePrefetchLandedCost = async () => {\n const stripeAddressReady = !!stripeStore.stripeAddressEventData?.complete;\n const stripeLinkReady = !!stripeStore.stripeLinkEventData?.complete;\n const shouldRefetch = isPrefetchInfoOutdated();\n\n if (shouldRefetch) {\n // if the info used when fetching landed cost is different from the current info, abort the previous request\n stripeStore.fetchingLandedCostAbordController?.abort();\n stripeStore.fetchingLandedCostAbordController = null;\n }\n\n // only fetch if we are not fetching or we need to refetch\n if (\n stripeAddressReady &&\n stripeLinkReady &&\n (shouldRefetch || !stripeStore.isFetchingLandedCost)\n ) {\n stripeStore.isFetchingLandedCost = true;\n if (stripeStore.stripeAddressEventData) {\n stripeStore.stripeAddressUsedWhenFetchingLC = {\n ...stripeStore.stripeAddressEventData,\n };\n }\n if (stripeStore.stripeLinkEventData) {\n stripeStore.stripeLinkUsedWhenFetchingLC = {\n ...stripeStore.stripeLinkEventData,\n };\n }\n try {\n const abortController = new AbortController();\n stripeStore.fetchingLandedCostAbordController = abortController;\n const { checkoutSessionWorkflow, shipmentRatingCalculateWorkflow } =\n await calculateLandedCost(abortController);\n\n // reset abort controller after we are done\n stripeStore.fetchingLandedCostAbordController = null;\n\n // update cart store with landed cost info\n cartStore.landedCostData =\n checkoutSessionWorkflow?.filter(Boolean) || null;\n\n cartStore.shippingData =\n shipmentRatingCalculateWorkflow?.filter(Boolean) || null;\n // apply new subtotal and total, this is mainly to show items in the presentment currency\n const firstLandedCostData = cartStore.landedCostData?.find(Boolean);\n const subtotals = !!firstLandedCostData\n ? firstLandedCostData.subtotals\n : null;\n if (subtotals) {\n // prefetch landed cost will not update shipping and taxes since we haven't selected shipping method yet\n cartStoreApplySubtotals({\n items: subtotals.items,\n landedCostTotal: 0,\n presentmentCurrencyCode: subtotals.presentmentCurrencyCode,\n shipping: 0,\n total: subtotals.items,\n });\n }\n } catch (err) {\n logError(err);\n }\n stripeStore.isFetchingLandedCost = false;\n }\n};\n\nconst getStripeMessageBasedOnStatus = (status?: PaymentIntent['status']) => {\n let messages: string[] = [];\n let isError = true;\n // Inspect the PaymentIntent `status` to indicate the status of the payment\n // to your customer.\n //\n // Some payment methods will [immediately succeed or fail][0] upon\n // confirmation, while others will first enter a `processing` state.\n //\n // [0]: https://stripe.com/docs/payments/payment-methods#payment-notification\n switch (status) {\n case 'succeeded': {\n messages = [\n translate(\n '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.',\n ),\n '',\n '',\n translate(\n \"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 ),\n ];\n isError = false;\n break;\n }\n case 'requires_capture':\n case 'processing': {\n messages = [\n translate(\n \"Payment processing. We'll update you when payment is received.\",\n ),\n ];\n isError = false;\n break;\n }\n\n case 'requires_payment_method': {\n messages = [\n translate('Payment failed. Please try another payment method.'),\n ];\n break;\n }\n\n default: {\n messages = [translate('Something went wrong.')];\n break;\n }\n }\n return {\n isError,\n messages,\n };\n};\n\nconst stripeStoreRetrievePayment = async ({\n clientSecret: _clientSecret,\n storybookForceStatus,\n}: {\n clientSecret?: string;\n storybookForceStatus?: PaymentIntent['status'];\n}) => {\n if (storybookForceStatus) {\n // return status right away if we are in storybook mode\n const { isError, messages } =\n getStripeMessageBasedOnStatus(storybookForceStatus);\n\n return { error: isError, messages };\n }\n const clientSecret = _clientSecret || stripeStore.clientSecret;\n if (!stripeStore.stripe || !clientSecret) {\n logError('Failed to retrieve payment intent. Stripe is not initialized');\n return { error: true, message: [translate('Something went wrong.')] };\n }\n const { paymentIntent } = await stripeStore.stripe.retrievePaymentIntent(\n clientSecret,\n );\n\n const status = paymentIntent?.status;\n\n const { isError, messages } = getStripeMessageBasedOnStatus(status);\n\n return { error: isError, messages };\n};\n\nconst stripeStoreConfirmPayment = async () => {\n const stripePaymentReady = !!stripeStore.stripePaymentEventData?.complete;\n const stripeElements = stripeStore.stripeElements;\n const stripe = stripeStore.stripe;\n const stripeClientSecret = stripeStore.clientSecret;\n if (stripe && stripeElements && stripePaymentReady && stripeClientSecret) {\n const { error } = await stripe.confirmPayment({\n confirmParams: {\n receipt_email: stripeStore.stripeLinkEventData?.value?.email,\n return_url: window.location.href,\n },\n elements: stripeElements,\n redirect: 'if_required',\n });\n\n if (error) {\n if (error.type === 'card_error' || error.type === 'validation_error') {\n throw new Error(error.message);\n }\n if (error.type === 'invalid_request_error') {\n if (error.code === 'payment_intent_unexpected_state') {\n // PaymentIntent was canceled or expired, or status is `require_capture`.\n // don't throw error here because we will reset the checkout session last step\n return;\n }\n }\n throw new Error('An unexpected error occurred.');\n }\n }\n};\n\ntype CheckoutSessionCreateRequest = {\n currency: string;\n itemsAmount: number;\n presentmentCountryCode: CountryCode | null;\n};\n\n/**\n * Init checkout session\n * @returns {boolean} whether or not the checkout session is successfully created\n */\nconst stripeStoreInitCheckoutSession = async () => {\n const total = cartStore.items.reduce(\n (amount, item) => amount + item.amount * item.quantity,\n 0,\n );\n\n if (!total || !localizationStore.targetCurrency) {\n logError('Fail to create checkout session - invalid total or currency');\n return false;\n }\n\n stripeStore.isFetchingSession = true;\n\n const { errors, json } = await handleFetch<\n CheckoutSessionCreateMutation,\n CheckoutSessionCreateRequest\n >(`${process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL}/api/create-checkout-session`, {\n body: {\n currency: cartStore.items.find(Boolean)?.currencyCode || '',\n itemsAmount: total,\n presentmentCountryCode: localizationStore.selectedCountryCode || null,\n },\n method: 'POST',\n });\n\n stripeStore.isFetchingSession = false;\n\n if (errors.length || !json) {\n logError(\n 'Error occurs when creating checkout session',\n JSON.stringify(errors, null, 2),\n );\n\n return false;\n }\n const result = json.checkoutSessionCreate;\n\n stripeStore.clientSecret = result.clientSecret;\n // update cart store with updated informations\n cartStore.checkoutSessionId = result.id;\n cartStoreApplySubtotals({\n ...result.subtotals,\n landedCostTotal: 0,\n shipping: 0,\n total: result.subtotals.items,\n });\n\n log('done-init-checkout-session');\n return true;\n};\n\ntype CheckoutSessionUpdateRequest = {\n currency?: string;\n id: string;\n itemsAmount?: number;\n landedCostId?: string;\n presentmentCountryCode: CountryCode | null;\n};\n/**\n * Update checkout session. Use for updating amount with landed cost id, or update session when cart items change\n */\nconst stripeStoreUpdateCheckoutSession = async ({\n currency,\n id,\n itemsAmount,\n landedCostId,\n presentmentCountryCode,\n}: CheckoutSessionUpdateRequest) => {\n // No need to set loading state here because this function will be called under the hood to update\n // landed cost id for the section.\n const { errors, json } = await handleFetch<\n CheckoutSessionUpdateMutation,\n CheckoutSessionUpdateRequest\n >(`${process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL}/api/update-checkout-session`, {\n body: {\n currency,\n id,\n itemsAmount,\n landedCostId,\n presentmentCountryCode,\n },\n method: 'POST',\n });\n\n if (errors.length || !json) {\n logError(\n 'Error occurs when updating checkout session',\n JSON.stringify(errors, null, 2),\n );\n return { errors, json };\n }\n\n return { errors: [], json };\n};\n\nonChange('clientSecret', clientSecret => {\n // update stripe elements when client secret changes\n if (clientSecret && stripeStore.stripe) {\n sessionStorage.setItem('zonos--client-secret', clientSecret);\n }\n\n if (!clientSecret) {\n sessionStorage.removeItem('zonos--client-secret');\n }\n});\n\nexport {\n initStripeElements,\n stripeStore,\n stripeStoreConfirmPayment,\n stripeStoreInitCheckoutSession,\n stripeStorePrefetchLandedCost,\n stripeStoreReset,\n stripeStoreRetrievePayment,\n stripeStoreUpdateCheckoutSession,\n};\n","type Params = {\n date: Date;\n /**\n * Format options for Intl.DateTimeFormat\n * @default {day:'numeric',weekday:'long',year:'numeric'} Thursday 3, 2023\n */\n formatOptions?: Intl.DateTimeFormatOptions;\n};\n\nexport const formatDate = ({\n date,\n formatOptions = { day: 'numeric', weekday: 'long', year: 'numeric' },\n}: Params): string => {\n // format date to Thursday 3, 2023\n return new Intl.DateTimeFormat('en-US', formatOptions).format(date);\n};\n","export const getDaysDifference = (targetDate: Date) => {\n const currentDate = new Date();\n const timeDifference = targetDate.getTime() - currentDate.getTime();\n const daysDifference = Math.floor(timeDifference / (1000 * 60 * 60 * 24)); // Convert milliseconds to days\n return daysDifference;\n};\n","import { createStore } from '@stencil/store';\n\nimport {\n stripeStore,\n stripeStoreUpdateCheckoutSession,\n} from 'src/components/store/checkout/stripe';\nimport { localizationStore } from 'src/components/store/hello/localization';\nimport { translate } from 'src/components/store/translationStore';\nimport { formatDate } from 'src/components/utils/formatDate';\nimport { getDaysDifference } from 'src/components/utils/getDaysDifference';\nimport { logError } from 'src/components/utils/logging/logError';\nimport type {\n CheckoutPresentmentFragment,\n CurrencyCode,\n ShipmentRatingFragment,\n} from 'src/types/generated/graphql.customer.types';\n\nexport type CartItem = {\n amount: number;\n countryOfOrigin?: string;\n currencyCode: string;\n description?: string;\n hsCode?: string;\n imageUrl?: string;\n name: string;\n productId?: string;\n quantity: number;\n};\n\ntype CartStore = {\n checkoutSessionId: string | null;\n currency: CurrencyCode;\n dutiesTaxFees: number;\n error: {\n messages: string[];\n title: string;\n } | null;\n isSelectedShippingAboveDeminimis: boolean;\n isSelectedShippingGuarantee: boolean;\n items: CartItem[];\n landedCostData: CheckoutPresentmentFragment[] | null;\n selectedLandedCost: CheckoutPresentmentFragment | null;\n selectedShippingOption: ShipmentRatingFragment | null;\n selectedShippingOptionExpectedDate: string;\n selectedShippingOptionTransitTime: string;\n shipping: number;\n shippingData: ShipmentRatingFragment[] | null;\n step: 'customer-info' | 'shipping' | 'payment' | 'finish' | 'error';\n subtotal: number;\n total: number;\n};\n\nconst {\n onChange,\n reset,\n state: cartStore,\n} = createStore<CartStore>(() => ({\n checkoutSessionId:\n sessionStorage.getItem('zonos--checkout-session-id') || null,\n currency: 'USD',\n dutiesTaxFees: 0,\n error: null,\n isSelectedShippingAboveDeminimis: false,\n isSelectedShippingGuarantee: false,\n items: [],\n landedCostData: null,\n selectedLandedCost: null,\n selectedShippingOption: null,\n selectedShippingOptionExpectedDate: '',\n selectedShippingOptionTransitTime: '',\n shipping: 0,\n shippingData: null,\n step: 'customer-info',\n subtotal: 0,\n total: 0,\n}));\n\n/**\n * Format shipping transit info to be displayed on UI\n * @returns\n * - expectedDate: Thursday, Aug 12\n * - maxTransit: 5\n * - minTransit: 3\n */\nconst cartStoreGetShippingTransitInfo = (item: ShipmentRatingFragment) => {\n const minTransit = item.minTransitAt\n ? getDaysDifference(new Date(item.minTransitAt))\n : '';\n const maxTransit = item.maxTransitAt\n ? getDaysDifference(new Date(item.maxTransitAt))\n : '';\n const expectedDate = item.minTransitAt\n ? formatDate({\n date: new Date(item.minTransitAt),\n })\n : '';\n return {\n expectedDate,\n maxTransit,\n minTransit,\n };\n};\n\nconst cartStoreReset = () => {\n sessionStorage.removeItem('zonos--checkout-session-id');\n\n // reset cart store\n reset();\n};\n\nconst cartStoreUpdateToErrorState = ({\n messages,\n title,\n}: {\n messages: string[];\n title: string;\n}) => {\n cartStore.step = 'error';\n cartStore.error = {\n messages,\n title,\n };\n};\n\ntype CartSubtotals = {\n items: number;\n landedCostTotal: number;\n presentmentCurrencyCode: CurrencyCode;\n shipping: number;\n total: number;\n};\n\nconst cartStoreApplySubtotals = (subtotals: CartSubtotals) => {\n cartStore.dutiesTaxFees = subtotals.landedCostTotal;\n cartStore.subtotal = subtotals.items;\n cartStore.total = subtotals.total;\n cartStore.currency = subtotals.presentmentCurrencyCode;\n};\n\ntype CartStoreRecalculateTotalParams = Omit<\n Parameters<typeof stripeStoreUpdateCheckoutSession>[0],\n 'id' | 'presentmentCountryCode'\n>;\n\nconst cartStoreReCalculateTotal = async ({\n currency,\n itemsAmount,\n landedCostId,\n}: CartStoreRecalculateTotalParams) => {\n if (landedCostId && cartStore.selectedLandedCost) {\n // update cart total right away if we have landed cost id to avoid order total flickering\n const subtotals = cartStore.selectedLandedCost.subtotals;\n cartStoreApplySubtotals(subtotals);\n }\n // update checkout session\n if (!cartStore.checkoutSessionId) {\n logError('Could update cart total without checkout session id');\n return false;\n }\n const { json } = await stripeStoreUpdateCheckoutSession({\n currency,\n id: cartStore.checkoutSessionId,\n itemsAmount,\n landedCostId,\n presentmentCountryCode: localizationStore.selectedCountryCode,\n });\n if (!json) {\n // do nothing if we can't get checkout session\n logError('Error occurs when updating checkout session');\n cartStoreUpdateToErrorState({\n messages: [\n translate(\n \"There's been an error updating your checkout session. Please reload and try again or contact support if the error persists\",\n ),\n ],\n title: translate('Error updating Checkout'),\n });\n return false;\n }\n if (!landedCostId) {\n // This is when first open the checkout modal and we just want to get info from the old cart session.\n // use subtotals from checkout session to update cart total\n cartStoreApplySubtotals(json.checkoutSessionUpdate.subtotals);\n }\n return true;\n};\n\nconst cartStoreUpdateSelectedShippingOption = async (\n selectedShippingOption: ShipmentRatingFragment,\n) => {\n cartStore.selectedShippingOption = selectedShippingOption;\n\n // update shipping transit info\n const { expectedDate, maxTransit, minTransit } =\n cartStoreGetShippingTransitInfo(cartStore.selectedShippingOption);\n cartStore.selectedShippingOptionExpectedDate = expectedDate;\n cartStore.selectedShippingOptionTransitTime =\n minTransit && maxTransit\n ? `${minTransit}-${maxTransit}`\n : `${minTransit || maxTransit}`;\n\n const selectedLandedCost = cartStore.landedCostData?.find(\n checkoutSessionPresentment =>\n checkoutSessionPresentment.landedCost?.shipmentRating?.id ===\n cartStore.selectedShippingOption?.id,\n );\n // save selected landed cost for later use\n cartStore.selectedLandedCost = selectedLandedCost || null;\n\n if (!selectedLandedCost) {\n // do nothing if we can't find landed cost for selected shipping option\n return false;\n }\n\n // update shipping value and dutiesTaxFees on selectedShippingOption change\n cartStore.shipping = selectedLandedCost.subtotals.shipping;\n\n // update deminimis status\n const isGuarantee =\n selectedLandedCost?.landedCost?.landedCostGuaranteeCode === 'ZONOS';\n // one item in deminimis with type of duty and tax has threshold value is \"ABOVE\"\n const isAboveDeminimis = !!selectedLandedCost?.landedCost?.deMinimis?.find(\n item => ['DUTY', 'TAX'].includes(item.type) && item.threshold === 'ABOVE',\n );\n cartStore.isSelectedShippingAboveDeminimis = isAboveDeminimis;\n cartStore.isSelectedShippingGuarantee = isGuarantee;\n // update session with selected landed cost\n const updateCalulateStatus = await cartStoreReCalculateTotal({\n landedCostId: selectedLandedCost.landedCost?.id,\n });\n return updateCalulateStatus;\n};\n\nonChange('checkoutSessionId', () => {\n if (!cartStore.checkoutSessionId) {\n sessionStorage.removeItem('zonos--checkout-session-id');\n return;\n }\n sessionStorage.setItem(\n 'zonos--checkout-session-id',\n cartStore.checkoutSessionId,\n );\n});\n\nconst cartStoreUpdateItems = async (items: CartItem[]) => {\n cartStore.items = items;\n const currency = items.find(Boolean)?.currencyCode as CurrencyCode;\n const total = items.reduce((amt, item) => {\n return amt + item.amount * item.quantity;\n }, 0);\n if (!currency || !total) {\n // do nothing if we can't get currency or total\n return;\n }\n cartStore.currency = currency;\n // set loading state here because this is first load checkout session when we already have checkout session id stored\n stripeStore.isFetchingSession = true;\n await cartStoreReCalculateTotal({\n currency: currency,\n itemsAmount: total,\n });\n stripeStore.isFetchingSession = false;\n};\n\nconst cartStoreResetSelectedShippingOption = () => {\n cartStore.selectedShippingOption = null;\n cartStore.isSelectedShippingAboveDeminimis = false;\n cartStore.isSelectedShippingGuarantee = false;\n cartStore.selectedShippingOptionExpectedDate = '';\n cartStore.selectedShippingOptionTransitTime = '';\n cartStore.shipping = 0;\n};\n\nconst cartStoreNextStep = () => {\n if (cartStore.step === 'customer-info') {\n cartStore.step = 'shipping';\n } else if (cartStore.step === 'shipping') {\n cartStore.step = 'payment';\n } else if (cartStore.step === 'payment') {\n cartStore.step = 'finish';\n }\n};\n\nconst cartStorePreviousStep = () => {\n if (cartStore.step === 'payment') {\n cartStore.step = 'shipping';\n } else if (cartStore.step === 'shipping') {\n cartStore.step = 'customer-info';\n // reset selected shipping option\n cartStoreResetSelectedShippingOption();\n }\n};\n\nexport {\n cartStore,\n cartStoreApplySubtotals,\n cartStoreGetShippingTransitInfo,\n cartStoreNextStep,\n cartStorePreviousStep,\n cartStoreReCalculateTotal,\n cartStoreReset,\n cartStoreUpdateItems,\n cartStoreUpdateSelectedShippingOption,\n cartStoreUpdateToErrorState,\n};\n"],"version":3}
@@ -1,2 +0,0 @@
1
- var __awaiter=this&&this.__awaiter||function(e,t,n,r){function i(e){return e instanceof n?e:new n((function(t){t(e)}))}return new(n||(n=Promise))((function(n,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r["throw"](e))}catch(e){o(e)}}function l(e){e.done?n(e.value):i(e.value).then(s,a)}l((r=r.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var n={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},r,i,o,s;return s={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(s[Symbol.iterator]=function(){return this}),s;function a(e){return function(t){return l([e,t])}}function l(a){if(r)throw new TypeError("Generator is already executing.");while(s&&(s=0,a[0]&&(n=0)),n)try{if(r=1,i&&(o=a[0]&2?i["return"]:a[0]?i["throw"]||((o=i["return"])&&o.call(i),0):i.next)&&!(o=o.call(i,a[1])).done)return o;if(i=0,o)a=[a[0]&2,o.value];switch(a[0]){case 0:case 1:o=a;break;case 4:n.label++;return{value:a[1],done:false};case 5:n.label++;i=a[1];a=[0];continue;case 7:a=n.ops.pop();n.trys.pop();continue;default:if(!(o=n.trys,o=o.length>0&&o[o.length-1])&&(a[0]===6||a[0]===2)){n=0;continue}if(a[0]===3&&(!o||a[1]>o[0]&&a[1]<o[3])){n.label=a[1];break}if(a[0]===6&&n.label<o[1]){n.label=o[1];o=a;break}if(o&&n.label<o[2]){n.label=o[2];n.ops.push(a);break}if(o[2])n.ops.pop();n.trys.pop();continue}a=t.call(e,n)}catch(e){a=[6,e];i=0}finally{r=o=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};System.register(["./zonosStore-77bcd7c0.system.js","./localization-3c43290f.system.js","./isDarkColor-dc2b7c8f.system.js","./getBorderRadius-4fbe49de.system.js"],(function(e){"use strict";var t,n,r,i,o,s,a,l,u;return{setters:[function(e){t=e.c;n=e.z},function(e){r=e.h;i=e.l;o=e.a;s=e.b;a=e.t},function(e){l=e.i},function(e){u=e.g}],execute:function(){var c=this;var d=function(){var e=y.stripeLinkEventData;var t=y.stripeAddressEventData;if(!t||!t.complete){throw new Error("Missing stripe address data")}return{checkoutSessionId:j.checkoutSessionId||"",contact:{email:(e===null||e===void 0?void 0:e.value.email)||"",firstName:t.value.firstName||"",lastName:t.value.lastName||"",phone:t.value.phone||""},items:j.items.map((function(e){return{amount:e.amount,countryOfOrigin:e.countryOfOrigin,currencyCode:e.currencyCode,imageUrl:e.imageUrl,name:e.name,productId:e.productId,quantity:e.quantity}})),shippingAddress:{addressLine1:t.value.address.line1,addressLine2:t.value.address.line2||"",city:t.value.address.city,country:t.value.address.country,postalCode:t.value.address.postal_code,state:t.value.address.state}}};var p=function(e){return __awaiter(c,void 0,void 0,(function(){var t,n,i,o;return __generator(this,(function(s){switch(s.label){case 0:t="".concat("https://route.js.zonos.com","/api/calculate-landed-cost");return[4,r(t,{body:d(),method:"POST",signal:e===null||e===void 0?void 0:e.signal})];case 1:n=s.sent(),i=n.errors,o=n.json;if(i.length||!o){throw new Error("Failed to calculate landed cost")}return[2,o]}}))}))};var v=function(e){var t=e.theme;switch(t){default:return{".Input":{padding:"0",paddingBottom:"8px",paddingLeft:"16px",paddingRight:"8px",paddingTop:"6px"}}}};var f=function(e){var t=e.borderStyle,n=e.theme;switch(n){case"DARK":return{borderRadius:u(t),colorBackground:"#101117",colorBackgroundText:"#C5C6CA",colorText:"#C5C6CA",colorTextPlaceholder:"#C5C6CA"};default:return{borderRadius:u(t)}}};var h=t((function(){return{clientSecret:sessionStorage.getItem("zonos--client-secret")||null,fetchingLandedCostAbordController:null,isFetchingLandedCost:false,isFetchingSession:false,stripe:null,stripeAddressElement:null,stripeAddressEventData:null,stripeAddressUsedWhenFetchingLC:null,stripeElements:null,stripeLinkElement:null,stripeLinkEventData:null,stripeLinkUsedWhenFetchingLC:null,stripePaymentElement:null,stripePaymentEventData:null}})),m=h.onChange,g=h.reset,y=h.state;e("s",y);var C=function(e){var t=e.clientSecret,r=e.overrideBorderRaidus,i=e.overridePrimaryColor,s=e.overrideTheme;var a=i||n.appearance.colorPrimary;var u=a&&l(a)?"night":"flat";var c=s==="DARK"?"night":"flat";return{appearance:{labels:"floating",rules:Object.assign({},v({theme:"LIGHT"})),theme:s?c:u,variables:Object.assign({},f({borderStyle:r,theme:"LIGHT"}))},clientSecret:t,locale:o.selectedLocale}};var S=e("i",(function(e){return __awaiter(c,void 0,void 0,(function(){var t,n,r;return __generator(this,(function(o){n=y.clientSecret;if(!y.stripe){i("Skip. Stripe is not initialized");return[2]}if(n){r=C({clientSecret:n,overrideBorderRaidus:e===null||e===void 0?void 0:e.overrideBorderRaidus,overridePrimaryColor:e===null||e===void 0?void 0:e.overridePrimaryColor,overrideTheme:e===null||e===void 0?void 0:e.overrideTheme});if(!y.stripeElements){y.stripeElements=(t=y.stripe)===null||t===void 0?void 0:t.elements(r)}else{y.stripeElements.update(r)}i("Stripe elements initialized")}return[2]}))}))}));var b=e("j",(function(){sessionStorage.removeItem("zonos--client-secret");g();y.stripe=window.Zonos.stripe}));var w=function(){var e,t,n,r;var i=y.fetchingLandedCostAbordController;if(!i){return false}var o=JSON.stringify((e=y.stripeLinkUsedWhenFetchingLC)===null||e===void 0?void 0:e.value)!==JSON.stringify((t=y.stripeLinkEventData)===null||t===void 0?void 0:t.value);var s=JSON.stringify((n=y.stripeAddressUsedWhenFetchingLC)===null||n===void 0?void 0:n.value)!==JSON.stringify((r=y.stripeAddressEventData)===null||r===void 0?void 0:r.value);return o||s};var _=e("f",(function(){return __awaiter(c,void 0,void 0,(function(){var e,t,n,r,i,o,a,l,u,c,d,v,f,h;return __generator(this,(function(m){switch(m.label){case 0:i=!!((e=y.stripeAddressEventData)===null||e===void 0?void 0:e.complete);o=!!((t=y.stripeLinkEventData)===null||t===void 0?void 0:t.complete);a=w();if(a){(n=y.fetchingLandedCostAbordController)===null||n===void 0?void 0:n.abort();y.fetchingLandedCostAbordController=null}if(!(i&&o&&(a||!y.isFetchingLandedCost)))return[3,5];y.isFetchingLandedCost=true;if(y.stripeAddressEventData){y.stripeAddressUsedWhenFetchingLC=Object.assign({},y.stripeAddressEventData)}if(y.stripeLinkEventData){y.stripeLinkUsedWhenFetchingLC=Object.assign({},y.stripeLinkEventData)}m.label=1;case 1:m.trys.push([1,3,,4]);l=new AbortController;y.fetchingLandedCostAbordController=l;return[4,p(l)];case 2:u=m.sent(),c=u.checkoutSessionWorkflow,d=u.shipmentRatingCalculateWorkflow;y.fetchingLandedCostAbordController=null;j.landedCostData=(c===null||c===void 0?void 0:c.filter(Boolean))||null;j.shippingData=(d===null||d===void 0?void 0:d.filter(Boolean))||null;v=(r=j.landedCostData)===null||r===void 0?void 0:r.find(Boolean);f=!!v?v.subtotals:null;if(f){U({items:f.items,landedCostTotal:0,presentmentCurrencyCode:f.presentmentCurrencyCode,shipping:0,total:f.items})}return[3,4];case 3:h=m.sent();s(h);return[3,4];case 4:y.isFetchingLandedCost=false;m.label=5;case 5:return[2]}}))}))}));var k=function(e){var t=[];var n=true;switch(e){case"succeeded":{t=[a("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."),"","",a("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=false;break}case"requires_capture":case"processing":{t=[a("Payment processing. We'll update you when payment is received.")];n=false;break}case"requires_payment_method":{t=[a("Payment failed. Please try another payment method.")];break}default:{t=[a("Something went wrong.")];break}}return{isError:n,messages:t}};var A=e("l",(function(e){var t=e.clientSecret,n=e.storybookForceStatus;return __awaiter(c,void 0,void 0,(function(){var e,r,i,o,l,u,c,d,p;return __generator(this,(function(v){switch(v.label){case 0:if(n){e=k(n),r=e.isError,i=e.messages;return[2,{error:r,messages:i}]}o=t||y.clientSecret;if(!y.stripe||!o){s("Failed to retrieve payment intent. Stripe is not initialized");return[2,{error:true,message:[a("Something went wrong.")]}]}return[4,y.stripe.retrievePaymentIntent(o)];case 1:l=v.sent().paymentIntent;u=l===null||l===void 0?void 0:l.status;c=k(u),d=c.isError,p=c.messages;return[2,{error:d,messages:p}]}}))}))}));var T=e("h",(function(){return __awaiter(c,void 0,void 0,(function(){var e,t,n,r,i,o,s,a;return __generator(this,(function(l){switch(l.label){case 0:r=!!((e=y.stripePaymentEventData)===null||e===void 0?void 0:e.complete);i=y.stripeElements;o=y.stripe;s=y.clientSecret;if(!(o&&i&&r&&s))return[3,2];return[4,o.confirmPayment({confirmParams:{receipt_email:(n=(t=y.stripeLinkEventData)===null||t===void 0?void 0:t.value)===null||n===void 0?void 0:n.email,return_url:window.location.href},elements:i,redirect:"if_required"})];case 1:a=l.sent().error;if(a){if(a.type==="card_error"||a.type==="validation_error"){throw new Error(a.message)}if(a.type==="invalid_request_error"){if(a.code==="payment_intent_unexpected_state"){return[2]}}throw new Error("An unexpected error occurred.")}l.label=2;case 2:return[2]}}))}))}));var D=e("d",(function(){return __awaiter(c,void 0,void 0,(function(){var e,t,n,a,l,u;return __generator(this,(function(c){switch(c.label){case 0:t=j.items.reduce((function(e,t){return e+t.amount*t.quantity}),0);if(!t||!o.targetCurrency){s("Fail to create checkout session - invalid total or currency");return[2,false]}y.isFetchingSession=true;return[4,r("".concat("https://route.js.zonos.com","/api/create-checkout-session"),{body:{currency:((e=j.items.find(Boolean))===null||e===void 0?void 0:e.currencyCode)||"",itemsAmount:t,presentmentCountryCode:o.selectedCountryCode||null},method:"POST"})];case 1:n=c.sent(),a=n.errors,l=n.json;y.isFetchingSession=false;if(a.length||!l){s("Error occurs when creating checkout session",JSON.stringify(a,null,2));return[2,false]}u=l.checkoutSessionCreate;y.clientSecret=u.clientSecret;j.checkoutSessionId=u.id;U(Object.assign(Object.assign({},u.subtotals),{landedCostTotal:0,shipping:0,total:u.subtotals.items}));i("done-init-checkout-session");return[2,true]}}))}))}));var E=function(e){var t=e.currency,n=e.id,i=e.itemsAmount,o=e.landedCostId,a=e.presentmentCountryCode;return __awaiter(c,void 0,void 0,(function(){var e,l,u;return __generator(this,(function(c){switch(c.label){case 0:return[4,r("".concat("https://route.js.zonos.com","/api/update-checkout-session"),{body:{currency:t,id:n,itemsAmount:i,landedCostId:o,presentmentCountryCode:a},method:"POST"})];case 1:e=c.sent(),l=e.errors,u=e.json;if(l.length||!u){s("Error occurs when updating checkout session",JSON.stringify(l,null,2));return[2,{errors:l,json:u}]}return[2,{errors:[],json:u}]}}))}))};m("clientSecret",(function(e){if(e&&y.stripe){sessionStorage.setItem("zonos--client-secret",e)}if(!e){sessionStorage.removeItem("zonos--client-secret")}}));var L=function(e){var t=e.date,n=e.formatOptions,r=n===void 0?{day:"numeric",weekday:"long",year:"numeric"}:n;return new Intl.DateTimeFormat("en-US",r).format(t)};var O=function(e){var t=new Date;var n=e.getTime()-t.getTime();var r=Math.floor(n/(1e3*60*60*24));return r};var I=t((function(){return{checkoutSessionId:sessionStorage.getItem("zonos--checkout-session-id")||null,currency:"USD",dutiesTaxFees:0,error:null,isSelectedShippingAboveDeminimis:false,isSelectedShippingGuarantee:false,items:[],landedCostData:null,selectedLandedCost:null,selectedShippingOption:null,selectedShippingOptionExpectedDate:"",selectedShippingOptionTransitTime:"",shipping:0,shippingData:null,step:"customer-info",subtotal:0,total:0}})),x=I.onChange,F=I.reset,j=I.state;e("c",j);var P=e("n",(function(e){var t=e.minTransitAt?O(new Date(e.minTransitAt)):"";var n=e.maxTransitAt?O(new Date(e.maxTransitAt)):"";var r=e.minTransitAt?L({date:new Date(e.minTransitAt)}):"";return{expectedDate:r,maxTransit:n,minTransit:t}}));var z=e("b",(function(){sessionStorage.removeItem("zonos--checkout-session-id");F()}));var B=e("e",(function(e){var t=e.messages,n=e.title;j.step="error";j.error={messages:t,title:n}}));var U=function(e){j.dutiesTaxFees=e.landedCostTotal;j.subtotal=e.items;j.total=e.total;j.currency=e.presentmentCurrencyCode};var N=function(e){var t=e.currency,n=e.itemsAmount,r=e.landedCostId;return __awaiter(c,void 0,void 0,(function(){var e,i;return __generator(this,(function(l){switch(l.label){case 0:if(r&&j.selectedLandedCost){e=j.selectedLandedCost.subtotals;U(e)}if(!j.checkoutSessionId){s("Could update cart total without checkout session id");return[2,false]}return[4,E({currency:t,id:j.checkoutSessionId,itemsAmount:n,landedCostId:r,presentmentCountryCode:o.selectedCountryCode})];case 1:i=l.sent().json;if(!i){s("Error occurs when updating checkout session");B({messages:[a("There's been an error updating your checkout session. Please reload and try again or contact support if the error persists")],title:a("Error updating Checkout")});return[2,false]}if(!r){U(i.checkoutSessionUpdate.subtotals)}return[2,true]}}))}))};var R=e("m",(function(e){return __awaiter(c,void 0,void 0,(function(){var t,n,r,i,o,s,a,l,u,c,d,p,v;return __generator(this,(function(f){switch(f.label){case 0:j.selectedShippingOption=e;s=P(j.selectedShippingOption),a=s.expectedDate,l=s.maxTransit,u=s.minTransit;j.selectedShippingOptionExpectedDate=a;j.selectedShippingOptionTransitTime=u&&l?"".concat(u,"-").concat(l):"".concat(u||l);c=(t=j.landedCostData)===null||t===void 0?void 0:t.find((function(e){var t,n,r;return((n=(t=e.landedCost)===null||t===void 0?void 0:t.shipmentRating)===null||n===void 0?void 0:n.id)===((r=j.selectedShippingOption)===null||r===void 0?void 0:r.id)}));j.selectedLandedCost=c||null;if(!c){return[2,false]}j.shipping=c.subtotals.shipping;d=((n=c===null||c===void 0?void 0:c.landedCost)===null||n===void 0?void 0:n.landedCostGuaranteeCode)==="ZONOS";p=!!((i=(r=c===null||c===void 0?void 0:c.landedCost)===null||r===void 0?void 0:r.deMinimis)===null||i===void 0?void 0:i.find((function(e){return["DUTY","TAX"].includes(e.type)&&e.threshold==="ABOVE"})));j.isSelectedShippingAboveDeminimis=p;j.isSelectedShippingGuarantee=d;return[4,N({landedCostId:(o=c.landedCost)===null||o===void 0?void 0:o.id})];case 1:v=f.sent();return[2,v]}}))}))}));x("checkoutSessionId",(function(){if(!j.checkoutSessionId){sessionStorage.removeItem("zonos--checkout-session-id");return}sessionStorage.setItem("zonos--checkout-session-id",j.checkoutSessionId)}));var W=e("a",(function(e){return __awaiter(c,void 0,void 0,(function(){var t,n,r;return __generator(this,(function(i){switch(i.label){case 0:j.items=e;n=(t=e.find(Boolean))===null||t===void 0?void 0:t.currencyCode;r=e.reduce((function(e,t){return e+t.amount*t.quantity}),0);if(!n||!r){return[2]}j.currency=n;y.isFetchingSession=true;return[4,N({currency:n,itemsAmount:r})];case 1:i.sent();y.isFetchingSession=false;return[2]}}))}))}));var q=function(){j.selectedShippingOption=null;j.isSelectedShippingAboveDeminimis=false;j.isSelectedShippingGuarantee=false;j.selectedShippingOptionExpectedDate="";j.selectedShippingOptionTransitTime="";j.shipping=0};var G=e("g",(function(){if(j.step==="customer-info"){j.step="shipping"}else if(j.step==="shipping"){j.step="payment"}else if(j.step==="payment"){j.step="finish"}}));var J=e("k",(function(){if(j.step==="payment"){j.step="shipping"}else if(j.step==="shipping"){j.step="customer-info";q()}}))}}}));
2
- //# sourceMappingURL=cart-ecd9011b.system.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["prepCalculateLandedCost","stripeLinkData","stripeStore","stripeLinkEventData","stripeAddressData","stripeAddressEventData","complete","Error","checkoutSessionId","cartStore","contact","email","value","firstName","lastName","phone","items","map","item","amount","countryOfOrigin","currencyCode","imageUrl","name","productId","quantity","shippingAddress","addressLine1","address","line1","addressLine2","line2","city","country","postalCode","postal_code","state","calculateLandedCost","abortController","__awaiter","_this","url","concat","handleFetch","body","method","signal","_f","_g","sent","errors","json","length","addressRuleStyle","theme","padding","paddingBottom","paddingLeft","paddingRight","paddingTop","defaultVariable","borderStyle","borderRadius","getBorderRadius","colorBackground","colorBackgroundText","colorText","colorTextPlaceholder","createStore","clientSecret","sessionStorage","getItem","fetchingLandedCostAbordController","isFetchingLandedCost","isFetchingSession","stripe","stripeAddressElement","stripeAddressUsedWhenFetchingLC","stripeElements","stripeLinkElement","stripeLinkUsedWhenFetchingLC","stripePaymentElement","stripePaymentEventData","onChange","reset","exports","getStripeOptions","overrideBorderRaidus","overridePrimaryColor","overrideTheme","primaryColor","zonosStore","appearance","colorPrimary","themeBasedColor","isDarkColor","labels","rules","Object","assign","variables","locale","localizationStore","selectedLocale","initStripeElements","props","log","stripeOptions","_a","elements","update","stripeStoreReset","removeItem","window","Zonos","isPrefetchInfoOutdated","hasAbortController","isLinkDataDirty","JSON","stringify","_b","isAddressDataDirty","_c","_d","stripeStorePrefetchLandedCost","stripeAddressReady","stripeLinkReady","shouldRefetch","abort","AbortController","checkoutSessionWorkflow","shipmentRatingCalculateWorkflow","landedCostData","filter","Boolean","shippingData","firstLandedCostData","find","subtotals","cartStoreApplySubtotals","landedCostTotal","presentmentCurrencyCode","shipping","total","logError","err_1","getStripeMessageBasedOnStatus","status","messages","isError","translate","stripeStoreRetrievePayment","_clientSecret","storybookForceStatus","isError_1","messages_1","error","message","retrievePaymentIntent","paymentIntent","_j","_h","stripeStoreConfirmPayment","stripePaymentReady","stripeClientSecret","confirmPayment","confirmParams","receipt_email","return_url","location","href","redirect","type","code","stripeStoreInitCheckoutSession","reduce","targetCurrency","currency","itemsAmount","presentmentCountryCode","selectedCountryCode","result","checkoutSessionCreate","id","stripeStoreUpdateCheckoutSession","landedCostId","setItem","formatDate","date","formatOptions","day","weekday","year","Intl","DateTimeFormat","format","getDaysDifference","targetDate","currentDate","Date","timeDifference","getTime","daysDifference","Math","floor","dutiesTaxFees","isSelectedShippingAboveDeminimis","isSelectedShippingGuarantee","selectedLandedCost","selectedShippingOption","selectedShippingOptionExpectedDate","selectedShippingOptionTransitTime","step","subtotal","cartStoreGetShippingTransitInfo","minTransit","minTransitAt","maxTransit","maxTransitAt","expectedDate","cartStoreReset","cartStoreUpdateToErrorState","title","cartStoreReCalculateTotal","checkoutSessionUpdate","cartStoreUpdateSelectedShippingOption","checkoutSessionPresentment","landedCost","shipmentRating","isGuarantee","landedCostGuaranteeCode","isAboveDeminimis","deMinimis","includes","threshold","_e","updateCalulateStatus","cartStoreUpdateItems","amt","cartStoreResetSelectedShippingOption","cartStoreNextStep","cartStorePreviousStep"],"sources":["src/components/utils/api/prepCalculateLandedCost.ts","src/components/utils/api/calculateLandedCost.ts","src/styles/stripe/addressRuleStyle.ts","src/styles/stripe/defaultVariable.ts","src/components/store/checkout/stripe.ts","src/components/utils/formatDate.ts","src/components/utils/getDaysDifference.ts","src/components/store/checkout/cart.ts"],"sourcesContent":["import { cartStore } from 'src/components/store/checkout/cart';\nimport { stripeStore } from 'src/components/store/checkout/stripe';\nimport type { CalculateLandedCostRequest } from 'src/types/checkout/api/CalculateLandedCostRequest';\n\nexport const prepCalculateLandedCost = (): CalculateLandedCostRequest => {\n // maybe we don't need email now for prefetch the landed cost\n const stripeLinkData = stripeStore.stripeLinkEventData;\n\n const stripeAddressData = stripeStore.stripeAddressEventData;\n if (!stripeAddressData || !stripeAddressData.complete) {\n throw new Error('Missing stripe address data');\n }\n\n return {\n checkoutSessionId: cartStore.checkoutSessionId || '',\n contact: {\n email: stripeLinkData?.value.email || '',\n // firstName and lastName should be valid now since stripe only mark\n // the address as complete when both fields are filled.\n firstName: stripeAddressData.value.firstName || '',\n lastName: stripeAddressData.value.lastName || '',\n phone: stripeAddressData.value.phone || '',\n },\n items: cartStore.items.map(item => ({\n amount: item.amount,\n countryOfOrigin: item.countryOfOrigin,\n currencyCode: item.currencyCode,\n imageUrl: item.imageUrl,\n name: item.name,\n productId: item.productId,\n quantity: item.quantity,\n })),\n shippingAddress: {\n addressLine1: stripeAddressData.value.address.line1,\n addressLine2: stripeAddressData.value.address.line2 || '',\n city: stripeAddressData.value.address.city,\n country: stripeAddressData.value.address.country,\n postalCode: stripeAddressData.value.address.postal_code,\n state: stripeAddressData.value.address.state,\n },\n };\n};\n","import { prepCalculateLandedCost } from 'src/components/utils/api/prepCalculateLandedCost';\nimport { handleFetch } from 'src/components/utils/handleFetch';\nimport type { CalculateLandedCostRequest } from 'src/types/checkout/api/CalculateLandedCostRequest';\nimport type { CalculateLandedCostMutation } from 'src/types/generated/graphql.customer.types';\n\nexport const calculateLandedCost = async (\n abortController?: AbortController,\n) => {\n // request to get landed cost info\n const url = `${process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL}/api/calculate-landed-cost`;\n const { errors, json } = await handleFetch<\n CalculateLandedCostMutation,\n CalculateLandedCostRequest\n >(url, {\n body: prepCalculateLandedCost(),\n method: 'POST',\n signal: abortController?.signal,\n });\n if (errors.length || !json) {\n throw new Error('Failed to calculate landed cost');\n }\n\n return json;\n};\n","import type { ElementsUiTheme, StripeRuleType } from 'src/types';\n\nexport const addressRuleStyle = ({\n theme,\n}: {\n theme: ElementsUiTheme;\n}): StripeRuleType => {\n switch (theme) {\n default:\n return {\n '.Input': {\n // need to reset everything and the paddingTop to default, otherwise the paddingTop will not be updated.\n padding: '0',\n paddingBottom: '8px',\n paddingLeft: '16px',\n paddingRight: '8px',\n // any value here will be add up to the default paddingTop (20px).\n paddingTop: '6px',\n },\n };\n }\n};\n","import type { Appearance } from '@stripe/stripe-js';\n\nimport { getBorderRadius } from 'src/components/utils/getBorderRadius';\nimport type {\n ElementsUiStyle,\n ElementsUiTheme,\n} from 'src/types/generated/graphql.customer.types';\n\nexport const defaultVariable = ({\n borderStyle,\n theme,\n}: {\n borderStyle?: ElementsUiStyle;\n theme: ElementsUiTheme;\n}): Appearance['variables'] => {\n switch (theme) {\n case 'DARK':\n return {\n borderRadius: getBorderRadius(borderStyle),\n colorBackground: '#101117',\n colorBackgroundText: '#C5C6CA',\n colorText: '#C5C6CA',\n colorTextPlaceholder: '#C5C6CA',\n };\n default:\n return {\n borderRadius: getBorderRadius(borderStyle),\n };\n }\n};\n","import { createStore } from '@stencil/store';\nimport type {\n PaymentIntent,\n Stripe,\n StripeAddressElement,\n StripeAddressElementChangeEvent,\n StripeElements,\n StripeElementsOptionsClientSecret,\n StripeLinkAuthenticationElement,\n StripeLinkAuthenticationElementChangeEvent,\n StripePaymentElement,\n StripePaymentElementChangeEvent,\n} from '@stripe/stripe-js';\n\nimport {\n cartStore,\n cartStoreApplySubtotals,\n} from 'src/components/store/checkout/cart';\nimport { localizationStore } from 'src/components/store/hello/localization';\nimport { translate } from 'src/components/store/translationStore';\nimport { zonosStore } from 'src/components/store/zonosStore';\nimport { calculateLandedCost } from 'src/components/utils/api/calculateLandedCost';\nimport { handleFetch } from 'src/components/utils/handleFetch';\nimport { isDarkColor } from 'src/components/utils/isDarkColor';\nimport { log } from 'src/components/utils/logging/log';\nimport { logError } from 'src/components/utils/logging/logError';\nimport { addressRuleStyle } from 'src/styles/stripe/addressRuleStyle';\nimport { defaultVariable } from 'src/styles/stripe/defaultVariable';\nimport type {\n CheckoutSessionCreateMutation,\n CheckoutSessionUpdateMutation,\n CountryCode,\n ElementsUiStyle,\n ElementsUiTheme,\n} from 'src/types/generated/graphql.customer.types';\n\nexport type ContactOption = {\n address: {\n city: string;\n country: string;\n line1: string;\n line2?: string;\n postal_code: string;\n state: string;\n };\n name: string;\n phone?: string;\n};\n\ntype StripeStore = {\n // client secret is used to render link and payment elements\n clientSecret: string | null;\n fetchingLandedCostAbordController: AbortController | null;\n // toggle to indicate if we are pre-fetching/fetching landed cost\n isFetchingLandedCost: boolean;\n // toggle to indicate if we are fetching checkout session\n isFetchingSession: boolean;\n stripe: Stripe | null;\n stripeAddressElement: StripeAddressElement | null;\n stripeAddressEventData: StripeAddressElementChangeEvent | null;\n stripeAddressUsedWhenFetchingLC: StripeAddressElementChangeEvent | null;\n stripeElements: StripeElements | null;\n stripeLinkElement: StripeLinkAuthenticationElement | null;\n stripeLinkEventData: StripeLinkAuthenticationElementChangeEvent | null;\n stripeLinkUsedWhenFetchingLC: StripeLinkAuthenticationElementChangeEvent | null;\n stripePaymentElement: StripePaymentElement | null;\n stripePaymentEventData: StripePaymentElementChangeEvent | null;\n};\n\nconst {\n onChange,\n reset,\n state: stripeStore,\n} = createStore<StripeStore>(() => ({\n clientSecret: sessionStorage.getItem('zonos--client-secret') || null,\n fetchingLandedCostAbordController: null,\n isFetchingLandedCost: false,\n isFetchingSession: false,\n stripe: null,\n stripeAddressElement: null,\n stripeAddressEventData: null,\n stripeAddressUsedWhenFetchingLC: null,\n stripeElements: null,\n stripeLinkElement: null,\n stripeLinkEventData: null,\n stripeLinkUsedWhenFetchingLC: null,\n stripePaymentElement: null,\n stripePaymentEventData: null,\n}));\n\nconst getStripeOptions = ({\n clientSecret,\n overrideBorderRaidus,\n overridePrimaryColor,\n overrideTheme,\n}: {\n clientSecret?: string;\n overrideBorderRaidus?: ElementsUiStyle;\n overridePrimaryColor?: string;\n overrideTheme?: ElementsUiTheme;\n}): StripeElementsOptionsClientSecret => {\n const primaryColor =\n overridePrimaryColor || zonosStore.appearance.colorPrimary;\n const themeBasedColor =\n primaryColor && isDarkColor(primaryColor) ? 'night' : 'flat';\n // if overrideTheme is provided, use it. Otherwise, use theme based on primary color\n const theme = overrideTheme === 'DARK' ? 'night' : 'flat';\n return {\n appearance: {\n labels: 'floating',\n rules: {\n ...addressRuleStyle({ theme: 'LIGHT' }),\n },\n // get contrast theme color base on primary color\n theme: overrideTheme ? theme : themeBasedColor,\n variables: {\n ...defaultVariable({\n borderStyle: overrideBorderRaidus,\n theme: 'LIGHT',\n }),\n },\n },\n clientSecret,\n locale: localizationStore.selectedLocale,\n };\n};\n\nconst initStripeElements = async (props?: {\n overrideBorderRaidus?: ElementsUiStyle;\n overridePrimaryColor?: string;\n overrideTheme?: ElementsUiTheme;\n}) => {\n const clientSecret = stripeStore.clientSecret;\n\n if (!stripeStore.stripe) {\n log('Skip. Stripe is not initialized');\n return;\n }\n if (clientSecret) {\n const stripeOptions = getStripeOptions({\n clientSecret,\n overrideBorderRaidus: props?.overrideBorderRaidus,\n overridePrimaryColor: props?.overridePrimaryColor,\n overrideTheme: props?.overrideTheme,\n });\n\n if (!stripeStore.stripeElements) {\n // init stripe elements if it doesn't exist\n stripeStore.stripeElements = stripeStore.stripe?.elements(stripeOptions);\n } else {\n // update elements with new option if it already exists\n stripeStore.stripeElements.update(stripeOptions);\n }\n log('Stripe elements initialized');\n }\n};\n\nconst stripeStoreReset = () => {\n // clean clientSecret so that we can start the new one.\n sessionStorage.removeItem('zonos--client-secret');\n\n // cleanup stripe elements\n reset();\n // set stripe back to window.Zonos.stripe\n stripeStore.stripe = window.Zonos.stripe;\n};\n\n/**\n * Check if the address and email info used when fetching landed cost with the current email and address info are different\n * Purpose is to resend the request if the info used when fetching landed cost is different from the current info\n */\nconst isPrefetchInfoOutdated = () => {\n const hasAbortController = stripeStore.fetchingLandedCostAbordController;\n if (!hasAbortController) {\n // if there is no abort controller, this is a new request\n return false;\n }\n\n const isLinkDataDirty =\n JSON.stringify(stripeStore.stripeLinkUsedWhenFetchingLC?.value) !==\n JSON.stringify(stripeStore.stripeLinkEventData?.value);\n const isAddressDataDirty =\n JSON.stringify(stripeStore.stripeAddressUsedWhenFetchingLC?.value) !==\n JSON.stringify(stripeStore.stripeAddressEventData?.value);\n\n return isLinkDataDirty || isAddressDataDirty;\n};\n\nconst stripeStorePrefetchLandedCost = async () => {\n const stripeAddressReady = !!stripeStore.stripeAddressEventData?.complete;\n const stripeLinkReady = !!stripeStore.stripeLinkEventData?.complete;\n const shouldRefetch = isPrefetchInfoOutdated();\n\n if (shouldRefetch) {\n // if the info used when fetching landed cost is different from the current info, abort the previous request\n stripeStore.fetchingLandedCostAbordController?.abort();\n stripeStore.fetchingLandedCostAbordController = null;\n }\n\n // only fetch if we are not fetching or we need to refetch\n if (\n stripeAddressReady &&\n stripeLinkReady &&\n (shouldRefetch || !stripeStore.isFetchingLandedCost)\n ) {\n stripeStore.isFetchingLandedCost = true;\n if (stripeStore.stripeAddressEventData) {\n stripeStore.stripeAddressUsedWhenFetchingLC = {\n ...stripeStore.stripeAddressEventData,\n };\n }\n if (stripeStore.stripeLinkEventData) {\n stripeStore.stripeLinkUsedWhenFetchingLC = {\n ...stripeStore.stripeLinkEventData,\n };\n }\n try {\n const abortController = new AbortController();\n stripeStore.fetchingLandedCostAbordController = abortController;\n const { checkoutSessionWorkflow, shipmentRatingCalculateWorkflow } =\n await calculateLandedCost(abortController);\n\n // reset abort controller after we are done\n stripeStore.fetchingLandedCostAbordController = null;\n\n // update cart store with landed cost info\n cartStore.landedCostData =\n checkoutSessionWorkflow?.filter(Boolean) || null;\n\n cartStore.shippingData =\n shipmentRatingCalculateWorkflow?.filter(Boolean) || null;\n // apply new subtotal and total, this is mainly to show items in the presentment currency\n const firstLandedCostData = cartStore.landedCostData?.find(Boolean);\n const subtotals = !!firstLandedCostData\n ? firstLandedCostData.subtotals\n : null;\n if (subtotals) {\n // prefetch landed cost will not update shipping and taxes since we haven't selected shipping method yet\n cartStoreApplySubtotals({\n items: subtotals.items,\n landedCostTotal: 0,\n presentmentCurrencyCode: subtotals.presentmentCurrencyCode,\n shipping: 0,\n total: subtotals.items,\n });\n }\n } catch (err) {\n logError(err);\n }\n stripeStore.isFetchingLandedCost = false;\n }\n};\n\nconst getStripeMessageBasedOnStatus = (status?: PaymentIntent['status']) => {\n let messages: string[] = [];\n let isError = true;\n // Inspect the PaymentIntent `status` to indicate the status of the payment\n // to your customer.\n //\n // Some payment methods will [immediately succeed or fail][0] upon\n // confirmation, while others will first enter a `processing` state.\n //\n // [0]: https://stripe.com/docs/payments/payment-methods#payment-notification\n switch (status) {\n case 'succeeded': {\n messages = [\n translate(\n '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.',\n ),\n '',\n '',\n translate(\n \"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 ),\n ];\n isError = false;\n break;\n }\n case 'requires_capture':\n case 'processing': {\n messages = [\n translate(\n \"Payment processing. We'll update you when payment is received.\",\n ),\n ];\n isError = false;\n break;\n }\n\n case 'requires_payment_method': {\n messages = [\n translate('Payment failed. Please try another payment method.'),\n ];\n break;\n }\n\n default: {\n messages = [translate('Something went wrong.')];\n break;\n }\n }\n return {\n isError,\n messages,\n };\n};\n\nconst stripeStoreRetrievePayment = async ({\n clientSecret: _clientSecret,\n storybookForceStatus,\n}: {\n clientSecret?: string;\n storybookForceStatus?: PaymentIntent['status'];\n}) => {\n if (storybookForceStatus) {\n // return status right away if we are in storybook mode\n const { isError, messages } =\n getStripeMessageBasedOnStatus(storybookForceStatus);\n\n return { error: isError, messages };\n }\n const clientSecret = _clientSecret || stripeStore.clientSecret;\n if (!stripeStore.stripe || !clientSecret) {\n logError('Failed to retrieve payment intent. Stripe is not initialized');\n return { error: true, message: [translate('Something went wrong.')] };\n }\n const { paymentIntent } = await stripeStore.stripe.retrievePaymentIntent(\n clientSecret,\n );\n\n const status = paymentIntent?.status;\n\n const { isError, messages } = getStripeMessageBasedOnStatus(status);\n\n return { error: isError, messages };\n};\n\nconst stripeStoreConfirmPayment = async () => {\n const stripePaymentReady = !!stripeStore.stripePaymentEventData?.complete;\n const stripeElements = stripeStore.stripeElements;\n const stripe = stripeStore.stripe;\n const stripeClientSecret = stripeStore.clientSecret;\n if (stripe && stripeElements && stripePaymentReady && stripeClientSecret) {\n const { error } = await stripe.confirmPayment({\n confirmParams: {\n receipt_email: stripeStore.stripeLinkEventData?.value?.email,\n return_url: window.location.href,\n },\n elements: stripeElements,\n redirect: 'if_required',\n });\n\n if (error) {\n if (error.type === 'card_error' || error.type === 'validation_error') {\n throw new Error(error.message);\n }\n if (error.type === 'invalid_request_error') {\n if (error.code === 'payment_intent_unexpected_state') {\n // PaymentIntent was canceled or expired, or status is `require_capture`.\n // don't throw error here because we will reset the checkout session last step\n return;\n }\n }\n throw new Error('An unexpected error occurred.');\n }\n }\n};\n\ntype CheckoutSessionCreateRequest = {\n currency: string;\n itemsAmount: number;\n presentmentCountryCode: CountryCode | null;\n};\n\n/**\n * Init checkout session\n * @returns {boolean} whether or not the checkout session is successfully created\n */\nconst stripeStoreInitCheckoutSession = async () => {\n const total = cartStore.items.reduce(\n (amount, item) => amount + item.amount * item.quantity,\n 0,\n );\n\n if (!total || !localizationStore.targetCurrency) {\n logError('Fail to create checkout session - invalid total or currency');\n return false;\n }\n\n stripeStore.isFetchingSession = true;\n\n const { errors, json } = await handleFetch<\n CheckoutSessionCreateMutation,\n CheckoutSessionCreateRequest\n >(`${process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL}/api/create-checkout-session`, {\n body: {\n currency: cartStore.items.find(Boolean)?.currencyCode || '',\n itemsAmount: total,\n presentmentCountryCode: localizationStore.selectedCountryCode || null,\n },\n method: 'POST',\n });\n\n stripeStore.isFetchingSession = false;\n\n if (errors.length || !json) {\n logError(\n 'Error occurs when creating checkout session',\n JSON.stringify(errors, null, 2),\n );\n\n return false;\n }\n const result = json.checkoutSessionCreate;\n\n stripeStore.clientSecret = result.clientSecret;\n // update cart store with updated informations\n cartStore.checkoutSessionId = result.id;\n cartStoreApplySubtotals({\n ...result.subtotals,\n landedCostTotal: 0,\n shipping: 0,\n total: result.subtotals.items,\n });\n\n log('done-init-checkout-session');\n return true;\n};\n\ntype CheckoutSessionUpdateRequest = {\n currency?: string;\n id: string;\n itemsAmount?: number;\n landedCostId?: string;\n presentmentCountryCode: CountryCode | null;\n};\n/**\n * Update checkout session. Use for updating amount with landed cost id, or update session when cart items change\n */\nconst stripeStoreUpdateCheckoutSession = async ({\n currency,\n id,\n itemsAmount,\n landedCostId,\n presentmentCountryCode,\n}: CheckoutSessionUpdateRequest) => {\n // No need to set loading state here because this function will be called under the hood to update\n // landed cost id for the section.\n const { errors, json } = await handleFetch<\n CheckoutSessionUpdateMutation,\n CheckoutSessionUpdateRequest\n >(`${process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL}/api/update-checkout-session`, {\n body: {\n currency,\n id,\n itemsAmount,\n landedCostId,\n presentmentCountryCode,\n },\n method: 'POST',\n });\n\n if (errors.length || !json) {\n logError(\n 'Error occurs when updating checkout session',\n JSON.stringify(errors, null, 2),\n );\n return { errors, json };\n }\n\n return { errors: [], json };\n};\n\nonChange('clientSecret', clientSecret => {\n // update stripe elements when client secret changes\n if (clientSecret && stripeStore.stripe) {\n sessionStorage.setItem('zonos--client-secret', clientSecret);\n }\n\n if (!clientSecret) {\n sessionStorage.removeItem('zonos--client-secret');\n }\n});\n\nexport {\n initStripeElements,\n stripeStore,\n stripeStoreConfirmPayment,\n stripeStoreInitCheckoutSession,\n stripeStorePrefetchLandedCost,\n stripeStoreReset,\n stripeStoreRetrievePayment,\n stripeStoreUpdateCheckoutSession,\n};\n","type Params = {\n date: Date;\n /**\n * Format options for Intl.DateTimeFormat\n * @default {day:'numeric',weekday:'long',year:'numeric'} Thursday 3, 2023\n */\n formatOptions?: Intl.DateTimeFormatOptions;\n};\n\nexport const formatDate = ({\n date,\n formatOptions = { day: 'numeric', weekday: 'long', year: 'numeric' },\n}: Params): string => {\n // format date to Thursday 3, 2023\n return new Intl.DateTimeFormat('en-US', formatOptions).format(date);\n};\n","export const getDaysDifference = (targetDate: Date) => {\n const currentDate = new Date();\n const timeDifference = targetDate.getTime() - currentDate.getTime();\n const daysDifference = Math.floor(timeDifference / (1000 * 60 * 60 * 24)); // Convert milliseconds to days\n return daysDifference;\n};\n","import { createStore } from '@stencil/store';\n\nimport {\n stripeStore,\n stripeStoreUpdateCheckoutSession,\n} from 'src/components/store/checkout/stripe';\nimport { localizationStore } from 'src/components/store/hello/localization';\nimport { translate } from 'src/components/store/translationStore';\nimport { formatDate } from 'src/components/utils/formatDate';\nimport { getDaysDifference } from 'src/components/utils/getDaysDifference';\nimport { logError } from 'src/components/utils/logging/logError';\nimport type {\n CheckoutPresentmentFragment,\n CurrencyCode,\n ShipmentRatingFragment,\n} from 'src/types/generated/graphql.customer.types';\n\nexport type CartItem = {\n amount: number;\n countryOfOrigin?: string;\n currencyCode: string;\n description?: string;\n hsCode?: string;\n imageUrl?: string;\n name: string;\n productId?: string;\n quantity: number;\n};\n\ntype CartStore = {\n checkoutSessionId: string | null;\n currency: CurrencyCode;\n dutiesTaxFees: number;\n error: {\n messages: string[];\n title: string;\n } | null;\n isSelectedShippingAboveDeminimis: boolean;\n isSelectedShippingGuarantee: boolean;\n items: CartItem[];\n landedCostData: CheckoutPresentmentFragment[] | null;\n selectedLandedCost: CheckoutPresentmentFragment | null;\n selectedShippingOption: ShipmentRatingFragment | null;\n selectedShippingOptionExpectedDate: string;\n selectedShippingOptionTransitTime: string;\n shipping: number;\n shippingData: ShipmentRatingFragment[] | null;\n step: 'customer-info' | 'shipping' | 'payment' | 'finish' | 'error';\n subtotal: number;\n total: number;\n};\n\nconst {\n onChange,\n reset,\n state: cartStore,\n} = createStore<CartStore>(() => ({\n checkoutSessionId:\n sessionStorage.getItem('zonos--checkout-session-id') || null,\n currency: 'USD',\n dutiesTaxFees: 0,\n error: null,\n isSelectedShippingAboveDeminimis: false,\n isSelectedShippingGuarantee: false,\n items: [],\n landedCostData: null,\n selectedLandedCost: null,\n selectedShippingOption: null,\n selectedShippingOptionExpectedDate: '',\n selectedShippingOptionTransitTime: '',\n shipping: 0,\n shippingData: null,\n step: 'customer-info',\n subtotal: 0,\n total: 0,\n}));\n\n/**\n * Format shipping transit info to be displayed on UI\n * @returns\n * - expectedDate: Thursday, Aug 12\n * - maxTransit: 5\n * - minTransit: 3\n */\nconst cartStoreGetShippingTransitInfo = (item: ShipmentRatingFragment) => {\n const minTransit = item.minTransitAt\n ? getDaysDifference(new Date(item.minTransitAt))\n : '';\n const maxTransit = item.maxTransitAt\n ? getDaysDifference(new Date(item.maxTransitAt))\n : '';\n const expectedDate = item.minTransitAt\n ? formatDate({\n date: new Date(item.minTransitAt),\n })\n : '';\n return {\n expectedDate,\n maxTransit,\n minTransit,\n };\n};\n\nconst cartStoreReset = () => {\n sessionStorage.removeItem('zonos--checkout-session-id');\n\n // reset cart store\n reset();\n};\n\nconst cartStoreUpdateToErrorState = ({\n messages,\n title,\n}: {\n messages: string[];\n title: string;\n}) => {\n cartStore.step = 'error';\n cartStore.error = {\n messages,\n title,\n };\n};\n\ntype CartSubtotals = {\n items: number;\n landedCostTotal: number;\n presentmentCurrencyCode: CurrencyCode;\n shipping: number;\n total: number;\n};\n\nconst cartStoreApplySubtotals = (subtotals: CartSubtotals) => {\n cartStore.dutiesTaxFees = subtotals.landedCostTotal;\n cartStore.subtotal = subtotals.items;\n cartStore.total = subtotals.total;\n cartStore.currency = subtotals.presentmentCurrencyCode;\n};\n\ntype CartStoreRecalculateTotalParams = Omit<\n Parameters<typeof stripeStoreUpdateCheckoutSession>[0],\n 'id' | 'presentmentCountryCode'\n>;\n\nconst cartStoreReCalculateTotal = async ({\n currency,\n itemsAmount,\n landedCostId,\n}: CartStoreRecalculateTotalParams) => {\n if (landedCostId && cartStore.selectedLandedCost) {\n // update cart total right away if we have landed cost id to avoid order total flickering\n const subtotals = cartStore.selectedLandedCost.subtotals;\n cartStoreApplySubtotals(subtotals);\n }\n // update checkout session\n if (!cartStore.checkoutSessionId) {\n logError('Could update cart total without checkout session id');\n return false;\n }\n const { json } = await stripeStoreUpdateCheckoutSession({\n currency,\n id: cartStore.checkoutSessionId,\n itemsAmount,\n landedCostId,\n presentmentCountryCode: localizationStore.selectedCountryCode,\n });\n if (!json) {\n // do nothing if we can't get checkout session\n logError('Error occurs when updating checkout session');\n cartStoreUpdateToErrorState({\n messages: [\n translate(\n \"There's been an error updating your checkout session. Please reload and try again or contact support if the error persists\",\n ),\n ],\n title: translate('Error updating Checkout'),\n });\n return false;\n }\n if (!landedCostId) {\n // This is when first open the checkout modal and we just want to get info from the old cart session.\n // use subtotals from checkout session to update cart total\n cartStoreApplySubtotals(json.checkoutSessionUpdate.subtotals);\n }\n return true;\n};\n\nconst cartStoreUpdateSelectedShippingOption = async (\n selectedShippingOption: ShipmentRatingFragment,\n) => {\n cartStore.selectedShippingOption = selectedShippingOption;\n\n // update shipping transit info\n const { expectedDate, maxTransit, minTransit } =\n cartStoreGetShippingTransitInfo(cartStore.selectedShippingOption);\n cartStore.selectedShippingOptionExpectedDate = expectedDate;\n cartStore.selectedShippingOptionTransitTime =\n minTransit && maxTransit\n ? `${minTransit}-${maxTransit}`\n : `${minTransit || maxTransit}`;\n\n const selectedLandedCost = cartStore.landedCostData?.find(\n checkoutSessionPresentment =>\n checkoutSessionPresentment.landedCost?.shipmentRating?.id ===\n cartStore.selectedShippingOption?.id,\n );\n // save selected landed cost for later use\n cartStore.selectedLandedCost = selectedLandedCost || null;\n\n if (!selectedLandedCost) {\n // do nothing if we can't find landed cost for selected shipping option\n return false;\n }\n\n // update shipping value and dutiesTaxFees on selectedShippingOption change\n cartStore.shipping = selectedLandedCost.subtotals.shipping;\n\n // update deminimis status\n const isGuarantee =\n selectedLandedCost?.landedCost?.landedCostGuaranteeCode === 'ZONOS';\n // one item in deminimis with type of duty and tax has threshold value is \"ABOVE\"\n const isAboveDeminimis = !!selectedLandedCost?.landedCost?.deMinimis?.find(\n item => ['DUTY', 'TAX'].includes(item.type) && item.threshold === 'ABOVE',\n );\n cartStore.isSelectedShippingAboveDeminimis = isAboveDeminimis;\n cartStore.isSelectedShippingGuarantee = isGuarantee;\n // update session with selected landed cost\n const updateCalulateStatus = await cartStoreReCalculateTotal({\n landedCostId: selectedLandedCost.landedCost?.id,\n });\n return updateCalulateStatus;\n};\n\nonChange('checkoutSessionId', () => {\n if (!cartStore.checkoutSessionId) {\n sessionStorage.removeItem('zonos--checkout-session-id');\n return;\n }\n sessionStorage.setItem(\n 'zonos--checkout-session-id',\n cartStore.checkoutSessionId,\n );\n});\n\nconst cartStoreUpdateItems = async (items: CartItem[]) => {\n cartStore.items = items;\n const currency = items.find(Boolean)?.currencyCode as CurrencyCode;\n const total = items.reduce((amt, item) => {\n return amt + item.amount * item.quantity;\n }, 0);\n if (!currency || !total) {\n // do nothing if we can't get currency or total\n return;\n }\n cartStore.currency = currency;\n // set loading state here because this is first load checkout session when we already have checkout session id stored\n stripeStore.isFetchingSession = true;\n await cartStoreReCalculateTotal({\n currency: currency,\n itemsAmount: total,\n });\n stripeStore.isFetchingSession = false;\n};\n\nconst cartStoreResetSelectedShippingOption = () => {\n cartStore.selectedShippingOption = null;\n cartStore.isSelectedShippingAboveDeminimis = false;\n cartStore.isSelectedShippingGuarantee = false;\n cartStore.selectedShippingOptionExpectedDate = '';\n cartStore.selectedShippingOptionTransitTime = '';\n cartStore.shipping = 0;\n};\n\nconst cartStoreNextStep = () => {\n if (cartStore.step === 'customer-info') {\n cartStore.step = 'shipping';\n } else if (cartStore.step === 'shipping') {\n cartStore.step = 'payment';\n } else if (cartStore.step === 'payment') {\n cartStore.step = 'finish';\n }\n};\n\nconst cartStorePreviousStep = () => {\n if (cartStore.step === 'payment') {\n cartStore.step = 'shipping';\n } else if (cartStore.step === 'shipping') {\n cartStore.step = 'customer-info';\n // reset selected shipping option\n cartStoreResetSelectedShippingOption();\n }\n};\n\nexport {\n cartStore,\n cartStoreApplySubtotals,\n cartStoreGetShippingTransitInfo,\n cartStoreNextStep,\n cartStorePreviousStep,\n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