@zonos/elements 1.3.170 → 1.3.172

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 (121) hide show
  1. package/dist/cjs/{CheckoutConfig-f5e68e14.js → CheckoutConfig-c5943bbf.js} +1 -1
  2. package/dist/cjs/{cart-36799bbe.js → cart-d91d9507.js} +13 -8
  3. package/dist/cjs/{handleFetch-7b7f9f7c.js → handleFetch-ff25db40.js} +10 -6
  4. package/dist/cjs/index.cjs.js +9 -9
  5. package/dist/cjs/loader.cjs.js +1 -1
  6. package/dist/cjs/{paypal-3eae38bd.js → paypal-82841277.js} +2 -2
  7. package/dist/cjs/zonos-address_7.cjs.entry.js +51 -18
  8. package/dist/cjs/zonos-cart-items_13.cjs.entry.js +10 -6
  9. package/dist/cjs/zonos-checkout.cjs.entry.js +114 -40
  10. package/dist/cjs/zonos-controller.cjs.entry.js +2 -2
  11. package/dist/cjs/zonos-country-flag.cjs.entry.js +2 -2
  12. package/dist/cjs/zonos-country-select_4.cjs.entry.js +2 -2
  13. package/dist/cjs/zonos-elements.cjs.js +1 -1
  14. package/dist/cjs/zonos-empty-state-payment_4.cjs.entry.js +3 -3
  15. package/dist/cjs/zonos-hello-dialog.cjs.entry.js +2 -2
  16. package/dist/cjs/zonos-hello.cjs.entry.js +2 -2
  17. package/dist/cjs/zonos-language-select_2.cjs.entry.js +2 -2
  18. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +122 -41
  19. package/dist/collection/components/checkout/zonos-checkout/zonos-customer-info/zonos-customer-info.js +10 -6
  20. package/dist/collection/components/store/checkout/cart.js +5 -0
  21. package/dist/collection/components/store/checkout/stripe.js +5 -7
  22. package/dist/collection/components/stripe/zonos-address/zonos-address.js +26 -15
  23. package/dist/collection/components/stripe/zonos-link-authentication/zonos-link-authentication.js +27 -4
  24. package/dist/collection/components/utils/handleFetch.js +9 -6
  25. package/dist/collection/components/utils/logging/getAdditionalLogMetadata.js +1 -0
  26. package/dist/collection/styles/stripe/defaultVariable.js +2 -0
  27. package/dist/collection/types/generated/graphql.internal.types.js +7 -0
  28. package/dist/esm/{CheckoutConfig-2994efd9.js → CheckoutConfig-75af3742.js} +1 -1
  29. package/dist/esm/{cart-b2e57589.js → cart-52e208cc.js} +13 -8
  30. package/dist/esm/{handleFetch-8d72c8cd.js → handleFetch-0109fb78.js} +10 -6
  31. package/dist/esm/index.js +10 -10
  32. package/dist/esm/loader.js +1 -1
  33. package/dist/esm/{paypal-38da5d52.js → paypal-2e1c560e.js} +2 -2
  34. package/dist/esm/zonos-address_7.entry.js +51 -18
  35. package/dist/esm/zonos-cart-items_13.entry.js +10 -6
  36. package/dist/esm/zonos-checkout.entry.js +114 -40
  37. package/dist/esm/zonos-controller.entry.js +2 -2
  38. package/dist/esm/zonos-country-flag.entry.js +2 -2
  39. package/dist/esm/zonos-country-select_4.entry.js +2 -2
  40. package/dist/esm/zonos-elements.js +1 -1
  41. package/dist/esm/zonos-empty-state-payment_4.entry.js +3 -3
  42. package/dist/esm/zonos-hello-dialog.entry.js +2 -2
  43. package/dist/esm/zonos-hello.entry.js +2 -2
  44. package/dist/esm/zonos-language-select_2.entry.js +2 -2
  45. package/dist/esm-es5/{CheckoutConfig-2994efd9.js → CheckoutConfig-75af3742.js} +1 -1
  46. package/dist/esm-es5/{cart-b2e57589.js → cart-52e208cc.js} +1 -1
  47. package/dist/esm-es5/handleFetch-0109fb78.js +1 -0
  48. package/dist/esm-es5/index.js +1 -1
  49. package/dist/esm-es5/loader.js +1 -1
  50. package/dist/esm-es5/{paypal-38da5d52.js → paypal-2e1c560e.js} +1 -1
  51. package/dist/esm-es5/zonos-address_7.entry.js +1 -1
  52. package/dist/esm-es5/zonos-cart-items_13.entry.js +1 -1
  53. package/dist/esm-es5/zonos-checkout.entry.js +1 -1
  54. package/dist/esm-es5/zonos-controller.entry.js +1 -1
  55. package/dist/esm-es5/zonos-country-flag.entry.js +1 -1
  56. package/dist/esm-es5/zonos-country-select_4.entry.js +1 -1
  57. package/dist/esm-es5/zonos-elements.js +1 -1
  58. package/dist/esm-es5/zonos-empty-state-payment_4.entry.js +1 -1
  59. package/dist/esm-es5/zonos-hello-dialog.entry.js +1 -1
  60. package/dist/esm-es5/zonos-hello.entry.js +1 -1
  61. package/dist/esm-es5/zonos-language-select_2.entry.js +1 -1
  62. package/dist/scripts/index.d.ts +25 -6
  63. package/dist/scripts/index.js +1 -1
  64. package/dist/scripts/loadZonos.js +1 -1
  65. package/dist/scripts/zonos.js +1 -1
  66. package/dist/types/components/checkout/zonos-checkout/zonos-checkout.d.ts +17 -3
  67. package/dist/types/components/checkout/zonos-checkout/zonos-customer-info/zonos-customer-info.d.ts +1 -1
  68. package/dist/types/components/store/checkout/cart.d.ts +4 -0
  69. package/dist/types/components/store/checkout/stripe.d.ts +10 -1
  70. package/dist/types/components/stripe/zonos-address/zonos-address.d.ts +2 -2
  71. package/dist/types/components/stripe/zonos-link-authentication/zonos-link-authentication.d.ts +1 -1
  72. package/dist/types/components/utils/api/getLocaleMessages.d.ts +1 -1
  73. package/dist/types/components/utils/logging/getAdditionalLogMetadata.d.ts +1 -0
  74. package/dist/types/components.d.ts +8 -6
  75. package/dist/types/types/checkout/CheckoutConfig.d.ts +1 -0
  76. package/dist/types/types/checkout/api/CheckoutSession.d.ts +8 -0
  77. package/dist/types/types/generated/graphql.frontend.types.d.ts +1 -1
  78. package/dist/types/types/generated/graphql.frontend.types.ts +1 -1
  79. package/dist/types/types/generated/graphql.internal.types.d.ts +92 -0
  80. package/dist/types/types/generated/graphql.internal.types.ts +105 -0
  81. package/dist/zonos-elements/assets/RemoveIcon.svg +1 -1
  82. package/dist/zonos-elements/index.esm.js +1 -1
  83. package/dist/zonos-elements/{p-56a8b1f6.system.entry.js → p-048e4b38.system.entry.js} +1 -1
  84. package/dist/zonos-elements/p-04c38987.system.js +1 -0
  85. package/dist/zonos-elements/{p-bf113a46.system.js → p-0ee42be2.system.js} +1 -1
  86. package/dist/zonos-elements/{p-ff1c6d9a.entry.js → p-10a9edf6.entry.js} +1 -1
  87. package/dist/zonos-elements/{p-864c7c7d.entry.js → p-14bd4766.entry.js} +1 -1
  88. package/dist/zonos-elements/{p-47f79a6d.js → p-1c488ecf.js} +1 -1
  89. package/dist/zonos-elements/{p-cb52cfdf.entry.js → p-1e3e4e22.entry.js} +1 -1
  90. package/dist/zonos-elements/p-221d4f15.system.entry.js +1 -0
  91. package/dist/zonos-elements/{p-e09cea9c.entry.js → p-246c3b28.entry.js} +1 -1
  92. package/dist/zonos-elements/p-2b8c5669.system.entry.js +1 -0
  93. package/dist/zonos-elements/{p-dd0259f4.js → p-2d2c70a3.js} +1 -1
  94. package/dist/zonos-elements/{p-c5c2976f.system.js → p-2ebb4fa7.system.js} +1 -1
  95. package/dist/zonos-elements/{p-a3888f1d.system.js → p-36c35a07.system.js} +1 -1
  96. package/dist/zonos-elements/p-46f6e5e9.system.js +1 -1
  97. package/dist/zonos-elements/{p-00ad3c73.entry.js → p-588ac238.entry.js} +1 -1
  98. package/dist/zonos-elements/{p-b0c39400.entry.js → p-68304407.entry.js} +1 -1
  99. package/dist/zonos-elements/{p-d24e0b90.system.js → p-7de48475.system.js} +1 -1
  100. package/dist/zonos-elements/p-839448c3.js +1 -0
  101. package/dist/zonos-elements/{p-53cb8867.system.entry.js → p-85d2da79.system.entry.js} +1 -1
  102. package/dist/zonos-elements/{p-1a20922f.system.entry.js → p-91a7ca64.system.entry.js} +1 -1
  103. package/dist/zonos-elements/{p-0bfca3a9.system.entry.js → p-9a10a63b.system.entry.js} +1 -1
  104. package/dist/zonos-elements/p-a08fad84.entry.js +1 -0
  105. package/dist/zonos-elements/{p-bfa028a2.entry.js → p-a61ef92f.entry.js} +1 -1
  106. package/dist/zonos-elements/{p-0def1397.system.entry.js → p-aa754137.system.entry.js} +1 -1
  107. package/dist/zonos-elements/{p-c82f488b.system.entry.js → p-aea22783.system.entry.js} +1 -1
  108. package/dist/zonos-elements/p-ba604bc4.entry.js +1 -0
  109. package/dist/zonos-elements/{p-48173901.js → p-bbf9dbe4.js} +1 -1
  110. package/dist/zonos-elements/{p-461ca324.entry.js → p-c719434a.entry.js} +1 -1
  111. package/dist/zonos-elements/{p-56758218.system.entry.js → p-e34c0f83.system.entry.js} +1 -1
  112. package/dist/zonos-elements/{p-1edbfb1f.system.entry.js → p-eb716dcc.system.entry.js} +1 -1
  113. package/dist/zonos-elements/zonos-elements.esm.js +1 -1
  114. package/package.json +1 -1
  115. package/dist/esm-es5/handleFetch-8d72c8cd.js +0 -1
  116. package/dist/zonos-elements/p-0dc78be4.system.entry.js +0 -1
  117. package/dist/zonos-elements/p-71539c8a.js +0 -1
  118. package/dist/zonos-elements/p-8b179fdc.entry.js +0 -1
  119. package/dist/zonos-elements/p-9261869c.system.js +0 -1
  120. package/dist/zonos-elements/p-9f9e4f74.entry.js +0 -1
  121. package/dist/zonos-elements/p-fd352222.system.entry.js +0 -1
