@economist/web-apple-pay 2.0.0-beta.2 → 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 +26 -8
  2. package/dist/index.js +647 -349
  3. package/dist/src/apple-pay-button.d.ts +18 -16
  4. package/dist/src/apple-pay-button.js +636 -340
  5. package/dist/src/apple-pay-button.stories.js +633 -339
  6. package/dist/src/apple-pay-modal.js +44 -39
  7. package/dist/src/apple-pay-modal.stories.js +633 -339
  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 +7 -28
  22. package/dist/src/constants.js +3 -7
  23. package/dist/src/index.d.ts +2 -4
  24. package/dist/src/index.js +647 -349
  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 +5 -6
  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 +0 -15
  39. package/dist/src/utils/expressCheckoutTracking.js +0 -27
  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",
@@ -1414,21 +1411,10 @@ var trackValidationFieldError = (field, errorType) => {
1414
1411
  var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
1415
1412
  var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a valid email address.";
1416
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.";
1417
1417
  var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
1418
- var BILLING_COUNTRY_MISMATCH_FALLBACK = "Country not supported for this purchase";
1419
- var MSG_BILLING_COUNTRY_MISMATCH_REDIRECT = "This country isn\u2019t supported for this purchase. Try updating your billing address.";
1420
- var buildCountryMismatchMessage = (countryCode) => {
1421
- if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
1422
- try {
1423
- const regionNames = new Intl.DisplayNames(["en"], { type: "region", fallback: "none" });
1424
- const upper = countryCode.toUpperCase();
1425
- const countryName = regionNames.of(upper);
1426
- const isResolved = countryName && countryName !== upper && countryName !== "Unknown Region";
1427
- return isResolved ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
1428
- } catch {
1429
- return BILLING_COUNTRY_MISMATCH_FALLBACK;
1430
- }
1431
- };
1432
1418
  var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
1433
1419
  var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
1434
1420
 
@@ -1466,7 +1452,12 @@ async function handleMerchantValidation(event, session, config) {
1466
1452
  redirectToFallbackCheckout(config);
1467
1453
  }
1468
1454
  }
