@zonos/elements 1.3.6 → 1.3.7-alpha.0

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 (188) hide show
  1. package/dist/cjs/{localization-2c9f5765.js → cart-ecc80eb0.js} +721 -2
  2. package/dist/cjs/{getBorderRadius-b252096d.js → getBorderRadius-834c321d.js} +1 -1
  3. package/dist/cjs/{isDarkColor-168002d6.js → isDarkColor-924e6a7a.js} +1 -1
  4. package/dist/cjs/{submitGtag-792fe45d.js → submitGtag-907e71d3.js} +3 -3
  5. package/dist/cjs/zonos-address_4.cjs.entry.js +22 -10
  6. package/dist/cjs/zonos-badge_2.cjs.entry.js +1 -1
  7. package/dist/cjs/zonos-banner.cjs.entry.js +1 -1
  8. package/dist/cjs/zonos-button_3.cjs.entry.js +3 -3
  9. package/dist/cjs/zonos-card_2.cjs.entry.js +7 -5
  10. package/dist/cjs/zonos-cart-items_9.cjs.entry.js +39 -31
  11. package/dist/cjs/zonos-checkout.cjs.entry.js +20 -21
  12. package/dist/cjs/zonos-controller.cjs.entry.js +27 -28
  13. package/dist/cjs/zonos-country-flag.cjs.entry.js +5 -3
  14. package/dist/cjs/zonos-country-select_3.cjs.entry.js +9 -8
  15. package/dist/cjs/zonos-hello-dialog.cjs.entry.js +18 -16
  16. package/dist/cjs/zonos-hello.cjs.entry.js +34 -32
  17. package/dist/cjs/zonos-logo.cjs.entry.js +1 -1
  18. package/dist/cjs/zonos-notification.cjs.entry.js +1 -1
  19. package/dist/cjs/zonos-payment.cjs.entry.js +4 -5
  20. package/dist/cjs/zonos-select-dialog-header_2.cjs.entry.js +1 -1
  21. package/dist/cjs/zonos-shipping-rich-radio.cjs.entry.js +2 -2
  22. package/dist/cjs/zonos-text.cjs.entry.js +1 -1
  23. package/dist/cjs/{zonosStore-5d94dabb.js → zonosStore-49d4c92a.js} +4 -4
  24. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js +9 -4
  25. package/dist/collection/components/checkout/zonos-checkout/zonos-customer-info/zonos-customer-info.css +2 -1
  26. package/dist/collection/components/common/zonos-collapse/zonos-collapse.js +15 -2
  27. package/dist/collection/components/store/checkout/stripe.js +3 -0
  28. package/dist/collection/components/store/hello/localization.js +27 -1
  29. package/dist/collection/components/store/zonosStore.js +4 -4
  30. package/dist/collection/types/generated/graphql.customer.types.js +6 -0
  31. package/dist/components/stripe.js +4040 -2
  32. package/dist/components/submitGtag.js +1 -1
  33. package/dist/components/zonos-address2.js +1 -2
  34. package/dist/components/zonos-cart-subtotal2.js +1 -2
  35. package/dist/components/zonos-checkout-finish2.js +14 -6
  36. package/dist/components/zonos-checkout-footer2.js +1 -1
  37. package/dist/components/zonos-checkout-payment2.js +1 -2
  38. package/dist/components/zonos-checkout.js +1 -2
  39. package/dist/components/zonos-collapse2.js +15 -2
  40. package/dist/components/zonos-controller.js +1 -2
  41. package/dist/components/zonos-country-flag2.js +1 -1
  42. package/dist/components/zonos-country-select2.js +1 -1
  43. package/dist/components/zonos-customer-info2.js +2 -3
  44. package/dist/components/zonos-hello-dialog-footer2.js +1 -1
  45. package/dist/components/zonos-hello-dialog2.js +1 -1
  46. package/dist/components/zonos-hello.js +1 -1
  47. package/dist/components/zonos-language-select2.js +1 -1
  48. package/dist/components/zonos-review2.js +1 -2
  49. package/dist/components/zonos-shipping2.js +1 -2
  50. package/dist/components/zonosStore.js +4 -4
  51. package/dist/esm/{localization-d8f6453b.js → cart-2a0a6871.js} +707 -3
  52. package/dist/esm/{getBorderRadius-e9736f7e.js → getBorderRadius-0c7dfcf0.js} +1 -1
  53. package/dist/esm/{isDarkColor-e982fa09.js → isDarkColor-d0a57fd2.js} +1 -1
  54. package/dist/esm/{submitGtag-bebe2cb0.js → submitGtag-a38aed23.js} +2 -2
  55. package/dist/esm/zonos-address_4.entry.js +19 -7
  56. package/dist/esm/zonos-badge_2.entry.js +1 -1
  57. package/dist/esm/zonos-banner.entry.js +1 -1
  58. package/dist/esm/zonos-button_3.entry.js +3 -3
  59. package/dist/esm/zonos-card_2.entry.js +4 -2
  60. package/dist/esm/zonos-cart-items_9.entry.js +19 -11
  61. package/dist/esm/zonos-checkout.entry.js +5 -6
  62. package/dist/esm/zonos-controller.entry.js +4 -5
  63. package/dist/esm/zonos-country-flag.entry.js +4 -2
  64. package/dist/esm/zonos-country-select_3.entry.js +4 -3
  65. package/dist/esm/zonos-hello-dialog.entry.js +4 -2
  66. package/dist/esm/zonos-hello.entry.js +4 -2
  67. package/dist/esm/zonos-logo.entry.js +1 -1
  68. package/dist/esm/zonos-notification.entry.js +1 -1
  69. package/dist/esm/zonos-payment.entry.js +4 -5
  70. package/dist/esm/zonos-select-dialog-header_2.entry.js +1 -1
  71. package/dist/esm/zonos-shipping-rich-radio.entry.js +2 -2
  72. package/dist/esm/zonos-text.entry.js +1 -1
  73. package/dist/esm/{zonosStore-e6c7be3a.js → zonosStore-dec6bd7e.js} +4 -4
  74. package/dist/esm-es5/cart-2a0a6871.js +1 -0
  75. package/dist/esm-es5/{getBorderRadius-e9736f7e.js → getBorderRadius-0c7dfcf0.js} +1 -1
  76. package/dist/esm-es5/{isDarkColor-e982fa09.js → isDarkColor-d0a57fd2.js} +1 -1
  77. package/dist/esm-es5/submitGtag-a38aed23.js +1 -0
  78. package/dist/esm-es5/zonos-address_4.entry.js +1 -1
  79. package/dist/esm-es5/zonos-badge_2.entry.js +1 -1
  80. package/dist/esm-es5/zonos-banner.entry.js +1 -1
  81. package/dist/esm-es5/zonos-button_3.entry.js +1 -1
  82. package/dist/esm-es5/zonos-card_2.entry.js +1 -1
  83. package/dist/esm-es5/zonos-cart-items_9.entry.js +1 -1
  84. package/dist/esm-es5/zonos-checkout.entry.js +1 -1
  85. package/dist/esm-es5/zonos-controller.entry.js +1 -1
  86. package/dist/esm-es5/zonos-country-flag.entry.js +1 -1
  87. package/dist/esm-es5/zonos-country-select_3.entry.js +1 -1
  88. package/dist/esm-es5/zonos-hello-dialog.entry.js +1 -1
  89. package/dist/esm-es5/zonos-hello.entry.js +1 -1
  90. package/dist/esm-es5/zonos-logo.entry.js +1 -1
  91. package/dist/esm-es5/zonos-notification.entry.js +1 -1
  92. package/dist/esm-es5/zonos-payment.entry.js +1 -1
  93. package/dist/esm-es5/zonos-select-dialog-header_2.entry.js +1 -1
  94. package/dist/esm-es5/zonos-shipping-rich-radio.entry.js +1 -1
  95. package/dist/esm-es5/zonos-text.entry.js +1 -1
  96. package/dist/esm-es5/{zonosStore-e6c7be3a.js → zonosStore-dec6bd7e.js} +1 -1
  97. package/dist/scripts/loadZonos.js +1 -1
  98. package/dist/scripts/zonos.js +1 -1
  99. package/dist/scripts/zonosBase.js +1 -1
  100. package/dist/types/components/store/checkout/stripe.d.ts +4 -0
  101. package/dist/types/components/store/zonosStore.d.ts +1 -1
  102. package/dist/types/components/utils/api/getLocaleMessages.d.ts +1 -1
  103. package/dist/types/components/utils/hello/currencyConversion/getLanguageCode.d.ts +1 -1
  104. package/dist/types/types/ICountryJson.d.ts +2 -1
  105. package/dist/types/types/generated/graphql.customer.types.d.ts +15 -0
  106. package/dist/types/types/generated/graphql.customer.types.ts +24 -0
  107. package/dist/types/types/generated/graphql.frontend.types.d.ts +1 -1
  108. package/dist/types/types/generated/graphql.frontend.types.ts +1 -1
  109. package/dist/zonos-elements/p-0057e374.entry.js +1 -0
  110. package/dist/zonos-elements/p-066c5893.system.js +1 -1
  111. package/dist/zonos-elements/p-0c72fb79.system.entry.js +1 -0
  112. package/dist/zonos-elements/p-1f85a98c.system.entry.js +1 -0
  113. package/dist/zonos-elements/{p-96aabe02.entry.js → p-290c3670.entry.js} +1 -1
  114. package/dist/zonos-elements/{p-e8a9bc56.entry.js → p-2d2e1831.entry.js} +1 -1
  115. package/dist/zonos-elements/p-2f1e1cbb.system.entry.js +1 -0
  116. package/dist/zonos-elements/{p-a682fd38.system.entry.js → p-33080cde.system.entry.js} +1 -1
  117. package/dist/zonos-elements/{p-17550a10.js → p-34c03be2.js} +1 -1
  118. package/dist/zonos-elements/{p-a33745e9.entry.js → p-34efed1d.entry.js} +1 -1
  119. package/dist/zonos-elements/p-375c472a.system.entry.js +1 -0
  120. package/dist/zonos-elements/{p-fcc4f140.system.js → p-549c181b.system.js} +1 -1
  121. package/dist/zonos-elements/{p-32bca9c8.system.entry.js → p-55970b10.system.entry.js} +1 -1
  122. package/dist/zonos-elements/p-561e44d6.entry.js +1 -0
  123. package/dist/zonos-elements/{p-50287643.system.js → p-591eb6dd.system.js} +1 -1
  124. package/dist/zonos-elements/p-5b44abc8.system.js +1 -0
  125. package/dist/zonos-elements/p-5c4dc123.js +1 -0
  126. package/dist/zonos-elements/{p-ec25f180.entry.js → p-656c836b.entry.js} +1 -1
  127. package/dist/zonos-elements/{p-49a764e9.system.entry.js → p-67737613.system.entry.js} +1 -1
  128. package/dist/zonos-elements/{p-dd7729fd.system.entry.js → p-79b910bf.system.entry.js} +1 -1
  129. package/dist/zonos-elements/p-7d1d862f.system.entry.js +1 -0
  130. package/dist/zonos-elements/{p-5a113c3d.system.entry.js → p-88a55076.system.entry.js} +1 -1
  131. package/dist/zonos-elements/{p-7dd8e8ba.system.entry.js → p-8aeb4679.system.entry.js} +1 -1
  132. package/dist/zonos-elements/p-8d645a00.entry.js +1 -0
  133. package/dist/zonos-elements/p-9878a770.js +1 -0
  134. package/dist/zonos-elements/p-a219689f.entry.js +1 -0
  135. package/dist/zonos-elements/p-a3d72a33.entry.js +1 -0
  136. package/dist/zonos-elements/p-a93c594f.entry.js +1 -0
  137. package/dist/zonos-elements/{p-0c7480a5.entry.js → p-a95c034c.entry.js} +1 -1
  138. package/dist/zonos-elements/{p-7a6144b1.entry.js → p-afe40057.entry.js} +1 -1
  139. package/dist/zonos-elements/p-b10ff468.entry.js +1 -0
  140. package/dist/zonos-elements/p-b6992dc2.system.entry.js +1 -0
  141. package/dist/zonos-elements/{p-3ef27745.js → p-bce46c41.js} +1 -1
  142. package/dist/zonos-elements/p-c56d4a44.entry.js +1 -0
  143. package/dist/zonos-elements/{p-bd6a2095.entry.js → p-c7098c3b.entry.js} +1 -1
  144. package/dist/zonos-elements/{p-f49dfd06.system.js → p-cbb1e700.system.js} +1 -1
  145. package/dist/zonos-elements/p-cc63a29f.system.entry.js +1 -0
  146. package/dist/zonos-elements/p-cd8bd5e9.system.entry.js +1 -0
  147. package/dist/zonos-elements/p-d36faf87.system.entry.js +1 -0
  148. package/dist/zonos-elements/p-dfd3edcf.entry.js +1 -0
  149. package/dist/zonos-elements/{p-ba43275e.entry.js → p-e161a08c.entry.js} +1 -1
  150. package/dist/zonos-elements/{p-9cbbf261.system.entry.js → p-e2770968.system.entry.js} +1 -1
  151. package/dist/zonos-elements/p-e2c6ad57.entry.js +1 -0
  152. package/dist/zonos-elements/{p-b81a0577.system.entry.js → p-e855966f.system.entry.js} +1 -1
  153. package/dist/zonos-elements/p-ea93943a.system.entry.js +1 -0
  154. package/dist/zonos-elements/{p-e99d79d9.system.js → p-ec4d08b3.system.js} +1 -1
  155. package/dist/zonos-elements/{p-47fac33f.js → p-f455e08c.js} +1 -1
  156. package/dist/zonos-elements/zonos-elements.esm.js +1 -1
  157. package/package.json +1 -1
  158. package/dist/cjs/cart-b8bbf22d.js +0 -698
  159. package/dist/components/localization.js +0 -4016
  160. package/dist/esm/cart-bc3bb22e.js +0 -682
  161. package/dist/esm-es5/cart-bc3bb22e.js +0 -1
  162. package/dist/esm-es5/localization-d8f6453b.js +0 -1
  163. package/dist/esm-es5/submitGtag-bebe2cb0.js +0 -1
  164. package/dist/zonos-elements/p-00d63df1.system.entry.js +0 -1
  165. package/dist/zonos-elements/p-04f63cea.entry.js +0 -1
  166. package/dist/zonos-elements/p-16b74c31.system.js +0 -1
  167. package/dist/zonos-elements/p-1d16a6fb.js +0 -1
  168. package/dist/zonos-elements/p-1ea68e3b.entry.js +0 -1
  169. package/dist/zonos-elements/p-1ed530cc.entry.js +0 -1
  170. package/dist/zonos-elements/p-289c8b1a.system.entry.js +0 -1
  171. package/dist/zonos-elements/p-2a00c270.system.entry.js +0 -1
  172. package/dist/zonos-elements/p-37f53a79.entry.js +0 -1
  173. package/dist/zonos-elements/p-394cf1cf.js +0 -1
  174. package/dist/zonos-elements/p-458fd100.system.entry.js +0 -1
  175. package/dist/zonos-elements/p-4fafb2a5.system.entry.js +0 -1
  176. package/dist/zonos-elements/p-4fb71a93.js +0 -1
  177. package/dist/zonos-elements/p-5276c61b.system.entry.js +0 -1
  178. package/dist/zonos-elements/p-6308b347.entry.js +0 -1
  179. package/dist/zonos-elements/p-63d1b1fe.entry.js +0 -1
  180. package/dist/zonos-elements/p-7347ee7c.system.entry.js +0 -1
  181. package/dist/zonos-elements/p-8c26a080.system.js +0 -1
  182. package/dist/zonos-elements/p-ba1a111a.system.entry.js +0 -1
  183. package/dist/zonos-elements/p-c4321084.system.entry.js +0 -1
  184. package/dist/zonos-elements/p-cdf114a2.entry.js +0 -1
  185. package/dist/zonos-elements/p-d5ae3cbb.system.entry.js +0 -1
  186. package/dist/zonos-elements/p-d5d7c8f5.entry.js +0 -1
  187. package/dist/zonos-elements/p-de339fb6.entry.js +0 -1
  188. package/dist/zonos-elements/p-f6f5f644.entry.js +0 -1