@@ -180,13 +180,30 @@ export class ZonosCheckout {
180
180
  settlementAmount: total,
181
181
  };
182
182
  };
183
+ this.getDefaultAddress = () => {
184
+ // If checkout customer is authenticated, use the address from the customer profile
185
+ if (this.defaultCustomerProfileAddress.length) {
186
+ return this.defaultCustomerProfileAddress;
187
+ }
188
+ // If default address is provided directly from the component, use it
189
+ if (Array.isArray(this.defaultAddress) && this.defaultAddress.length) {
190
+ return this.defaultAddress;
191
+ }
192
+ if (!Array.isArray(this.defaultAddress) &&
193
+ typeof this.defaultAddress === 'object') {
194
+ return [this.defaultAddress];
195
+ }
196
+ return this.defaultAddressParams;
197
+ };
183
198
  this.appearanceSettingsOverride = undefined;
184
199
  this.preview = false;
185
200
  this.mobile = false;
186
201
  this.overrideStagingMode = undefined;
187
- this.defaultAddress = null;
202
+ this.defaultAddress = [];
188
203
  this.forceDialogOpen = false;
189
- this.defaultAddressParams = null;
204
+ this.defaultAddressParams = [];
205
+ this.defaultCustomerProfileAddress = [];
206
+ this.customerProfile = null;
190
207
  this.open = this.forceDialogOpen;
191
208
  this.stripe = window.Zonos.stripe;
192
209
  this.submitLoading = false;
