@economist/web-apple-pay 2.0.0-beta.1 → 2.0.0-beta.3

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 (51) hide show
  1. package/README.md +34 -12
  2. package/dist/index.js +661 -351
  3. package/dist/src/apple-pay-button.d.ts +21 -14
  4. package/dist/src/apple-pay-button.js +650 -343
  5. package/dist/src/apple-pay-button.stories.js +647 -342
  6. package/dist/src/apple-pay-modal.js +44 -39
  7. package/dist/src/apple-pay-modal.stories.js +647 -342
  8. package/dist/src/clients/payment-checkout/apple-session.d.ts +14 -1
  9. package/dist/src/clients/payment-checkout/apple-session.js +46 -11
  10. package/dist/src/clients/payment-checkout/billing-contact-details.js +43 -0
  11. package/dist/src/clients/payment-checkout/delivery-contact-details.d.ts +16 -0
  12. package/dist/src/clients/payment-checkout/delivery-contact-details.js +395 -0
  13. package/dist/src/clients/payment-checkout/detects.d.ts +5 -0
  14. package/dist/src/clients/payment-checkout/detects.js +18 -14
  15. package/dist/src/clients/payment-checkout/messages.d.ts +6 -0
  16. package/dist/src/clients/payment-checkout/messages.js +7 -1
  17. package/dist/src/clients/payment-checkout/payment-handler.d.ts +10 -1
  18. package/dist/src/clients/payment-checkout/payment-handler.js +397 -30
  19. package/dist/src/clients/payment-checkout/session.js +13 -1
  20. package/dist/src/clients/payment-checkout/types.d.ts +7 -0
  21. package/dist/src/constants.d.ts +8 -28
  22. package/dist/src/constants.js +4 -7
  23. package/dist/src/index.d.ts +2 -4
  24. package/dist/src/index.js +661 -351
  25. package/dist/src/types/offer.types.d.ts +1 -1
  26. package/dist/src/utils/address-rules.d.ts +23 -0
  27. package/dist/src/utils/address-rules.js +258 -0
  28. package/dist/src/utils/addressParityFlag.d.ts +13 -0
  29. package/dist/src/utils/addressParityFlag.js +5 -0
  30. package/dist/src/utils/applePayExpressEligibility.d.ts +7 -9
  31. package/dist/src/utils/applePayExpressEligibility.js +2 -2
  32. package/dist/src/utils/buttonCopyFlag.d.ts +22 -0
  33. package/dist/src/utils/buttonCopyFlag.js +12 -0
  34. package/dist/src/utils/delivery-countries.d.ts +9 -0
  35. package/dist/src/utils/delivery-countries.js +255 -0
  36. package/dist/src/utils/expressCheckoutRedirect.d.ts +20 -2
  37. package/dist/src/utils/expressCheckoutRedirect.js +13 -1
  38. package/dist/src/utils/expressCheckoutTracking.d.ts +10 -16
  39. package/dist/src/utils/expressCheckoutTracking.js +5 -29
  40. package/dist/src/utils/latin-characters.d.ts +3 -0
  41. package/dist/src/utils/latin-characters.js +10 -0
  42. package/dist/src/utils/printOffersFlag.d.ts +11 -0
  43. package/dist/src/utils/printOffersFlag.js +5 -0
  44. package/dist/src/utils/recaptcha.d.ts +3 -2
  45. package/dist/src/utils/recaptcha.js +17 -8
  46. package/package.json +1 -1
  47. package/dist/src/apple-pay-logo.d.ts +0 -1
  48. package/dist/src/apple-pay-logo.js +0 -14
  49. package/dist/src/types/experiment-integration.d.js +0 -0
  50. package/dist/src/utils/getExperimentKeyFromNextData.d.ts +0 -8
  51. package/dist/src/utils/getExperimentKeyFromNextData.js +0 -9
@@ -63,18 +63,6 @@ function formatPrice(price, currencyCode, shouldFixDecimalPlaces = true, roundUp
63
63
  }
64
64
  }
65
65
 
66
- // src/apple-pay-logo.ts
67
- var LOGO_DEFS_ID = "apple-pay-logo-defs";
68
- var LOGO_PATH = "M10.2651 4.21143C10.4299 4.21143 10.7106 4.23763 11.1074 4.29004C11.5042 4.34245 11.9385 4.49219 12.4102 4.73926C12.8893 4.97884 13.3236 5.37939 13.7129 5.94092C13.6904 5.96338 13.5819 6.04574 13.3872 6.18799C13.1925 6.32275 12.9754 6.5249 12.7358 6.79443C12.4963 7.05648 12.2866 7.39339 12.1069 7.80518C11.9272 8.20947 11.8374 8.69238 11.8374 9.25391C11.8374 9.89779 11.9497 10.4443 12.1743 10.8936C12.4064 11.3428 12.6722 11.7059 12.9717 11.9829C13.2786 12.2524 13.5482 12.4508 13.7803 12.5781C14.0199 12.7054 14.1471 12.7728 14.1621 12.7803C14.1546 12.8102 14.0573 13.076 13.8701 13.5776C13.6904 14.0793 13.391 14.637 12.9717 15.251C12.6048 15.7826 12.208 16.2729 11.7812 16.7222C11.362 17.1714 10.8566 17.396 10.2651 17.396C9.86833 17.396 9.54264 17.3398 9.28809 17.2275C9.03353 17.1077 8.77148 16.9917 8.50195 16.8794C8.23242 16.7596 7.8693 16.6997 7.4126 16.6997C6.97087 16.6997 6.60026 16.7596 6.30078 16.8794C6.00879 16.9992 5.72803 17.119 5.4585 17.2388C5.19645 17.3586 4.88574 17.4185 4.52637 17.4185C3.97982 17.4185 3.50065 17.2013 3.08887 16.7671C2.67708 16.3328 2.25407 15.8125 1.81982 15.2061C1.3182 14.4873 0.887695 13.6113 0.52832 12.5781C0.176432 11.5374 0.000488281 10.4893 0.000488281 9.43359C0.000488281 8.30306 0.213867 7.35596 0.640625 6.59229C1.06738 5.82113 1.61393 5.24089 2.28027 4.85156C2.9541 4.45475 3.65039 4.25635 4.36914 4.25635C4.75098 4.25635 5.11035 4.31999 5.44727 4.44727C5.78418 4.56706 6.09863 4.69059 6.39062 4.81787C6.6901 4.94515 6.95964 5.00879 7.19922 5.00879C7.43132 5.00879 7.70085 4.94141 8.00781 4.80664C8.31478 4.67188 8.65918 4.54085 9.04102 4.41357C9.42285 4.27881 9.83089 4.21143 10.2651 4.21143ZM9.64746 2.78516C9.35547 3.13704 8.98861 3.43278 8.54688 3.67236C8.10514 3.90446 7.68587 4.02051 7.28906 4.02051C7.20671 4.02051 7.12809 4.01302 7.05322 3.99805C7.04574 3.97559 7.03825 3.93441 7.03076 3.87451C7.02327 3.81462 7.01953 3.75098 7.01953 3.68359C7.01953 3.23438 7.11686 2.80013 7.31152 2.38086C7.50618 1.9541 7.72705 1.60221 7.97412 1.3252C8.28857 0.950846 8.68538 0.640137 9.16455 0.393066C9.64372 0.145996 10.1004 0.014974 10.5347 0C10.5571 0.0973307 10.5684 0.213379 10.5684 0.348145C10.5684 0.797363 10.4823 1.23535 10.3101 1.66211C10.1379 2.08138 9.91699 2.45573 9.64746 2.78516ZM17.6885 11.5112V9.71436H22.0459C23.2064 9.71436 24.1048 9.41488 24.7412 8.81592C25.3776 8.20947 25.6958 7.37467 25.6958 6.31152V6.28906C25.6958 5.21842 25.3776 4.38363 24.7412 3.78467C24.1048 3.18571 23.2064 2.88623 22.0459 2.88623H17.6885V1.08936H22.5625C23.5807 1.08936 24.4792 1.30648 25.2578 1.74072C26.0365 2.17497 26.6466 2.78141 27.0884 3.56006C27.5376 4.3387 27.7622 5.24089 27.7622 6.2666V6.28906C27.7622 7.31478 27.5376 8.2207 27.0884 9.00684C26.6466 9.79297 26.0365 10.4069 25.2578 10.8486C24.4792 11.2904 23.5807 11.5112 22.5625 11.5112H17.6885ZM16.6777 17.2949V1.08936H18.6992V17.2949H16.6777ZM32.6699 17.5195C31.9062 17.5195 31.2249 17.3735 30.626 17.0815C30.0345 16.7896 29.5703 16.3778 29.2334 15.8462C28.904 15.3071 28.7393 14.682 28.7393 13.9707V13.9482C28.7393 13.2594 28.9077 12.668 29.2446 12.1738C29.5815 11.6797 30.0682 11.2904 30.7046 11.0059C31.3485 10.7139 32.1234 10.5417 33.0293 10.4893L37.3979 10.2422V11.7695L33.2539 12.0278C32.4303 12.0728 31.8052 12.2599 31.3784 12.5894C30.9517 12.9188 30.7383 13.3643 30.7383 13.9258V13.9482C30.7383 14.5322 30.9554 14.9927 31.3896 15.3296C31.8239 15.659 32.3929 15.8237 33.0967 15.8237C33.7331 15.8237 34.2983 15.6927 34.7925 15.4307C35.2941 15.1686 35.6909 14.813 35.9829 14.3638C36.2749 13.9071 36.4209 13.3979 36.4209 12.8364V9.27637C36.4209 8.55762 36.1963 7.99609 35.7471 7.5918C35.2979 7.1875 34.6502 6.98535 33.8042 6.98535C33.063 6.98535 32.4603 7.13883 31.9961 7.4458C31.5394 7.74528 31.2474 8.14958 31.1201 8.65869L31.0977 8.7373H29.1885L29.1997 8.625C29.2746 7.98861 29.5067 7.41585 29.896 6.90674C30.2928 6.39762 30.8244 5.99707 31.4907 5.70508C32.1646 5.4056 32.9469 5.25586 33.8379 5.25586C34.7812 5.25586 35.5898 5.41683 36.2637 5.73877C36.945 6.05322 37.4653 6.50244 37.8247 7.08643C38.1916 7.66292 38.375 8.35173 38.375 9.15283V17.2949H36.4209V15.4307H36.3311C36.0915 15.8574 35.7845 16.228 35.4102 16.5425C35.0433 16.8569 34.6278 17.1003 34.1636 17.2725C33.6994 17.4372 33.2015 17.5195 32.6699 17.5195ZM42.1484 21.3267C41.9837 21.3267 41.8115 21.3192 41.6318 21.3042C41.4521 21.2892 41.2987 21.2705 41.1714 21.248V19.6421C41.2612 19.6646 41.366 19.6795 41.4858 19.687C41.6056 19.702 41.7292 19.7095 41.8564 19.7095C42.4554 19.7095 42.9383 19.5897 43.3052 19.3501C43.672 19.1105 43.9678 18.6576 44.1924 17.9912L44.4282 17.3062L40.0371 5.48047H42.126L45.6187 15.981L45.0796 15.2734H45.7759L45.248 15.981L48.7407 5.48047H50.7959L46.1802 18.0249C45.8807 18.826 45.555 19.4661 45.2031 19.9453C44.8512 20.432 44.432 20.7839 43.9453 21.001C43.4587 21.2181 42.8597 21.3267 42.1484 21.3267Z";
69
- function ensureApplePayLogoSymbol() {
70
- if (document.getElementById(LOGO_DEFS_ID)) {
71
- return;
72
- }
73
- const tmp = document.createElement("div");
74
- tmp.innerHTML = `<svg aria-hidden="true" style="display:none" id="${LOGO_DEFS_ID}"><defs><symbol id="apple-pay-logo" viewBox="0 0 51 22"><path d="${LOGO_PATH}" fill="currentColor"/></symbol></defs></svg>`;
75
- document.body.prepend(tmp.firstElementChild);
76
- }
77
-
78
66
  // src/templates/apple-pay-modal.template.html