@@ -1,4 +1,6 @@
1
- import { c as createStore, z as zonosStore } from './zonosStore-e6c7be3a.js';
1
+ import { c as createStore, z as zonosStore } from './zonosStore-dec6bd7e.js';
2
+ import { i as isDarkColor } from './isDarkColor-d0a57fd2.js';
3
+ import { g as getBorderRadius } from './getBorderRadius-0c7dfcf0.js';
2
4
 
3
5
  const stringsArabic = {
4
6
  'Above de minimis threshold for': {
@@ -3987,7 +3989,7 @@ const initLocalizationStore = async () => {
3987
3989
  // Filter countries to only include countries in the shipping zone
3988
3990
  const filteredCountries = shippingZoneCountries === null || shippingZoneCountries === void 0 ? void 0 : shippingZoneCountries.reduce((acc, countryCode) => {
3989
3991
  const countryInfo = allCountries === null || allCountries === void 0 ? void 0 : allCountries[countryCode];
3990
- return countryInfo
3992
+ return countryInfo && countryInfo.active
3991
3993
  ? Object.assign(Object.assign({}, acc), { [countryCode]: countryInfo }) : acc;
3992
3994
  }, {});
3993
3995
  localizationStore.shippingZoneCountries = filteredCountries || null;
@@ -4008,9 +4010,711 @@ const initLocalizationStore = async () => {
4008
4010
  localizationStore.localizationLoaded = true;
4009
4011
  void getCustomMessages();
4010
4012
  };
4013
+ const updateCheckoutSessionLanguage = async () => {
4014
+ if (!cartStore.checkoutSessionId) {
4015
+ return null;
4016
+ }
4017
+ const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/update-checkout-session-metadata`, {
4018
+ body: {
4019
+ id: cartStore.checkoutSessionId,
4020
+ metadata: [
4021
+ {
4022
+ key: 'language',
4023
+ value: localizationStore.selectedLocale,
4024
+ },
4025
+ ],
4026
+ },
4027
+ method: 'POST',
4028
+ });
4029
+ if (errors.length || !json) {
4030
+ logError('Error occurs when updating checkout session', JSON.stringify(errors, null, 2));
4031
+ return { errors, json };
4032
+ }
4033
+ return { errors: [], json };
4034
+ };
4011
4035
  const localizationStoreUpdateSelectedLocale = (newSelectedLocale) => {
4012
4036
  localizationStore.selectedLocale = newSelectedLocale;
4013
4037
  translationStoreUpdateLanguage(newSelectedLocale);
4038
+ void updateCheckoutSessionLanguage();
4039
+ };
4040
+
4041
+ const prepCalculateLandedCost = () => {
4042
+ // maybe we don't need email now for prefetch the landed cost
4043
+ const stripeLinkData = stripeStore.stripeLinkEventData;
4044
+ const stripeAddressData = stripeStore.stripeAddressEventData;
4045
+ const stripeBillingAddressData = stripeStore.stripeShippingSameAsBilling
4046
+ ? stripeStore.stripeAddressEventData
4047
+ : stripeStore.stripeBillingAddressEventData;
4048
+ if (!(stripeAddressData === null || stripeAddressData === void 0 ? void 0 : stripeAddressData.complete) || !(stripeBillingAddressData === null || stripeBillingAddressData === void 0 ? void 0 : stripeBillingAddressData.complete)) {
4049
+ throw new Error('Missing stripe address data');
4050
+ }
4051
+ return {
4052
+ billingAddress: {
4053
+ addressLine1: stripeBillingAddressData.value.address.line1,
4054
+ addressLine2: stripeBillingAddressData.value.address.line2 || '',
4055
+ city: stripeBillingAddressData.value.address.city,
4056
+ country: stripeBillingAddressData.value.address.country,
4057
+ postalCode: stripeBillingAddressData.value.address.postal_code,
4058
+ state: stripeBillingAddressData.value.address.state,
4059
+ },
4060
+ billingContact: {
4061
+ // firstName and lastName should be valid now since stripe only mark
4062
+ // the address as complete when both fields are filled.
4063
+ firstName: stripeBillingAddressData.value.firstName || '',
4064
+ lastName: stripeBillingAddressData.value.lastName || '',
4065
+ phone: stripeBillingAddressData.value.phone || '',
4066
+ },
4067
+ checkoutSessionId: cartStore.checkoutSessionId || '',
4068
+ contact: {
4069
+ email: (stripeLinkData === null || stripeLinkData === void 0 ? void 0 : stripeLinkData.value.email) || '',
4070
+ // firstName and lastName should be valid now since stripe only mark
4071
+ // the address as complete when both fields are filled.
4072
+ firstName: stripeAddressData.value.firstName || '',
4073
+ lastName: stripeAddressData.value.lastName || '',
4074
+ phone: stripeAddressData.value.phone || '',
4075
+ },
4076
+ items: cartStore.items.map(item => item),
4077
+ shippingAddress: {
4078
+ addressLine1: stripeAddressData.value.address.line1,
4079
+ addressLine2: stripeAddressData.value.address.line2 || '',
4080
+ city: stripeAddressData.value.address.city,
4081
+ country: stripeAddressData.value.address.country,
4082
+ postalCode: stripeAddressData.value.address.postal_code,
4083
+ state: stripeAddressData.value.address.state,
4084
+ },
4085
+ };
4086
+ };
4087
+
4088
+ const triggerBuildLandedCost = async (buildLandedCost) => {
4089
+ var _a, _b, _c, _d;
4090
+ const data = prepCalculateLandedCost();
4091
+ const landedCost = await buildLandedCost({
4092
+ billingAddress: data.billingAddress,
4093
+ billingContact: data.billingContact,
4094
+ checkoutSessionId: data.checkoutSessionId,
4095
+ contact: data.contact,
4096
+ shippingAddress: data.shippingAddress,
4097
+ });
4098
+ if (!landedCost || ((_a = landedCost.errors) === null || _a === void 0 ? void 0 : _a.length)) {
4099
+ throw new Error(`Failed to build landed cost: ${((_c = (_b = landedCost === null || landedCost === void 0 ? void 0 : landedCost.errors) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.message) || 'Unknown error'}`);
4100
+ }
4101
+ // Validate the landed cost object to make sure the returned value from buildLandedCost has a valid schema
4102
+ const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/validate-landed-cost`, {
4103
+ body: landedCost,
4104
+ headers: {
4105
+ 'Content-Type': 'application/json',
4106
+ },
4107
+ method: 'POST',
4108
+ });
4109
+ if (!json || errors.length) {
4110
+ throw new Error(`Invalid landed cost object: ${((_d = errors.find(Boolean)) === null || _d === void 0 ? void 0 : _d.message) || 'Unknown error'}`);
4111
+ }
4112
+ return landedCost;
4113
+ };
4114
+
4115
+ const calculateLandedCost = async (abortController) => {
4116
+ var _a;
4117
+ // If buildLandedCost callback is supplied, use that instead of our regular request to '/calculate-landed-cost'
4118
+ const buildLandedCost = zonosStore.checkoutSettings.buildLandedCost;
4119
+ if (buildLandedCost) {
4120
+ const json = await triggerBuildLandedCost(buildLandedCost);
4121
+ return json;
4122
+ }
4123
+ // request to get landed cost info
4124
+ const url = `${"https://v1.route.js.zonos.com"}/api/zonos-elements/calculate-landed-cost`;
4125
+ const { errors, json } = await handleFetch(url, {
4126
+ body: prepCalculateLandedCost(),
4127
+ method: 'POST',
4128
+ signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
4129
+ });
4130
+ if (errors.length || !json) {
4131
+ const isAbortedRequest = ((_a = errors[0]) === null || _a === void 0 ? void 0 : _a.message) === 'The user aborted a request.';
4132
+ const errorMessage = isAbortedRequest
4133
+ ? 'The landed cost calculation request was aborted to initiate a new one.'
4134
+ : 'Failed to calculate landed cost';
4135
+ throw new Error(errorMessage);
4136
+ }
4137
+ return json;
4138
+ };
4139
+
4140
+ const addressRuleStyle = ({ theme, }) => {
4141
+ switch (theme) {
4142
+ default:
4143
+ return {
4144
+ '.Input': {
4145
+ // need to reset everything and the paddingTop to default, otherwise the paddingTop will not be updated.
4146
+ padding: '0',
4147
+ paddingBottom: '8px',
4148
+ paddingLeft: '16px',
4149
+ paddingRight: '8px',
4150
+ // any value here will be add up to the default paddingTop (20px).
4151
+ paddingTop: '6px',
4152
+ },
4153
+ };
4154
+ }
4155
+ };
4156
+
4157
+ const defaultVariable = ({ borderStyle, theme, }) => {
4158
+ switch (theme) {
4159
+ case 'DARK':
4160
+ return {
4161
+ borderRadius: getBorderRadius(borderStyle),
4162
+ colorBackground: '#101117',
4163
+ colorBackgroundText: '#C5C6CA',
4164
+ colorText: '#C5C6CA',
4165
+ colorTextPlaceholder: '#C5C6CA',
4166
+ };
4167
+ default:
4168
+ return {
4169
+ borderRadius: getBorderRadius(borderStyle),
4170
+ };
4171
+ }
4172
+ };
4173
+
4174
+ const { onChange: onChange$1, reset: reset$1, state: stripeStore, } = createStore(() => ({
4175
+ clientSecret: sessionStorage.getItem('zonos--client-secret') || null,
4176
+ fetchingLandedCostAbordController: null,
4177
+ isFetchingLandedCost: false,
4178
+ isFetchingSession: false,
4179
+ stripe: null,
4180
+ stripeAddressElement: null,
4181
+ stripeAddressEventData: null,
4182
+ stripeAddressUsedWhenFetchingLC: null,
4183
+ stripeBillingAddressElement: null,
4184
+ stripeBillingAddressEventData: null,
4185
+ stripeBillingAddressUsedWhenFetchingLC: null,
4186
+ stripeElements: null,
4187
+ stripeElementsForBillingAddress: null,
4188
+ stripeElementsOptions: null,
4189
+ stripeLinkElement: null,
4190
+ stripeLinkEventData: null,
4191
+ stripeLinkUsedWhenFetchingLC: null,
4192
+ stripePaymentElement: null,
4193
+ stripePaymentEventData: null,
4194
+ stripeShippingSameAsBilling: true,
4195
+ }));
4196
+ const getStripeOptions = ({ clientSecret, overrideBorderRaidus, overridePrimaryColor, overrideSecondaryColor, overrideTheme, }) => {
4197
+ const primaryColor = overridePrimaryColor || zonosStore.appearance.colorPrimary;
4198
+ const secondaryColor = overrideSecondaryColor || zonosStore.appearance.colorSecondary;
4199
+ const themeBasedColor = primaryColor && isDarkColor(primaryColor) ? 'night' : 'flat';
4200
+ // if overrideTheme is provided, use it. Otherwise, use theme based on primary color
4201
+ const theme = overrideTheme === 'DARK' ? 'night' : 'flat';
4202
+ return {
4203
+ appearance: {
4204
+ labels: 'floating',
4205
+ rules: Object.assign({}, addressRuleStyle({ theme: 'LIGHT' })),
4206
+ // get contrast theme color base on primary color
4207
+ theme: overrideTheme ? theme : themeBasedColor,
4208
+ variables: Object.assign(Object.assign({}, defaultVariable({
4209
+ borderStyle: overrideBorderRaidus,
4210
+ theme: 'LIGHT',
4211
+ })), {
4212
+ // use the button background color for input glow color
4213
+ colorPrimary: secondaryColor }),
4214
+ },
4215
+ clientSecret,
4216
+ locale: localizationStore.selectedLocale,
4217
+ };
4218
+ };
4219
+ const initStripeElements = async (props) => {
4220
+ var _a, _b;
4221
+ const clientSecret = stripeStore.clientSecret;
4222
+ if (!stripeStore.stripe) {
4223
+ log('Skip. Stripe is not initialized');
4224
+ return;
4225
+ }
4226
+ if (clientSecret) {
4227
+ const stripeOptions = getStripeOptions({
4228
+ clientSecret,
4229
+ overrideBorderRaidus: props === null || props === void 0 ? void 0 : props.overrideBorderRaidus,
4230
+ overridePrimaryColor: props === null || props === void 0 ? void 0 : props.overridePrimaryColor,
4231
+ overrideSecondaryColor: props === null || props === void 0 ? void 0 : props.overrideSecondaryColor,
4232
+ overrideTheme: props === null || props === void 0 ? void 0 : props.overrideTheme,
4233
+ });
4234
+ // compare with the previous options to see if we need to update
4235
+ const isSameOptions = JSON.stringify(stripeOptions) ===
4236
+ JSON.stringify(stripeStore.stripeElementsOptions);
4237
+ if (!stripeStore.stripeElements ||
4238
+ !stripeStore.stripeElementsForBillingAddress) {
4239
+ // init stripe elements if it doesn't exist
4240
+ stripeStore.stripeElements = (_a = stripeStore.stripe) === null || _a === void 0 ? void 0 : _a.elements(stripeOptions);
4241
+ // save stripe elements options for later comparison
4242
+ stripeStore.stripeElementsOptions = stripeOptions;
4243
+ log('Stripe elements initialized');
4244
+ // init stripe elements for billing address
4245
+ stripeStore.stripeElementsForBillingAddress =
4246
+ (_b = stripeStore.stripe) === null || _b === void 0 ? void 0 : _b.elements(stripeOptions);
4247
+ log('Stripe elements for billing address initialized');
4248
+ return;
4249
+ }
4250
+ if (!isSameOptions) {
4251
+ // update elements with new option if it already exists
4252
+ stripeStore.stripeElements.update(stripeOptions);
4253
+ // update elements for stripe billing address
4254
+ stripeStore.stripeElementsForBillingAddress.update(stripeOptions);
4255
+ // save stripe elements options for later comparison
4256
+ stripeStore.stripeElementsOptions = stripeOptions;
4257
+ }
4258
+ log('Stripe elements initialized');
4259
+ }
4260
+ };
4261
+ const stripeStoreReset = () => {
4262
+ // clean clientSecret so that we can start the new one.
4263
+ sessionStorage.removeItem('zonos--client-secret');
4264
+ // cleanup stripe elements
4265
+ reset$1();
4266
+ // set stripe back to window.Zonos.stripe
4267
+ stripeStore.stripe = window.Zonos.stripe;
4268
+ };
4269
+ /**
4270
+ * Check if the address and email info used when fetching landed cost with the current email and address info are different
4271
+ * Purpose is to resend the request if the info used when fetching landed cost is different from the current info
4272
+ */
4273
+ const isPrefetchInfoOutdated = () => {
4274
+ var _a, _b, _c, _d, _e, _f;
4275
+ const hasAbortController = stripeStore.fetchingLandedCostAbordController;
4276
+ if (!hasAbortController) {
4277
+ // if there is no abort controller, this is a new request
4278
+ return false;
4279
+ }
4280
+ const isLinkDataDirty = JSON.stringify((_a = stripeStore.stripeLinkUsedWhenFetchingLC) === null || _a === void 0 ? void 0 : _a.value) !==
4281
+ JSON.stringify((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.value);
4282
+ const isAddressDataDirty = JSON.stringify((_c = stripeStore.stripeAddressUsedWhenFetchingLC) === null || _c === void 0 ? void 0 : _c.value) !==
4283
+ JSON.stringify((_d = stripeStore.stripeAddressEventData) === null || _d === void 0 ? void 0 : _d.value);
4284
+ const isBillingAddressDataDirty = !stripeStore.stripeShippingSameAsBilling &&
4285
+ JSON.stringify((_e = stripeStore.stripeBillingAddressEventData) === null || _e === void 0 ? void 0 : _e.value) !==
4286
+ JSON.stringify((_f = stripeStore.stripeBillingAddressUsedWhenFetchingLC) === null || _f === void 0 ? void 0 : _f.value);
4287
+ return isLinkDataDirty || isAddressDataDirty || isBillingAddressDataDirty;
4288
+ };
4289
+ const stripeStorePrefetchLandedCost = async () => {
4290
+ var _a, _b, _c, _d, _e, _f;
4291
+ const stripeAddressReady = !!((_a = stripeStore.stripeAddressEventData) === null || _a === void 0 ? void 0 : _a.complete);
4292
+ const stripeLinkReady = !!((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.complete);
4293
+ const stripeBillingAddressReady = stripeStore.stripeShippingSameAsBilling
4294
+ ? !!((_c = stripeStore.stripeLinkEventData) === null || _c === void 0 ? void 0 : _c.complete)
4295
+ : !!((_d = stripeStore.stripeBillingAddressEventData) === null || _d === void 0 ? void 0 : _d.complete);
4296
+ const shouldRefetch = isPrefetchInfoOutdated();
4297
+ if (shouldRefetch) {
4298
+ // if the info used when fetching landed cost is different from the current info, abort the previous request
4299
+ (_e = stripeStore.fetchingLandedCostAbordController) === null || _e === void 0 ? void 0 : _e.abort();
4300
+ stripeStore.fetchingLandedCostAbordController = null;
4301
+ }
4302
+ // only fetch if we are not fetching or we need to refetch
4303
+ if (stripeAddressReady &&
4304
+ stripeLinkReady &&
4305
+ stripeBillingAddressReady &&
4306
+ (shouldRefetch || !stripeStore.isFetchingLandedCost)) {
4307
+ stripeStore.isFetchingLandedCost = true;
4308
+ if (stripeStore.stripeAddressEventData) {
4309
+ stripeStore.stripeAddressUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeAddressEventData);
4310
+ }
4311
+ if (stripeStore.stripeBillingAddressEventData) {
4312
+ stripeStore.stripeBillingAddressUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeBillingAddressEventData);
4313
+ }
4314
+ if (stripeStore.stripeLinkEventData) {
4315
+ stripeStore.stripeLinkUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeLinkEventData);
4316
+ }
4317
+ try {
4318
+ const abortController = new AbortController();
4319
+ stripeStore.fetchingLandedCostAbordController = abortController;
4320
+ const { checkoutSessionWorkflow, shipmentRatingCalculateWorkflow } = await calculateLandedCost(abortController);
4321
+ // reset abort controller after we are done
4322
+ stripeStore.fetchingLandedCostAbordController = null;
4323
+ // update cart store with landed cost info
4324
+ cartStore.landedCostData =
4325
+ (checkoutSessionWorkflow === null || checkoutSessionWorkflow === void 0 ? void 0 : checkoutSessionWorkflow.filter(Boolean)) || null;
4326
+ cartStore.shippingData =
4327
+ (shipmentRatingCalculateWorkflow === null || shipmentRatingCalculateWorkflow === void 0 ? void 0 : shipmentRatingCalculateWorkflow.filter(Boolean)) || null;
4328
+ // apply new subtotal and total, this is mainly to show items in the presentment currency
4329
+ const firstLandedCostData = (_f = cartStore.landedCostData) === null || _f === void 0 ? void 0 : _f.find(Boolean);
4330
+ const subtotals = !!firstLandedCostData
4331
+ ? firstLandedCostData.subtotals
4332
+ : null;
4333
+ if (subtotals) {
4334
+ // prefetch landed cost will not update shipping and taxes since we haven't selected shipping method yet
4335
+ cartStoreApplySubtotals({
4336
+ exchangeRate: subtotals.exchangeRate,
4337
+ items: subtotals.items,
4338
+ landedCostTotal: 0,
4339
+ presentmentCurrencyCode: subtotals.presentmentCurrencyCode,
4340
+ shipping: 0,
4341
+ total: subtotals.items,
4342
+ });
4343
+ }
4344
+ }
4345
+ catch (err) {
4346
+ logError(err);
4347
+ }
4348
+ stripeStore.isFetchingLandedCost = false;
4349
+ }
4350
+ };
4351
+ const getStripeMessageBasedOnStatus = (status) => {
4352
+ let messages = [];
4353
+ let isError = true;
4354
+ // Inspect the PaymentIntent `status` to indicate the status of the payment
4355
+ // to your customer.
4356
+ //
4357
+ // Some payment methods will [immediately succeed or fail][0] upon
4358
+ // confirmation, while others will first enter a `processing` state.
4359
+ //
4360
+ // [0]: https://stripe.com/docs/payments/payment-methods#payment-notification
4361
+ switch (status) {
4362
+ case 'succeeded': {
4363
+ messages = [
4364
+ 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.'),
4365
+ '',
4366
+ '',
4367
+ 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."),
4368
+ ];
4369
+ isError = false;
4370
+ break;
4371
+ }
4372
+ case 'requires_capture':
4373
+ case 'processing': {
4374
+ messages = [
4375
+ translate("Payment processing. We'll update you when payment is received."),
4376
+ ];
4377
+ isError = false;
4378
+ break;
4379
+ }
4380
+ case 'requires_payment_method': {
4381
+ messages = [
4382
+ translate('Payment failed. Please try another payment method.'),
4383
+ ];
4384
+ break;
4385
+ }
4386
+ default: {
4387
+ messages = [translate('Something went wrong.')];
4388
+ break;
4389
+ }
4390
+ }
4391
+ return {
4392
+ isError,
4393
+ messages,
4394
+ };
4395
+ };
4396
+ const stripeStoreRetrievePayment = async ({ clientSecret: _clientSecret, storybookForceStatus, }) => {
4397
+ if (storybookForceStatus) {
4398
+ // return status right away if we are in storybook mode
4399
+ const { isError, messages } = getStripeMessageBasedOnStatus(storybookForceStatus);
4400
+ return { error: isError, messages };
4401
+ }
4402
+ const clientSecret = _clientSecret || stripeStore.clientSecret;
4403
+ if (!stripeStore.stripe || !clientSecret) {
4404
+ logError('Failed to retrieve payment intent. Stripe is not initialized');
4405
+ return { error: true, message: [translate('Something went wrong.')] };
4406
+ }
4407
+ const { paymentIntent } = await stripeStore.stripe.retrievePaymentIntent(clientSecret);
4408
+ const status = paymentIntent === null || paymentIntent === void 0 ? void 0 : paymentIntent.status;
4409
+ const { isError, messages } = getStripeMessageBasedOnStatus(status);
4410
+ return { error: isError, messages };
4411
+ };
4412
+ const stripeStoreConfirmPayment = async () => {
4413
+ var _a, _b, _c;
4414
+ const stripePaymentReady = !!((_a = stripeStore.stripePaymentEventData) === null || _a === void 0 ? void 0 : _a.complete);
4415
+ const stripeElements = stripeStore.stripeElements;
4416
+ const stripe = stripeStore.stripe;
4417
+ const stripeClientSecret = stripeStore.clientSecret;
4418
+ if (stripe && stripeElements && stripePaymentReady && stripeClientSecret) {
4419
+ const { error } = await stripe.confirmPayment({
4420
+ confirmParams: {
4421
+ receipt_email: (_c = (_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.email,
4422
+ return_url: window.location.href,
4423
+ },
4424
+ elements: stripeElements,
4425
+ redirect: 'if_required',
4426
+ });
4427
+ if (error) {
4428
+ if (error.type === 'card_error' || error.type === 'validation_error') {
4429
+ throw new Error(error.message);
4430
+ }
4431
+ if (error.type === 'invalid_request_error') {
4432
+ if (error.code === 'payment_intent_unexpected_state') {
4433
+ // PaymentIntent was canceled or expired, or status is `require_capture`.
4434
+ // don't throw error here because we will reset the checkout session last step
4435
+ return;
4436
+ }
4437
+ }
4438
+ throw new Error('An unexpected error occurred.');
4439
+ }
4440
+ }
4441
+ };
4442
+ /**
4443
+ * Init checkout session
4444
+ * @returns {boolean} whether or not the checkout session is successfully created
4445
+ */
4446
+ const stripeStoreInitCheckoutSession = async () => {
4447
+ var _a;
4448
+ const total = cartStore.items.reduce((amount, item) => amount + item.amount * item.quantity, 0);
4449
+ if (!total || !localizationStore.targetCurrency) {
4450
+ logError('Fail to create checkout session - invalid total or currency');
4451
+ return false;
4452
+ }
4453
+ stripeStore.isFetchingSession = true;
4454
+ const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/create-checkout-session`, {
4455
+ body: {
4456
+ currency: ((_a = cartStore.items.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode) || '',
4457
+ itemsAmount: total,
4458
+ metadata: [
4459
+ { key: 'language', value: localizationStore.selectedLocale },
4460
+ ],
4461
+ presentmentCountryCode: localizationStore.selectedCountryCode || null,
4462
+ },
4463
+ method: 'POST',
4464
+ });
4465
+ stripeStore.isFetchingSession = false;
4466
+ if (errors.length || !json) {
4467
+ logError('Error occurs when creating checkout session', JSON.stringify(errors, null, 2));
4468
+ return false;
4469
+ }
4470
+ const result = json.checkoutSessionCreate;
4471
+ stripeStore.clientSecret = result.clientSecret;
4472
+ // update cart store with updated informations
4473
+ cartStore.checkoutSessionId = result.id;
4474
+ cartStoreApplySubtotals(Object.assign(Object.assign({}, result.subtotals), { landedCostTotal: 0, shipping: 0, total: result.subtotals.items }));
4475
+ log('Exchange rate updated for cart items (checkout session create)', 'info', cartStore.exchangeRate);
4476
+ log('done-init-checkout-session');
4477
+ return true;
4478
+ };
4479
+ /**
4480
+ * Update checkout session. Use for updating amount with landed cost id, or update session when cart items change
4481
+ */
4482
+ const stripeStoreUpdateCheckoutSession = async ({ currency, id, itemsAmount, landedCostId, presentmentCountryCode, }) => {
4483
+ // No need to set loading state here because this function will be called under the hood to update
4484
+ // landed cost id for the section.
4485
+ const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/update-checkout-session`, {
4486
+ body: {
4487
+ currency,
4488
+ id,
4489
+ itemsAmount,
4490
+ landedCostId,
4491
+ presentmentCountryCode,
4492
+ },
4493
+ method: 'POST',
4494
+ });
4495
+ if (errors.length || !json) {
4496
+ logError('Error occurs when updating checkout session', JSON.stringify(errors, null, 2));
4497
+ return { errors, json };
4498
+ }
4499
+ return { errors: [], json };
4500
+ };
4501
+ onChange$1('clientSecret', clientSecret => {
4502
+ // update stripe elements when client secret changes
4503
+ if (clientSecret && stripeStore.stripe) {
4504
+ sessionStorage.setItem('zonos--client-secret', clientSecret);
4505
+ }
4506
+ if (!clientSecret) {
4507
+ sessionStorage.removeItem('zonos--client-secret');
4508
+ }
4509
+ });
4510
+
4511
+ const formatDate = ({ date, formatOptions = { day: 'numeric', weekday: 'long', year: 'numeric' }, }) => {
4512
+ // format date to Thursday 3, 2023
4513
+ return new Intl.DateTimeFormat('en-US', formatOptions).format(date);
4514
+ };
4515
+
4516
+ const getDaysDifference = (targetDate) => {
4517
+ const currentDate = new Date();
4518
+ const timeDifference = targetDate.getTime() - currentDate.getTime();
4519
+ const daysDifference = Math.floor(timeDifference / (1000 * 60 * 60 * 24)); // Convert milliseconds to days
4520
+ return daysDifference;
4521
+ };
4522
+
4523
+ const { onChange, reset, state: cartStore, } = createStore(() => ({
4524
+ checkoutSessionId: sessionStorage.getItem('zonos--checkout-session-id') || null,
4525
+ currency: 'USD',
4526
+ dutiesTaxFees: 0,
4527
+ error: null,
4528
+ exchangeRate: null,
4529
+ isSelectedShippingAboveDeminimis: false,
4530
+ isSelectedShippingGuarantee: false,
4531
+ items: [],
4532
+ landedCostData: null,
4533
+ selectedLandedCost: null,
4534
+ selectedShippingOption: null,
4535
+ selectedShippingOptionExpectedDate: '',
4536
+ selectedShippingOptionTransitTime: '',
4537
+ shipping: 0,
4538
+ shippingData: null,
4539
+ step: 'customer-info',
4540
+ subtotal: 0,
4541
+ total: 0,
4542
+ }));
4543
+ /**
4544
+ * Format shipping transit info to be displayed on UI
4545
+ * @returns
4546
+ * - expectedDate: Thursday, Aug 12
4547
+ * - maxTransit: 5
4548
+ * - minTransit: 3
4549
+ */
4550
+ const cartStoreGetShippingTransitInfo = (item) => {
4551
+ const minTransit = item.minTransitAt
4552
+ ? getDaysDifference(new Date(item.minTransitAt))
4553
+ : '';
4554
+ const maxTransit = item.maxTransitAt
4555
+ ? getDaysDifference(new Date(item.maxTransitAt))
4556
+ : '';
4557
+ const expectedDate = item.minTransitAt
4558
+ ? formatDate({
4559
+ date: new Date(item.minTransitAt),
4560
+ })
4561
+ : '';
4562
+ return {
4563
+ expectedDate,
4564
+ maxTransit,
4565
+ minTransit,
4566
+ };
4567
+ };
4568
+ const cartStoreReset = () => {
4569
+ sessionStorage.removeItem('zonos--checkout-session-id');
4570
+ // reset cart store
4571
+ reset();
4572
+ };
4573
+ const cartStoreUpdateToErrorState = ({ messages, title, }) => {
4574
+ cartStoreReset();
4575
+ stripeStoreReset();
4576
+ cartStore.step = 'error';
4577
+ cartStore.error = {
4578
+ messages,
4579
+ title,
4580
+ };
4581
+ };
4582
+ const cartStoreApplySubtotals = (subtotals) => {
4583
+ // update exchange rate so we can use it to display cart items
4584
+ cartStore.exchangeRate = subtotals.exchangeRate;
4585
+ cartStore.dutiesTaxFees = subtotals.landedCostTotal;
4586
+ cartStore.subtotal = subtotals.items;
4587
+ cartStore.total = subtotals.total;
4588
+ cartStore.currency = subtotals.presentmentCurrencyCode;
4589
+ };
4590
+ const cartStoreReCalculateTotal = async ({ currency, itemsAmount, landedCostId, }) => {
4591
+ if (landedCostId && cartStore.selectedLandedCost) {
4592
+ // update cart total right away if we have landed cost id to avoid order total flickering
4593
+ const subtotals = cartStore.selectedLandedCost.subtotals;
4594
+ cartStoreApplySubtotals(subtotals);
4595
+ log('Exchange rate updated for cart items (landed cost subtotal)', 'info', cartStore.exchangeRate);
4596
+ }
4597
+ // update checkout session
4598
+ if (!cartStore.checkoutSessionId) {
4599
+ logError('Could not update cart total without checkout session id');
4600
+ return false;
4601
+ }
4602
+ const { json } = await stripeStoreUpdateCheckoutSession({
4603
+ currency,
4604
+ id: cartStore.checkoutSessionId,
4605
+ itemsAmount,
4606
+ landedCostId,
4607
+ presentmentCountryCode: localizationStore.selectedCountryCode,
4608
+ });
4609
+ if (!json) {
4610
+ // do nothing if we can't get checkout session
4611
+ logError('Error occurs when updating checkout session');
4612
+ cartStoreUpdateToErrorState({
4613
+ messages: [
4614
+ translate("There's been an error updating your checkout session. Please reload and try again or contact support if the error persists"),
4615
+ ],
4616
+ title: translate('Error updating Checkout'),
4617
+ });
4618
+ return false;
4619
+ }
4620
+ if (!landedCostId) {
4621
+ // This is when first open the checkout modal and we just want to get info from the old cart session.
4622
+ // use subtotals from checkout session to update cart total
4623
+ cartStoreApplySubtotals(json.checkoutSessionUpdate.subtotals);
4624
+ log('Exchange rate updated for cart items (checkout session update)', 'info', cartStore.exchangeRate);
4625
+ }
4626
+ return true;
4627
+ };
4628
+ const cartStoreUpdateSelectedShippingOption = async (selectedShippingOption) => {
4629
+ var _a, _b, _c, _d, _e;
4630
+ cartStore.selectedShippingOption = selectedShippingOption;
4631
+ // update shipping transit info
4632
+ const { expectedDate, maxTransit, minTransit } = cartStoreGetShippingTransitInfo(cartStore.selectedShippingOption);
4633
+ cartStore.selectedShippingOptionExpectedDate = expectedDate;
4634
+ cartStore.selectedShippingOptionTransitTime =
4635
+ minTransit && maxTransit
4636
+ ? `${minTransit}-${maxTransit}`
4637
+ : `${minTransit || maxTransit}`;
4638
+ const selectedLandedCost = (_a = cartStore.landedCostData) === null || _a === void 0 ? void 0 : _a.find(checkoutSessionPresentment => {
4639
+ var _a, _b, _c;
4640
+ return ((_b = (_a = checkoutSessionPresentment.landedCost) === null || _a === void 0 ? void 0 : _a.shipmentRating) === null || _b === void 0 ? void 0 : _b.id) ===
4641
+ ((_c = cartStore.selectedShippingOption) === null || _c === void 0 ? void 0 : _c.id);
4642
+ });
4643
+ // save selected landed cost for later use
4644
+ cartStore.selectedLandedCost = selectedLandedCost || null;
4645
+ if (!selectedLandedCost) {
4646
+ // do nothing if we can't find landed cost for selected shipping option
4647
+ return false;
4648
+ }
4649
+ // update shipping value and dutiesTaxFees on selectedShippingOption change
4650
+ cartStore.shipping = selectedLandedCost.subtotals.shipping;
4651
+ // update deminimis status
4652
+ const isGuarantee = ((_b = selectedLandedCost === null || selectedLandedCost === void 0 ? void 0 : selectedLandedCost.landedCost) === null || _b === void 0 ? void 0 : _b.landedCostGuaranteeCode) === 'ZONOS';
4653
+ // one item in deminimis with type of duty and tax has threshold value is "ABOVE"
4654
+ const isAboveDeminimis = !!((_d = (_c = selectedLandedCost === null || selectedLandedCost === void 0 ? void 0 : selectedLandedCost.landedCost) === null || _c === void 0 ? void 0 : _c.deMinimis) === null || _d === void 0 ? void 0 : _d.find(item => ['DUTY', 'TAX'].includes(item.type) && item.threshold === 'ABOVE'));
4655
+ cartStore.isSelectedShippingAboveDeminimis = isAboveDeminimis;
4656
+ cartStore.isSelectedShippingGuarantee = isGuarantee;
4657
+ // update session with selected landed cost
4658
+ const updateCalulateStatus = await cartStoreReCalculateTotal({
4659
+ landedCostId: (_e = selectedLandedCost.landedCost) === null || _e === void 0 ? void 0 : _e.id,
4660
+ });
4661
+ return updateCalulateStatus;
4662
+ };
4663
+ onChange('checkoutSessionId', () => {
4664
+ if (!cartStore.checkoutSessionId) {
4665
+ sessionStorage.removeItem('zonos--checkout-session-id');
4666
+ return;
4667
+ }
4668
+ sessionStorage.setItem('zonos--checkout-session-id', cartStore.checkoutSessionId);
4669
+ });
4670
+ const cartStoreUpdateItems = async (items) => {
4671
+ var _a;
4672
+ cartStore.items = items;
4673
+ const currency = (_a = items.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode;
4674
+ const total = items.reduce((amt, item) => {
4675
+ return amt + item.amount * item.quantity;
4676
+ }, 0);
4677
+ if (!currency || !total) {
4678
+ // do nothing if we can't get currency or total
4679
+ return;
4680
+ }
4681
+ cartStore.currency = currency;
4682
+ // set loading state here because this is first load checkout session when we already have checkout session id stored
4683
+ stripeStore.isFetchingSession = true;
4684
+ await cartStoreReCalculateTotal({
4685
+ currency: currency,
4686
+ itemsAmount: total,
4687
+ });
4688
+ stripeStore.isFetchingSession = false;
4689
+ };
4690
+ const cartStoreResetSelectedShippingOption = () => {
4691
+ cartStore.selectedShippingOption = null;
4692
+ cartStore.isSelectedShippingAboveDeminimis = false;
4693
+ cartStore.isSelectedShippingGuarantee = false;
4694
+ cartStore.selectedShippingOptionExpectedDate = '';
4695
+ cartStore.selectedShippingOptionTransitTime = '';
4696
+ cartStore.shipping = 0;
4697
+ };
4698
+ const cartStoreNextStep = () => {
4699
+ if (cartStore.step === 'customer-info') {
4700
+ cartStore.step = 'shipping';
4701
+ }
4702
+ else if (cartStore.step === 'shipping') {
4703
+ cartStore.step = 'payment';
4704
+ }
4705
+ else if (cartStore.step === 'payment') {
4706
+ cartStore.step = 'finish';
4707
+ }
4708
+ };
4709
+ const cartStorePreviousStep = () => {
4710
+ if (cartStore.step === 'payment') {
4711
+ cartStore.step = 'shipping';
4712
+ }
4713
+ else if (cartStore.step === 'shipping') {
4714
+ cartStore.step = 'customer-info';
4715
+ // reset selected shipping option
4716
+ cartStoreResetSelectedShippingOption();
4717
+ }
4014
4718
  };
4015
4719
 
4016
- export { log as a, logError as b, initLocalizationStore as c, localizationStoreUpdateSelectedCountryCode as d, currencyDisplay as e, currencyConvertAndFormat as f, getZCountryUrlParam as g, handleFetch as h, isValidSelector as i, currencyConvert as j, currencyFormat as k, localizationStore as l, localizationStoreUpdateSelectedLocale as m, setZCountryUrlParam as s, translate as t };
4720
+ export { stripeStoreRetrievePayment as A, cartStoreUpdateSelectedShippingOption as B, cartStoreGetShippingTransitInfo as C, localizationStoreUpdateSelectedLocale as D, log as a, cartStoreUpdateItems as b, cartStore as c, cartStoreReset as d, stripeStoreInitCheckoutSession as e, cartStoreUpdateToErrorState as f, stripeStorePrefetchLandedCost as g, cartStoreNextStep as h, initStripeElements as i, stripeStoreConfirmPayment as j, stripeStoreReset as k, localizationStore as l, cartStorePreviousStep as m, handleFetch as n, logError as o, isValidSelector as p, initLocalizationStore as q, localizationStoreUpdateSelectedCountryCode as r, stripeStore as s, translate as t, getZCountryUrlParam as u, setZCountryUrlParam as v, currencyDisplay as w, currencyConvertAndFormat as x, currencyConvert as y, currencyFormat as z };