@@ -203,6 +220,7 @@ export class ZonosCheckout {
203
220
  this.inventoryCheckErrorMessage = null;
204
221
  this.placedOrderInfo = null;
205
222
  this.clientSecret = stripeStore.clientSecret;
223
+ this.stripeCustomerSessionClientSecret = stripeStore.stripeCustomerSessionClientSecret;
206
224
  }
207
225
  /**
208
226
  * Init cart info handler event
@@ -263,6 +281,8 @@ export class ZonosCheckout {
263
281
  cartId = cartIdResult.cartId;
264
282
  // set prefill address if provided in createCartId callback result
265
283
  this.useShippingDataFromCreateCartId(cartIdResult.shippingData);
284
+ cartStore.customerAuthenticationToken =
285
+ cartIdResult.customerAuthenticationToken || null;
266
286
  }
267
287
  else {
268
288
  cartId = cartIdResult;
@@ -426,12 +446,6 @@ export class ZonosCheckout {
426
446
  });
427
447
  button.addEventListener('click', async (e) => {
428
448
  var _a;
429
- if (!window.Zonos.logIntervalId) {
430
- // log the load time of all API calls every 2 seconds. This is to track the load time of all API calls for checkout user
431
- window.Zonos.logIntervalId = setInterval(() => {
432
- void sendBulkLoadTimeApiLog();
433
- }, 2000);
434
- }
435
449
  // Start tracking load time
436
450
  const startTime = performance.now();
437
451
  // Allow no country set for legacy facades. Otherwise enforce it being a shippable country and not disabled.
@@ -456,6 +470,16 @@ export class ZonosCheckout {
456
470
  if (!shouldAllowOrder) {
457
471
  return;
458
472
  }
473
+ /**
474
+ * We are checking the payment state when Zonos script is loaded (user clicked "Checkout" button prviously), the hidden checkout button would be injected and clicked when the page is loaded, which leads to recording the load time on page load.
475
+ * Move the logic below checking Stripe payment state so we don't record the load time on page load and only do so when checkout modal is actually showed up.
476
+ */
477
+ if (!window.Zonos.logIntervalId) {
478
+ // log the load time of all API calls every 2 seconds. This is to track the load time of all API calls for checkout user
479
+ window.Zonos.logIntervalId = setInterval(() => {
480
+ void sendBulkLoadTimeApiLog();
481
+ }, 2000);
482
+ }
459
483
  // start loading
460
484
  stripeStore.isFetchingSession = true;
461
485
  this.open = true;