1455
+ var requiredShippingFields = (config) => [
1456
+ ...config.delivery ? ["postalAddress", "name", "phone"] : [],
1457
+ ...config.userLoggedIn ? [] : ["email"]
1458
+ ];
1469
1459
  function startApplePaySession(config) {
1460
+ const shippingFields = requiredShippingFields(config);
1470
1461
  const paymentRequest = {
1471
1462
  countryCode: config.countryCode,
1472
1463
  currencyCode: config.currencyCode,
@@ -1477,14 +1468,33 @@ function startApplePaySession(config) {
1477
1468
  amount: config.totalAmount
1478
1469
  },
1479
1470
  requiredBillingContactFields: ["postalAddress", "name"],
1480
- // Only request email from Apple Pay sheet if user is NOT logged in
1481
- ...!config.userLoggedIn && { requiredShippingContactFields: ["email"] }
1471
+ ...shippingFields.length > 0 && {
1472
+ requiredShippingContactFields: shippingFields
1473
+ }
1482
1474
  };
1483
1475
  try {
1484
1476
  const session = new ApplePaySession(3, paymentRequest);
1485
1477
  session.onvalidatemerchant = async (event) => {
1486
1478
  await handleMerchantValidation(event, session, config);
1487
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
+ }
1488
1498
  session.onpaymentauthorized = (event) => {
1489
1499
  trackWalletPaymentAuthorised(config.skuId);
1490
1500
  config.onPaymentAuthorized(event, session).catch(() => {
@@ -1525,6 +1535,16 @@ var ContactValidationError = class extends Error {
1525
1535
  }
1526
1536
  };
1527
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
+
1528
1548
  // src/clients/payment-checkout/billing-contact-details.ts
1529
1549
  var countriesWithoutCityField = ["KY", "CK", "NR", "TC"];
1530
1550
  var countriesRequiringAllFields = ["US", "CA", "GB"];
@@ -1572,6 +1592,35 @@ var validateCountrySupport = (errors, country, supportedBillingCountries) => {
1572
1592
  );
1573
1593
  }
1574
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
+ };
1575
1624
  var billingContactDetails = (contact, supportedBillingCountries) => {
1576
1625
  const errors = [];
1577
1626
  const country = contact.countryCode?.toUpperCase() || pushRequiredFieldError(errors, "billing", "country");
@@ -1579,6 +1628,9 @@ var billingContactDetails = (contact, supportedBillingCountries) => {
1579
1628
  validateAddressFields(errors, contact, config);
1580
1629
  const { firstName, lastName } = validateNameFields(errors, contact);
1581
1630
  validateCountrySupport(errors, country, supportedBillingCountries);
1631
+ if (ADDRESS_PARITY_ENABLED) {
1632
+ validateLatinCharacters(errors, contact, firstName, lastName);
1633
+ }
1582
1634
  if (errors.length > 0) {
1583
1635
  throw new ContactValidationError(errors);
1584
1636
  }
@@ -1618,123 +1670,6 @@ var shippingContactDetails = (shippingContact) => {
1618
1670
  return { emailAddress };
1619
1671
  };
1620
1672
 
1621
- // src/clients/payment-checkout/payment-handler.ts
1622
- var failApplePaySession = (session, errors = []) => {
1623
- session.completePayment({
1624
- status: ApplePaySession.STATUS_FAILURE,
1625
- errors
1626
- });
1627
- };
1628
- function parseWalletApiError(err) {
1629
- const body = err instanceof ApiError ? err.body : err;
1630
- if (body && typeof body === "object" && "errorType" in body && "message" in body) {
1631
- return body;
1632
- }
1633
- return null;
1634
- }
1635
- function validateContacts(event, sessionData, supportedBillingCountries) {
1636
- billingContactDetails(
1637
- event.payment.billingContact,
1638
- supportedBillingCountries
1639
- );
1640
- if (!sessionData.loggedIn) {
1641
- return shippingContactDetails(event.payment.shippingContact).emailAddress;
1642
- }
1643
- return void 0;
1644
- }
1645
- function redirectFallback(skuId, returnUrl, country, options) {
1646
- writeCheckoutRedirect(returnUrl);
1647
- trackFallbackCheckout(skuId);
1648
- window.location.href = redirectToCheckoutFallback({
1649
- skuId,
1650
- country,
1651
- ...options
1652
- });
1653
- }
1654
- var ERROR_HANDLERS = {
1655
- // emailError flows as an inline field error on the email input.
1656
- // email pre-populates the input so the user doesn't have to retype it.
1657
- EMAIL_COLLISION: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
1658
- emailError: walletError.message,
1659
- email: validatedEmail
1660
- }),
1661
- PAYMENT_DECLINED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1662
- ELIGIBILITY_REJECTED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1663
- REGISTRATION_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1664
- ACCOUNT_CREATION_FAILED: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
1665
- emailError: walletError.message,
1666
- email: validatedEmail
1667
- }),
1668
- VALIDATION_ERROR: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1669
- RECAPTCHA_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message })
1670
- };
1671
- function handleStructuredError(ctx) {
1672
- const handler = ERROR_HANDLERS[ctx.walletError.errorType];
1673
- if (handler) {
1674
- handler(ctx);
1675
- } else {
1676
- redirectFallback(ctx.skuId, ctx.returnUrl, ctx.country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
1677
- }
1678
- }
1679
- async function handlePaymentAuthorized(event, session, sessionData, config) {
1680
- const { skuId, returnUrl, country } = config;
1681
- let validatedEmail;
1682
- try {
1683
- validatedEmail = validateContacts(
1684
- event,
1685
- sessionData,
1686
- config.supportedBillingCountries
1687
- );
1688
- const result = await performPurchase({
1689
- applePayToken: event.payment.token,
1690
- skuId: config.skuId,
1691
- currency: config.currency,
1692
- billingContact: event.payment.billingContact,
1693
- ...event.payment.shippingContact && {
1694
- shippingContact: event.payment.shippingContact
1695
- },
1696
- recaptchaToken: config.recaptchaToken
1697
- });
1698
- trackWalletPaymentSuccess(skuId, result.basketId);
1699
- session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
1700
- const successEmail = sessionData.loggedIn ? sessionData.emailAddress : validatedEmail;
1701
- const userStatus = sessionData.loggedIn ? "lex" : "nex";
1702
- writeCheckoutRedirect(returnUrl);
1703
- window.location.href = redirectToCheckoutComplete({
1704
- basketId: result.basketId,
1705
- status: userStatus,
1706
- skuId: decodeSku(skuId),
1707
- email: successEmail,
1708
- country
1709
- });
1710
- } catch (err) {
1711
- if (err instanceof ContactValidationError) {
1712
- const isBillingCountryMismatch = err.errors.some(
1713
- (e) => e.contactField === "countryCode"
1714
- );
1715
- if (isBillingCountryMismatch) {
1716
- const countryCode = event.payment.billingContact?.countryCode;
1717
- const userMessage = buildCountryMismatchMessage(countryCode);
1718
- failApplePaySession(session, [
1719
- new ApplePayError("billingContactInvalid", "countryCode", userMessage)
1720
- ]);
1721
- redirectFallback(skuId, returnUrl, country, { inlineError: MSG_BILLING_COUNTRY_MISMATCH_REDIRECT });
1722
- } else {
1723
- failApplePaySession(session, err.errors);
1724
- }
1725
- return;
1726
- }
1727
- const walletError = parseWalletApiError(err);
1728
- trackWalletPaymentFailure(skuId, walletError?.errorType ?? "UNKNOWN");
1729
- failApplePaySession(session);
1730
- if (!walletError) {
1731
- redirectFallback(skuId, returnUrl, country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
1732
- return;
1733
- }
1734
- handleStructuredError({ skuId, returnUrl, country, validatedEmail, walletError });
1735
- }
1736
- }
1737
-
1738
1673
  // src/data/price-zones.json
1739
1674
  var price_zones_default = {
1740
1675
  "AS-AS": [
@@ -1940,6 +1875,254 @@ var price_zones_default = {
1940
1875
  "UK-UK": ["GB"]
1941
1876
  };
1942
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
+
1943
2126
  // src/data/eea-countries.json
1944
2127
  var eea_countries_default = [
1945
2128
  "AT",
@@ -1977,10 +2160,10 @@ var eea_countries_default = [
1977
2160
  ];
1978
2161
 
1979
2162
  // src/utils/billing-countries.ts
1980
- var priceZones = price_zones_default;
2163
+ var priceZones2 = price_zones_default;
1981
2164
  var eeaCountries = eea_countries_default;
1982
- var ALL_COUNTRY_CODES = Object.values(priceZones).flat();
1983
- 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;
1984
2167
  var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1985
2168
  if (offerVariant === "bundle" || offerVariant === "insider_print") {
1986
2169
  return [...ALL_COUNTRY_CODES];
@@ -1989,52 +2172,130 @@ var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1989
2172
  if (!zone) {
1990
2173
  return [...ALL_COUNTRY_CODES];
1991
2174
  }
1992
- const zoneCountries = priceZones[zone];
2175
+ const zoneCountries = priceZones2[zone];
1993
2176
  if (eeaCountries.includes(offerCountry)) {
1994
2177
  return Array.from(/* @__PURE__ */ new Set([...zoneCountries, ...eeaCountries]));
1995
2178
  }
1996
2179
  return [...zoneCountries];
1997
2180
  };
1998
2181
 
1999
- // src/utils/getExperimentKeyFromNextData.ts
2000
- var getExperimentKeyFromNextData = (flagKey) => {
2001
- const experiments = window.__NEXT_DATA__?.props?.pageProps?.experiments;
2002
- const experimentKey = experiments?.[flagKey]?.metadata?.experimentKey;
2003
- 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
+ );
2228
+ };
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" }
2004
2238
  };
2239
+ var getButtonCopy = (enabled = CONTINUE_WITH_COPY_ENABLED) => enabled ? BUTTON_COPY.continue : BUTTON_COPY.subscribe;
2005
2240
 
2006
2241
  // src/utils/applePayExpressEligibility.ts
2007
- var isEligibleForApplePayExpressPaywallExperiment = () => isAppleDeviceOrSafari();
2242
+ var isEligibleForApplePayExpressPaywall = () => isAppleDeviceOrSafari();
2008
2243
 
2009
2244
  // src/apple-pay-button.ts
2245
+ var PRINT_VARIANTS = ["bundle", "insider_print"];
2246
+ var NO_EXCLUSIONS = [];
2010
2247
  var ENTRY_POINT_CONFIG = {
2011
2248
  ["dual_offer_banner" /* DUAL_OFFER_BANNER */]: {
2012
- isEligible: () => true
2013
- // no experimentFlagKey → always-on after offer exclusions
2249
+ isEligible: () => true,
2250
+ returnUrl: "current_page" /* CURRENT_PAGE */,
2251
+ allowsPrintOffers: false
2014
2252
  },
2015
2253
  ["free_trial_banner" /* FREE_TRIAL_BANNER */]: {
2016
- isEligible: () => true
2017
- // Dual parity — no experimentFlagKey, no homepage gate here
2254
+ isEligible: () => true,
2255
+ returnUrl: "current_page" /* CURRENT_PAGE */,
2256
+ allowsPrintOffers: false
2018
2257
  },
2019
2258
  ["article_paywall" /* PAYWALL */]: {
2020
- isEligible: isEligibleForApplePayExpressPaywallExperiment,
2021
- experimentFlagKey: APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY
2259
+ isEligible: isEligibleForApplePayExpressPaywall,
2260
+ returnUrl: "current_page" /* CURRENT_PAGE */,
2261
+ allowsPrintOffers: false
2022
2262
  },
2023
2263
  ["article_regwall" /* REGWALL */]: {
2024
2264
  isEligible: () => true,
2025
- 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
2026
2287
  }
2027
2288
  };
2028
- var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
2289
+ var DEFAULT_ENTRY_POINT = "dual_offer_banner" /* DUAL_OFFER_BANNER */;
2029
2290
  var TOTAL_LABEL = "The Economist";
2030
2291
  var DEFAULT_CURRENCY = "USD";
2031
2292
  var DEFAULT_TOTAL = "0.00";
2032
2293
  var SEL_CONTAINER = ".apple-pay-container";
2033
2294
  var SEL_BUTTON = ".apple-pay-btn";
2034
- var APPLE_PAY_EXCLUDED_VARIANTS = [
2035
- "bundle",
2036
- "insider_print"
2037
- ];
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
+ };
2038
2299
  var ApplePayButton = class _ApplePayButton extends HTMLElement {
2039
2300
  static tag = "teg-apple-pay-button";
2040
2301
  static define() {
@@ -2044,26 +2305,18 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2044
2305
  * Creates and configures an ApplePayButton when the entry point allows it.
2045
2306
  *
2046
2307
  * - `DUAL_OFFER_BANNER` (or omitted): always-on after offer exclusions —
2047
- * no homepage/Safari gate here, no banners experiment read, and no banners
2048
- * `$exposure`.
2308
+ * no homepage/Safari gate here. Safari/Apple is enforced later by
2309
+ * `isApplePayAvailable()` on mount.
2049
2310
  * - `FREE_TRIAL_BANNER`: same always-on-after-exclusions gate as Dual; distinct
2050
2311
  * TEDL `entry_point` string (`free_trial_banner`) for wallet impression attribution.
2051
- * - `PAYWALL`: experiment-gated via {@link APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY}
2052
- * (`treatment` or QA URL param). The host must set up
2053
- * `window.experimentIntegration` before calling for this entry point.
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`.
2054
2316
  * - `REGWALL`: inert — always returns null.
2055
2317
  *
2056
- * **PAYWALL only — transition period:** the legacy
2057
- * `FEATURE_APPLE_PAY_EXPRESS_CHECKOUT` URL param can show the button without
2058
- * treatment (and without inflating `$exposure`). For banners there is no
2059
- * experiment gate; `BYPASS_APPLE_PAY_CHECKS` only skips device checks in
2060
- * `isApplePayAvailable()` on mount.
2061
- *
2062
- * **Eligibility:**
2063
- * - `DUAL_OFFER_BANNER` / `FREE_TRIAL_BANNER` (or omitted): always eligible at
2064
- * this gate (homepage placement is host-owned; Safari/Apple is enforced
2065
- * later by `isApplePayAvailable()` on mount)
2066
- * - `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).
2067
2320
  *
2068
2321
  * @param offer - The offer to display in the Apple Pay flow.
2069
2322
  * @param country - The user's country code.
@@ -2073,44 +2326,22 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2073
2326
  if (!offer) {
2074
2327
  return null;
2075
2328
  }
2076
- if (APPLE_PAY_EXCLUDED_VARIANTS.includes(offer.product?.variant)) {
2077
- return null;
2078
- }
2079
- const hasUrlParamFlag = new URLSearchParams(window.location.search).has(
2080
- FEATURE_APPLE_PAY_EXPRESS_CHECKOUT
2081
- );
2082
- const resolvedEntryPoint = entryPoint || "dual_offer_banner" /* DUAL_OFFER_BANNER */;
2329
+ const resolvedEntryPoint = entryPoint || DEFAULT_ENTRY_POINT;
2083
2330
  const config = ENTRY_POINT_CONFIG[resolvedEntryPoint];
2084
2331
  if (!config) {
2085
2332
  return null;
2086
2333
  }
2087
- const { isEligible: eligibilityCheck, experimentFlagKey } = config;
2334
+ if (getExcludedVariants(resolvedEntryPoint).includes(offer.product?.variant)) {
2335
+ return null;
2336
+ }
2337
+ const { isEligible: eligibilityCheck } = config;
2088
2338
  const isEligible = eligibilityCheck();
2089
2339
  if (config.enabled === false) {
2090
2340
  return null;
2091
2341
  }
2092
- if (!hasUrlParamFlag && !bypassApplePayChecks() && !isEligible) {
2342
+ if (!bypassApplePayChecks() && !isEligible) {
2093
2343
  return null;
2094
2344
  }
2095
- if (experimentFlagKey) {
2096
- const experimentValue = window.experimentIntegration?.getVariant?.(experimentFlagKey);
2097
- const isExperimentVariant = experimentValue === APPLE_PAY_EXPRESS_VARIANTS.CONTROL || experimentValue === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
2098
- if (isExperimentVariant && isEligible && !bypassApplePayChecks() && !hasUrlParamFlag) {
2099
- void isApplePayAvailable().then((available) => {
2100
- if (available) {
2101
- trackApplePayExperimentExposure(
2102
- experimentValue,
2103
- getExperimentKeyFromNextData(experimentFlagKey),
2104
- experimentFlagKey
2105
- );
2106
- }
2107
- });
2108
- }
2109
- const isTreatment = experimentValue === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
2110
- if (!isTreatment && !hasUrlParamFlag) {
2111
- return null;
2112
- }
2113
- }
2114
2345
  _ApplePayButton.define();
2115
2346
  const button = document.createElement(_ApplePayButton.tag);
2116
2347
  button.offer = offer;
@@ -2136,8 +2367,13 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2136
2367
  #readyPromise = null;
2137
2368
  #sessionData = null;
2138
2369
  #paymentOptions = null;
2370
+ /** URL of the page the button is on (sent to payment options). */
2139
2371
  #returnUrl = "";
2372
+ /** `checkout-redirect` to persist after purchase, per the entry point's `ReturnUrlPolicy`; `null` = leave it. */
2373
+ #checkoutRedirectUrl = null;
2140
2374
  #supportedBillingCountries = [];
2375
+ /** Print (bundle) offers only: countries the offer can be delivered to; `null` for offers without delivery. */
2376
+ #supportedDeliveryCountries = null;
2141
2377
  #entryPoint = "";
2142
2378
  // ─── Public API ─────────────────────────────────────────────────────────────
2143
2379
  get offer() {
@@ -2202,33 +2438,52 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2202
2438
  this.#sessionData = null;
2203
2439
  this.#paymentOptions = null;
2204
2440
  this.#returnUrl = "";
2441
+ this.#checkoutRedirectUrl = null;
2205
2442
  this.#supportedBillingCountries = [];
2443
+ this.#supportedDeliveryCountries = null;
2206
2444
  this.querySelector(SEL_CONTAINER)?.remove();
2207
2445
  }
2208
2446
  // ─── Render pipeline ────────────────────────────────────────────────────────
2209
2447
  async #run() {
2210
2448
  try {
2211
2449
  this.#renderTemplate();
2450
+ this.#captureReturnUrl();
2451
+ const requests = this.#startWalletRequests();
2212
2452
  if (await this.#checkAvailability()) return;
2213
2453
  if (this.#checkOffer()) return;
2214
- if (await this.#checkSession()) return;
2215
- this.#captureReturnUrl();
2216
2454
  this.#computeBillingCountries();
2217
- 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;
2218
2459
  this.#finishLoading();
2219
2460
  } catch {
2220
- this.style.display = "none";
2221
- this.querySelector(SEL_CONTAINER)?.remove();
2461
+ this.#hide();
2222
2462
  } finally {
2223
2463
  this.#rendering = false;
2224
2464
  }
2225
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
+ }
2226
2482
  /** Returns `true` (hide) when Apple Pay is unavailable on this device/browser. */
2227
2483
  async #checkAvailability() {
2228
2484
  const available = await isApplePayAvailable();
2229
2485
  if (!available) {
2230
- this.style.display = "none";
2231
- this.querySelector(SEL_CONTAINER)?.remove();
2486
+ this.#hide();
2232
2487
  return true;
2233
2488
  }
2234
2489
  return false;
@@ -2237,11 +2492,17 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2237
2492
  * Returns `true` (hide) when the user already has an active subscription or is B2B.
2238
2493
  * Session fetch errors are swallowed — the component continues as an anonymous user.
2239
2494
  */
2240
- async #checkSession() {
2241
- 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;
2242
2504
  if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
2243
- this.style.display = "none";
2244
- this.querySelector(SEL_CONTAINER)?.remove();
2505
+ this.#hide();
2245
2506
  return true;
2246
2507
  }
2247
2508
  return false;
@@ -2249,8 +2510,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2249
2510
  /** Returns `true` (hide) when no offer has been set before mount. */
2250
2511
  #checkOffer() {
2251
2512
  if (!this.#offer) {
2252
- this.style.display = "none";
2253
- this.querySelector(SEL_CONTAINER)?.remove();
2513
+ this.#hide();
2254
2514
  return true;
2255
2515
  }
2256
2516
  return false;
@@ -2258,6 +2518,11 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2258
2518
  /** Captures the current page URL once at mount for reuse across the session lifetime. */
2259
2519
  #captureReturnUrl() {
2260
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
+ );
2261
2526
  }
2262
2527
  /**
2263
2528
  * Computes supported billing countries once at mount.
@@ -2270,15 +2535,32 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2270
2535
  this.#offer.product?.variant ?? ""
2271
2536
  );
2272
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
+ }
2273
2556
  /**
2274
2557
  * Returns `true` (hide) when the wallet BFF reports Apple Pay is unavailable
2275
2558
  * for this offer. The response is cached and reused in `#initiateApplePay`.
2276
2559
  */
2277
- async #fetchAndCacheOptions() {
2278
- this.#paymentOptions = await this.#fetchPaymentOptions();
2560
+ #applyPaymentOptions(options) {
2561
+ this.#paymentOptions = options;
2279
2562
  if (!this.#paymentOptions?.options?.apple_pay) {
2280
- this.style.display = "none";
2281
- this.querySelector(SEL_CONTAINER)?.remove();
2563
+ this.#hide();
2282
2564
  return true;
2283
2565
  }
2284
2566
  return false;
@@ -2286,11 +2568,14 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2286
2568
  /** Injects the button template and wires click and confirm event listeners. */
2287
2569
  #renderTemplate() {
2288
2570
  this.style.removeProperty("display");
2289
- ensureApplePayLogoSymbol();
2290
2571
  const template = document.createElement("template");
2291
2572
  template.innerHTML = apple_pay_button_template_default;
2292
2573
  this.appendChild(template.content.cloneNode(true));
2293
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;
2294
2579
  button.classList.add("wap-loading");
2295
2580
  button.setAttribute("disabled", "");
2296
2581
  button.setAttribute("aria-disabled", "true");
@@ -2378,16 +2663,25 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2378
2663
  totalAmount,
2379
2664
  totalLabel: TOTAL_LABEL,
2380
2665
  skuId,
2381
- returnUrl: this.#returnUrl,
2666
+ returnUrl: this.#checkoutRedirectUrl,
2382
2667
  userLoggedIn: sessionData.loggedIn,
2668
+ ...this.#supportedDeliveryCountries && {
2669
+ delivery: { supportedCountries: this.#supportedDeliveryCountries }
2670
+ },
2383
2671
  onPaymentAuthorized: async (event, session) => {
2384
2672
  const recaptchaToken = await recaptchaTokenPromise;
2385
2673
  return handlePaymentAuthorized(event, session, sessionData, {
2386
2674
  skuId,
2387
2675
  country,
2388
2676
  currency: offer.price?.currency_code ?? DEFAULT_CURRENCY,
2389
- returnUrl: this.#returnUrl,
2677
+ returnUrl: this.#checkoutRedirectUrl,
2390
2678
  supportedBillingCountries: this.#supportedBillingCountries,
2679
+ ...this.#supportedDeliveryCountries && {
2680
+ delivery: {
2681
+ offerCountry: country,
2682
+ supportedCountries: this.#supportedDeliveryCountries
2683
+ }
2684
+ },
2391
2685
  recaptchaToken
2392
2686
  });
2393
2687
  }
@@ -2411,7 +2705,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2411
2705
  );
2412
2706
  } catch {
2413
2707
  redirectToFallbackCheckout({
2414
- returnUrl: this.#returnUrl,
2708
+ returnUrl: this.#checkoutRedirectUrl,
2415
2709
  skuId,
2416
2710
  countryCode: country
2417
2711
  });