79
67
  var apple_pay_modal_template_default = `<style>
80
68
  .apm-overlay {
@@ -83,8 +71,10 @@ var apple_pay_modal_template_default = `<style>
83
71
  left: 0;
84
72
  width: 100%;
85
73
  height: 100%;
86
- z-index: 97;
87
- background: rgba(13, 13, 13, 0.7);
74
+ /* Above acquisition DualOfferBanner (1000) and Engagement ribbon (96).
75
+ Was 97 for wall/ribbon hosts only; hosts without a ribbon clamp need this. */
76
+ z-index: 1100;
77
+ background: rgba(13, 13, 13, 0.3);
88
78
  display: flex;
89
79
  align-items: center;
90
80
  justify-content: center;
@@ -95,8 +85,8 @@ var apple_pay_modal_template_default = `<style>
95
85
  .apm {
96
86
  position: relative;
97
87
  background: #fff;
98
- border-radius: 0.5rem 0.5rem 0 0;
99
- border: 0.0625rem solid #d9d9d9;
88
+ border-radius: var(--mb-spacing-xs, 0.5rem);
89
+ border: none;
100
90
  padding: var(--mb-spacing-lg, 1.5rem);
101
91
  width: 25rem;
102
92
  max-width: 25rem;
@@ -159,6 +149,10 @@ var apple_pay_modal_template_default = `<style>
159
149
  margin: 0 0 0.75rem 0;
160
150
  }
161
151
 
152
+ .apm__due-today strong {
153
+ font-weight: var(--mb-font-weight-semibold, 600);
154
+ }
155
+
162
156
  .apm__rule {
163
157
  border: none;
164
158
  border-top: 0.0625rem solid #d9d9d9;
@@ -176,7 +170,7 @@ var apple_pay_modal_template_default = `<style>
176
170
  }
177
171
 
178
172
  .apm__terms-bullets {
179
- list-style: disc outside;
173
+ list-style: square outside;
180
174
  padding-left: 1.25rem;
181
175
  margin: 0 0 0.75rem 0;
182
176
  }
@@ -370,9 +364,18 @@ var apple_pay_modal_template_default = `<style>
370
364
  }
371
365
  }
372
366
 
