@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,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const zonosStore = require('./zonosStore-5d94dabb.js');
3
+ const zonosStore = require('./zonosStore-49d4c92a.js');
4
+ const isDarkColor = require('./isDarkColor-924e6a7a.js');
5
+ const getBorderRadius = require('./getBorderRadius-834c321d.js');
4
6
 
5
7
  const stringsArabic = {
6
8
  'Above de minimis threshold for': {
@@ -3989,7 +3991,7 @@ const initLocalizationStore = async () => {
3989
3991
  // Filter countries to only include countries in the shipping zone
3990
3992
  const filteredCountries = shippingZoneCountries === null || shippingZoneCountries === void 0 ? void 0 : shippingZoneCountries.reduce((acc, countryCode) => {
3991
3993
  const countryInfo = allCountries === null || allCountries === void 0 ? void 0 : allCountries[countryCode];
3992
- return countryInfo
3994
+ return countryInfo && countryInfo.active
3993
3995
  ? Object.assign(Object.assign({}, acc), { [countryCode]: countryInfo }) : acc;
3994
3996
  }, {});
3995
3997
  localizationStore.shippingZoneCountries = filteredCountries || null;
@@ -4010,11 +4012,721 @@ const initLocalizationStore = async () => {
4010
4012
  localizationStore.localizationLoaded = true;
4011
4013
  void getCustomMessages();
4012
4014
  };
4015
+ const updateCheckoutSessionLanguage = async () => {
4016
+ if (!cartStore.checkoutSessionId) {
4017
+ return null;
4018
+ }
4019
+ const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/update-checkout-session-metadata`, {
4020
+ body: {
4021
+ id: cartStore.checkoutSessionId,
4022
+ metadata: [
4023
+ {
4024
+ key: 'language',
4025
+ value: localizationStore.selectedLocale,
4026
+ },
4027
+ ],
4028
+ },
4029
+ method: 'POST',
4030
+ });
4031
+ if (errors.length || !json) {
4032
+ logError('Error occurs when updating checkout session', JSON.stringify(errors, null, 2));
4033
+ return { errors, json };
4034
+ }
4035
+ return { errors: [], json };
4036
+ };
4013
4037
  const localizationStoreUpdateSelectedLocale = (newSelectedLocale) => {
4014
4038
  localizationStore.selectedLocale = newSelectedLocale;
4015
4039
  translationStoreUpdateLanguage(newSelectedLocale);
4040
+ void updateCheckoutSessionLanguage();
4041
+ };
4042
+
4043
+ const prepCalculateLandedCost = () => {
4044
+ // maybe we don't need email now for prefetch the landed cost
4045
+ const stripeLinkData = stripeStore.stripeLinkEventData;
4046
+ const stripeAddressData = stripeStore.stripeAddressEventData;
4047
+ const stripeBillingAddressData = stripeStore.stripeShippingSameAsBilling
4048
+ ? stripeStore.stripeAddressEventData
4049
+ : stripeStore.stripeBillingAddressEventData;
4050
+ if (!(stripeAddressData === null || stripeAddressData === void 0 ? void 0 : stripeAddressData.complete) || !(stripeBillingAddressData === null || stripeBillingAddressData === void 0 ? void 0 : stripeBillingAddressData.complete)) {
4051
+ throw new Error('Missing stripe address data');
4052
+ }
4053
+ return {
4054
+ billingAddress: {
4055
+ addressLine1: stripeBillingAddressData.value.address.line1,
4056
+ addressLine2: stripeBillingAddressData.value.address.line2 || '',
4057
+ city: stripeBillingAddressData.value.address.city,
4058
+ country: stripeBillingAddressData.value.address.country,
4059
+ postalCode: stripeBillingAddressData.value.address.postal_code,
4060
+ state: stripeBillingAddressData.value.address.state,
4061
+ },
4062
+ billingContact: {
4063
+ // firstName and lastName should be valid now since stripe only mark
4064
+ // the address as complete when both fields are filled.
4065
+ firstName: stripeBillingAddressData.value.firstName || '',
4066
+ lastName: stripeBillingAddressData.value.lastName || '',
4067
+ phone: stripeBillingAddressData.value.phone || '',
4068
+ },
4069
+ checkoutSessionId: cartStore.checkoutSessionId || '',
4070
+ contact: {
4071
+ email: (stripeLinkData === null || stripeLinkData === void 0 ? void 0 : stripeLinkData.value.email) || '',
4072
+ // firstName and lastName should be valid now since stripe only mark
4073
+ // the address as complete when both fields are filled.
4074
+ firstName: stripeAddressData.value.firstName || '',
4075
+ lastName: stripeAddressData.value.lastName || '',
4076
+ phone: stripeAddressData.value.phone || '',
4077
+ },
4078
+ items: cartStore.items.map(item => item),
4079
+ shippingAddress: {
4080
+ addressLine1: stripeAddressData.value.address.line1,
4081
+ addressLine2: stripeAddressData.value.address.line2 || '',
4082
+ city: stripeAddressData.value.address.city,
4083
+ country: stripeAddressData.value.address.country,
4084
+ postalCode: stripeAddressData.value.address.postal_code,
4085
+ state: stripeAddressData.value.address.state,
4086
+ },
4087
+ };
4088
+ };
4089
+
4090
+ const triggerBuildLandedCost = async (buildLandedCost) => {
4091
+ var _a, _b, _c, _d;
4092
+ const data = prepCalculateLandedCost();
4093
+ const landedCost = await buildLandedCost({
4094
+ billingAddress: data.billingAddress,
4095
+ billingContact: data.billingContact,
4096
+ checkoutSessionId: data.checkoutSessionId,
4097
+ contact: data.contact,
4098
+ shippingAddress: data.shippingAddress,
4099
+ });
4100
+ if (!landedCost || ((_a = landedCost.errors) === null || _a === void 0 ? void 0 : _a.length)) {
4101
+ 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'}`);
4102
+ }
4103
+ // Validate the landed cost object to make sure the returned value from buildLandedCost has a valid schema
4104
+ const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/validate-landed-cost`, {
4105
+ body: landedCost,
4106
+ headers: {
4107
+ 'Content-Type': 'application/json',
4108
+ },
4109
+ method: 'POST',
4110
+ });
4111
+ if (!json || errors.length) {
4112
+ throw new Error(`Invalid landed cost object: ${((_d = errors.find(Boolean)) === null || _d === void 0 ? void 0 : _d.message) || 'Unknown error'}`);
4113
+ }
4114
+ return landedCost;
4115
+ };
4116
+
4117
+ const calculateLandedCost = async (abortController) => {
4118
+ var _a;
4119
+ // If buildLandedCost callback is supplied, use that instead of our regular request to '/calculate-landed-cost'
4120
+ const buildLandedCost = zonosStore.zonosStore.checkoutSettings.buildLandedCost;
4121
+ if (buildLandedCost) {
4122
+ const json = await triggerBuildLandedCost(buildLandedCost);
4123
+ return json;
4124
+ }
4125
+ // request to get landed cost info
4126
+ const url = `${"https://v1.route.js.zonos.com"}/api/zonos-elements/calculate-landed-cost`;
4127
+ const { errors, json } = await handleFetch(url, {
4128
+ body: prepCalculateLandedCost(),
4129
+ method: 'POST',
4130
+ signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
4131
+ });
4132
+ if (errors.length || !json) {
4133
+ const isAbortedRequest = ((_a = errors[0]) === null || _a === void 0 ? void 0 : _a.message) === 'The user aborted a request.';
4134
+ const errorMessage = isAbortedRequest
4135
+ ? 'The landed cost calculation request was aborted to initiate a new one.'
4136
+ : 'Failed to calculate landed cost';
4137
+ throw new Error(errorMessage);
4138
+ }
4139
+ return json;
4140
+ };
4141
+
4142
+ const addressRuleStyle = ({ theme, }) => {
4143
+ switch (theme) {
4144
+ default:
4145
+ return {
4146
+ '.Input': {
4147
+ // need to reset everything and the paddingTop to default, otherwise the paddingTop will not be updated.
4148
+ padding: '0',
4149
+ paddingBottom: '8px',
4150
+ paddingLeft: '16px',
4151
+ paddingRight: '8px',
4152
+ // any value here will be add up to the default paddingTop (20px).
4153
+ paddingTop: '6px',
4154
+ },
4155
+ };
4156
+ }
4157
+ };
4158
+
4159
+ const defaultVariable = ({ borderStyle, theme, }) => {
4160
+ switch (theme) {
4161
+ case 'DARK':
4162
+ return {
4163
+ borderRadius: getBorderRadius.getBorderRadius(borderStyle),
4164
+ colorBackground: '#101117',
4165
+ colorBackgroundText: '#C5C6CA',
4166
+ colorText: '#C5C6CA',
4167
+ colorTextPlaceholder: '#C5C6CA',
4168
+ };
4169
+ default:
4170
+ return {
4171
+ borderRadius: getBorderRadius.getBorderRadius(borderStyle),
4172
+ };
4173
+ }
4174
+ };
4175
+
4176
+ const { onChange: onChange$1, reset: reset$1, state: stripeStore, } = zonosStore.createStore(() => ({
4177
+ clientSecret: sessionStorage.getItem('zonos--client-secret') || null,
4178
+ fetchingLandedCostAbordController: null,
4179
+ isFetchingLandedCost: false,
4180
+ isFetchingSession: false,
4181
+ stripe: null,
4182
+ stripeAddressElement: null,
4183
+ stripeAddressEventData: null,
4184
+ stripeAddressUsedWhenFetchingLC: null,
4185
+ stripeBillingAddressElement: null,
4186
+ stripeBillingAddressEventData: null,
4187
+ stripeBillingAddressUsedWhenFetchingLC: null,
4188
+ stripeElements: null,
4189
+ stripeElementsForBillingAddress: null,
4190
+ stripeElementsOptions: null,
4191
+ stripeLinkElement: null,
4192
+ stripeLinkEventData: null,
4193
+ stripeLinkUsedWhenFetchingLC: null,
4194
+ stripePaymentElement: null,
4195
+ stripePaymentEventData: null,
4196
+ stripeShippingSameAsBilling: true,
4197
+ }));
4198
+ const getStripeOptions = ({ clientSecret, overrideBorderRaidus, overridePrimaryColor, overrideSecondaryColor, overrideTheme, }) => {
4199
+ const primaryColor = overridePrimaryColor || zonosStore.zonosStore.appearance.colorPrimary;
4200
+ const secondaryColor = overrideSecondaryColor || zonosStore.zonosStore.appearance.colorSecondary;
4201
+ const themeBasedColor = primaryColor && isDarkColor.isDarkColor(primaryColor) ? 'night' : 'flat';
4202
+ // if overrideTheme is provided, use it. Otherwise, use theme based on primary color
4203
+ const theme = overrideTheme === 'DARK' ? 'night' : 'flat';
4204
+ return {
4205
+ appearance: {
4206
+ labels: 'floating',
4207
+ rules: Object.assign({}, addressRuleStyle({ theme: 'LIGHT' })),
4208
+ // get contrast theme color base on primary color
4209
+ theme: overrideTheme ? theme : themeBasedColor,
4210
+ variables: Object.assign(Object.assign({}, defaultVariable({
4211
+ borderStyle: overrideBorderRaidus,
4212
+ theme: 'LIGHT',
4213
+ })), {
4214
+ // use the button background color for input glow color
4215
+ colorPrimary: secondaryColor }),
4216
+ },
4217
+ clientSecret,
4218
+ locale: localizationStore.selectedLocale,
4219
+ };
4220
+ };
4221
+ const initStripeElements = async (props) => {
4222
+ var _a, _b;
4223
+ const clientSecret = stripeStore.clientSecret;
4224
+ if (!stripeStore.stripe) {
4225
+ log('Skip. Stripe is not initialized');
4226
+ return;
4227
+ }
4228
+ if (clientSecret) {
4229
+ const stripeOptions = getStripeOptions({
4230
+ clientSecret,
4231
+ overrideBorderRaidus: props === null || props === void 0 ? void 0 : props.overrideBorderRaidus,
4232
+ overridePrimaryColor: props === null || props === void 0 ? void 0 : props.overridePrimaryColor,
4233
+ overrideSecondaryColor: props === null || props === void 0 ? void 0 : props.overrideSecondaryColor,
4234
+ overrideTheme: props === null || props === void 0 ? void 0 : props.overrideTheme,
4235
+ });
4236
+ // compare with the previous options to see if we need to update
4237
+ const isSameOptions = JSON.stringify(stripeOptions) ===
4238
+ JSON.stringify(stripeStore.stripeElementsOptions);
4239
+ if (!stripeStore.stripeElements ||
4240
+ !stripeStore.stripeElementsForBillingAddress) {
4241
+ // init stripe elements if it doesn't exist
4242
+ stripeStore.stripeElements = (_a = stripeStore.stripe) === null || _a === void 0 ? void 0 : _a.elements(stripeOptions);
4243
+ // save stripe elements options for later comparison
4244
+ stripeStore.stripeElementsOptions = stripeOptions;
4245
+ log('Stripe elements initialized');
4246
+ // init stripe elements for billing address
4247
+ stripeStore.stripeElementsForBillingAddress =
4248
+ (_b = stripeStore.stripe) === null || _b === void 0 ? void 0 : _b.elements(stripeOptions);
4249
+ log('Stripe elements for billing address initialized');
4250
+ return;
4251
+ }
4252
+ if (!isSameOptions) {
4253
+ // update elements with new option if it already exists
4254
+ stripeStore.stripeElements.update(stripeOptions);
4255
+ // update elements for stripe billing address
4256
+ stripeStore.stripeElementsForBillingAddress.update(stripeOptions);
4257
+ // save stripe elements options for later comparison
4258
+ stripeStore.stripeElementsOptions = stripeOptions;
4259
+ }
4260
+ log('Stripe elements initialized');
4261
+ }
4262
+ };
4263
+ const stripeStoreReset = () => {
4264
+ // clean clientSecret so that we can start the new one.
4265
+ sessionStorage.removeItem('zonos--client-secret');
4266
+ // cleanup stripe elements
4267
+ reset$1();
4268
+ // set stripe back to window.Zonos.stripe
4269
+ stripeStore.stripe = window.Zonos.stripe;
4270
+ };
4271
+ /**
4272
+ * Check if the address and email info used when fetching landed cost with the current email and address info are different
4273
+ * Purpose is to resend the request if the info used when fetching landed cost is different from the current info
4274
+ */
4275
+ const isPrefetchInfoOutdated = () => {
4276
+ var _a, _b, _c, _d, _e, _f;
4277
+ const hasAbortController = stripeStore.fetchingLandedCostAbordController;
4278
+ if (!hasAbortController) {
4279
+ // if there is no abort controller, this is a new request
4280
+ return false;
4281
+ }
4282
+ const isLinkDataDirty = JSON.stringify((_a = stripeStore.stripeLinkUsedWhenFetchingLC) === null || _a === void 0 ? void 0 : _a.value) !==
4283
+ JSON.stringify((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.value);
4284
+ const isAddressDataDirty = JSON.stringify((_c = stripeStore.stripeAddressUsedWhenFetchingLC) === null || _c === void 0 ? void 0 : _c.value) !==
4285
+ JSON.stringify((_d = stripeStore.stripeAddressEventData) === null || _d === void 0 ? void 0 : _d.value);
4286
+ const isBillingAddressDataDirty = !stripeStore.stripeShippingSameAsBilling &&
4287
+ JSON.stringify((_e = stripeStore.stripeBillingAddressEventData) === null || _e === void 0 ? void 0 : _e.value) !==
4288
+ JSON.stringify((_f = stripeStore.stripeBillingAddressUsedWhenFetchingLC) === null || _f === void 0 ? void 0 : _f.value);
4289
+ return isLinkDataDirty || isAddressDataDirty || isBillingAddressDataDirty;
4290
+ };
4291
+ const stripeStorePrefetchLandedCost = async () => {
4292
+ var _a, _b, _c, _d, _e, _f;
4293
+ const stripeAddressReady = !!((_a = stripeStore.stripeAddressEventData) === null || _a === void 0 ? void 0 : _a.complete);
4294
+ const stripeLinkReady = !!((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.complete);
4295
+ const stripeBillingAddressReady = stripeStore.stripeShippingSameAsBilling
4296
+ ? !!((_c = stripeStore.stripeLinkEventData) === null || _c === void 0 ? void 0 : _c.complete)
4297
+ : !!((_d = stripeStore.stripeBillingAddressEventData) === null || _d === void 0 ? void 0 : _d.complete);
4298
+ const shouldRefetch = isPrefetchInfoOutdated();
4299
+ if (shouldRefetch) {
4300
+ // if the info used when fetching landed cost is different from the current info, abort the previous request
4301
+ (_e = stripeStore.fetchingLandedCostAbordController) === null || _e === void 0 ? void 0 : _e.abort();
4302
+ stripeStore.fetchingLandedCostAbordController = null;
4303
+ }
4304
+ // only fetch if we are not fetching or we need to refetch
4305
+ if (stripeAddressReady &&
4306
+ stripeLinkReady &&
4307
+ stripeBillingAddressReady &&
4308
+ (shouldRefetch || !stripeStore.isFetchingLandedCost)) {
4309
+ stripeStore.isFetchingLandedCost = true;
4310
+ if (stripeStore.stripeAddressEventData) {
4311
+ stripeStore.stripeAddressUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeAddressEventData);
4312
+ }
4313
+ if (stripeStore.stripeBillingAddressEventData) {
4314
+ stripeStore.stripeBillingAddressUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeBillingAddressEventData);
4315
+ }
4316
+ if (stripeStore.stripeLinkEventData) {
4317
+ stripeStore.stripeLinkUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeLinkEventData);
4318
+ }
4319
+ try {
4320
+ const abortController = new AbortController();
4321
+ stripeStore.fetchingLandedCostAbordController = abortController;
4322
+ const { checkoutSessionWorkflow, shipmentRatingCalculateWorkflow } = await calculateLandedCost(abortController);
4323
+ // reset abort controller after we are done
4324
+ stripeStore.fetchingLandedCostAbordController = null;
4325
+ // update cart store with landed cost info
4326
+ cartStore.landedCostData =
4327
+ (checkoutSessionWorkflow === null || checkoutSessionWorkflow === void 0 ? void 0 : checkoutSessionWorkflow.filter(Boolean)) || null;
4328
+ cartStore.shippingData =
4329
+ (shipmentRatingCalculateWorkflow === null || shipmentRatingCalculateWorkflow === void 0 ? void 0 : shipmentRatingCalculateWorkflow.filter(Boolean)) || null;
4330
+ // apply new subtotal and total, this is mainly to show items in the presentment currency
4331
+ const firstLandedCostData = (_f = cartStore.landedCostData) === null || _f === void 0 ? void 0 : _f.find(Boolean);
4332
+ const subtotals = !!firstLandedCostData
4333
+ ? firstLandedCostData.subtotals
4334
+ : null;
4335
+ if (subtotals) {
4336
+ // prefetch landed cost will not update shipping and taxes since we haven't selected shipping method yet
4337
+ cartStoreApplySubtotals({
4338
+ exchangeRate: subtotals.exchangeRate,
4339
+ items: subtotals.items,
4340
+ landedCostTotal: 0,
4341
+ presentmentCurrencyCode: subtotals.presentmentCurrencyCode,
4342
+ shipping: 0,
4343
+ total: subtotals.items,
4344
+ });
4345
+ }
4346
+ }
4347
+ catch (err) {
4348
+ logError(err);
4349
+ }
4350
+ stripeStore.isFetchingLandedCost = false;
4351
+ }
4352
+ };
4353
+ const getStripeMessageBasedOnStatus = (status) => {
4354
+ let messages = [];
4355
+ let isError = true;
4356
+ // Inspect the PaymentIntent `status` to indicate the status of the payment
4357
+ // to your customer.
4358
+ //
4359
+ // Some payment methods will [immediately succeed or fail][0] upon
4360
+ // confirmation, while others will first enter a `processing` state.
4361
+ //
4362
+ // [0]: https://stripe.com/docs/payments/payment-methods#payment-notification
4363
+ switch (status) {
4364
+ case 'succeeded': {
4365
+ messages = [
4366
+ 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.'),
4367
+ '',
4368
+ '',
4369
+ 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."),
4370
+ ];
4371
+ isError = false;
4372
+ break;
4373
+ }
4374
+ case 'requires_capture':
4375
+ case 'processing': {
4376
+ messages = [
4377
+ translate("Payment processing. We'll update you when payment is received."),
4378
+ ];
4379
+ isError = false;
4380
+ break;
4381
+ }
4382
+ case 'requires_payment_method': {
4383
+ messages = [
4384
+ translate('Payment failed. Please try another payment method.'),
4385
+ ];
4386
+ break;
4387
+ }
4388
+ default: {
4389
+ messages = [translate('Something went wrong.')];
4390
+ break;
4391
+ }
4392
+ }
4393
+ return {
4394
+ isError,
4395
+ messages,
4396
+ };
4397
+ };
4398
+ const stripeStoreRetrievePayment = async ({ clientSecret: _clientSecret, storybookForceStatus, }) => {
4399
+ if (storybookForceStatus) {
4400
+ // return status right away if we are in storybook mode
4401
+ const { isError, messages } = getStripeMessageBasedOnStatus(storybookForceStatus);
4402
+ return { error: isError, messages };
4403
+ }
4404
+ const clientSecret = _clientSecret || stripeStore.clientSecret;
4405
+ if (!stripeStore.stripe || !clientSecret) {
4406
+ logError('Failed to retrieve payment intent. Stripe is not initialized');
4407
+ return { error: true, message: [translate('Something went wrong.')] };
4408
+ }
4409
+ const { paymentIntent } = await stripeStore.stripe.retrievePaymentIntent(clientSecret);
4410
+ const status = paymentIntent === null || paymentIntent === void 0 ? void 0 : paymentIntent.status;
4411
+ const { isError, messages } = getStripeMessageBasedOnStatus(status);
4412
+ return { error: isError, messages };
4413
+ };
4414
+ const stripeStoreConfirmPayment = async () => {
4415
+ var _a, _b, _c;
4416
+ const stripePaymentReady = !!((_a = stripeStore.stripePaymentEventData) === null || _a === void 0 ? void 0 : _a.complete);
4417
+ const stripeElements = stripeStore.stripeElements;
4418
+ const stripe = stripeStore.stripe;
4419
+ const stripeClientSecret = stripeStore.clientSecret;
4420
+ if (stripe && stripeElements && stripePaymentReady && stripeClientSecret) {
4421
+ const { error } = await stripe.confirmPayment({
4422
+ confirmParams: {
4423
+ receipt_email: (_c = (_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.email,
4424
+ return_url: window.location.href,
4425
+ },
4426
+ elements: stripeElements,
4427
+ redirect: 'if_required',
4428
+ });
4429
+ if (error) {
4430
+ if (error.type === 'card_error' || error.type === 'validation_error') {
4431
+ throw new Error(error.message);
4432
+ }
4433
+ if (error.type === 'invalid_request_error') {
4434
+ if (error.code === 'payment_intent_unexpected_state') {
4435
+ // PaymentIntent was canceled or expired, or status is `require_capture`.
4436
+ // don't throw error here because we will reset the checkout session last step
4437
+ return;
4438
+ }
4439
+ }
4440
+ throw new Error('An unexpected error occurred.');
4441
+ }
4442
+ }
4443
+ };
4444
+ /**
4445
+ * Init checkout session
4446
+ * @returns {boolean} whether or not the checkout session is successfully created
4447
+ */
4448
+ const stripeStoreInitCheckoutSession = async () => {
4449
+ var _a;
4450
+ const total = cartStore.items.reduce((amount, item) => amount + item.amount * item.quantity, 0);
4451
+ if (!total || !localizationStore.targetCurrency) {
4452
+ logError('Fail to create checkout session - invalid total or currency');
4453
+ return false;
4454
+ }
4455
+ stripeStore.isFetchingSession = true;
4456
+ const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/create-checkout-session`, {
4457
+ body: {
4458
+ currency: ((_a = cartStore.items.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode) || '',
4459
+ itemsAmount: total,
4460
+ metadata: [
4461
+ { key: 'language', value: localizationStore.selectedLocale },
4462
+ ],
4463
+ presentmentCountryCode: localizationStore.selectedCountryCode || null,
4464
+ },
4465
+ method: 'POST',
4466
+ });
4467
+ stripeStore.isFetchingSession = false;
4468
+ if (errors.length || !json) {
4469
+ logError('Error occurs when creating checkout session', JSON.stringify(errors, null, 2));
4470
+ return false;
4471
+ }
4472
+ const result = json.checkoutSessionCreate;
4473
+ stripeStore.clientSecret = result.clientSecret;
4474
+ // update cart store with updated informations
4475
+ cartStore.checkoutSessionId = result.id;
4476
+ cartStoreApplySubtotals(Object.assign(Object.assign({}, result.subtotals), { landedCostTotal: 0, shipping: 0, total: result.subtotals.items }));
4477
+ log('Exchange rate updated for cart items (checkout session create)', 'info', cartStore.exchangeRate);
4478
+ log('done-init-checkout-session');
4479
+ return true;
4480
+ };
4481
+ /**
4482
+ * Update checkout session. Use for updating amount with landed cost id, or update session when cart items change
4483
+ */
4484
+ const stripeStoreUpdateCheckoutSession = async ({ currency, id, itemsAmount, landedCostId, presentmentCountryCode, }) => {
4485
+ // No need to set loading state here because this function will be called under the hood to update
4486
+ // landed cost id for the section.
4487
+ const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/update-checkout-session`, {
4488
+ body: {
4489
+ currency,
4490
+ id,
4491
+ itemsAmount,
4492
+ landedCostId,
4493
+ presentmentCountryCode,
4494
+ },
4495
+ method: 'POST',
4496
+ });
4497
+ if (errors.length || !json) {
4498
+ logError('Error occurs when updating checkout session', JSON.stringify(errors, null, 2));
4499
+ return { errors, json };
4500
+ }
4501
+ return { errors: [], json };
4502
+ };
4503
+ onChange$1('clientSecret', clientSecret => {
4504
+ // update stripe elements when client secret changes
4505
+ if (clientSecret && stripeStore.stripe) {
4506
+ sessionStorage.setItem('zonos--client-secret', clientSecret);
4507
+ }
4508
+ if (!clientSecret) {
4509
+ sessionStorage.removeItem('zonos--client-secret');
4510
+ }
4511
+ });
4512
+
4513
+ const formatDate = ({ date, formatOptions = { day: 'numeric', weekday: 'long', year: 'numeric' }, }) => {
4514
+ // format date to Thursday 3, 2023
4515
+ return new Intl.DateTimeFormat('en-US', formatOptions).format(date);
4516
+ };
4517
+
4518
+ const getDaysDifference = (targetDate) => {
4519
+ const currentDate = new Date();
4520
+ const timeDifference = targetDate.getTime() - currentDate.getTime();
4521
+ const daysDifference = Math.floor(timeDifference / (1000 * 60 * 60 * 24)); // Convert milliseconds to days
4522
+ return daysDifference;
4523
+ };
4524
+
4525
+ const { onChange, reset, state: cartStore, } = zonosStore.createStore(() => ({
4526
+ checkoutSessionId: sessionStorage.getItem('zonos--checkout-session-id') || null,
4527
+ currency: 'USD',
4528
+ dutiesTaxFees: 0,
4529
+ error: null,
4530
+ exchangeRate: null,
4531
+ isSelectedShippingAboveDeminimis: false,
4532
+ isSelectedShippingGuarantee: false,
4533
+ items: [],
4534
+ landedCostData: null,
4535
+ selectedLandedCost: null,
4536
+ selectedShippingOption: null,
4537
+ selectedShippingOptionExpectedDate: '',
4538
+ selectedShippingOptionTransitTime: '',
4539
+ shipping: 0,
4540
+ shippingData: null,
4541
+ step: 'customer-info',
4542
+ subtotal: 0,
4543
+ total: 0,
4544
+ }));
4545
+ /**
4546
+ * Format shipping transit info to be displayed on UI
4547
+ * @returns
4548
+ * - expectedDate: Thursday, Aug 12
4549
+ * - maxTransit: 5
4550
+ * - minTransit: 3
4551
+ */
4552
+ const cartStoreGetShippingTransitInfo = (item) => {
4553
+ const minTransit = item.minTransitAt
4554
+ ? getDaysDifference(new Date(item.minTransitAt))
4555
+ : '';
4556
+ const maxTransit = item.maxTransitAt
4557
+ ? getDaysDifference(new Date(item.maxTransitAt))
4558
+ : '';
4559
+ const expectedDate = item.minTransitAt
4560
+ ? formatDate({
4561
+ date: new Date(item.minTransitAt),
4562
+ })
4563
+ : '';
4564
+ return {
4565
+ expectedDate,
4566
+ maxTransit,
4567
+ minTransit,
4568
+ };
4569
+ };
4570
+ const cartStoreReset = () => {
4571
+ sessionStorage.removeItem('zonos--checkout-session-id');
4572
+ // reset cart store
4573
+ reset();
4574
+ };
4575
+ const cartStoreUpdateToErrorState = ({ messages, title, }) => {
4576
+ cartStoreReset();
4577
+ stripeStoreReset();
4578
+ cartStore.step = 'error';
4579
+ cartStore.error = {
4580
+ messages,
4581
+ title,
4582
+ };
4583
+ };
4584
+ const cartStoreApplySubtotals = (subtotals) => {
4585
+ // update exchange rate so we can use it to display cart items
4586
+ cartStore.exchangeRate = subtotals.exchangeRate;
4587
+ cartStore.dutiesTaxFees = subtotals.landedCostTotal;
4588
+ cartStore.subtotal = subtotals.items;
4589
+ cartStore.total = subtotals.total;
4590
+ cartStore.currency = subtotals.presentmentCurrencyCode;
4591
+ };
4592
+ const cartStoreReCalculateTotal = async ({ currency, itemsAmount, landedCostId, }) => {
4593
+ if (landedCostId && cartStore.selectedLandedCost) {
4594
+ // update cart total right away if we have landed cost id to avoid order total flickering
4595
+ const subtotals = cartStore.selectedLandedCost.subtotals;
4596
+ cartStoreApplySubtotals(subtotals);
4597
+ log('Exchange rate updated for cart items (landed cost subtotal)', 'info', cartStore.exchangeRate);
4598
+ }
4599
+ // update checkout session
4600
+ if (!cartStore.checkoutSessionId) {
4601
+ logError('Could not update cart total without checkout session id');
4602
+ return false;
4603
+ }
4604
+ const { json } = await stripeStoreUpdateCheckoutSession({
4605
+ currency,
4606
+ id: cartStore.checkoutSessionId,
4607
+ itemsAmount,
4608
+ landedCostId,
4609
+ presentmentCountryCode: localizationStore.selectedCountryCode,
4610
+ });
4611
+ if (!json) {
4612
+ // do nothing if we can't get checkout session
4613
+ logError('Error occurs when updating checkout session');
4614
+ cartStoreUpdateToErrorState({
4615
+ messages: [
4616
+ translate("There's been an error updating your checkout session. Please reload and try again or contact support if the error persists"),
4617
+ ],
4618
+ title: translate('Error updating Checkout'),
4619
+ });
4620
+ return false;
4621
+ }
4622
+ if (!landedCostId) {
4623
+ // This is when first open the checkout modal and we just want to get info from the old cart session.
4624
+ // use subtotals from checkout session to update cart total
4625
+ cartStoreApplySubtotals(json.checkoutSessionUpdate.subtotals);
4626
+ log('Exchange rate updated for cart items (checkout session update)', 'info', cartStore.exchangeRate);
4627
+ }
4628
+ return true;
4629
+ };
4630
+ const cartStoreUpdateSelectedShippingOption = async (selectedShippingOption) => {
4631
+ var _a, _b, _c, _d, _e;
4632
+ cartStore.selectedShippingOption = selectedShippingOption;
4633
+ // update shipping transit info
4634
+ const { expectedDate, maxTransit, minTransit } = cartStoreGetShippingTransitInfo(cartStore.selectedShippingOption);
4635
+ cartStore.selectedShippingOptionExpectedDate = expectedDate;
4636
+ cartStore.selectedShippingOptionTransitTime =
4637
+ minTransit && maxTransit
4638
+ ? `${minTransit}-${maxTransit}`
4639
+ : `${minTransit || maxTransit}`;
4640
+ const selectedLandedCost = (_a = cartStore.landedCostData) === null || _a === void 0 ? void 0 : _a.find(checkoutSessionPresentment => {
4641
+ var _a, _b, _c;
4642
+ return ((_b = (_a = checkoutSessionPresentment.landedCost) === null || _a === void 0 ? void 0 : _a.shipmentRating) === null || _b === void 0 ? void 0 : _b.id) ===
4643
+ ((_c = cartStore.selectedShippingOption) === null || _c === void 0 ? void 0 : _c.id);
4644
+ });
4645
+ // save selected landed cost for later use
4646
+ cartStore.selectedLandedCost = selectedLandedCost || null;
4647
+ if (!selectedLandedCost) {
4648
+ // do nothing if we can't find landed cost for selected shipping option
4649
+ return false;
4650
+ }
4651
+ // update shipping value and dutiesTaxFees on selectedShippingOption change
4652
+ cartStore.shipping = selectedLandedCost.subtotals.shipping;
4653
+ // update deminimis status
4654
+ const isGuarantee = ((_b = selectedLandedCost === null || selectedLandedCost === void 0 ? void 0 : selectedLandedCost.landedCost) === null || _b === void 0 ? void 0 : _b.landedCostGuaranteeCode) === 'ZONOS';
4655
+ // one item in deminimis with type of duty and tax has threshold value is "ABOVE"
4656
+ 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'));
4657
+ cartStore.isSelectedShippingAboveDeminimis = isAboveDeminimis;
4658
+ cartStore.isSelectedShippingGuarantee = isGuarantee;
4659
+ // update session with selected landed cost
4660
+ const updateCalulateStatus = await cartStoreReCalculateTotal({
4661
+ landedCostId: (_e = selectedLandedCost.landedCost) === null || _e === void 0 ? void 0 : _e.id,
4662
+ });
4663
+ return updateCalulateStatus;
4664
+ };
4665
+ onChange('checkoutSessionId', () => {
4666
+ if (!cartStore.checkoutSessionId) {
4667
+ sessionStorage.removeItem('zonos--checkout-session-id');
4668
+ return;
4669
+ }
4670
+ sessionStorage.setItem('zonos--checkout-session-id', cartStore.checkoutSessionId);
4671
+ });
4672
+ const cartStoreUpdateItems = async (items) => {
4673
+ var _a;
4674
+ cartStore.items = items;
4675
+ const currency = (_a = items.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode;
4676
+ const total = items.reduce((amt, item) => {
4677
+ return amt + item.amount * item.quantity;
4678
+ }, 0);
4679
+ if (!currency || !total) {
4680
+ // do nothing if we can't get currency or total
4681
+ return;
4682
+ }
4683
+ cartStore.currency = currency;
4684
+ // set loading state here because this is first load checkout session when we already have checkout session id stored
4685
+ stripeStore.isFetchingSession = true;
4686
+ await cartStoreReCalculateTotal({
4687
+ currency: currency,
4688
+ itemsAmount: total,
4689
+ });
4690
+ stripeStore.isFetchingSession = false;
4691
+ };
4692
+ const cartStoreResetSelectedShippingOption = () => {
4693
+ cartStore.selectedShippingOption = null;
4694
+ cartStore.isSelectedShippingAboveDeminimis = false;
4695
+ cartStore.isSelectedShippingGuarantee = false;
4696
+ cartStore.selectedShippingOptionExpectedDate = '';
4697
+ cartStore.selectedShippingOptionTransitTime = '';
4698
+ cartStore.shipping = 0;
4699
+ };
4700
+ const cartStoreNextStep = () => {
4701
+ if (cartStore.step === 'customer-info') {
4702
+ cartStore.step = 'shipping';
4703
+ }
4704
+ else if (cartStore.step === 'shipping') {
4705
+ cartStore.step = 'payment';
4706
+ }
4707
+ else if (cartStore.step === 'payment') {
4708
+ cartStore.step = 'finish';
4709
+ }
4710
+ };
4711
+ const cartStorePreviousStep = () => {
4712
+ if (cartStore.step === 'payment') {
4713
+ cartStore.step = 'shipping';
4714
+ }
4715
+ else if (cartStore.step === 'shipping') {
4716
+ cartStore.step = 'customer-info';
4717
+ // reset selected shipping option
4718
+ cartStoreResetSelectedShippingOption();
4719
+ }
4016
4720
  };
4017
4721
 
4722
+ exports.cartStore = cartStore;
4723
+ exports.cartStoreGetShippingTransitInfo = cartStoreGetShippingTransitInfo;
4724
+ exports.cartStoreNextStep = cartStoreNextStep;
4725
+ exports.cartStorePreviousStep = cartStorePreviousStep;
4726
+ exports.cartStoreReset = cartStoreReset;
4727
+ exports.cartStoreUpdateItems = cartStoreUpdateItems;
4728
+ exports.cartStoreUpdateSelectedShippingOption = cartStoreUpdateSelectedShippingOption;
4729
+ exports.cartStoreUpdateToErrorState = cartStoreUpdateToErrorState;
4018
4730
  exports.currencyConvert = currencyConvert;
4019
4731
  exports.currencyConvertAndFormat = currencyConvertAndFormat;
4020
4732
  exports.currencyDisplay = currencyDisplay;
@@ -4022,6 +4734,7 @@ exports.currencyFormat = currencyFormat;
4022
4734
  exports.getZCountryUrlParam = getZCountryUrlParam;
4023
4735
  exports.handleFetch = handleFetch;
4024
4736
  exports.initLocalizationStore = initLocalizationStore;
4737
+ exports.initStripeElements = initStripeElements;
4025
4738
  exports.isValidSelector = isValidSelector;
4026
4739
  exports.localizationStore = localizationStore;
4027
4740
  exports.localizationStoreUpdateSelectedCountryCode = localizationStoreUpdateSelectedCountryCode;
@@ -4029,4 +4742,10 @@ exports.localizationStoreUpdateSelectedLocale = localizationStoreUpdateSelectedL
4029
4742
  exports.log = log;
4030
4743
  exports.logError = logError;
4031
4744
  exports.setZCountryUrlParam = setZCountryUrlParam;
4745
+ exports.stripeStore = stripeStore;
4746
+ exports.stripeStoreConfirmPayment = stripeStoreConfirmPayment;
4747
+ exports.stripeStoreInitCheckoutSession = stripeStoreInitCheckoutSession;
4748
+ exports.stripeStorePrefetchLandedCost = stripeStorePrefetchLandedCost;
4749
+ exports.stripeStoreReset = stripeStoreReset;
4750
+ exports.stripeStoreRetrievePayment = stripeStoreRetrievePayment;
4032
4751
  exports.translate = translate;