@@ -617,7 +641,6 @@ export class ZonosCheckout {
617
641
  const phone = address.customerPhone || '';
618
642
  const postal_code = address.customerZip || '';
619
643
  const state = address.customerState || '';
620
- const countryCode = country === 'UK' ? 'GB' : country;
621
644
  /**
622
645
  * If one of the value is null, no need to preset the default address.
623
646
  * City and state are optional (they are not always provided for example Puerto Rico)
@@ -633,19 +656,27 @@ export class ZonosCheckout {
633
656
  .join(', '));
634
657
  return;
635
658
  }
636
- this.defaultAddressParams = {
637
- address: {
638
- city: city || '',
639
- country: countryCode,
640
- line1,
641
- line2,
642
- postal_code,
643
- state,
659
+ if (country &&
660
+ localizationStore.shippingZoneCountries &&
661
+ !(country in localizationStore.shippingZoneCountries)) {
662
+ log(`Country "${country}" is not in the shipping zone, so it can not be prefilled`, 'warn');
663
+ return;
664
+ }
665
+ this.defaultAddressParams = [
666
+ {
667
+ address: {
668
+ city: city || '',
669
+ country,
670
+ line1,
671
+ line2,
672
+ postal_code,
673
+ state,
674
+ },
675
+ email,
676
+ name,
677
+ phone,
644
678
  },
645
- email,
646
- name,
647
- phone,
648
- };
679
+ ];
649
680
  log('Prefill address applied', 'info', {
650
681
  prefillAddress: this.defaultAddressParams,
651
682
  providedAddress: address,
@@ -671,19 +702,21 @@ export class ZonosCheckout {
671
702
  domesticRedirectedBtnSelector: domesticRedirectedBtnSelector,
672
703
  onShippingAddressSessionFound: shippingAddressSession => {
673
704
  // prefilled the default address if shipping address session is found for checkout on open
674
- this.defaultAddress = {
675
- address: {
676
- city: shippingAddressSession.city,
677
- country: shippingAddressSession.countryCode,
678
- line1: shippingAddressSession.address1,
679
- line2: shippingAddressSession.address2,
680
- postal_code: shippingAddressSession.postalCode,
681
- state: shippingAddressSession.state,
705
+ this.defaultAddress = [
706
+ {
707
+ address: {
708
+ city: shippingAddressSession.city,
709
+ country: shippingAddressSession.countryCode,
710
+ line1: shippingAddressSession.address1,
711
+ line2: shippingAddressSession.address2,
712
+ postal_code: shippingAddressSession.postalCode,
713
+ state: shippingAddressSession.state,
714
+ },
715
+ email: '',
716
+ name: `${shippingAddressSession.firstName} ${shippingAddressSession.lastName}`,
717
+ phone: shippingAddressSession.phone,
682
718
  },
683
- email: '',
684
- name: `${shippingAddressSession.firstName} ${shippingAddressSession.lastName}`,
685
- phone: shippingAddressSession.phone,
686
- };
719
+ ];
687
720
  },
688
721
  });
689
722
  /**
@@ -926,9 +959,39 @@ export class ZonosCheckout {
926
959
  handleAddressChange() {
927
960
  stripeStoreReset();
928
961
  }
962
+ handleCustomerProfileChange() {
963
+ var _a, _b;
964
+ if (!this.customerProfile) {
965
+ log('No customer profile', 'info');
966
+ this.defaultCustomerProfileAddress = [];
967
+ return;
968
+ }
969
+ log('Customer profile found', 'info', {
970
+ customerProfile: this.customerProfile,
971
+ });
972
+ // Build and set saved locations from checkout customers
973
+ this.defaultCustomerProfileAddress =
974
+ ((_b = (_a = stripeStore.customerProfile) === null || _a === void 0 ? void 0 : _a.locations) === null || _b === void 0 ? void 0 : _b.map(location => {
975
+ var _a;
976
+ return {
977
+ address: {
978
+ city: location.locality,
979
+ country: location.countryCode,
980
+ line1: location.line1,
981
+ line2: location.line2 || '',
982
+ postal_code: location.postalCode,
983
+ state: location.administrativeArea,
984
+ },
985
+ email: location.email || ((_a = stripeStore.customerProfile) === null || _a === void 0 ? void 0 : _a.email) || '',
986
+ name: location.name || '',
987
+ phone: location.phone || '',
988
+ };
989
+ })) || [];
990
+ }
929
991
  handleClientSecretChange() {
930
- log('=== Client secret changed', 'info', {
931
- clientSecret: stripeStore.clientSecret,
992
+ log('==== Client secret changed', 'info', {
993
+ clientSecret: this.clientSecret,
994
+ stripeCustomerSessionClientSecret: this.stripeCustomerSessionClientSecret,
932
995
  });
933
996
  // apply theme to stripe elements
934
997
  void this.applyStripeTheme();
@@ -950,6 +1013,8 @@ export class ZonosCheckout {
950
1013
  html.style.overflow = 'hidden';
951
1014
  }
952
1015
  else {
1016
+ // Should reset stripeCustomerSessionClientSecret state when dialog is closed since merchant would need to re-authenticate, get an OTP again and we will get a new customer session.
1017
+ this.stripeCustomerSessionClientSecret = null;
953
1018
  const bodyOverflow = body.getAttribute(overflowAttrKey);
954
1019
  const htmlOverflow = html.getAttribute(overflowAttrKey);
955
1020
  // reset overflow state to original state
@@ -997,8 +1062,15 @@ export class ZonosCheckout {
997
1062
  }
998
1063
  render() {
999
1064
  var _a, _b, _c, _d;
1065
+ this.customerProfile = stripeStore.customerProfile;
1000
1066
  // Set client secret so that we can add this to @Watch listener
1001
1067
  this.clientSecret = stripeStore.clientSecret;
1068
+ // Only set and update stripeCustomerSession state if it's available, since it would only be available at the time checkout session is created, afterward access checkout session the value would be `null`.
1069
+ if (stripeStore.stripeCustomerSessionClientSecret) {
1070
+ // Set stripe customer session client secret so that we can add this to @Watch listener
1071
+ this.stripeCustomerSessionClientSecret =
1072
+ stripeStore.stripeCustomerSessionClientSecret;
1073
+ }
1002
1074
  const dialogLoading =
1003
1075
  // if it's last step, don't need to check stripe elements
1004
1076
  (cartStore.step !== 'finish' &&
@@ -1051,7 +1123,7 @@ export class ZonosCheckout {
1051
1123
  '--zonos--primary-color': !this.isMobile
1052
1124
  ? colorPrimary
1053
1125
  : undefined,
1054
- }) }, !this.isMobile && renderTopHeader(), cartStore.step === 'customer-info' && (h("zonos-customer-info", { continueLoading: this.submitLoading, defaultAddress: this.defaultAddress || this.defaultAddressParams, isMobile: this.isMobile, onContinueClicked: () => this.handleCustomerInfoContinue(), submitBtnColor: submitButtonColor })), cartStore.step === 'shipping' && (h("zonos-shipping", { continueLoading: this.submitLoading, onContinueClicked: () => this.handleShippingContinue(), submitBtnColor: submitButtonColor })), cartStore.step === 'payment' && (h("zonos-checkout-payment", { continueLoading: this.submitLoading, isMobile: this.isMobile, onContinueClicked: async () => {
1126
+ }) }, !this.isMobile && renderTopHeader(), cartStore.step === 'customer-info' && (h("zonos-customer-info", { continueLoading: this.submitLoading, defaultAddress: this.getDefaultAddress(), isMobile: this.isMobile, onContinueClicked: () => this.handleCustomerInfoContinue(), submitBtnColor: submitButtonColor })), cartStore.step === 'shipping' && (h("zonos-shipping", { continueLoading: this.submitLoading, onContinueClicked: () => this.handleShippingContinue(), submitBtnColor: submitButtonColor })), cartStore.step === 'payment' && (h("zonos-checkout-payment", { continueLoading: this.submitLoading, isMobile: this.isMobile, onContinueClicked: async () => {
1055
1127
  await this.handleStripePaymentContinue();
1056
1128
  }, submitBtnColor: submitButtonColor }))), h("div", { class: "zonos--right", "data-theme": rightSideTheme }, this.isMobile && renderTopHeader(), h("div", { class: "zonos--right-actions" }, window.Zonos.showBaseForeign && (h("zonos-currency-toggle", null)), !this.isLegacyCheckout && (h("zonos-button", { class: "zonos--close-button", icon: h("zonos-icon", { "aria-label": "Close checkout dialog", content: RemoveIcon }), noBackground: true, onClick: () => this.closeDialogHandler() }))), h("div", { class: "flex--wrapper" }, h("div", { class: "zonos--wrapper" }, h("zonos-review", { collapsed: this.collapseReviewMobile, mobile: this.isMobile, onClick: () => {
1057
1129
  // do nothing if it's not mobile
@@ -1229,8 +1301,8 @@ export class ZonosCheckout {
1229
1301
  "type": "unknown",
1230
1302
  "mutable": false,
1231
1303
  "complexType": {
1232
- "original": "StripeStoreContactOption | null",
1233
- "resolved": "null | { address: { city: string; country: string; line1: string; line2?: string | undefined; postal_code: string; state: string; }; email: string; name: string; phone?: string | undefined; }",
1304
+ "original": "| StripeStoreContactOption[]\n | StripeStoreContactOption",
1305
+ "resolved": "StripeStoreContactOption[] | { address: { city: string; country: string; line1: string; line2?: string | undefined; postal_code: string; state: string; }; email: string; name: string; phone?: string | undefined; }",
1234
1306
  "references": {
1235
1307
  "StripeStoreContactOption": {
1236
1308
  "location": "import",
@@ -1247,7 +1319,7 @@ export class ZonosCheckout {
1247
1319
  },
1248
1320
  "getter": false,
1249
1321
  "setter": false,
1250
- "defaultValue": "null"
1322
+ "defaultValue": "[]"
1251
1323
  },
1252
1324
  "forceDialogOpen": {
1253
1325
  "type": "boolean",
@@ -1274,6 +1346,8 @@ export class ZonosCheckout {
1274
1346
  static get states() {
1275
1347
  return {
1276
1348
  "defaultAddressParams": {},
1349
+ "defaultCustomerProfileAddress": {},
1350
+ "customerProfile": {},
1277
1351
  "open": {},
1278
1352
  "stripe": {},
1279
1353
  "submitLoading": {},
@@ -1289,7 +1363,8 @@ export class ZonosCheckout {
1289
1363
  "payInUsdConfirmDialogOpen": {},
1290
1364
  "inventoryCheckErrorMessage": {},
1291
1365
  "placedOrderInfo": {},
1292
- "clientSecret": {}
1366
+ "clientSecret": {},
1367
+ "stripeCustomerSessionClientSecret": {}
1293
1368
  };
1294
1369
  }
1295
1370
  static get methods() {
@@ -1363,7 +1438,7 @@ export class ZonosCheckout {
1363
1438
  "signature": "(session: CheckoutSessionDetailsFragment) => Promise<void>",
1364
1439
  "parameters": [{
1365
1440
  "name": "session",
1366
- "type": "{ cartId: string | null; clientSecret: string; id: string; landedCost: { amountSubtotals: { discounts: number | null; duties: number; fees: number; items: number; landedCostTotal: number; shipping: number; taxes: number; } | null; id: string; landedCostGuaranteeCode: LandedCostGuaranteeCode; method: IncotermCode; shipmentRating: { displayName: string; }; } | null; metadata: ({ key: string; value: string; } | null)[] | null; organizationId: string; subtotals: { adjustments: number; duties: number; exchangeRate: { id: string; rate: number; sourceCurrencyCode: CurrencyCode; targetCurrencyCode: CurrencyCode; type: ExchangeRateType; }; fees: number; items: number; landedCostTotal: number; presentmentCurrencyCode: CurrencyCode; shipping: number; taxes: number; total: number; }; }",
1441
+ "type": "{ cartId: string | null; clientSecret: string; customerProfile: { email: string | null; locations: { administrativeArea: string; countryCode: CountryCode; email: string | null; line1: string; line2: string | null; locality: string; name: string | null; phone: string | null; postalCode: string; }[] | null; name: string | null; } | null; customerSessionClientSecret: string | null; id: string; landedCost: { amountSubtotals: { discounts: number | null; duties: number; fees: number; items: number; landedCostTotal: number; shipping: number; taxes: number; } | null; id: string; landedCostGuaranteeCode: LandedCostGuaranteeCode; method: IncotermCode; shipmentRating: { displayName: string; }; } | null; metadata: ({ key: string; value: string; } | null)[] | null; organizationId: string; subtotals: { adjustments: number; duties: number; exchangeRate: { id: string; rate: number; sourceCurrencyCode: CurrencyCode; targetCurrencyCode: CurrencyCode; type: ExchangeRateType; }; fees: number; items: number; landedCostTotal: number; presentmentCurrencyCode: CurrencyCode; shipping: number; taxes: number; total: number; }; }",
1367
1442
  "docs": ""
1368
1443
  }],
1369
1444
  "references": {
@@ -1402,9 +1477,15 @@ export class ZonosCheckout {
1402
1477
  }, {
1403
1478
  "propName": "defaultAddress",
1404
1479
  "methodName": "handleAddressChange"
1480
+ }, {
1481
+ "propName": "customerProfile",
1482
+ "methodName": "handleCustomerProfileChange"
1405
1483
  }, {
1406
1484
  "propName": "clientSecret",
1407
1485
  "methodName": "handleClientSecretChange"
1486
+ }, {
1487
+ "propName": "stripeCustomerSessionClientSecret",
1488
+ "methodName": "handleClientSecretChange"
1408
1489
  }, {
1409
1490
  "propName": "open",
1410
1491
  "methodName": "handleOpenChange"
@@ -148,7 +148,7 @@ export class ZonosCustomerInfo {
148
148
  this.submitBtnType = undefined;
149
149
  this.submitBtnColor = undefined;
150
150
  this.isMobile = false;
151
- this.defaultAddress = null;
151
+ this.defaultAddress = [];
152
152
  this.showErrorBanner = false;
153
153
  this.shippingCountry = '';
154
154
  this.isCheckingForRestrictedItems = false;
@@ -205,7 +205,7 @@ export class ZonosCustomerInfo {
205
205
  } }), this.isTaxIdError && (h("zonos-text", { textColor: 'red-600', type: "caption" }, translate('Tax id is required')))));
206
206
  }
207
207
  render() {
208
- var _a, _b;
208
+ var _a, _b, _c, _d, _e, _f;
209
209
  if (!stripeStore.stripeElements) {
210
210
  return null;
211
211
  }
@@ -224,11 +224,15 @@ export class ZonosCustomerInfo {
224
224
  const showBilling = !stripeStore.stripeShippingSameAsBilling;
225
225
  // Get theme for the update dialog, inherit from the theme, no from this component theme
226
226
  const theme = getZonosStoreTheme(zonosStore.appearance.theme);
227
+ // Attempt to get the email from email from customer profile's locations, if not provided, just use the email from root customer profile
228
+ const defaultEmail = ((_b = this.defaultAddress.find(Boolean)) === null || _b === void 0 ? void 0 : _b.email) ||
229
+ ((_e = (_d = (_c = stripeStore.customerProfile) === null || _c === void 0 ? void 0 : _c.locations) === null || _d === void 0 ? void 0 : _d.find(Boolean)) === null || _e === void 0 ? void 0 : _e.email) ||
230
+ ((_f = stripeStore.customerProfile) === null || _f === void 0 ? void 0 : _f.email);
227
231
  // start validate on typing after error banner is shown, and hide it if the form is complete
228
232
  if (this.showErrorBanner) {
229
233
  this.showErrorBanner = !this.handleValidate();
230
234
  }
231
- return (h(Host, { class: "zonos--customer-info zonos--elements" }, h("div", { class: "zonos--group" }, h("zonos-text", { class: "zonos--title", type: "semiBoldSubheader" }, translate('Customer information')), this.showErrorBanner && (h("zonos-banner", { class: "zonos--error-banner", intent: "error" }, translate('Missing required fields. Make sure all fields are completed.'))), h("zonos-link-authentication", { defaultEmail: (_b = this.defaultAddress) === null || _b === void 0 ? void 0 : _b.email, isEmailError: this.isEmailError, onLinkAuthenticationChange: this.handleEmailValidation, titleText: translate('Contact') }), h("zonos-address", { defaultAddress: this.defaultAddress, titleText: translate('Address'), type: "shipping" }), this.renderTaxIdInput(this.shippingCountry), h("zonos-checkbox", { class: "zonos--shipping-same-as-billing-cbx", isChecked: stripeStore.stripeShippingSameAsBilling, label: translate('Shipping address same as billing'), onCheckboxSelected: e => {
235
+ return (h(Host, { class: "zonos--customer-info zonos--elements" }, h("div", { class: "zonos--group" }, h("zonos-text", { class: "zonos--title", type: "semiBoldSubheader" }, translate('Customer information')), this.showErrorBanner && (h("zonos-banner", { class: "zonos--error-banner", intent: "error" }, translate('Missing required fields. Make sure all fields are completed.'))), h("zonos-link-authentication", { defaultEmail: defaultEmail, isEmailError: this.isEmailError, onLinkAuthenticationChange: this.handleEmailValidation, titleText: translate('Contact') }), h("zonos-address", { defaultAddress: this.defaultAddress, titleText: translate('Address'), type: "shipping" }), this.renderTaxIdInput(this.shippingCountry), h("zonos-checkbox", { class: "zonos--shipping-same-as-billing-cbx", isChecked: stripeStore.stripeShippingSameAsBilling, label: translate('Shipping address same as billing'), onCheckboxSelected: e => {
232
236
  stripeStore.stripeShippingSameAsBilling = e.detail;
233
237
  } }), h("zonos-collapse", { collapsed: !showBilling }, h("zonos-address", { defaultAddress: this.defaultAddress, titleText: translate('Billing address'), type: "billing" })), h("div", { class: "zonos--group-btn" }, h("zonos-button", { backgroundColor: this.submitBtnColor, bold: true, loading: this.continueLoading, onClick: () => this.continueClickHandler(), size: "lg",
234
238
  // use primary type when on mobile mode
@@ -348,8 +352,8 @@ export class ZonosCustomerInfo {
348
352
  "type": "unknown",
349
353
  "mutable": false,
350
354
  "complexType": {
351
- "original": "StripeStoreContactOption | null",
352
- "resolved": "null | { address: { city: string; country: string; line1: string; line2?: string | undefined; postal_code: string; state: string; }; email: string; name: string; phone?: string | undefined; }",
355
+ "original": "StripeStoreContactOption[]",
356
+ "resolved": "StripeStoreContactOption[]",
353
357
  "references": {
354
358
  "StripeStoreContactOption": {
355
359
  "location": "import",
@@ -366,7 +370,7 @@ export class ZonosCustomerInfo {
366
370
  },
367
371
  "getter": false,
368
372
  "setter": false,
369
- "defaultValue": "null"
373
+ "defaultValue": "[]"
370
374
  }
371
375
  };
372
376
  }
@@ -15,6 +15,7 @@ const { onChange, reset, state: cartStore, } = createStore(() => ({
15
15
  checkoutTimeoutInterval: null,
16
16
  currency: 'USD',
17
17
  customQuotingError: null,
18
+ customerAuthenticationToken: null,
18
19
  displayBaseCurrency: false,
19
20
  dutiesTaxesFees: null,
20
21
  dutiesTaxesFeesEstimate: null,
@@ -167,7 +168,11 @@ const cartStoreHasOneEligibleItem = () => {
167
168
  };
168
169
  const cartStoreSetCheckoutSession = (checkoutSession) => {
169
170
  var _a, _b, _c, _d, _e;
171
+ // update stripe store with updated information
170
172
  stripeStore.clientSecret = checkoutSession.clientSecret;
173
+ stripeStore.stripeCustomerSessionClientSecret =
174
+ checkoutSession.customerSessionClientSecret;
175
+ stripeStore.customerProfile = checkoutSession.customerProfile;
171
176
  cartStore.checkoutSession = checkoutSession;
172
177
  cartStore.checkoutSessionId = checkoutSession.id;
173
178
  // Check if there is a redirect URL in the metadata to override
@@ -21,6 +21,7 @@ const { onChange, reset, state: stripeStore, } = createStore(() => ({
21
21
  clientSecret: sessionStorage.getItem('zonos--client-secret') || '',
22
22
  companyName: '',
23
23
  customErrorMessage: null,
24
+ customerProfile: null,
24
25
  fetchingLandedCostAbortController: null,
25
26
  hasPaymentError: false,
26
27
  isFetchingLandedCost: false,
@@ -43,6 +44,7 @@ const { onChange, reset, state: stripeStore, } = createStore(() => ({
43
44
  stripeBillingAddressEventData: null,
44
45
  stripeBillingAddressUsedWhenFetchingLC: null,
45
46
  stripeBillingAddressUsedWhenValidatingAddress: null,
47
+ stripeCustomerSessionClientSecret: null,
46
48
  stripeElements: null,
47
49
  stripeElementsForBillingAddress: null,
48
50
  stripeElementsOptions: null,
@@ -85,6 +87,7 @@ const getStripeOptions = ({ clientSecret, overrideBorderRadius, overridePrimaryC
85
87
  },
86
88
  // Client secret can be undefined since we will load other elements that doesn't require client secret first, then load client secret and render one that requires it later
87
89
  clientSecret: clientSecret || undefined,
90
+ customerSessionClientSecret: stripeStore.stripeCustomerSessionClientSecret || undefined,
88
91
  externalPaymentMethodTypes: [...paypalPaymentType],
89
92
  locale: localizationStore.selectedLocale,
90
93
  };
@@ -540,6 +543,7 @@ export const getCheckoutSessionBody = () => {
540
543
  adjustmentsAmount: cartStore.adjustments.reduce((prev, adj) => prev + adj.amount, 0),
541
544
  cartId: window.Zonos.cartId,
542
545
  currency: ((_a = cartStore.items.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode) || '',
546
+ customerAuthenticationToken: cartStore.customerAuthenticationToken || undefined,
543
547
  itemsAmount: total,
544
548
  metadata: [
545
549
  {
@@ -566,10 +570,6 @@ export const getCheckoutSessionBody = () => {
566
570
  };
567
571
  const stripeStoreGetPaymentIntent = async () => {
568
572
  var _a;
569
- if (stripeStore.clientSecret) {
570
- log('Payment intent already exists, skipping fetching payment intent');
571
- return;
572
- }
573
573
  if (!cartStore.checkoutSessionId) {
574
574
  // We want to log the error anytime we fail to create a checkout session
575
575
  void sendErrorLog({
@@ -616,9 +616,6 @@ const stripeStoreGetPaymentIntent = async () => {
616
616
  });
617
617
  return;
618
618
  }
619
- // update stripe store with updated information
620
- stripeStore.clientSecret =
621
- json.checkoutSessionPaymentIntentCreate.clientSecret;
622
619
  // update cart store checkout session with updated from checkout session payment intent creation call so the checkout session and payment intent are in sync
623
620
  cartStoreSetCheckoutSession(json.checkoutSessionPaymentIntentCreate);
624
621
  };
@@ -695,6 +692,7 @@ const stripeStoreUpdateCheckoutSession = async ({ adjustmentsAmount, cartId, cur
695
692
  adjustmentsAmount,
696
693
  cartId,
697
694
  currency,
695
+ customerAuthenticationToken: cartStore.customerAuthenticationToken || undefined,
698
696
  id,
699
697
  itemsAmount,
700
698
  landedCostId,
@@ -17,7 +17,7 @@ export class ZonosAddress {
17
17
  this.isAutoCompleteAdjusted = false;
18
18
  this.type = undefined;
19
19
  this.titleText = undefined;
20
- this.defaultAddress = null;
20
+ this.defaultAddress = [];
21
21
  this.stripe = window.Zonos.stripe;
22
22
  this.isDirtyAddress = false;
23
23
  }
@@ -53,19 +53,15 @@ export class ZonosAddress {
53
53
  stripeStore.stripeBillingAddressElement = stripeAddressElement;
54
54
  }
55
55
  async watchInitStripe() {
56
- var _a, _b;
57
56
  this.stripe = window.Zonos.stripe;
58
57
  const { stripeAddressEventData, stripeElements } = this.getStripeAddressInstance();
59
58
  if (!this.stripe || !stripeElements) {
60
59
  logError("Stripe is not initialized. Couldn't load stripe element.");
61
60
  return;
62
61
  }
63
- const phone = (_a = this.defaultAddress) === null || _a === void 0 ? void 0 : _a.phone;
64
- if (!phone) {
65
- // remove phone from default address if it's not provided, stripe
66
- // will throw error if key phone exist and its value is empty or 'undefined'.
67
- (_b = this.defaultAddress) === null || _b === void 0 ? true : delete _b.phone;
68
- }
62
+ // remove phone from default address if it's not provided, stripe
63
+ // will throw error if key phone exist and its value is empty or 'undefined'.
64
+ const defaultAddress = this.defaultAddress.map(address => (Object.assign(Object.assign({}, address), { name: address.name, phone: address.phone || undefined })));
69
65
  const shippableCountries = localizationStore.shippingZoneCountries;
70
66
  const shippingZone = shippableCountries
71
67
  ? Object.values(shippableCountries).map(country => country.code)
@@ -79,8 +75,8 @@ export class ZonosAddress {
79
75
  const addressElement = stripeElements.create('address', {
80
76
  allowedCountries: checkoutAllCountries ? [] : allowedCountries,
81
77
  // only show the default address if stripeAddressEventData is not provided
82
- contacts: this.defaultAddress && !stripeAddressEventData
83
- ? [this.defaultAddress]
78
+ contacts: defaultAddress.length && !stripeAddressEventData
79
+ ? this.defaultAddress
84
80
  : [],
85
81
  defaultValues: {
86
82
  address: Object.assign(Object.assign({}, stripeAddressEventData === null || stripeAddressEventData === void 0 ? void 0 : stripeAddressEventData.value.address), { country: defaultAddressCountry }),
@@ -138,12 +134,27 @@ export class ZonosAddress {
138
134
  type: this.type,
139
135
  });
140
136
  }
141
- defaultAddressChanged() {
137
+ defaultAddressChanged(oldAddress, newAddress) {
138
+ // check if stringified json of oldAddress is different from newAddress
139
+ const oldAddressString = JSON.stringify(oldAddress);
140
+ const newAddressString = JSON.stringify(newAddress);
141
+ // No need to reset address element if the default address is the same
142
+ if (oldAddressString === newAddressString) {
143
+ return;
144
+ }
142
145
  log('Reset address element when default address property is changed', 'info', {
143
146
  defaultAddress: this.defaultAddress,
144
147
  });
145
148
  const stripeElement = this.getStripeAddressInstance().stripeAddressElement;
149
+ stripeElement === null || stripeElement === void 0 ? void 0 : stripeElement.clear();
146
150
  stripeElement === null || stripeElement === void 0 ? void 0 : stripeElement.destroy();
151
+ // Reset stripe address event data
152
+ if (this.type === 'shipping') {
153
+ stripeStore.stripeAddressEventData = null;
154
+ }
155
+ else {
156
+ stripeStore.stripeBillingAddressEventData = null;
157
+ }
147
158
  void this.watchInitStripe();
148
159
  }
149
160
  renderCompanyNameInput() {
@@ -177,7 +188,7 @@ export class ZonosAddress {
177
188
  }
178
189
  render() {
179
190
  // this component loads iframe from the stripe elements and puts here, so we don't need to do anything here
180
- return (h(Host, { key: '18d2602886588dfeb39c7c0386354671076dd9bf', class: "zonos--address zonos--elements" }, h("zonos-text", { key: '9c4f704259e307932930995b14a9f2edd51dd3e3', class: "zonos--title", type: "semiBoldLabel" }, this.titleText), this.renderCompanyNameInput(), h("div", { key: '7b2031b0b29cc8153b9b6376f27ccd331cc46e7a', class: "zonos--address-component" })));
191
+ return (h(Host, { key: '455356fe5ca9910fe34df12eb02b499316167bc7', class: "zonos--address zonos--elements" }, h("zonos-text", { key: '44ae4b872ca4aea9e9d8e1cfa0de5e421e4ea524', class: "zonos--title", type: "semiBoldLabel" }, this.titleText), this.renderCompanyNameInput(), h("div", { key: '188976d8eef8c23b41c1b82fc7d5c4d2069fc92b', class: "zonos--address-component" })));
181
192
  }
182
193
  static get is() { return "zonos-address"; }
183
194
  static get encapsulation() { return "scoped"; }
@@ -235,8 +246,8 @@ export class ZonosAddress {
235
246
  "type": "unknown",
236
247
  "mutable": false,
237
248
  "complexType": {
238
- "original": "ContactOption | null",
239
- "resolved": "ContactOption | null",
249
+ "original": "ContactOption[]",
250
+ "resolved": "ContactOption[]",
240
251
  "references": {
241
252
  "ContactOption": {
242
253
  "location": "import",
@@ -253,7 +264,7 @@ export class ZonosAddress {
253
264
  },
254
265
  "getter": false,
255
266
  "setter": false,
256
- "defaultValue": "null"
267
+ "defaultValue": "[]"
257
268
  }
258
269
  };
259
270
  }
@@ -4,6 +4,7 @@ import { cartStore } from "../../store/checkout/cart";
4
4
  import { stripeStore } from "../../store/checkout/stripe";
5
5
  import { translate } from "../../store/translationStore";
6
6
  import { getBorderRadius } from "../../utils/getBorderRadius";
7
+ import { log } from "../../utils/logging/log";
7
8
  import { logError } from "../../utils/logging/logError";
8
9
  import { validateEmailValue } from "../../utils/validateEmailValue";
9
10
  /**
@@ -59,7 +60,7 @@ export class ZonosLinkAuthentication {
59
60
  // Create and mount the Authentication Element in ${type} mode
60
61
  const linkAuthenticationElement = stripeStore.stripeLinkElement ||
61
62
  stripeStore.stripeElements.create('linkAuthentication', {
62
- defaultValues: defaultValues || undefined,
63
+ defaultValues: defaultValues,
63
64
  });
64
65
  const linkAuthenticationElementContainer = this.el.querySelector('.zonos--link-authentication-component');
65
66
  if (!linkAuthenticationElementContainer) {
@@ -74,11 +75,33 @@ export class ZonosLinkAuthentication {
74
75
  });
75
76
  stripeStore.stripeLinkElement = linkAuthenticationElement;
76
77
  }
77
- watchDefaultEmail() {
78
- if (!this.defaultEmail) {
78
+ watchDefaultEmail(newDefaultEmail, oldDefaultEmail) {
79
+ var _a, _b;
80
+ log('Default email is changed', 'info', {
81
+ newDefaultEmail,
82
+ oldDefaultEmail,
83
+ });
84
+ if (oldDefaultEmail === newDefaultEmail) {
79
85
  return;
80
86
  }
81
- this.setCustomEmailInputToLinkEvent(this.defaultEmail);
87
+ if (!newDefaultEmail) {
88
+ stripeStore.stripeLinkEventData = null;
89
+ }
90
+ // Only set value for Stripe input input to stripeLinkEventData when checkout is in staging mode
91
+ if (cartStore.isStagingMode) {
92
+ this.setCustomEmailInputToLinkEvent(newDefaultEmail || '');
93
+ return;
94
+ }
95
+ (_a = stripeStore.stripeLinkElement) === null || _a === void 0 ? void 0 : _a.clear();
96
+ (_b = stripeStore.stripeLinkElement) === null || _b === void 0 ? void 0 : _b.destroy();
97
+ stripeStore.stripeLinkElement = null;
98
+ stripeStore.stripeLinkEventData = null;
99
+ log('Reset stripe link element when default email is changed', 'info', {
100
+ defaultEmail: newDefaultEmail,
101
+ });
102
+ setTimeout(() => {
103
+ void this.watchInitStripe();
104
+ }, 5);
82
105
  }
83
106
  componentDidLoad() {
84
107
  // @Watch doesn't get trigger on initial load
@@ -165,12 +165,15 @@ const handleRequestWithFallback = async ({ basePathType: _basePathType, options,
165
165
  log(`${path} (${duration.toFixed(2)}ms)`, 'info');
166
166
  // No need to send the load time api log for the log-script-load endpoint
167
167
  const internalDuration = response === null || response === void 0 ? void 0 : response.headers.get('Zonos-Duration');
168
- prepLoadTimeApiLog({
169
- apiPath: path,
170
- apiType: basePathType,
171
- loadTimeInternal: internalDuration ? Number(internalDuration) : 0,
172
- loadTimeTotal: duration,
173
- });
168
+ // Only record if the response status is 200, some endpoint will return 200 with error
169
+ if ((response === null || response === void 0 ? void 0 : response.status) === 200) {
170
+ prepLoadTimeApiLog({
171
+ apiPath: path,
172
+ apiType: basePathType,
173
+ loadTimeInternal: internalDuration ? Number(internalDuration) : 0,
174
+ loadTimeTotal: duration,
175
+ });
176
+ }
174
177
  const nextFallbackApiType = getNextFallbackApiType(basePathType);
175
178
  const unknownError = errors.find(({ type }) => type === 'unknown');
176
179
  const isUnknownError = !!unknownError || (response === null || response === void 0 ? void 0 : response.status) === 404;
@@ -10,6 +10,7 @@ export const getAdditionalLogMetadata = () => {
10
10
  connectionEffectiveType: baseConnection === null || baseConnection === void 0 ? void 0 : baseConnection.effectiveType,
11
11
  connectionRtt: baseConnection === null || baseConnection === void 0 ? void 0 : baseConnection.rtt,
12
12
  connectionSaveData: baseConnection === null || baseConnection === void 0 ? void 0 : baseConnection.saveData,
13
+ isHostedCheckout: window.Zonos.isLegacyCheckout,
13
14
  screenHeight: window.screen.height,
14
15
  screenWidth: window.screen.width,
15
16
  userAgent: userAgentData && userAgentData.brands.length > 0
@@ -12,6 +12,8 @@ export const defaultVariable = ({ borderStyle, theme, }) => {
12
12
  default:
13
13
  return {
14
14
  borderRadius: getBorderRadius({ overrideBorderStyle: borderStyle }),
15
+ iconMenuColor: 'var(--colorText)',
16
+ iconMenuHoverColor: 'var(--colorText)',
15
17
  };
16
18
  }
17
19
  };