373
- .apm__cta svg {
374
- flex-shrink: 0;
375
- display: block;
367
+ /* Text wordmark, same as the entry button (Figma Play Global Spec 3268:39728): Apple glyph + "Pay" (510) */
368
+ .apm__cta-logo {
369
+ display: inline-flex;
370
+ align-items: baseline;
371
+ font-size: var(--mb-typestyle-label-3-size, 1.0625rem);
372
+ line-height: normal;
373
+ font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro', system-ui, sans-serif;
374
+ }
375
+
376
+ .apm__cta-logo-word {
377
+ font-weight: 510;
378
+ font-variation-settings: 'wdth' 100;
376
379
  }
377
380
 
378
381
  @media (min-width: 22.5rem) and (max-width: 37.5rem) {
@@ -382,12 +385,6 @@ var apple_pay_modal_template_default = `<style>
382
385
  }
383
386
  }
384
387
 
385
- @media (min-width: 37.5625rem) {
386
- .apm {
387
- border-radius: 0.5rem;
388
- }
389
- }
390
-
391
388
  @media (max-width: 22.4375rem) {
392
389
  .apm {
393
390
  width: 20rem;
@@ -539,15 +536,15 @@ var apple_pay_modal_template_default = `<style>
539
536
  fill="#C91D42"
540
537
  />
541
538
  </svg>
542
- Please accept the terms to continue
539
+ Please accept to continue
543
540
  </div>
544
541
  <button class="apm__cta" id="apple-pay-modal-cta" aria-label="Continue with Apple Pay">
545
542
  <span class="apm__cta-content">
546
543
  <span class="apm__cta-label">
547
544
  Continue with
548
- <svg width="51" height="22" aria-hidden="true" role="img">
549
- <use href="#apple-pay-logo" />
550
- </svg>
545
+ <span class="apm__cta-logo" aria-hidden="true"
546
+ ><span>&#63743;</span><span class="apm__cta-logo-word">Pay</span></span
547
+ >
551
548
  </span>
552
549
  </span>
553
550
  <span class="apm__cta-loading" aria-hidden="true">Loading...</span>
@@ -570,15 +567,21 @@ var resetApplePayConfig = () => {
570
567
  };
571
568
 
572
569
  // src/utils/recaptcha.ts
570
+ var findScriptForKey = (siteKey) => Array.from(
571
+ document.querySelectorAll(
572
+ 'script[src*="recaptcha/api.js"]'
573
+ )
574
+ ).find((script) => script.src.includes(`render=${siteKey}`));
575
+ var pendingLoads = /* @__PURE__ */ new Map();
573
576
  var loadRecaptchaScript = (siteKey) => {
574
- return new Promise((resolve, reject) => {
575
- if (typeof grecaptcha !== "undefined") return resolve();
576
- const existingScript = document.querySelector(
577
- 'script[src*="recaptcha/api.js"]'
578
- );
579
- if (existingScript) {
580
- existingScript.addEventListener("load", () => resolve());
581
- existingScript.addEventListener("error", () => {
577
+ const pending = pendingLoads.get(siteKey);
578
+ if (pending) return pending;
579
+ const ownScript = findScriptForKey(siteKey);
580
+ if (ownScript && typeof grecaptcha !== "undefined") return Promise.resolve();
581
+ const load = new Promise((resolve, reject) => {
582
+ if (ownScript) {
583
+ ownScript.addEventListener("load", () => resolve());
584
+ ownScript.addEventListener("error", () => {
582
585
  reject(new Error("Failed to load existing reCAPTCHA script"));
583
586
  });
584
587
  return;
@@ -593,6 +596,9 @@ var loadRecaptchaScript = (siteKey) => {
593
596
  };
594
597
  document.head.appendChild(script);
595
598
  });
599
+ pendingLoads.set(siteKey, load);
600
+ load.catch(() => pendingLoads.delete(siteKey));
601
+ return load;
596
602
  };
597
603
  var getRecaptchaToken = async (action) => {
598
604
  const siteKey = getApplePayConfig()?.recaptchaSiteKey;
@@ -857,7 +863,6 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
857
863
  if (this.querySelector(".apm-overlay")) {
858
864
  return;
859
865
  }
860
- ensureApplePayLogoSymbol();
861
866
  const template = document.createElement("template");
862
867
  template.innerHTML = apple_pay_modal_template_default;
863
868
  this.appendChild(template.content.cloneNode(true));
@@ -1010,8 +1015,13 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
1010
1015
  // src/templates/apple-pay-button.template.html
1011
1016
  var apple_pay_button_template_default = `<style>
1012
1017
  /*
1013
- * Entry CTA: \u201CSubscribe with\u201D + Apple Pay wordmark (Figma 1118:14088).
1014
- * \u201CSubscribe with\u201D matches Continue to checkout typography (EconomistSans Regular / 17 / 24 / 400).
1018
+ * Entry CTA: caption + Apple Pay wordmark, built from text (no SVG), as in Figma (Play Global Spec 3268:39728):
1019
+ * black #0d0d0d, 4px radius, 40px high, 8px 16px padding, 4px gap.
1020
+ * Marber tokens (as bound in Figma): caption size label-2-size (15px), line height label-3-leading (24px);
1021
+ * glyph + "Pay" 17px (label-3-size) with auto line height; padding spacing-xs / spacing-md; gap + radius spacing-2xs;
1022
+ * background london-5. Expected content widths in Figma: caption 98px, wordmark 42px, button content 176px.
1023
+ * Caption: SF Pro Regular. Wordmark: the Apple glyph (U+F8FF, Regular) + "Pay" (Medium 510).
1024
+ * SF Pro is the system font on Apple devices, which are the only devices Apple Pay is shown on.
1015
1025
  */
1016
1026
  teg-apple-pay-button {
1017
1027
  display: block;
@@ -1036,46 +1046,45 @@ var apple_pay_button_template_default = `<style>
1036
1046
  min-width: 0;
1037
1047
  height: 100%;
1038
1048
  min-height: var(--apple-pay-height, 2.5rem);
1039
- padding: 0;
1049
+ /* Figma button content: 8px 16px */
1050
+ padding: var(--mb-spacing-xs, 0.5rem) var(--mb-spacing-md, 1rem);
1040
1051
  box-sizing: border-box;
1041
- background-color: var(--apple-pay-background-color, #1a1a1a);
1052
+ background-color: var(--apple-pay-background-color, var(--mb-colour-greyscale-london-5, #0d0d0d));
1042
1053
  color: var(--apple-pay-foreground-color, #fff);
1043
1054
  border: none;
1044
- border-radius: var(--apple-pay-border-radius, 0.25rem);
1055
+ border-radius: var(--apple-pay-border-radius, var(--mb-spacing-2xs, 0.25rem));
1045
1056
  cursor: pointer;
1046
- /* Same as wall Continue to checkout / Marber button large */
1047
- font-family: var(
1048
- --mb-typeface-sans,
1049
- var(--wall-type-system-sans, 'EconomistSans', system-ui, sans-serif)
1050
- );
1051
- font-size: var(--mb-button-font-size, 1.0625rem);
1052
- font-weight: var(--mb-font-weight-regular, 400);
1053
- line-height: 1;
1057
+ /* Figma: SF Pro (system font on Apple devices), Regular 15 / 24 */
1058
+ font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro', system-ui, sans-serif;
1059
+ font-size: var(--mb-typestyle-label-2-size, 0.9375rem);
1060
+ font-weight: 400;
1061
+ font-variation-settings: 'wdth' 100;
1062
+ /* Figma letter spacing 0 */
1063
+ letter-spacing: 0;
1064
+ /* Figma caption: line height is the label-3-leading token (24px) */
1065
+ line-height: var(--mb-typestyle-label-3-leading, 1.5rem);
1054
1066
  }
1055
1067
 
1056
1068
  teg-apple-pay-button .apple-pay-btn__label {
1057
1069
  display: inline-flex;
1058
1070
  align-items: center;
1059
- /* No flex gap \u2014 spacing after \u201Cwith\u201D uses the same word-space as \u201CSubscribe with\u201D */
1060
- gap: 0;
1071
+ /* Figma: 4px between the caption and the wordmark */
1072
+ gap: var(--mb-spacing-2xs, 0.25rem);
1061
1073
  white-space: nowrap;
1062
1074
  }
1063
1075
 
1064
- teg-apple-pay-button .apple-pay-btn__caption {
1065
- /* One typographic word space after \u201Cwith\u201D, matching Subscribe\u2194with */
1066
- padding-right: 0.25em;
1076
+ teg-apple-pay-button .apple-pay-btn__logo {
1077
+ display: inline-flex;
1078
+ align-items: baseline;
1079
+ /* Figma "Pay" layer: 17px (label-3 size) with AUTO line height (a 20px box centred in the 24px caption row),
1080
+ not the 24px leading token the caption uses. */
1081
+ font-size: var(--mb-typestyle-label-3-size, 1.0625rem);
1082
+ line-height: normal;
1067
1083
  }
1068
1084
 
1069
- teg-apple-pay-button .apple-pay-btn__logo {
1070
- flex-shrink: 0;
1071
- display: block;
1072
- /* Match caption font-size so mark aligns with text metrics */
1073
- height: 1.05em;
1074
- width: auto;
1075
- aspect-ratio: 51 / 22;
1076
- color: currentColor;
1077
- /* Optical nudge \u2014 SVG viewBox sits slightly high vs EconomistSans caps */
1078
- transform: translateY(0.06em);
1085
+ teg-apple-pay-button .apple-pay-btn__logo-word {
1086
+ font-weight: 510;
1087
+ font-variation-settings: 'wdth' 100;
1079
1088
  }
1080
1089
 
1081
1090
  teg-apple-pay-button .apple-pay-btn.wap-loading {
@@ -1112,6 +1121,7 @@ var apple_pay_button_template_default = `<style>
1112
1121
  transform: translate(-50%, -50%) rotate(360deg);
1113
1122
  }
1114
1123
  }
1124
+
1115
1125
  </style>
1116
1126
 
1117
1127
  <div class="apple-pay-container" aria-label="Subscribe with Apple Pay">
@@ -1123,16 +1133,10 @@ var apple_pay_button_template_default = `<style>
1123
1133
  >
1124
1134
  <span class="apple-pay-btn__label"
1125
1135
  ><span class="apple-pay-btn__caption">Subscribe with</span
1126
- ><svg
1127
- class="apple-pay-btn__logo"
1128
- width="42"
1129
- height="18"
1130
- viewBox="0 0 51 22"
1131
- aria-hidden="true"
1132
- role="img"
1133
- >
1134
- <use href="#apple-pay-logo" />
1135
- </svg
1136
+ ><span class="apple-pay-btn__logo" aria-hidden="true"
1137
+ ><span class="apple-pay-btn__logo-glyph">&#63743;</span
1138
+ ><span class="apple-pay-btn__logo-word">Pay</span
1139
+ ></span
1136
1140
  ></span>
1137
1141
  <span class="apple-pay-btn__loading" aria-hidden="true">Loading...</span>
1138
1142
  </button>
@@ -1146,7 +1150,7 @@ var isAppleDeviceOrSafari = () => {
1146
1150
  return isIOSOrMacTouchDevice || isSafariBrowser;
1147
1151
  };
1148
1152
  var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null;
1149
- var isApplePayAvailable = async () => {
1153
+ var isApplePayCapable = () => {
1150
1154
  if (bypassApplePayChecks()) {
1151
1155
  return true;
1152
1156
  }
@@ -1158,18 +1162,21 @@ var isApplePayAvailable = async () => {
1158
1162
  return false;
1159
1163
  }
1160
1164
  try {
1161
- if (typeof applePaySession.canMakePayments !== "function") {
1162
- return false;
1163
- }
1164
- if (!applePaySession.canMakePayments()) {
1165
- return false;
1166
- }
1167
- const merchantId = getApplePayConfig()?.merchantId;
1168
- if (!merchantId) {
1169
- return false;
1170
- }
1171
- const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
1172
- return hasActiveCard;
1165
+ return typeof applePaySession.canMakePayments === "function" && applePaySession.canMakePayments() && Boolean(getApplePayConfig()?.merchantId);
1166
+ } catch {
1167
+ return false;
1168
+ }
1169
+ };
1170
+ var isApplePayAvailable = async () => {
1171
+ if (bypassApplePayChecks()) {
1172
+ return true;
1173
+ }
1174
+ if (!isApplePayCapable()) {
1175
+ return false;
1176
+ }
1177
+ try {
1178
+ const merchantId = getApplePayConfig().merchantId;
1179
+ return await window.ApplePaySession.canMakePaymentsWithActiveCard(merchantId);
1173
1180
  } catch {
1174
1181
  return false;
1175
1182
  }
@@ -1250,11 +1257,23 @@ var performPurchase = (data) => {
1250
1257
  };
1251
1258
 
1252
1259
  // src/clients/payment-checkout/session.ts
1260
+ var inFlight = null;
1253
1261
  var getExpressCheckoutSession = () => {
1254
- return apiFetch("/v1/wallet/session", {
1262
+ if (inFlight) {
1263
+ return inFlight;
1264
+ }
1265
+ const request = apiFetch("/v1/wallet/session", {
1255
1266
  method: "GET",
1256
1267
  credentials: "include"
1257
1268
  });
1269
+ inFlight = request;
1270
+ const clear = () => {
1271
+ if (inFlight === request) {
1272
+ inFlight = null;
1273
+ }
1274
+ };
1275
+ request.then(clear, clear);
1276
+ return request;
1258
1277
  };
1259
1278
 
1260
1279
  // src/utils/expressCheckoutRedirect.ts
@@ -1269,8 +1288,13 @@ function isAllowedRedirectUrl(url) {
1269
1288
  return false;
1270
1289
  }
1271
1290
  }
1291
+ var CHECKOUT_REDIRECT_BY_POLICY = {
1292
+ ["current_page" /* CURRENT_PAGE */]: (currentPageUrl) => currentPageUrl,
1293
+ ["host_managed" /* HOST_MANAGED */]: () => null
1294
+ };
1295
+ var resolveCheckoutRedirectUrl = (policy, currentPageUrl) => CHECKOUT_REDIRECT_BY_POLICY[policy](currentPageUrl);
1272
1296
  var writeCheckoutRedirect = (originUrl) => {
1273
- if (!isAllowedRedirectUrl(originUrl)) return;
1297
+ if (originUrl === null || !isAllowedRedirectUrl(originUrl)) return;
1274
1298
  try {
1275
1299
  localStorage.setItem(CHECKOUT_REDIRECT_KEY, originUrl);
1276
1300
  } catch {
@@ -1306,13 +1330,6 @@ var redirectToCheckoutFallback = (params) => {
1306
1330
  return url.pathname + url.search;
1307
1331
  };
1308
1332
 
1309
- // src/constants.ts
1310
- var APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY = "apple-pay-express-checkout-on-paywalls";
1311
- var APPLE_PAY_EXPRESS_VARIANTS = {
1312
- CONTROL: "control",
1313
- TREATMENT: "treatment"
1314
- };
1315
-
1316
1333
  // src/utils/expressCheckoutTracking.ts
1317
1334
  var EXPRESS_CHECKOUT_EVENTS = {
1318
1335
  /** Wallet button displayed */
@@ -1350,26 +1367,6 @@ var track = (action, extra) => {
1350
1367
  ...extra
1351
1368
  });
1352
1369
  };
1353
- var trackApplePayExperimentExposure = (variant, experimentKey, flagKey) => {
1354
- const isActiveVariant = variant === APPLE_PAY_EXPRESS_VARIANTS.CONTROL || variant === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
1355
- if (!isActiveVariant) {
1356
- return;
1357
- }
1358
- const exposures = window.__applePayExperimentExposures ?? {};
1359
- window.__applePayExperimentExposures = exposures;
1360
- const pathname = window.location?.pathname ?? "";
1361
- const dedupeKey = `${pathname}:${flagKey}:${variant}`;
1362
- if (exposures[dedupeKey]) {
1363
- return;
1364
- }
1365
- exposures[dedupeKey] = true;
1366
- emitTedlEvent({
1367
- name: "$exposure",
1368
- flag_key: flagKey,
1369
- variant,
1370
- ...experimentKey ? { experiment_key: experimentKey } : {}
1371
- });
1372
- };
1373
1370
  var trackExpressWalletImpression = (skuId, { entryPoint, country }) => {
1374
1371
  track(EXPRESS_CHECKOUT_EVENTS.IMPRESSION, {
1375
1372
  wallet_type: "apple_pay",
@@ -1379,8 +1376,11 @@ var trackExpressWalletImpression = (skuId, { entryPoint, country }) => {
1379
1376
  device: getDevice()
1380
1377
  });
1381
1378
  };
1382
- var trackExpressWalletClick = (skuId) => {
1383
- track(EXPRESS_CHECKOUT_EVENTS.BUTTON_CLICK, { sku_id: skuId });
1379
+ var trackExpressWalletClick = (skuId, { entryPoint } = {}) => {
1380
+ track(EXPRESS_CHECKOUT_EVENTS.BUTTON_CLICK, {
1381
+ sku_id: skuId,
1382
+ ...entryPoint ? { entry_point: entryPoint } : {}
1383
+ });
1384
1384
  };
1385
1385
  var trackWalletPaymentSheetOpen = (skuId) => {
1386
1386
  track(EXPRESS_CHECKOUT_EVENTS.SHEET_OPEN, { sku_id: skuId });
@@ -1411,21 +1411,10 @@ var trackValidationFieldError = (field, errorType) => {
1411
1411
  var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
1412
1412
  var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a valid email address.";
1413
1413
  var MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
1414
+ var MSG_NON_LATIN_CHARACTERS = "Please use Latin characters only.";
1415
+ var msgFieldTooLong = (label, max) => `${label} must be ${max} characters or less`;
1416
+ var MSG_UNSUPPORTED_DELIVERY_COUNTRY = "We can't deliver this print edition to that country. Try a different delivery address.";
1414
1417
  var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
1415
- var BILLING_COUNTRY_MISMATCH_FALLBACK = "Country not supported for this purchase";
1416
- var MSG_BILLING_COUNTRY_MISMATCH_REDIRECT = "This country isn\u2019t supported for this purchase. Try updating your billing address.";
1417
- var buildCountryMismatchMessage = (countryCode) => {
1418
- if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
1419
- try {
1420
- const regionNames = new Intl.DisplayNames(["en"], { type: "region", fallback: "none" });
1421
- const upper = countryCode.toUpperCase();
1422
- const countryName = regionNames.of(upper);
1423
- const isResolved = countryName && countryName !== upper && countryName !== "Unknown Region";
1424
- return isResolved ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
1425
- } catch {
1426
- return BILLING_COUNTRY_MISMATCH_FALLBACK;
1427
- }
1428
- };
1429
1418
  var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
1430
1419
  var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
1431
1420
 
@@ -1463,7 +1452,12 @@ async function handleMerchantValidation(event, session, config) {
1463
1452
  redirectToFallbackCheckout(config);
1464
1453
  }
1465
1454
  }
1455
+ var requiredShippingFields = (config) => [
1456
+ ...config.delivery ? ["postalAddress", "name", "phone"] : [],
1457
+ ...config.userLoggedIn ? [] : ["email"]
1458
+ ];
1466
1459
  function startApplePaySession(config) {
1460
+ const shippingFields = requiredShippingFields(config);
1467
1461
  const paymentRequest = {
1468
1462
  countryCode: config.countryCode,
1469
1463
  currencyCode: config.currencyCode,
@@ -1474,14 +1468,33 @@ function startApplePaySession(config) {
1474
1468
  amount: config.totalAmount
1475
1469
  },
1476
1470
  requiredBillingContactFields: ["postalAddress", "name"],
1477
- // Only request email from Apple Pay sheet if user is NOT logged in
1478
- ...!config.userLoggedIn && { requiredShippingContactFields: ["email"] }
1471
+ ...shippingFields.length > 0 && {
1472
+ requiredShippingContactFields: shippingFields
1473
+ }
1479
1474
  };
1480
1475
  try {
1481
1476
  const session = new ApplePaySession(3, paymentRequest);
1482
1477
  session.onvalidatemerchant = async (event) => {
1483
1478
  await handleMerchantValidation(event, session, config);
1484
1479
  };
1480
+ const delivery = config.delivery;
1481
+ if (delivery) {
1482
+ session.onshippingcontactselected = (event) => {
1483
+ const country = event.shippingContact.countryCode?.toUpperCase();
1484
+ session.completeShippingContactSelection({
1485
+ newTotal: paymentRequest.total,
1486
+ ...country && !delivery.supportedCountries.includes(country) && {
1487
+ errors: [
1488
+ new ApplePayError(
1489
+ "shippingContactInvalid",
1490
+ "countryCode",
1491
+ MSG_UNSUPPORTED_DELIVERY_COUNTRY
1492
+ )
1493
+ ]
1494
+ }
1495
+ });
1496
+ };
1497
+ }
1485
1498
  session.onpaymentauthorized = (event) => {
1486
1499
  trackWalletPaymentAuthorised(config.skuId);
1487
1500
  config.onPaymentAuthorized(event, session).catch(() => {
@@ -1522,6 +1535,16 @@ var ContactValidationError = class extends Error {
1522
1535
  }
1523
1536
  };
1524
1537
 
1538
+ // src/utils/latin-characters.ts
1539
+ var SUPPORTED_DIACRITICS = "\xE0\xE1\xE2\u0101\u0103\u0105\u0227\u01CE\u0201\u0203\xC0\xC1\xC2\u0100\u0102\u0104\u0226\u01CD\u0200\u0202\xE3\xE4\xC3\xC4\xE6\xC6\xE5\xC5\xE8\xE9\xEA\u1EBD\xEB\u0113\u0115\u0119\u0117\u011B\u0205\u0207\xC8\xC9\xCA\u1EBC\xCB\u0112\u0114\u0118\u0116\u011A\u0204\u0206\xEC\xED\xEE\u0129\xEF\u012B\u012D\u012F\u01D0\u0209\u020B\xCC\xCD\xCE\u0128\xCF\u012A\u012C\u012E\u01CF\u0208\u020A\xF2\xF3\xF4\xF5\u014D\u014F\u01EB\u022F\u0151\u01D2\u020D\u020F\xD2\xD3\xD4\xD5\u014C\u014E\u01EA\u022E\u0150\u01D1\u020C\u020E\xF6\xD6\xF8\xD8\u016F\xF9\xFA\xFB\u0169\u016B\u016D\u0173\u0171\u01D4\u0215\u0217\u016E\xD9\xDA\xDB\u0168\u016A\u016C\u0172\u0170\u01D3\u0214\u0216\xFC\xDC\u1EF3\xFD\u0177\u1EF9\xFF\u0233\u1E8F\u1EF2\xDD\u0176\u1EF8\u0178\u0232\u1E8E\xE7\xC7\u0107\u010D\u0106\u010C\xDF\xFE\xDE\xAA\u0159\u0155\u0158\u0154\u0142\u013E\u013A\u013C\u0141\u013D\u0139\u013B\xF1\u0144\u0148\u0146\xD1\u0143\u0147\u0145\u015B\u0161\u015A\u0160\u015F\u0219\u015E\u0218\u017A\u017C\u017E\u0179\u017B\u017D\u010F\xF0\u010E\xD0\u0165\u021B\u0164\u021A\u011F\u0123\u011E\u0122\u0137\u0136\u2019";
1540
+ var LATIN_CHARACTERS_REGEX = new RegExp(
1541
+ `^[\\x20-\\x7E${SUPPORTED_DIACRITICS}]*$`
1542
+ );
1543
+ var isLatinCharacters = (value) => LATIN_CHARACTERS_REGEX.test(value);
1544
+
1545
+ // src/utils/addressParityFlag.ts
1546
+ var ADDRESS_PARITY_ENABLED = true;
1547
+
1525
1548
  // src/clients/payment-checkout/billing-contact-details.ts
1526
1549
  var countriesWithoutCityField = ["KY", "CK", "NR", "TC"];
1527
1550
  var countriesRequiringAllFields = ["US", "CA", "GB"];
@@ -1569,6 +1592,35 @@ var validateCountrySupport = (errors, country, supportedBillingCountries) => {
1569
1592
  );
1570
1593
  }
1571
1594
  };
1595
+ var validateLatinCharacters = (errors, contact, firstName, lastName) => {
1596
+ if (!isLatinCharacters(firstName) || !isLatinCharacters(lastName)) {
1597
+ pushFieldError(
1598
+ errors,
1599
+ "billing",
1600
+ "name",
1601
+ "format",
1602
+ MSG_NON_LATIN_CHARACTERS
1603
+ );
1604
+ }
1605
+ const addressFields = [
1606
+ ["addressLines", contact.addressLines?.at(0)],
1607
+ ["addressLines", contact.addressLines?.at(1)],
1608
+ ["locality", contact.locality],
1609
+ ["administrativeArea", contact.administrativeArea],
1610
+ ["postalCode", contact.postalCode]
1611
+ ];
1612
+ for (const [field, value] of addressFields) {
1613
+ if (value && !isLatinCharacters(value)) {
1614
+ pushFieldError(
1615
+ errors,
1616
+ "billing",
1617
+ field,
1618
+ "format",
1619
+ MSG_NON_LATIN_CHARACTERS
1620
+ );
1621
+ }
1622
+ }
1623
+ };
1572
1624
  var billingContactDetails = (contact, supportedBillingCountries) => {
1573
1625
  const errors = [];
1574
1626
  const country = contact.countryCode?.toUpperCase() || pushRequiredFieldError(errors, "billing", "country");
@@ -1576,6 +1628,9 @@ var billingContactDetails = (contact, supportedBillingCountries) => {
1576
1628
  validateAddressFields(errors, contact, config);
1577
1629
  const { firstName, lastName } = validateNameFields(errors, contact);
1578
1630
  validateCountrySupport(errors, country, supportedBillingCountries);
1631
+ if (ADDRESS_PARITY_ENABLED) {
1632
+ validateLatinCharacters(errors, contact, firstName, lastName);
1633
+ }
1579
1634
  if (errors.length > 0) {
1580
1635
  throw new ContactValidationError(errors);
1581
1636
  }
@@ -1615,123 +1670,6 @@ var shippingContactDetails = (shippingContact) => {
1615
1670
  return { emailAddress };
1616
1671
  };
1617
1672
 
1618
- // src/clients/payment-checkout/payment-handler.ts
1619
- var failApplePaySession = (session, errors = []) => {
1620
- session.completePayment({
1621
- status: ApplePaySession.STATUS_FAILURE,
1622
- errors
1623
- });
1624
- };
1625
- function parseWalletApiError(err) {
1626
- const body = err instanceof ApiError ? err.body : err;
1627
- if (body && typeof body === "object" && "errorType" in body && "message" in body) {
1628
- return body;
1629
- }
1630
- return null;
1631
- }
1632
- function validateContacts(event, sessionData, supportedBillingCountries) {
1633
- billingContactDetails(
1634
- event.payment.billingContact,
1635
- supportedBillingCountries
1636
- );
1637
- if (!sessionData.loggedIn) {
1638
- return shippingContactDetails(event.payment.shippingContact).emailAddress;
1639
- }
1640
- return void 0;
1641
- }
1642
- function redirectFallback(skuId, returnUrl, country, options) {
1643
- writeCheckoutRedirect(returnUrl);
1644
- trackFallbackCheckout(skuId);
1645
- window.location.href = redirectToCheckoutFallback({
1646
- skuId,
1647
- country,
1648
- ...options
1649
- });
1650
- }
1651
- var ERROR_HANDLERS = {
1652
- // emailError flows as an inline field error on the email input.
1653
- // email pre-populates the input so the user doesn't have to retype it.
1654
- EMAIL_COLLISION: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
1655
- emailError: walletError.message,
1656
- email: validatedEmail
1657
- }),
1658
- PAYMENT_DECLINED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1659
- ELIGIBILITY_REJECTED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1660
- REGISTRATION_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1661
- ACCOUNT_CREATION_FAILED: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
1662
- emailError: walletError.message,
1663
- email: validatedEmail
1664
- }),
1665
- VALIDATION_ERROR: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1666
- RECAPTCHA_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message })
1667
- };
1668
- function handleStructuredError(ctx) {
1669
- const handler = ERROR_HANDLERS[ctx.walletError.errorType];
1670
- if (handler) {
1671
- handler(ctx);
1672
- } else {
1673
- redirectFallback(ctx.skuId, ctx.returnUrl, ctx.country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
1674
- }
1675
- }
1676
- async function handlePaymentAuthorized(event, session, sessionData, config) {
1677
- const { skuId, returnUrl, country } = config;
1678
- let validatedEmail;
1679
- try {
1680
- validatedEmail = validateContacts(
1681
- event,
1682
- sessionData,
1683
- config.supportedBillingCountries
1684
- );
1685
- const result = await performPurchase({
1686
- applePayToken: event.payment.token,
1687
- skuId: config.skuId,
1688
- currency: config.currency,
1689
- billingContact: event.payment.billingContact,
1690
- ...event.payment.shippingContact && {
1691
- shippingContact: event.payment.shippingContact
1692
- },
1693
- recaptchaToken: config.recaptchaToken
1694
- });
1695
- trackWalletPaymentSuccess(skuId, result.basketId);
1696
- session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
1697
- const successEmail = sessionData.loggedIn ? sessionData.emailAddress : validatedEmail;
1698
- const userStatus = sessionData.loggedIn ? "lex" : "nex";
1699
- writeCheckoutRedirect(returnUrl);
1700
- window.location.href = redirectToCheckoutComplete({
1701
- basketId: result.basketId,
1702
- status: userStatus,
1703
- skuId: decodeSku(skuId),
1704
- email: successEmail,
1705
- country
1706
- });
1707
- } catch (err) {
1708
- if (err instanceof ContactValidationError) {
1709
- const isBillingCountryMismatch = err.errors.some(
1710
- (e) => e.contactField === "countryCode"
1711
- );
1712
- if (isBillingCountryMismatch) {
1713
- const countryCode = event.payment.billingContact?.countryCode;
1714
- const userMessage = buildCountryMismatchMessage(countryCode);
1715
- failApplePaySession(session, [
1716
- new ApplePayError("billingContactInvalid", "countryCode", userMessage)
1717
- ]);
1718
- redirectFallback(skuId, returnUrl, country, { inlineError: MSG_BILLING_COUNTRY_MISMATCH_REDIRECT });
1719
- } else {
1720
- failApplePaySession(session, err.errors);
1721
- }
1722
- return;
1723
- }
1724
- const walletError = parseWalletApiError(err);
1725
- trackWalletPaymentFailure(skuId, walletError?.errorType ?? "UNKNOWN");
1726
- failApplePaySession(session);
1727
- if (!walletError) {
1728
- redirectFallback(skuId, returnUrl, country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
1729
- return;
1730
- }
1731
- handleStructuredError({ skuId, returnUrl, country, validatedEmail, walletError });
1732
- }
1733
- }
1734
-
1735
1673
  // src/data/price-zones.json
1736
1674
  var price_zones_default = {
1737
1675
  "AS-AS": [
@@ -1937,6 +1875,254 @@ var price_zones_default = {
1937
1875
  "UK-UK": ["GB"]
1938
1876
  };
1939
1877
 
1878
+ // src/utils/address-rules.ts
1879
+ var priceZones = price_zones_default;
1880
+ var ADDRESS_LIMITS = {
1881
+ address1: 35,
1882
+ address2: 35,
1883
+ city: 40,
1884
+ state: 40,
1885
+ postalCode: 20,
1886
+ phone: 35
1887
+ };
1888
+ var zoneOf = (country) => Object.keys(priceZones).find((zone) => priceZones[zone].includes(country));
1889
+ var COUNTRIES_REQUIRING_PHONE = ["IN", "CN"];
1890
+ var requiredDeliveryFields = (offerCountry, country) => {
1891
+ const zone = zoneOf(offerCountry);
1892
+ const fields = ["address1", "city"];
1893
+ if (zone === "AS-AU" || zone === "AS-JP" || zone === "NA-CA" || country === "US") {
1894
+ fields.push("state");
1895
+ }
1896
+ if ((zone !== "AS-HK" || country === "MO") && zone !== "CE-AF" && zone !== "CE-ME") {
1897
+ fields.push("postalCode");
1898
+ }
1899
+ if (COUNTRIES_REQUIRING_PHONE.includes(country)) fields.push("phone");
1900
+ return fields;
1901
+ };
1902
+ var postalCodeFormatError = (offerCountry, postalCode) => {
1903
+ if (!postalCode) return null;
1904
+ const zone = zoneOf(offerCountry);
1905
+ if (zone === "NA-US" && !/(^\d{5}$)|(^\d{5}-\d{4}$)/.test(postalCode)) {
1906
+ return "Zip code must be a valid US zip code";
1907
+ }
1908
+ if (zone === "NA-CA" && !/^[A-Za-z]\d[A-Za-z][ -]?\d[A-Za-z]\d$/.test(postalCode)) {
1909
+ return "Postal code must be a valid Canadian postal code";
1910
+ }
1911
+ return null;
1912
+ };
1913
+ var COUNTRY_CALLING_CODES = {
1914
+ IN: "91",
1915
+ CN: "86"
1916
+ };
1917
+ var normaliseDeliveryPhone = (raw, country) => {
1918
+ const trimmed = raw?.trim() ?? "";
1919
+ const digits = trimmed.replace(/[^0-9]+/g, "");
1920
+ if (!digits) return void 0;
1921
+ if (trimmed.startsWith("+")) return `+${digits}`;
1922
+ const callingCode = COUNTRY_CALLING_CODES[country];
1923
+ return callingCode ? `+${callingCode}${digits.replace(/^0+/, "")}` : void 0;
1924
+ };
1925
+
1926
+ // src/clients/payment-checkout/delivery-contact-details.ts
1927
+ var APPLE_FIELD = {
1928
+ address1: "addressLines",
1929
+ city: "locality",
1930
+ state: "administrativeArea",
1931
+ postalCode: "postalCode",
1932
+ phone: "phoneNumber"
1933
+ };
1934
+ var LABEL = {
1935
+ address1: "Address line 1",
1936
+ address2: "Address line 2",
1937
+ city: "City",
1938
+ state: "State",
1939
+ postalCode: "Postcode",
1940
+ phone: "Phone number"
1941
+ };
1942
+ var deliveryContactDetails = (contact, { offerCountry, supportedDeliveryCountries }) => {
1943
+ const errors = [];
1944
+ const fail = (field, type, message) => pushFieldError(errors, "shipping", field, type, message);
1945
+ const country = contact?.countryCode?.trim().toUpperCase() ?? "";
1946
+ const firstName = contact?.givenName?.trim() ?? "";
1947
+ const lastName = contact?.familyName?.trim() ?? "";
1948
+ const address1 = contact?.addressLines?.at(0)?.trim() ?? "";
1949
+ const address2 = contact?.addressLines?.at(1)?.trim() ?? "";
1950
+ const city = contact?.locality?.trim() ?? "";
1951
+ const state = contact?.administrativeArea?.trim() ?? "";
1952
+ const postalCode = contact?.postalCode?.trim() ?? "";
1953
+ const phone = normaliseDeliveryPhone(contact?.phoneNumber, country) ?? "";
1954
+ if (!country) {
1955
+ pushRequiredFieldError(errors, "shipping", "country");
1956
+ } else if (!supportedDeliveryCountries.includes(country)) {
1957
+ fail("countryCode", "not-supported", MSG_UNSUPPORTED_DELIVERY_COUNTRY);
1958
+ }
1959
+ if (!firstName || !lastName) {
1960
+ pushRequiredFieldError(errors, "shipping", "name");
1961
+ }
1962
+ const values = {
1963
+ address1,
1964
+ city,
1965
+ state,
1966
+ postalCode,
1967
+ phone
1968
+ };
1969
+ for (const field of requiredDeliveryFields(offerCountry, country)) {
1970
+ if (!values[field]) {
1971
+ pushRequiredFieldError(errors, "shipping", APPLE_FIELD[field]);
1972
+ }
1973
+ }
1974
+ const limited = [
1975
+ ["address1", "addressLines", address1, ADDRESS_LIMITS.address1],
1976
+ ["address2", "addressLines", address2, ADDRESS_LIMITS.address2],
1977
+ ["city", "locality", city, ADDRESS_LIMITS.city],
1978
+ ["state", "administrativeArea", state, ADDRESS_LIMITS.state],
1979
+ ["postalCode", "postalCode", postalCode, ADDRESS_LIMITS.postalCode],
1980
+ ["phone", "phoneNumber", phone, ADDRESS_LIMITS.phone]
1981
+ ];
1982
+ for (const [field, appleField, value, max] of limited) {
1983
+ if (value.length > max) {
1984
+ fail(appleField, "format", msgFieldTooLong(LABEL[field], max));
1985
+ }
1986
+ }
1987
+ const formatError = postalCodeFormatError(offerCountry, postalCode);
1988
+ if (formatError) {
1989
+ fail("postalCode", "format", formatError);
1990
+ }
1991
+ const latin = [
1992
+ ["name", firstName],
1993
+ ["name", lastName],
1994
+ ["addressLines", address1],
1995
+ ["addressLines", address2],
1996
+ ["locality", city],
1997
+ ["administrativeArea", state],
1998
+ ["postalCode", postalCode]
1999
+ ];
2000
+ for (const [field, value] of latin) {
2001
+ if (!isLatinCharacters(value)) {
2002
+ fail(field, "format", MSG_NON_LATIN_CHARACTERS);
2003
+ }
2004
+ }
2005
+ if (errors.length > 0) {
2006
+ throw new ContactValidationError(errors);
2007
+ }
2008
+ };
2009
+
2010
+ // src/clients/payment-checkout/payment-handler.ts
2011
+ var failApplePaySession = (session, errors = []) => {
2012
+ session.completePayment({
2013
+ status: ApplePaySession.STATUS_FAILURE,
2014
+ errors
2015
+ });
2016
+ };
2017
+ function parseWalletApiError(err) {
2018
+ const body = err instanceof ApiError ? err.body : err;
2019
+ if (body && typeof body === "object" && "errorType" in body && "message" in body) {
2020
+ return body;
2021
+ }
2022
+ return null;
2023
+ }
2024
+ function validateContacts(event, sessionData, supportedBillingCountries, delivery) {
2025
+ billingContactDetails(
2026
+ event.payment.billingContact,
2027
+ supportedBillingCountries
2028
+ );
2029
+ if (delivery) {
2030
+ deliveryContactDetails(event.payment.shippingContact, {
2031
+ offerCountry: delivery.offerCountry,
2032
+ supportedDeliveryCountries: delivery.supportedCountries
2033
+ });
2034
+ }
2035
+ if (!sessionData.loggedIn) {
2036
+ return shippingContactDetails(event.payment.shippingContact).emailAddress;
2037
+ }
2038
+ return void 0;
2039
+ }
2040
+ function redirectFallback(skuId, returnUrl, country, options) {
2041
+ writeCheckoutRedirect(returnUrl);
2042
+ trackFallbackCheckout(skuId);
2043
+ window.location.href = redirectToCheckoutFallback({
2044
+ skuId,
2045
+ country,
2046
+ ...options
2047
+ });
2048
+ }
2049
+ var ERROR_HANDLERS = {
2050
+ // emailError flows as an inline field error on the email input.
2051
+ // email pre-populates the input so the user doesn't have to retype it.
2052
+ EMAIL_COLLISION: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
2053
+ emailError: walletError.message,
2054
+ email: validatedEmail
2055
+ }),
2056
+ PAYMENT_DECLINED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
2057
+ ELIGIBILITY_REJECTED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
2058
+ REGISTRATION_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
2059
+ ACCOUNT_CREATION_FAILED: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
2060
+ emailError: walletError.message,
2061
+ email: validatedEmail
2062
+ }),
2063
+ VALIDATION_ERROR: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
2064
+ RECAPTCHA_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message })
2065
+ };
2066
+ function handleStructuredError(ctx) {
2067
+ const handler = ERROR_HANDLERS[ctx.walletError.errorType];
2068
+ if (handler) {
2069
+ handler(ctx);
2070
+ } else {
2071
+ redirectFallback(ctx.skuId, ctx.returnUrl, ctx.country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
2072
+ }
2073
+ }
2074
+ async function handlePaymentAuthorized(event, session, sessionData, config) {
2075
+ const { skuId, returnUrl, country } = config;
2076
+ let validatedEmail;
2077
+ try {
2078
+ validatedEmail = validateContacts(
2079
+ event,
2080
+ sessionData,
2081
+ config.supportedBillingCountries,
2082
+ config.delivery
2083
+ );
2084
+ const result = await performPurchase({
2085
+ applePayToken: event.payment.token,
2086
+ skuId: config.skuId,
2087
+ currency: config.currency,
2088
+ billingContact: event.payment.billingContact,
2089
+ ...event.payment.shippingContact && {
2090
+ shippingContact: event.payment.shippingContact
2091
+ },
2092
+ ...config.delivery && {
2093
+ supportedDeliveryCountries: config.delivery.supportedCountries
2094
+ },
2095
+ ...ADDRESS_PARITY_ENABLED ? { strictAddressRules: true } : {},
2096
+ recaptchaToken: config.recaptchaToken
2097
+ });
2098
+ trackWalletPaymentSuccess(skuId, result.basketId);
2099
+ session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
2100
+ const successEmail = sessionData.loggedIn ? sessionData.emailAddress : validatedEmail;
2101
+ const userStatus = sessionData.loggedIn ? "lex" : "nex";
2102
+ writeCheckoutRedirect(returnUrl);
2103
+ window.location.href = redirectToCheckoutComplete({
2104
+ basketId: result.basketId,
2105
+ status: userStatus,
2106
+ skuId: decodeSku(skuId),
2107
+ email: successEmail,
2108
+ country
2109
+ });
2110
+ } catch (err) {
2111
+ if (err instanceof ContactValidationError) {
2112
+ failApplePaySession(session, err.errors);
2113
+ return;
2114
+ }
2115
+ const walletError = parseWalletApiError(err);
2116
+ trackWalletPaymentFailure(skuId, walletError?.errorType ?? "UNKNOWN");
2117
+ failApplePaySession(session);
2118
+ if (!walletError) {
2119
+ redirectFallback(skuId, returnUrl, country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
2120
+ return;
2121
+ }
2122
+ handleStructuredError({ skuId, returnUrl, country, validatedEmail, walletError });
2123
+ }
2124
+ }
2125
+
1940
2126
  // src/data/eea-countries.json
1941
2127
  var eea_countries_default = [
1942
2128
  "AT",
@@ -1974,10 +2160,10 @@ var eea_countries_default = [
1974
2160
  ];
1975
2161
 
1976
2162
  // src/utils/billing-countries.ts
1977
- var priceZones = price_zones_default;
2163
+ var priceZones2 = price_zones_default;
1978
2164
  var eeaCountries = eea_countries_default;
1979
- var ALL_COUNTRY_CODES = Object.values(priceZones).flat();
1980
- var getZoneByCountry = (country) => Object.keys(priceZones).find((key) => priceZones[key].includes(country)) ?? null;
2165
+ var ALL_COUNTRY_CODES = Object.values(priceZones2).flat();
2166
+ var getZoneByCountry = (country) => Object.keys(priceZones2).find((key) => priceZones2[key].includes(country)) ?? null;
1981
2167
  var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1982
2168
  if (offerVariant === "bundle" || offerVariant === "insider_print") {
1983
2169
  return [...ALL_COUNTRY_CODES];
@@ -1986,50 +2172,130 @@ var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1986
2172
  if (!zone) {
1987
2173
  return [...ALL_COUNTRY_CODES];
1988
2174
  }
1989
- const zoneCountries = priceZones[zone];
2175
+ const zoneCountries = priceZones2[zone];
1990
2176
  if (eeaCountries.includes(offerCountry)) {
1991
2177
  return Array.from(/* @__PURE__ */ new Set([...zoneCountries, ...eeaCountries]));
1992
2178
  }
1993
2179
  return [...zoneCountries];
1994
2180
  };
1995
2181
 
1996
- // src/utils/getExperimentKeyFromNextData.ts
1997
- var getExperimentKeyFromNextData = (flagKey) => {
1998
- const experiments = window.__NEXT_DATA__?.props?.pageProps?.experiments;
1999
- const experimentKey = experiments?.[flagKey]?.metadata?.experimentKey;
2000
- return typeof experimentKey === "string" ? experimentKey : void 0;
2182
+ // src/data/no-delivery-countries.json
2183
+ var no_delivery_countries_default = [
2184
+ "KH",
2185
+ "MM",
2186
+ "PK",
2187
+ "BI",
2188
+ "CV",
2189
+ "CF",
2190
+ "TD",
2191
+ "CG",
2192
+ "DJ",
2193
+ "EG",
2194
+ "GM",
2195
+ "GN",
2196
+ "GW",
2197
+ "LB",
2198
+ "LR",
2199
+ "LY",
2200
+ "ML",
2201
+ "MU",
2202
+ "RE",
2203
+ "SL",
2204
+ "AZ",
2205
+ "BY",
2206
+ "UA",
2207
+ "BM",
2208
+ "BO",
2209
+ "KY",
2210
+ "EC",
2211
+ "HN",
2212
+ "PA",
2213
+ "PE",
2214
+ "UY"
2215
+ ];
2216
+
2217
+ // src/utils/delivery-countries.ts
2218
+ var priceZones3 = price_zones_default;
2219
+ var noDeliveryCountries = no_delivery_countries_default;
2220
+ var getSupportedDeliveryCountries = (offerCountry) => {
2221
+ const zone = Object.keys(priceZones3).find(
2222
+ (key) => priceZones3[key].includes(offerCountry)
2223
+ );
2224
+ if (!zone) return [];
2225
+ return priceZones3[zone].filter(
2226
+ (country) => !noDeliveryCountries.includes(country)
2227
+ );
2001
2228
  };
2002
2229
 
2230
+ // src/utils/printOffersFlag.ts
2231
+ var PRINT_OFFERS_ENABLED = true;
2232
+
2233
+ // src/utils/buttonCopyFlag.ts
2234
+ var CONTINUE_WITH_COPY_ENABLED = true;
2235
+ var BUTTON_COPY = {
2236
+ subscribe: { caption: "Subscribe with", label: "Subscribe with Apple Pay" },
2237
+ continue: { caption: "Continue with", label: "Continue with Apple Pay" }
2238
+ };
2239
+ var getButtonCopy = (enabled = CONTINUE_WITH_COPY_ENABLED) => enabled ? BUTTON_COPY.continue : BUTTON_COPY.subscribe;
2240
+
2003
2241
  // src/utils/applePayExpressEligibility.ts
2004
- var isApplePayExpressHomepage = (pathname = window.location.pathname) => pathname === "/";
2005
- var isEligibleForApplePayExpressBanner = () => isApplePayExpressHomepage() && isAppleDeviceOrSafari();
2006
- var isEligibleForApplePayExpressPaywallExperiment = () => isAppleDeviceOrSafari();
2242
+ var isEligibleForApplePayExpressPaywall = () => isAppleDeviceOrSafari();
2007
2243
 
2008
2244
  // src/apple-pay-button.ts
2245
+ var PRINT_VARIANTS = ["bundle", "insider_print"];
2246
+ var NO_EXCLUSIONS = [];
2009
2247
  var ENTRY_POINT_CONFIG = {
2010
2248
  ["dual_offer_banner" /* DUAL_OFFER_BANNER */]: {
2011
- isEligible: isEligibleForApplePayExpressBanner
2012
- // no experimentFlagKey → always-on after eligibility / exclusions
2249
+ isEligible: () => true,
2250
+ returnUrl: "current_page" /* CURRENT_PAGE */,
2251
+ allowsPrintOffers: false
2252
+ },
2253
+ ["free_trial_banner" /* FREE_TRIAL_BANNER */]: {
2254
+ isEligible: () => true,
2255
+ returnUrl: "current_page" /* CURRENT_PAGE */,
2256
+ allowsPrintOffers: false
2013
2257
  },
2014
2258
  ["article_paywall" /* PAYWALL */]: {
2015
- isEligible: isEligibleForApplePayExpressPaywallExperiment,
2016
- experimentFlagKey: APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY
2259
+ isEligible: isEligibleForApplePayExpressPaywall,
2260
+ returnUrl: "current_page" /* CURRENT_PAGE */,
2261
+ allowsPrintOffers: false
2017
2262
  },
2018
2263
  ["article_regwall" /* REGWALL */]: {
2019
2264
  isEligible: () => true,
2020
- enabled: false
2265
+ enabled: false,
2266
+ returnUrl: "current_page" /* CURRENT_PAGE */,
2267
+ allowsPrintOffers: false
2268
+ },
2269
+ ["free_trial_popup" /* FREE_TRIAL_POPUP */]: {
2270
+ isEligible: () => true,
2271
+ returnUrl: "current_page" /* CURRENT_PAGE */,
2272
+ allowsPrintOffers: false
2273
+ },
2274
+ ["subscribe" /* SUBSCRIBE */]: {
2275
+ isEligible: () => true,
2276
+ // Always-on after offer exclusions — host (sma-checkout) owns rollout toggle
2277
+ // The offers page is not a place to return to: the host keeps the article the user arrived from (or home).
2278
+ returnUrl: "host_managed" /* HOST_MANAGED */,
2279
+ allowsPrintOffers: true
2280
+ },
2281
+ ["sales_page" /* SALES_PAGE */]: {
2282
+ isEligible: () => true,
2283
+ // Host-owned page (sma-checkout), like /subscribe: the host keeps the user's return target.
2284
+ returnUrl: "host_managed" /* HOST_MANAGED */,
2285
+ // Print stays off until a sales page needs it; flip to true (and QA) to take print there.
2286
+ allowsPrintOffers: false
2021
2287
  }
2022
2288
  };
2023
- var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
2289
+ var DEFAULT_ENTRY_POINT = "dual_offer_banner" /* DUAL_OFFER_BANNER */;
2024
2290
  var TOTAL_LABEL = "The Economist";
2025
2291
  var DEFAULT_CURRENCY = "USD";
2026
2292
  var DEFAULT_TOTAL = "0.00";
2027
2293
  var SEL_CONTAINER = ".apple-pay-container";
2028
2294
  var SEL_BUTTON = ".apple-pay-btn";
2029
- var APPLE_PAY_EXCLUDED_VARIANTS = [
2030
- "bundle",
2031
- "insider_print"
2032
- ];
2295
+ var getExcludedVariants = (entryPoint) => {
2296
+ const config = ENTRY_POINT_CONFIG[entryPoint || DEFAULT_ENTRY_POINT] ?? ENTRY_POINT_CONFIG[DEFAULT_ENTRY_POINT];
2297
+ return PRINT_OFFERS_ENABLED && config.allowsPrintOffers ? NO_EXCLUSIONS : PRINT_VARIANTS;
2298
+ };
2033
2299
  var ApplePayButton = class _ApplePayButton extends HTMLElement {
2034
2300
  static tag = "teg-apple-pay-button";
2035
2301
  static define() {
@@ -2038,22 +2304,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2038
2304
  /**
2039
2305
  * Creates and configures an ApplePayButton when the entry point allows it.
2040
2306
  *
2041
- * - `DUAL_OFFER_BANNER` (or omitted): always-on after eligibility / exclusions —
2042
- * no banners experiment read and no banners `$exposure`.
2043
- * - `PAYWALL`: experiment-gated via {@link APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY}
2044
- * (`treatment` or QA URL param). The host must set up
2045
- * `window.experimentIntegration` before calling for this entry point.
2307
+ * - `DUAL_OFFER_BANNER` (or omitted): always-on after offer exclusions —
2308
+ * no homepage/Safari gate here. Safari/Apple is enforced later by
2309
+ * `isApplePayAvailable()` on mount.
2310
+ * - `FREE_TRIAL_BANNER`: same always-on-after-exclusions gate as Dual; distinct
2311
+ * TEDL `entry_point` string (`free_trial_banner`) for wallet impression attribution.
2312
+ * - `FREE_TRIAL_POPUP`: same always-on-after-exclusions gate. Distinct TEDL
2313
+ * `entry_point` (`free_trial_popup`).
2314
+ * - `PAYWALL`: always-on after offer exclusions + Safari/Apple placement
2315
+ * eligibility. No Amplitude experiment / `$exposure`.
2046
2316
  * - `REGWALL`: inert — always returns null.
2047
2317
  *
2048
- * **PAYWALL only — transition period:** the legacy
2049
- * `FEATURE_APPLE_PAY_EXPRESS_CHECKOUT` URL param can show the button without
2050
- * treatment (and without inflating `$exposure`). For banners, the same URL
2051
- * param / `BYPASS_APPLE_PAY_CHECKS` only bypass **eligibility**, not an
2052
- * experiment gate.
2053
- *
2054
- * **Eligibility:**
2055
- * - `DUAL_OFFER_BANNER` (or omitted): homepage + Safari/iPhone
2056
- * - `PAYWALL`: Safari/Apple device only (no homepage) — article paywalls
2318
+ * `BYPASS_APPLE_PAY_CHECKS` skips placement eligibility here and device checks
2319
+ * in `isApplePayAvailable()` on mount (QA on non-Apple browsers).
2057
2320
  *
2058
2321
  * @param offer - The offer to display in the Apple Pay flow.
2059
2322
  * @param country - The user's country code.
@@ -2063,46 +2326,22 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2063
2326
  if (!offer) {
2064
2327
  return null;
2065
2328
  }
2066
- if (APPLE_PAY_EXCLUDED_VARIANTS.includes(offer.product?.variant)) {
2067
- return null;
2068
- }
2069
- const hasUrlParamFlag = new URLSearchParams(window.location.search).has(
2070
- FEATURE_APPLE_PAY_EXPRESS_CHECKOUT
2071
- );
2072
- const resolvedEntryPoint = entryPoint || "dual_offer_banner" /* DUAL_OFFER_BANNER */;
2329
+ const resolvedEntryPoint = entryPoint || DEFAULT_ENTRY_POINT;
2073
2330
  const config = ENTRY_POINT_CONFIG[resolvedEntryPoint];
2074
2331
  if (!config) {
2075
2332
  return null;
2076
2333
  }
2077
- const { isEligible: eligibilityCheck, experimentFlagKey } = config;
2334
+ if (getExcludedVariants(resolvedEntryPoint).includes(offer.product?.variant)) {
2335
+ return null;
2336
+ }
2337
+ const { isEligible: eligibilityCheck } = config;
2078
2338
  const isEligible = eligibilityCheck();
2079
2339
  if (config.enabled === false) {
2080
2340
  return null;
2081
2341
  }
2082
- if (!hasUrlParamFlag && !bypassApplePayChecks() && !isEligible) {
2342
+ if (!bypassApplePayChecks() && !isEligible) {
2083
2343
  return null;
2084
2344
  }
2085
- if (experimentFlagKey) {
2086
- const experimentValue = window.experimentIntegration?.getVariant?.(
2087
- experimentFlagKey
2088
- );
2089
- const isExperimentVariant = experimentValue === APPLE_PAY_EXPRESS_VARIANTS.CONTROL || experimentValue === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
2090
- if (isExperimentVariant && isEligible && !bypassApplePayChecks() && !hasUrlParamFlag) {
2091
- void isApplePayAvailable().then((available) => {
2092
- if (available) {
2093
- trackApplePayExperimentExposure(
2094
- experimentValue,
2095
- getExperimentKeyFromNextData(experimentFlagKey),
2096
- experimentFlagKey
2097
- );
2098
- }
2099
- });
2100
- }
2101
- const isTreatment = experimentValue === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
2102
- if (!isTreatment && !hasUrlParamFlag) {
2103
- return null;
2104
- }
2105
- }
2106
2345
  _ApplePayButton.define();
2107
2346
  const button = document.createElement(_ApplePayButton.tag);
2108
2347
  button.offer = offer;
@@ -2128,8 +2367,13 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2128
2367
  #readyPromise = null;
2129
2368
  #sessionData = null;
2130
2369
  #paymentOptions = null;
2370
+ /** URL of the page the button is on (sent to payment options). */
2131
2371
  #returnUrl = "";
2372
+ /** `checkout-redirect` to persist after purchase, per the entry point's `ReturnUrlPolicy`; `null` = leave it. */
2373
+ #checkoutRedirectUrl = null;
2132
2374
  #supportedBillingCountries = [];
2375
+ /** Print (bundle) offers only: countries the offer can be delivered to; `null` for offers without delivery. */
2376
+ #supportedDeliveryCountries = null;
2133
2377
  #entryPoint = "";
2134
2378
  // ─── Public API ─────────────────────────────────────────────────────────────
2135
2379
  get offer() {
@@ -2194,33 +2438,52 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2194
2438
  this.#sessionData = null;
2195
2439
  this.#paymentOptions = null;
2196
2440
  this.#returnUrl = "";
2441
+ this.#checkoutRedirectUrl = null;
2197
2442
  this.#supportedBillingCountries = [];
2443
+ this.#supportedDeliveryCountries = null;
2198
2444
  this.querySelector(SEL_CONTAINER)?.remove();
2199
2445
  }
2200
2446
  // ─── Render pipeline ────────────────────────────────────────────────────────
2201
2447
  async #run() {
2202
2448
  try {
2203
2449
  this.#renderTemplate();
2450
+ this.#captureReturnUrl();
2451
+ const requests = this.#startWalletRequests();
2204
2452
  if (await this.#checkAvailability()) return;
2205
2453
  if (this.#checkOffer()) return;
2206
- if (await this.#checkSession()) return;
2207
- this.#captureReturnUrl();
2208
2454
  this.#computeBillingCountries();
2209
- if (await this.#fetchAndCacheOptions()) return;
2455
+ if (this.#computeDeliveryCountries()) return;
2456
+ const [session, options] = await requests;
2457
+ if (this.#applySession(session)) return;
2458
+ if (this.#applyPaymentOptions(options)) return;
2210
2459
  this.#finishLoading();
2211
2460
  } catch {
2212
- this.style.display = "none";
2213
- this.querySelector(SEL_CONTAINER)?.remove();
2461
+ this.#hide();
2214
2462
  } finally {
2215
2463
  this.#rendering = false;
2216
2464
  }
2217
2465
  }
2466
+ /**
2467
+ * Stop the loading spinner before tear-down so Safari does not leave a GPU
2468
+ * ghost of `.apple-pay-btn.wap-loading::before` after the container is removed.
2469
+ */
2470
+ #hide() {
2471
+ const button = this.querySelector(SEL_BUTTON);
2472
+ if (button) {
2473
+ button.classList.remove("wap-loading");
2474
+ button.removeAttribute("aria-busy");
2475
+ button.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
2476
+ }
2477
+ this.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
2478
+ void this.offsetHeight;
2479
+ this.style.display = "none";
2480
+ this.querySelector(SEL_CONTAINER)?.remove();
2481
+ }
2218
2482
  /** Returns `true` (hide) when Apple Pay is unavailable on this device/browser. */
2219
2483
  async #checkAvailability() {
2220
2484
  const available = await isApplePayAvailable();
2221
2485
  if (!available) {
2222
- this.style.display = "none";
2223
- this.querySelector(SEL_CONTAINER)?.remove();
2486
+ this.#hide();
2224
2487
  return true;
2225
2488
  }
2226
2489
  return false;
@@ -2229,11 +2492,17 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2229
2492
  * Returns `true` (hide) when the user already has an active subscription or is B2B.
2230
2493
  * Session fetch errors are swallowed — the component continues as an anonymous user.
2231
2494
  */
2232
- async #checkSession() {
2233
- this.#sessionData = await this.#fetchSession();
2495
+ /** Starts the session and payment-options calls together (neither depends on the other). */
2496
+ #startWalletRequests() {
2497
+ if (!this.#offer || !isApplePayCapable()) {
2498
+ return Promise.resolve([null, null]);
2499
+ }
2500
+ return Promise.all([this.#fetchSession(), this.#fetchPaymentOptions()]);
2501
+ }
2502
+ #applySession(session) {
2503
+ this.#sessionData = session;
2234
2504
  if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
2235
- this.style.display = "none";
2236
- this.querySelector(SEL_CONTAINER)?.remove();
2505
+ this.#hide();
2237
2506
  return true;
2238
2507
  }
2239
2508
  return false;
@@ -2241,8 +2510,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2241
2510
  /** Returns `true` (hide) when no offer has been set before mount. */
2242
2511
  #checkOffer() {
2243
2512
  if (!this.#offer) {
2244
- this.style.display = "none";
2245
- this.querySelector(SEL_CONTAINER)?.remove();
2513
+ this.#hide();
2246
2514
  return true;
2247
2515
  }
2248
2516
  return false;
@@ -2250,6 +2518,11 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2250
2518
  /** Captures the current page URL once at mount for reuse across the session lifetime. */
2251
2519
  #captureReturnUrl() {
2252
2520
  this.#returnUrl = captureOriginUrl();
2521
+ const config = ENTRY_POINT_CONFIG[this.#entryPoint || DEFAULT_ENTRY_POINT] ?? ENTRY_POINT_CONFIG[DEFAULT_ENTRY_POINT];
2522
+ this.#checkoutRedirectUrl = resolveCheckoutRedirectUrl(
2523
+ config.returnUrl,
2524
+ this.#returnUrl
2525
+ );
2253
2526
  }
2254
2527
  /**
2255
2528
  * Computes supported billing countries once at mount.
@@ -2262,15 +2535,32 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2262
2535
  this.#offer.product?.variant ?? ""
2263
2536
  );
2264
2537
  }
2538
+ /**
2539
+ * Print (bundle) offers need a delivery address, which the Apple Pay sheet collects. Returns `true` (hide)
2540
+ * when the offer has no country it can be delivered to, because no valid address could ever be entered.
2541
+ */
2542
+ #computeDeliveryCountries() {
2543
+ const variant = this.#offer.product?.variant;
2544
+ if (!PRINT_VARIANTS.includes(variant)) {
2545
+ this.#supportedDeliveryCountries = null;
2546
+ return false;
2547
+ }
2548
+ const countries = getSupportedDeliveryCountries(this.#country);
2549
+ if (countries.length === 0) {
2550
+ this.#hide();
2551
+ return true;
2552
+ }
2553
+ this.#supportedDeliveryCountries = countries;
2554
+ return false;
2555
+ }
2265
2556
  /**
2266
2557
  * Returns `true` (hide) when the wallet BFF reports Apple Pay is unavailable
2267
2558
  * for this offer. The response is cached and reused in `#initiateApplePay`.
2268
2559
  */
2269
- async #fetchAndCacheOptions() {
2270
- this.#paymentOptions = await this.#fetchPaymentOptions();
2560
+ #applyPaymentOptions(options) {
2561
+ this.#paymentOptions = options;
2271
2562
  if (!this.#paymentOptions?.options?.apple_pay) {
2272
- this.style.display = "none";
2273
- this.querySelector(SEL_CONTAINER)?.remove();
2563
+ this.#hide();
2274
2564
  return true;
2275
2565
  }
2276
2566
  return false;
@@ -2278,11 +2568,14 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2278
2568
  /** Injects the button template and wires click and confirm event listeners. */
2279
2569
  #renderTemplate() {
2280
2570
  this.style.removeProperty("display");
2281
- ensureApplePayLogoSymbol();
2282
2571
  const template = document.createElement("template");
2283
2572
  template.innerHTML = apple_pay_button_template_default;
2284
2573
  this.appendChild(template.content.cloneNode(true));
2285
2574
  const button = this.querySelector(SEL_BUTTON);
2575
+ const { caption, label } = getButtonCopy();
2576
+ this.querySelector(SEL_CONTAINER)?.setAttribute("aria-label", label);
2577
+ button.setAttribute("aria-label", label);
2578
+ this.querySelector(".apple-pay-btn__caption").textContent = caption;
2286
2579
  button.classList.add("wap-loading");
2287
2580
  button.setAttribute("disabled", "");
2288
2581
  button.setAttribute("aria-disabled", "true");
@@ -2323,7 +2616,10 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2323
2616
  if (document.querySelector(ApplePayModal.tag)) {
2324
2617
  return;
2325
2618
  }
2326
- trackExpressWalletClick(this.#offer.sku_id);
2619
+ trackExpressWalletClick(
2620
+ this.#offer.sku_id,
2621
+ this.#entryPoint ? { entryPoint: this.#entryPoint } : void 0
2622
+ );
2327
2623
  ApplePayModal.define();
2328
2624
  const modal = document.createElement(ApplePayModal.tag);
2329
2625
  modal.offer = this.#offer;
@@ -2367,16 +2663,25 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2367
2663
  totalAmount,
2368
2664
  totalLabel: TOTAL_LABEL,
2369
2665
  skuId,
2370
- returnUrl: this.#returnUrl,
2666
+ returnUrl: this.#checkoutRedirectUrl,
2371
2667
  userLoggedIn: sessionData.loggedIn,
2668
+ ...this.#supportedDeliveryCountries && {
2669
+ delivery: { supportedCountries: this.#supportedDeliveryCountries }
2670
+ },
2372
2671
  onPaymentAuthorized: async (event, session) => {
2373
2672
  const recaptchaToken = await recaptchaTokenPromise;
2374
2673
  return handlePaymentAuthorized(event, session, sessionData, {
2375
2674
  skuId,
2376
2675
  country,
2377
2676
  currency: offer.price?.currency_code ?? DEFAULT_CURRENCY,
2378
- returnUrl: this.#returnUrl,
2677
+ returnUrl: this.#checkoutRedirectUrl,
2379
2678
  supportedBillingCountries: this.#supportedBillingCountries,
2679
+ ...this.#supportedDeliveryCountries && {
2680
+ delivery: {
2681
+ offerCountry: country,
2682
+ supportedCountries: this.#supportedDeliveryCountries
2683
+ }
2684
+ },
2380
2685
  recaptchaToken
2381
2686
  });
2382
2687
  }
@@ -2400,7 +2705,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2400
2705
  );
2401
2706
  } catch {
2402
2707
  redirectToFallbackCheckout({
2403
- returnUrl: this.#returnUrl,
2708
+ returnUrl: this.#checkoutRedirectUrl,
2404
2709
  skuId,
2405
2710
  countryCode: country
2406
2711
  });