@economist/web-apple-pay 2.0.0-beta.2 → 2.0.0-beta.4

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 (56) hide show
  1. package/README.md +20 -12
  2. package/dist/index.js +681 -361
  3. package/dist/src/apple-pay-button.d.ts +18 -16
  4. package/dist/src/apple-pay-button.js +670 -352
  5. package/dist/src/apple-pay-button.stories.js +667 -351
  6. package/dist/src/apple-pay-modal.js +44 -39
  7. package/dist/src/apple-pay-modal.stories.js +667 -351
  8. package/dist/src/clients/payment-checkout/apple-session.d.ts +14 -1
  9. package/dist/src/clients/payment-checkout/apple-session.js +66 -17
  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 +397 -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 +414 -36
  19. package/dist/src/clients/payment-checkout/session.js +13 -1
  20. package/dist/src/clients/payment-checkout/types.d.ts +11 -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 +681 -361
  25. package/dist/src/types/offer.types.d.ts +1 -1
  26. package/dist/src/utils/address-rules.d.ts +29 -0
  27. package/dist/src/utils/address-rules.js +260 -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/billing-countries.js +46 -37
  33. package/dist/src/utils/buttonCopyFlag.d.ts +22 -0
  34. package/dist/src/utils/buttonCopyFlag.js +12 -0
  35. package/dist/src/utils/delivery-countries.d.ts +9 -0
  36. package/dist/src/utils/delivery-countries.js +255 -0
  37. package/dist/src/utils/expressCheckoutRedirect.d.ts +20 -2
  38. package/dist/src/utils/expressCheckoutRedirect.js +13 -1
  39. package/dist/src/utils/expressCheckoutTracking.d.ts +13 -20
  40. package/dist/src/utils/expressCheckoutTracking.js +22 -37
  41. package/dist/src/utils/latin-characters.d.ts +3 -0
  42. package/dist/src/utils/latin-characters.js +10 -0
  43. package/dist/src/utils/price-zones.d.ts +7 -0
  44. package/dist/src/utils/price-zones.js +212 -0
  45. package/dist/src/utils/print-variants.d.ts +5 -0
  46. package/dist/src/utils/print-variants.js +10 -0
  47. package/dist/src/utils/printOffersFlag.d.ts +11 -0
  48. package/dist/src/utils/printOffersFlag.js +5 -0
  49. package/dist/src/utils/recaptcha.d.ts +3 -2
  50. package/dist/src/utils/recaptcha.js +17 -8
  51. package/package.json +1 -1
  52. package/dist/src/apple-pay-logo.d.ts +0 -1
  53. package/dist/src/apple-pay-logo.js +0 -14
  54. package/dist/src/types/experiment-integration.d.js +0 -0
  55. package/dist/src/utils/getExperimentKeyFromNextData.d.ts +0 -8
  56. 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>
@@ -562,15 +559,21 @@ var runtimeConfig = null;
562
559
  var getApplePayConfig = () => runtimeConfig;
563
560
 
564
561
  // src/utils/recaptcha.ts
562
+ var findScriptForKey = (siteKey) => Array.from(
563
+ document.querySelectorAll(
564
+ 'script[src*="recaptcha/api.js"]'
565
+ )
566
+ ).find((script) => script.src.includes(`render=${siteKey}`));
567
+ var pendingLoads = /* @__PURE__ */ new Map();
565
568
  var loadRecaptchaScript = (siteKey) => {
566
- return new Promise((resolve, reject) => {
567
- if (typeof grecaptcha !== "undefined") return resolve();
568
- const existingScript = document.querySelector(
569
- 'script[src*="recaptcha/api.js"]'
570
- );
571
- if (existingScript) {
572
- existingScript.addEventListener("load", () => resolve());
573
- existingScript.addEventListener("error", () => {
569
+ const pending = pendingLoads.get(siteKey);
570
+ if (pending) return pending;
571
+ const ownScript = findScriptForKey(siteKey);
572
+ if (ownScript && typeof grecaptcha !== "undefined") return Promise.resolve();
573
+ const load = new Promise((resolve, reject) => {
574
+ if (ownScript) {
575
+ ownScript.addEventListener("load", () => resolve());
576
+ ownScript.addEventListener("error", () => {
574
577
  reject(new Error("Failed to load existing reCAPTCHA script"));
575
578
  });
576
579
  return;
@@ -585,6 +588,9 @@ var loadRecaptchaScript = (siteKey) => {
585
588
  };
586
589
  document.head.appendChild(script);
587
590
  });
591
+ pendingLoads.set(siteKey, load);
592
+ load.catch(() => pendingLoads.delete(siteKey));
593
+ return load;
588
594
  };
589
595
  var getRecaptchaToken = async (action) => {
590
596
  const siteKey = getApplePayConfig()?.recaptchaSiteKey;
@@ -849,7 +855,6 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
849
855
  if (this.querySelector(".apm-overlay")) {
850
856
  return;
851
857
  }
852
- ensureApplePayLogoSymbol();
853
858
  const template = document.createElement("template");
854
859
  template.innerHTML = apple_pay_modal_template_default;
855
860
  this.appendChild(template.content.cloneNode(true));
@@ -1002,8 +1007,11 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
1002
1007
  // src/templates/apple-pay-button.template.html
1003
1008
  var apple_pay_button_template_default = `<style>
1004
1009
  /*
1005
- * Entry CTA: \u201CSubscribe with\u201D + Apple Pay wordmark (Figma 1118:14088).
1006
- * \u201CSubscribe with\u201D matches Continue to checkout typography (EconomistSans Regular / 17 / 24 / 400).
1010
+ * Entry CTA: caption + Apple Pay wordmark, built from text (no SVG). Figma: Play pilot 7781:7325 (text style) and
1011
+ * Play Global Spec 3268:39728 (layout): black #0d0d0d, 4px radius, 40px high, 8px 16px padding, 4px gap.
1012
+ * Text: SF Pro Medium 510, line height normal; caption size label-2-size (15px), glyph + "Pay" 17px (label-3-size).
1013
+ * Padding spacing-xs / spacing-md; gap + radius spacing-2xs; background london-5.
1014
+ * SF Pro is the system font on Apple devices, which are the only devices Apple Pay is shown on.
1007
1015
  */
1008
1016
  teg-apple-pay-button {
1009
1017
  display: block;
@@ -1028,46 +1036,43 @@ var apple_pay_button_template_default = `<style>
1028
1036
  min-width: 0;
1029
1037
  height: 100%;
1030
1038
  min-height: var(--apple-pay-height, 2.5rem);
1031
- padding: 0;
1039
+ /* Figma button content: 8px 16px */
1040
+ padding: var(--mb-spacing-xs, 0.5rem) var(--mb-spacing-md, 1rem);
1032
1041
  box-sizing: border-box;
1033
- background-color: var(--apple-pay-background-color, #1a1a1a);
1042
+ background-color: var(--apple-pay-background-color, var(--mb-colour-greyscale-london-5, #0d0d0d));
1034
1043
  color: var(--apple-pay-foreground-color, #fff);
1035
1044
  border: none;
1036
- border-radius: var(--apple-pay-border-radius, 0.25rem);
1045
+ border-radius: var(--apple-pay-border-radius, var(--mb-spacing-2xs, 0.25rem));
1037
1046
  cursor: pointer;
1038
- /* Same as wall Continue to checkout / Marber button large */
1039
- font-family: var(
1040
- --mb-typeface-sans,
1041
- var(--wall-type-system-sans, 'EconomistSans', system-ui, sans-serif)
1042
- );
1043
- font-size: var(--mb-button-font-size, 1.0625rem);
1044
- font-weight: var(--mb-font-weight-regular, 400);
1045
- line-height: 1;
1047
+ /* Figma Play pilot 7781:7325: SF Pro (system font on Apple devices), Medium 510, 15px, line height normal */
1048
+ font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro', system-ui, sans-serif;
1049
+ font-size: var(--mb-typestyle-label-2-size, 0.9375rem);
1050
+ font-weight: 510;
1051
+ font-variation-settings: 'wdth' 100;
1052
+ /* Figma letter spacing 0 */
1053
+ letter-spacing: 0;
1054
+ line-height: normal;
1046
1055
  }
1047
1056
 
1048
1057
  teg-apple-pay-button .apple-pay-btn__label {
1049
1058
  display: inline-flex;
1050
1059
  align-items: center;
1051
- /* No flex gap \u2014 spacing after \u201Cwith\u201D uses the same word-space as \u201CSubscribe with\u201D */
1052
- gap: 0;
1060
+ /* Figma: 4px between the caption and the wordmark */
1061
+ gap: var(--mb-spacing-2xs, 0.25rem);
1053
1062
  white-space: nowrap;
1054
1063
  }
1055
1064
 
1056
- teg-apple-pay-button .apple-pay-btn__caption {
1057
- /* One typographic word space after \u201Cwith\u201D, matching Subscribe\u2194with */
1058
- padding-right: 0.25em;
1065
+ teg-apple-pay-button .apple-pay-btn__logo {
1066
+ display: inline-flex;
1067
+ align-items: baseline;
1068
+ /* Figma "Pay" layer: 17px (label-3 size), line height normal. */
1069
+ font-size: var(--mb-typestyle-label-3-size, 1.0625rem);
1070
+ line-height: normal;
1059
1071
  }
1060
1072
 
1061
- teg-apple-pay-button .apple-pay-btn__logo {
1062
- flex-shrink: 0;
1063
- display: block;
1064
- /* Match caption font-size so mark aligns with text metrics */
1065
- height: 1.05em;
1066
- width: auto;
1067
- aspect-ratio: 51 / 22;
1068
- color: currentColor;
1069
- /* Optical nudge \u2014 SVG viewBox sits slightly high vs EconomistSans caps */
1070
- transform: translateY(0.06em);
1073
+ teg-apple-pay-button .apple-pay-btn__logo-word {
1074
+ font-weight: 510;
1075
+ font-variation-settings: 'wdth' 100;
1071
1076
  }
1072
1077
 
1073
1078
  teg-apple-pay-button .apple-pay-btn.wap-loading {
@@ -1104,27 +1109,22 @@ var apple_pay_button_template_default = `<style>
1104
1109
  transform: translate(-50%, -50%) rotate(360deg);
1105
1110
  }
1106
1111
  }
1112
+
1107
1113
  </style>
1108
1114
 
1109
- <div class="apple-pay-container" aria-label="Subscribe with Apple Pay">
1115
+ <div class="apple-pay-container" aria-label="Continue with Apple Pay">
1110
1116
  <button
1111
1117
  class="apple-pay-btn"
1112
1118
  type="button"
1113
- aria-label="Subscribe with Apple Pay"
1119
+ aria-label="Continue with Apple Pay"
1114
1120
  data-analytics="paywall:apple-pay-checkout"
1115
1121
  >
1116
1122
  <span class="apple-pay-btn__label"
1117
- ><span class="apple-pay-btn__caption">Subscribe with</span
1118
- ><svg
1119
- class="apple-pay-btn__logo"
1120
- width="42"
1121
- height="18"
1122
- viewBox="0 0 51 22"
1123
- aria-hidden="true"
1124
- role="img"
1125
- >
1126
- <use href="#apple-pay-logo" />
1127
- </svg
1123
+ ><span class="apple-pay-btn__caption">Continue with</span
1124
+ ><span class="apple-pay-btn__logo" aria-hidden="true"
1125
+ ><span class="apple-pay-btn__logo-glyph">&#63743;</span
1126
+ ><span class="apple-pay-btn__logo-word">Pay</span
1127
+ ></span
1128
1128
  ></span>
1129
1129
  <span class="apple-pay-btn__loading" aria-hidden="true">Loading...</span>
1130
1130
  </button>
@@ -1138,7 +1138,7 @@ var isAppleDeviceOrSafari = () => {
1138
1138
  return isIOSOrMacTouchDevice || isSafariBrowser;
1139
1139
  };
1140
1140
  var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null;
1141
- var isApplePayAvailable = async () => {
1141
+ var isApplePayCapable = () => {
1142
1142
  if (bypassApplePayChecks()) {
1143
1143
  return true;
1144
1144
  }
@@ -1150,18 +1150,21 @@ var isApplePayAvailable = async () => {
1150
1150
  return false;
1151
1151
  }
1152
1152
  try {
1153
- if (typeof applePaySession.canMakePayments !== "function") {
1154
- return false;
1155
- }
1156
- if (!applePaySession.canMakePayments()) {
1157
- return false;
1158
- }
1159
- const merchantId = getApplePayConfig()?.merchantId;
1160
- if (!merchantId) {
1161
- return false;
1162
- }
1163
- const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
1164
- return hasActiveCard;
1153
+ return typeof applePaySession.canMakePayments === "function" && applePaySession.canMakePayments() && Boolean(getApplePayConfig()?.merchantId);
1154
+ } catch {
1155
+ return false;
1156
+ }
1157
+ };
1158
+ var isApplePayAvailable = async () => {
1159
+ if (bypassApplePayChecks()) {
1160
+ return true;
1161
+ }
1162
+ if (!isApplePayCapable()) {
1163
+ return false;
1164
+ }
1165
+ try {
1166
+ const merchantId = getApplePayConfig().merchantId;
1167
+ return await window.ApplePaySession.canMakePaymentsWithActiveCard(merchantId);
1165
1168
  } catch {
1166
1169
  return false;
1167
1170
  }
@@ -1242,11 +1245,23 @@ var performPurchase = (data) => {
1242
1245
  };
1243
1246
 
1244
1247
  // src/clients/payment-checkout/session.ts
1248
+ var inFlight = null;
1245
1249
  var getExpressCheckoutSession = () => {
1246
- return apiFetch("/v1/wallet/session", {
1250
+ if (inFlight) {
1251
+ return inFlight;
1252
+ }
1253
+ const request = apiFetch("/v1/wallet/session", {
1247
1254
  method: "GET",
1248
1255
  credentials: "include"
1249
1256
  });
1257
+ inFlight = request;
1258
+ const clear = () => {
1259
+ if (inFlight === request) {
1260
+ inFlight = null;
1261
+ }
1262
+ };
1263
+ request.then(clear, clear);
1264
+ return request;
1250
1265
  };
1251
1266
 
1252
1267
  // src/utils/expressCheckoutRedirect.ts
@@ -1261,8 +1276,13 @@ function isAllowedRedirectUrl(url) {
1261
1276
  return false;
1262
1277
  }
1263
1278
  }
1279
+ var CHECKOUT_REDIRECT_BY_POLICY = {
1280
+ ["current_page" /* CURRENT_PAGE */]: (currentPageUrl) => currentPageUrl,
1281
+ ["host_managed" /* HOST_MANAGED */]: () => null
1282
+ };
1283
+ var resolveCheckoutRedirectUrl = (policy, currentPageUrl) => CHECKOUT_REDIRECT_BY_POLICY[policy](currentPageUrl);
1264
1284
  var writeCheckoutRedirect = (originUrl) => {
1265
- if (!isAllowedRedirectUrl(originUrl)) return;
1285
+ if (originUrl === null || !isAllowedRedirectUrl(originUrl)) return;
1266
1286
  try {
1267
1287
  localStorage.setItem(CHECKOUT_REDIRECT_KEY, originUrl);
1268
1288
  } catch {
@@ -1298,13 +1318,6 @@ var redirectToCheckoutFallback = (params) => {
1298
1318
  return url.pathname + url.search;
1299
1319
  };
1300
1320
 
1301
- // src/constants.ts
1302
- var APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY = "apple-pay-express-checkout-on-paywalls";
1303
- var APPLE_PAY_EXPRESS_VARIANTS = {
1304
- CONTROL: "control",
1305
- TREATMENT: "treatment"
1306
- };
1307
-
1308
1321
  // src/utils/expressCheckoutTracking.ts
1309
1322
  var EXPRESS_CHECKOUT_EVENTS = {
1310
1323
  /** Wallet button displayed */
@@ -1342,26 +1355,6 @@ var track = (action, extra) => {
1342
1355
  ...extra
1343
1356
  });
1344
1357
  };
1345
- var trackApplePayExperimentExposure = (variant, experimentKey, flagKey) => {
1346
- const isActiveVariant = variant === APPLE_PAY_EXPRESS_VARIANTS.CONTROL || variant === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
1347
- if (!isActiveVariant) {
1348
- return;
1349
- }
1350
- const exposures = window.__applePayExperimentExposures ?? {};
1351
- window.__applePayExperimentExposures = exposures;
1352
- const pathname = window.location?.pathname ?? "";
1353
- const dedupeKey = `${pathname}:${flagKey}:${variant}`;
1354
- if (exposures[dedupeKey]) {
1355
- return;
1356
- }
1357
- exposures[dedupeKey] = true;
1358
- emitTedlEvent({
1359
- name: "$exposure",
1360
- flag_key: flagKey,
1361
- variant,
1362
- ...experimentKey ? { experiment_key: experimentKey } : {}
1363
- });
1364
- };
1365
1358
  var trackExpressWalletImpression = (skuId, { entryPoint, country }) => {
1366
1359
  track(EXPRESS_CHECKOUT_EVENTS.IMPRESSION, {
1367
1360
  wallet_type: "apple_pay",
@@ -1371,32 +1364,44 @@ var trackExpressWalletImpression = (skuId, { entryPoint, country }) => {
1371
1364
  device: getDevice()
1372
1365
  });
1373
1366
  };
1367
+ var withEntryPoint = ({ entryPoint } = {}) => entryPoint ? { entry_point: entryPoint } : {};
1374
1368
  var trackExpressWalletClick = (skuId, { entryPoint } = {}) => {
1375
1369
  track(EXPRESS_CHECKOUT_EVENTS.BUTTON_CLICK, {
1376
1370
  sku_id: skuId,
1377
1371
  ...entryPoint ? { entry_point: entryPoint } : {}
1378
1372
  });
1379
1373
  };
1380
- var trackWalletPaymentSheetOpen = (skuId) => {
1381
- track(EXPRESS_CHECKOUT_EVENTS.SHEET_OPEN, { sku_id: skuId });
1374
+ var trackWalletPaymentSheetOpen = (skuId, metadata) => {
1375
+ track(EXPRESS_CHECKOUT_EVENTS.SHEET_OPEN, {
1376
+ sku_id: skuId,
1377
+ ...withEntryPoint(metadata)
1378
+ });
1382
1379
  };
1383
- var trackWalletPaymentAuthorised = (skuId) => {
1384
- track(EXPRESS_CHECKOUT_EVENTS.AUTHORISED, { sku_id: skuId });
1380
+ var trackWalletPaymentAuthorised = (skuId, metadata) => {
1381
+ track(EXPRESS_CHECKOUT_EVENTS.AUTHORISED, {
1382
+ sku_id: skuId,
1383
+ ...withEntryPoint(metadata)
1384
+ });
1385
1385
  };
1386
- var trackWalletPaymentSuccess = (skuId, basketId) => {
1386
+ var trackWalletPaymentSuccess = (skuId, basketId, metadata) => {
1387
1387
  track(EXPRESS_CHECKOUT_EVENTS.SUCCESS, {
1388
1388
  sku_id: skuId,
1389
- basket_id: basketId
1389
+ basket_id: basketId,
1390
+ ...withEntryPoint(metadata)
1390
1391
  });
1391
1392
  };
1392
- var trackWalletPaymentFailure = (skuId, reason) => {
1393
+ var trackWalletPaymentFailure = (skuId, reason, metadata) => {
1393
1394
  track(EXPRESS_CHECKOUT_EVENTS.FAILURE, {
1394
1395
  sku_id: skuId,
1395
- failure_reason: reason
1396
+ failure_reason: reason,
1397
+ ...withEntryPoint(metadata)
1396
1398
  });
1397
1399
  };
1398
- var trackFallbackCheckout = (skuId) => {
1399
- track(EXPRESS_CHECKOUT_EVENTS.FALLBACK_CHECKOUT, { sku_id: skuId });
1400
+ var trackFallbackCheckout = (skuId, metadata) => {
1401
+ track(EXPRESS_CHECKOUT_EVENTS.FALLBACK_CHECKOUT, {
1402
+ sku_id: skuId,
1403
+ ...withEntryPoint(metadata)
1404
+ });
1400
1405
  };
1401
1406
  var trackValidationFieldError = (field, errorType) => {
1402
1407
  track(`validation_${field}_${errorType}`, {});
@@ -1406,21 +1411,10 @@ var trackValidationFieldError = (field, errorType) => {
1406
1411
  var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
1407
1412
  var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a valid email address.";
1408
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.";
1409
1417
  var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
1410
- var BILLING_COUNTRY_MISMATCH_FALLBACK = "Country not supported for this purchase";
1411
- var MSG_BILLING_COUNTRY_MISMATCH_REDIRECT = "This country isn\u2019t supported for this purchase. Try updating your billing address.";
1412
- var buildCountryMismatchMessage = (countryCode) => {
1413
- if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
1414
- try {
1415
- const regionNames = new Intl.DisplayNames(["en"], { type: "region", fallback: "none" });
1416
- const upper = countryCode.toUpperCase();
1417
- const countryName = regionNames.of(upper);
1418
- const isResolved = countryName && countryName !== upper && countryName !== "Unknown Region";
1419
- return isResolved ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
1420
- } catch {
1421
- return BILLING_COUNTRY_MISMATCH_FALLBACK;
1422
- }
1423
- };
1424
1418
  var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
1425
1419
  var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
1426
1420
 
@@ -1458,7 +1452,12 @@ async function handleMerchantValidation(event, session, config) {
1458
1452
  redirectToFallbackCheckout(config);
1459
1453
  }
1460
1454
  }
1455
+ var requiredShippingFields = (config) => [
1456
+ ...config.delivery ? ["postalAddress", "name", "phone"] : [],
1457
+ ...config.userLoggedIn ? [] : ["email"]
1458
+ ];
1461
1459
  function startApplePaySession(config) {
1460
+ const shippingFields = requiredShippingFields(config);
1462
1461
  const paymentRequest = {
1463
1462
  countryCode: config.countryCode,
1464
1463
  currencyCode: config.currencyCode,
@@ -1469,14 +1468,37 @@ function startApplePaySession(config) {
1469
1468
  amount: config.totalAmount
1470
1469
  },
1471
1470
  requiredBillingContactFields: ["postalAddress", "name"],
1472
- // Only request email from Apple Pay sheet if user is NOT logged in
1473
- ...!config.userLoggedIn && { requiredShippingContactFields: ["email"] }
1471
+ ...shippingFields.length > 0 && {
1472
+ requiredShippingContactFields: shippingFields
1473
+ },
1474
+ // Restrict the shipping country picker for print; onshippingcontactselected still validates as a backstop.
1475
+ ...config.delivery && config.delivery.supportedCountries.length > 0 && {
1476
+ supportedCountries: config.delivery.supportedCountries
1477
+ }
1474
1478
  };
1475
1479
  try {
1476
1480
  const session = new ApplePaySession(3, paymentRequest);
1477
1481
  session.onvalidatemerchant = async (event) => {
1478
1482
  await handleMerchantValidation(event, session, config);
1479
1483
  };
1484
+ const delivery = config.delivery;
1485
+ if (delivery) {
1486
+ session.onshippingcontactselected = (event) => {
1487
+ const country = event.shippingContact.countryCode?.toUpperCase();
1488
+ session.completeShippingContactSelection({
1489
+ newTotal: paymentRequest.total,
1490
+ ...country && !delivery.supportedCountries.includes(country) && {
1491
+ errors: [
1492
+ new ApplePayError(
1493
+ "shippingContactInvalid",
1494
+ "countryCode",
1495
+ MSG_UNSUPPORTED_DELIVERY_COUNTRY
1496
+ )
1497
+ ]
1498
+ }
1499
+ });
1500
+ };
1501
+ }
1480
1502
  session.onpaymentauthorized = (event) => {
1481
1503
  trackWalletPaymentAuthorised(config.skuId);
1482
1504
  config.onPaymentAuthorized(event, session).catch(() => {
@@ -1517,6 +1539,16 @@ var ContactValidationError = class extends Error {
1517
1539
  }
1518
1540
  };
1519
1541
 
1542
+ // src/utils/latin-characters.ts
1543
+ 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";
1544
+ var LATIN_CHARACTERS_REGEX = new RegExp(
1545
+ `^[\\x20-\\x7E${SUPPORTED_DIACRITICS}]*$`
1546
+ );
1547
+ var isLatinCharacters = (value) => LATIN_CHARACTERS_REGEX.test(value);
1548
+
1549
+ // src/utils/addressParityFlag.ts
1550
+ var ADDRESS_PARITY_ENABLED = true;
1551
+
1520
1552
  // src/clients/payment-checkout/billing-contact-details.ts
1521
1553
  var countriesWithoutCityField = ["KY", "CK", "NR", "TC"];
1522
1554
  var countriesRequiringAllFields = ["US", "CA", "GB"];
@@ -1564,6 +1596,35 @@ var validateCountrySupport = (errors, country, supportedBillingCountries) => {
1564
1596
  );
1565
1597
  }
1566
1598
  };
1599
+ var validateLatinCharacters = (errors, contact, firstName, lastName) => {
1600
+ if (!isLatinCharacters(firstName) || !isLatinCharacters(lastName)) {
1601
+ pushFieldError(
1602
+ errors,
1603
+ "billing",
1604
+ "name",
1605
+ "format",
1606
+ MSG_NON_LATIN_CHARACTERS
1607
+ );
1608
+ }
1609
+ const addressFields = [
1610
+ ["addressLines", contact.addressLines?.at(0)],
1611
+ ["addressLines", contact.addressLines?.at(1)],
1612
+ ["locality", contact.locality],
1613
+ ["administrativeArea", contact.administrativeArea],
1614
+ ["postalCode", contact.postalCode]
1615
+ ];
1616
+ for (const [field, value] of addressFields) {
1617
+ if (value && !isLatinCharacters(value)) {
1618
+ pushFieldError(
1619
+ errors,
1620
+ "billing",
1621
+ field,
1622
+ "format",
1623
+ MSG_NON_LATIN_CHARACTERS
1624
+ );
1625
+ }
1626
+ }
1627
+ };
1567
1628
  var billingContactDetails = (contact, supportedBillingCountries) => {
1568
1629
  const errors = [];
1569
1630
  const country = contact.countryCode?.toUpperCase() || pushRequiredFieldError(errors, "billing", "country");
@@ -1571,6 +1632,9 @@ var billingContactDetails = (contact, supportedBillingCountries) => {
1571
1632
  validateAddressFields(errors, contact, config);
1572
1633
  const { firstName, lastName } = validateNameFields(errors, contact);
1573
1634
  validateCountrySupport(errors, country, supportedBillingCountries);
1635
+ if (ADDRESS_PARITY_ENABLED) {
1636
+ validateLatinCharacters(errors, contact, firstName, lastName);
1637
+ }
1574
1638
  if (errors.length > 0) {
1575
1639
  throw new ContactValidationError(errors);
1576
1640
  }
@@ -1610,123 +1674,6 @@ var shippingContactDetails = (shippingContact) => {
1610
1674
  return { emailAddress };
1611
1675
  };
1612
1676
 
1613
- // src/clients/payment-checkout/payment-handler.ts
1614
- var failApplePaySession = (session, errors = []) => {
1615
- session.completePayment({
1616
- status: ApplePaySession.STATUS_FAILURE,
1617
- errors
1618
- });
1619
- };
1620
- function parseWalletApiError(err) {
1621
- const body = err instanceof ApiError ? err.body : err;
1622
- if (body && typeof body === "object" && "errorType" in body && "message" in body) {
1623
- return body;
1624
- }
1625
- return null;
1626
- }
1627
- function validateContacts(event, sessionData, supportedBillingCountries) {
1628
- billingContactDetails(
1629
- event.payment.billingContact,
1630
- supportedBillingCountries
1631
- );
1632
- if (!sessionData.loggedIn) {
1633
- return shippingContactDetails(event.payment.shippingContact).emailAddress;
1634
- }
1635
- return void 0;
1636
- }
1637
- function redirectFallback(skuId, returnUrl, country, options) {
1638
- writeCheckoutRedirect(returnUrl);
1639
- trackFallbackCheckout(skuId);
1640
- window.location.href = redirectToCheckoutFallback({
1641
- skuId,
1642
- country,
1643
- ...options
1644
- });
1645
- }
1646
- var ERROR_HANDLERS = {
1647
- // emailError flows as an inline field error on the email input.
1648
- // email pre-populates the input so the user doesn't have to retype it.
1649
- EMAIL_COLLISION: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
1650
- emailError: walletError.message,
1651
- email: validatedEmail
1652
- }),
1653
- PAYMENT_DECLINED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1654
- ELIGIBILITY_REJECTED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1655
- REGISTRATION_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1656
- ACCOUNT_CREATION_FAILED: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
1657
- emailError: walletError.message,
1658
- email: validatedEmail
1659
- }),
1660
- VALIDATION_ERROR: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1661
- RECAPTCHA_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message })
1662
- };
1663
- function handleStructuredError(ctx) {
1664
- const handler = ERROR_HANDLERS[ctx.walletError.errorType];
1665
- if (handler) {
1666
- handler(ctx);
1667
- } else {
1668
- redirectFallback(ctx.skuId, ctx.returnUrl, ctx.country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
1669
- }
1670
- }
1671
- async function handlePaymentAuthorized(event, session, sessionData, config) {
1672
- const { skuId, returnUrl, country } = config;
1673
- let validatedEmail;
1674
- try {
1675
- validatedEmail = validateContacts(
1676
- event,
1677
- sessionData,
1678
- config.supportedBillingCountries
1679
- );
1680
- const result = await performPurchase({
1681
- applePayToken: event.payment.token,
1682
- skuId: config.skuId,
1683
- currency: config.currency,
1684
- billingContact: event.payment.billingContact,
1685
- ...event.payment.shippingContact && {
1686
- shippingContact: event.payment.shippingContact
1687
- },
1688
- recaptchaToken: config.recaptchaToken
1689
- });
1690
- trackWalletPaymentSuccess(skuId, result.basketId);
1691
- session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
1692
- const successEmail = sessionData.loggedIn ? sessionData.emailAddress : validatedEmail;
1693
- const userStatus = sessionData.loggedIn ? "lex" : "nex";
1694
- writeCheckoutRedirect(returnUrl);
1695
- window.location.href = redirectToCheckoutComplete({
1696
- basketId: result.basketId,
1697
- status: userStatus,
1698
- skuId: decodeSku(skuId),
1699
- email: successEmail,
1700
- country
1701
- });
1702
- } catch (err) {
1703
- if (err instanceof ContactValidationError) {
1704
- const isBillingCountryMismatch = err.errors.some(
1705
- (e) => e.contactField === "countryCode"
1706
- );
1707
- if (isBillingCountryMismatch) {
1708
- const countryCode = event.payment.billingContact?.countryCode;
1709
- const userMessage = buildCountryMismatchMessage(countryCode);
1710
- failApplePaySession(session, [
1711
- new ApplePayError("billingContactInvalid", "countryCode", userMessage)
1712
- ]);
1713
- redirectFallback(skuId, returnUrl, country, { inlineError: MSG_BILLING_COUNTRY_MISMATCH_REDIRECT });
1714
- } else {
1715
- failApplePaySession(session, err.errors);
1716
- }
1717
- return;
1718
- }
1719
- const walletError = parseWalletApiError(err);
1720
- trackWalletPaymentFailure(skuId, walletError?.errorType ?? "UNKNOWN");
1721
- failApplePaySession(session);
1722
- if (!walletError) {
1723
- redirectFallback(skuId, returnUrl, country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
1724
- return;
1725
- }
1726
- handleStructuredError({ skuId, returnUrl, country, validatedEmail, walletError });
1727
- }
1728
- }
1729
-
1730
1677
  // src/data/price-zones.json
1731
1678
  var price_zones_default = {
1732
1679
  "AS-AS": [
@@ -1932,6 +1879,259 @@ var price_zones_default = {
1932
1879
  "UK-UK": ["GB"]
1933
1880
  };
1934
1881
 
1882
+ // src/utils/price-zones.ts
1883
+ var priceZones = price_zones_default;
1884
+ var getZoneByCountry = (country) => Object.keys(priceZones).find((key) => priceZones[key].includes(country)) ?? null;
1885
+
1886
+ // src/utils/address-rules.ts
1887
+ var ADDRESS_LIMITS = {
1888
+ address1: 35,
1889
+ address2: 35,
1890
+ city: 40,
1891
+ state: 40,
1892
+ postalCode: 20,
1893
+ phone: 35
1894
+ };
1895
+ var COUNTRIES_REQUIRING_PHONE = ["IN", "CN"];
1896
+ var requiredDeliveryFields = (offerCountry, country) => {
1897
+ const zone = getZoneByCountry(offerCountry);
1898
+ const fields = ["address1", "city"];
1899
+ if (zone === "AS-AU" || zone === "AS-JP" || zone === "NA-CA" || country === "US") {
1900
+ fields.push("state");
1901
+ }
1902
+ if ((zone !== "AS-HK" || country === "MO") && zone !== "CE-AF" && zone !== "CE-ME") {
1903
+ fields.push("postalCode");
1904
+ }
1905
+ if (COUNTRIES_REQUIRING_PHONE.includes(country)) fields.push("phone");
1906
+ return fields;
1907
+ };
1908
+ var postalCodeFormatError = (offerCountry, postalCode) => {
1909
+ if (!postalCode) return null;
1910
+ const zone = getZoneByCountry(offerCountry);
1911
+ if (zone === "NA-US" && !/(^\d{5}$)|(^\d{5}-\d{4}$)/.test(postalCode)) {
1912
+ return "Zip code must be a valid US zip code";
1913
+ }
1914
+ if (zone === "NA-CA" && !/^[A-Za-z]\d[A-Za-z][ -]?\d[A-Za-z]\d$/.test(postalCode)) {
1915
+ return "Postal code must be a valid Canadian postal code";
1916
+ }
1917
+ return null;
1918
+ };
1919
+ var COUNTRY_CALLING_CODES = {
1920
+ IN: "91",
1921
+ CN: "86"
1922
+ };
1923
+ var normaliseDeliveryPhone = (raw, country) => {
1924
+ const trimmed = raw?.trim() ?? "";
1925
+ const digits = trimmed.replace(/[^0-9]+/g, "");
1926
+ if (!digits) return void 0;
1927
+ if (trimmed.startsWith("+")) return `+${digits}`;
1928
+ const callingCode = COUNTRY_CALLING_CODES[country];
1929
+ return callingCode ? `+${callingCode}${digits.replace(/^0+/, "")}` : void 0;
1930
+ };
1931
+
1932
+ // src/clients/payment-checkout/delivery-contact-details.ts
1933
+ var APPLE_FIELD = {
1934
+ address1: "addressLines",
1935
+ city: "locality",
1936
+ state: "administrativeArea",
1937
+ postalCode: "postalCode",
1938
+ phone: "phoneNumber"
1939
+ };
1940
+ var LABEL = {
1941
+ address1: "Address line 1",
1942
+ address2: "Address line 2",
1943
+ city: "City",
1944
+ state: "State",
1945
+ postalCode: "Postcode",
1946
+ phone: "Phone number"
1947
+ };
1948
+ var deliveryContactDetails = (contact, { offerCountry, supportedDeliveryCountries }) => {
1949
+ const errors = [];
1950
+ const fail = (field, type, message) => pushFieldError(errors, "shipping", field, type, message);
1951
+ const country = contact?.countryCode?.trim().toUpperCase() ?? "";
1952
+ const firstName = contact?.givenName?.trim() ?? "";
1953
+ const lastName = contact?.familyName?.trim() ?? "";
1954
+ const address1 = contact?.addressLines?.at(0)?.trim() ?? "";
1955
+ const address2 = contact?.addressLines?.at(1)?.trim() ?? "";
1956
+ const city = contact?.locality?.trim() ?? "";
1957
+ const state = contact?.administrativeArea?.trim() ?? "";
1958
+ const postalCode = contact?.postalCode?.trim() ?? "";
1959
+ const phone = normaliseDeliveryPhone(contact?.phoneNumber, country) ?? "";
1960
+ if (!country) {
1961
+ pushRequiredFieldError(errors, "shipping", "country");
1962
+ } else if (!supportedDeliveryCountries.includes(country)) {
1963
+ fail("countryCode", "not-supported", MSG_UNSUPPORTED_DELIVERY_COUNTRY);
1964
+ }
1965
+ if (!firstName || !lastName) {
1966
+ pushRequiredFieldError(errors, "shipping", "name");
1967
+ }
1968
+ const values = {
1969
+ address1,
1970
+ city,
1971
+ state,
1972
+ postalCode,
1973
+ phone
1974
+ };
1975
+ for (const field of requiredDeliveryFields(offerCountry, country)) {
1976
+ if (!values[field]) {
1977
+ pushRequiredFieldError(errors, "shipping", APPLE_FIELD[field]);
1978
+ }
1979
+ }
1980
+ const limited = [
1981
+ ["address1", "addressLines", address1, ADDRESS_LIMITS.address1],
1982
+ ["address2", "addressLines", address2, ADDRESS_LIMITS.address2],
1983
+ ["city", "locality", city, ADDRESS_LIMITS.city],
1984
+ ["state", "administrativeArea", state, ADDRESS_LIMITS.state],
1985
+ ["postalCode", "postalCode", postalCode, ADDRESS_LIMITS.postalCode],
1986
+ ["phone", "phoneNumber", phone, ADDRESS_LIMITS.phone]
1987
+ ];
1988
+ for (const [field, appleField, value, max] of limited) {
1989
+ if (value.length > max) {
1990
+ fail(appleField, "format", msgFieldTooLong(LABEL[field], max));
1991
+ }
1992
+ }
1993
+ const formatError = postalCodeFormatError(offerCountry, postalCode);
1994
+ if (formatError) {
1995
+ fail("postalCode", "format", formatError);
1996
+ }
1997
+ const latin = [
1998
+ ["name", firstName],
1999
+ ["name", lastName],
2000
+ ["addressLines", address1],
2001
+ ["addressLines", address2],
2002
+ ["locality", city],
2003
+ ["administrativeArea", state],
2004
+ ["postalCode", postalCode]
2005
+ ];
2006
+ for (const [field, value] of latin) {
2007
+ if (!isLatinCharacters(value)) {
2008
+ fail(field, "format", MSG_NON_LATIN_CHARACTERS);
2009
+ }
2010
+ }
2011
+ if (errors.length > 0) {
2012
+ throw new ContactValidationError(errors);
2013
+ }
2014
+ };
2015
+
2016
+ // src/clients/payment-checkout/payment-handler.ts
2017
+ var failApplePaySession = (session, errors = []) => {
2018
+ session.completePayment({
2019
+ status: ApplePaySession.STATUS_FAILURE,
2020
+ errors
2021
+ });
2022
+ };
2023
+ function parseWalletApiError(err) {
2024
+ const body = err instanceof ApiError ? err.body : err;
2025
+ if (body && typeof body === "object" && "errorType" in body && "message" in body) {
2026
+ return body;
2027
+ }
2028
+ return null;
2029
+ }
2030
+ function validateContacts(event, sessionData, supportedBillingCountries, delivery) {
2031
+ billingContactDetails(
2032
+ event.payment.billingContact,
2033
+ supportedBillingCountries
2034
+ );
2035
+ if (delivery) {
2036
+ deliveryContactDetails(event.payment.shippingContact, {
2037
+ offerCountry: delivery.offerCountry,
2038
+ supportedDeliveryCountries: delivery.supportedCountries
2039
+ });
2040
+ }
2041
+ if (!sessionData.loggedIn) {
2042
+ return shippingContactDetails(event.payment.shippingContact).emailAddress;
2043
+ }
2044
+ return void 0;
2045
+ }
2046
+ function redirectFallback(skuId, returnUrl, country, options) {
2047
+ writeCheckoutRedirect(returnUrl);
2048
+ trackFallbackCheckout(skuId);
2049
+ window.location.href = redirectToCheckoutFallback({
2050
+ skuId,
2051
+ country,
2052
+ ...options
2053
+ });
2054
+ }
2055
+ var ERROR_HANDLERS = {
2056
+ // emailError flows as an inline field error on the email input.
2057
+ // email pre-populates the input so the user doesn't have to retype it.
2058
+ EMAIL_COLLISION: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
2059
+ emailError: walletError.message,
2060
+ email: validatedEmail
2061
+ }),
2062
+ PAYMENT_DECLINED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
2063
+ ELIGIBILITY_REJECTED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
2064
+ REGISTRATION_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
2065
+ ACCOUNT_CREATION_FAILED: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
2066
+ emailError: walletError.message,
2067
+ email: validatedEmail
2068
+ }),
2069
+ VALIDATION_ERROR: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
2070
+ RECAPTCHA_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message })
2071
+ };
2072
+ function handleStructuredError(ctx) {
2073
+ const handler = ERROR_HANDLERS[ctx.walletError.errorType];
2074
+ if (handler) {
2075
+ handler(ctx);
2076
+ } else {
2077
+ redirectFallback(ctx.skuId, ctx.returnUrl, ctx.country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
2078
+ }
2079
+ }
2080
+ async function handlePaymentAuthorized(event, session, sessionData, config) {
2081
+ const { skuId, returnUrl, country } = config;
2082
+ let validatedEmail;
2083
+ try {
2084
+ validatedEmail = validateContacts(
2085
+ event,
2086
+ sessionData,
2087
+ config.supportedBillingCountries,
2088
+ config.delivery
2089
+ );
2090
+ const result = await performPurchase({
2091
+ applePayToken: event.payment.token,
2092
+ skuId: config.skuId,
2093
+ // Offer/geo country — must not fall back to billing country on the BFF (print billing is unrestricted).
2094
+ countryCode: config.country,
2095
+ currency: config.currency,
2096
+ billingContact: event.payment.billingContact,
2097
+ supportedBillingCountries: config.supportedBillingCountries,
2098
+ ...event.payment.shippingContact && {
2099
+ shippingContact: event.payment.shippingContact
2100
+ },
2101
+ ...config.delivery && {
2102
+ supportedDeliveryCountries: config.delivery.supportedCountries
2103
+ },
2104
+ ...ADDRESS_PARITY_ENABLED ? { strictAddressRules: true } : {},
2105
+ recaptchaToken: config.recaptchaToken
2106
+ });
2107
+ trackWalletPaymentSuccess(skuId, result.basketId);
2108
+ session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
2109
+ const successEmail = sessionData.loggedIn ? sessionData.emailAddress : validatedEmail;
2110
+ const userStatus = sessionData.loggedIn ? "lex" : "nex";
2111
+ writeCheckoutRedirect(returnUrl);
2112
+ window.location.href = redirectToCheckoutComplete({
2113
+ basketId: result.basketId,
2114
+ status: userStatus,
2115
+ skuId: decodeSku(skuId),
2116
+ email: successEmail,
2117
+ country
2118
+ });
2119
+ } catch (err) {
2120
+ if (err instanceof ContactValidationError) {
2121
+ failApplePaySession(session, err.errors);
2122
+ return;
2123
+ }
2124
+ const walletError = parseWalletApiError(err);
2125
+ trackWalletPaymentFailure(skuId, walletError?.errorType ?? "UNKNOWN");
2126
+ failApplePaySession(session);
2127
+ if (!walletError) {
2128
+ redirectFallback(skuId, returnUrl, country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
2129
+ return;
2130
+ }
2131
+ handleStructuredError({ skuId, returnUrl, country, validatedEmail, walletError });
2132
+ }
2133
+ }
2134
+
1935
2135
  // src/data/eea-countries.json
1936
2136
  var eea_countries_default = [
1937
2137
  "AT",
@@ -1968,13 +2168,18 @@ var eea_countries_default = [
1968
2168
  "SE"
1969
2169
  ];
1970
2170
 
2171
+ // src/utils/print-variants.ts
2172
+ var PRINT_VARIANTS = [
2173
+ "bundle",
2174
+ "insider_print"
2175
+ ];
2176
+ var isPrintVariant = (variant) => PRINT_VARIANTS.includes(variant ?? "");
2177
+
1971
2178
  // src/utils/billing-countries.ts
1972
- var priceZones = price_zones_default;
1973
2179
  var eeaCountries = eea_countries_default;
1974
2180
  var ALL_COUNTRY_CODES = Object.values(priceZones).flat();
1975
- var getZoneByCountry = (country) => Object.keys(priceZones).find((key) => priceZones[key].includes(country)) ?? null;
1976
2181
  var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1977
- if (offerVariant === "bundle" || offerVariant === "insider_print") {
2182
+ if (isPrintVariant(offerVariant)) {
1978
2183
  return [...ALL_COUNTRY_CODES];
1979
2184
  }
1980
2185
  const zone = getZoneByCountry(offerCountry);
@@ -1988,45 +2193,124 @@ var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1988
2193
  return [...zoneCountries];
1989
2194
  };
1990
2195
 
1991
- // src/utils/getExperimentKeyFromNextData.ts
1992
- var getExperimentKeyFromNextData = (flagKey) => {
1993
- const experiments = window.__NEXT_DATA__?.props?.pageProps?.experiments;
1994
- const experimentKey = experiments?.[flagKey]?.metadata?.experimentKey;
1995
- return typeof experimentKey === "string" ? experimentKey : void 0;
2196
+ // src/data/no-delivery-countries.json
2197
+ var no_delivery_countries_default = [
2198
+ "KH",
2199
+ "MM",
2200
+ "PK",
2201
+ "BI",
2202
+ "CV",
2203
+ "CF",
2204
+ "TD",
2205
+ "CG",
2206
+ "DJ",
2207
+ "EG",
2208
+ "GM",
2209
+ "GN",
2210
+ "GW",
2211
+ "LB",
2212
+ "LR",
2213
+ "LY",
2214
+ "ML",
2215
+ "MU",
2216
+ "RE",
2217
+ "SL",
2218
+ "AZ",
2219
+ "BY",
2220
+ "UA",
2221
+ "BM",
2222
+ "BO",
2223
+ "KY",
2224
+ "EC",
2225
+ "HN",
2226
+ "PA",
2227
+ "PE",
2228
+ "UY"
2229
+ ];
2230
+
2231
+ // src/utils/delivery-countries.ts
2232
+ var priceZones2 = price_zones_default;
2233
+ var noDeliveryCountries = no_delivery_countries_default;
2234
+ var getSupportedDeliveryCountries = (offerCountry) => {
2235
+ const zone = Object.keys(priceZones2).find(
2236
+ (key) => priceZones2[key].includes(offerCountry)
2237
+ );
2238
+ if (!zone) return [];
2239
+ return priceZones2[zone].filter(
2240
+ (country) => !noDeliveryCountries.includes(country)
2241
+ );
1996
2242
  };
1997
2243
 
2244
+ // src/utils/printOffersFlag.ts
2245
+ var PRINT_OFFERS_ENABLED = true;
2246
+
2247
+ // src/utils/buttonCopyFlag.ts
2248
+ var CONTINUE_WITH_COPY_ENABLED = true;
2249
+ var BUTTON_COPY = {
2250
+ subscribe: { caption: "Subscribe with", label: "Subscribe with Apple Pay" },
2251
+ continue: { caption: "Continue with", label: "Continue with Apple Pay" }
2252
+ };
2253
+ var getButtonCopy = (enabled = CONTINUE_WITH_COPY_ENABLED) => enabled ? BUTTON_COPY.continue : BUTTON_COPY.subscribe;
2254
+
1998
2255
  // src/utils/applePayExpressEligibility.ts
1999
- var isEligibleForApplePayExpressPaywallExperiment = () => isAppleDeviceOrSafari();
2256
+ var isEligibleForApplePayExpressPaywall = () => isAppleDeviceOrSafari();
2000
2257
 
2001
2258
  // src/apple-pay-button.ts
2259
+ var PRINT_VARIANTS2 = ["bundle", "insider_print"];
2260
+ var NO_EXCLUSIONS = [];
2002
2261
  var ENTRY_POINT_CONFIG = {
2003
2262
  ["dual_offer_banner" /* DUAL_OFFER_BANNER */]: {
2004
- isEligible: () => true
2005
- // no experimentFlagKey → always-on after offer exclusions
2263
+ isEligible: () => true,
2264
+ returnUrl: "current_page" /* CURRENT_PAGE */,
2265
+ allowsPrintOffers: false
2006
2266
  },
2007
2267
  ["free_trial_banner" /* FREE_TRIAL_BANNER */]: {
2008
- isEligible: () => true
2009
- // Dual parity — no experimentFlagKey, no homepage gate here
2268
+ isEligible: () => true,
2269
+ returnUrl: "current_page" /* CURRENT_PAGE */,
2270
+ allowsPrintOffers: false
2010
2271
  },
2011
2272
  ["article_paywall" /* PAYWALL */]: {
2012
- isEligible: isEligibleForApplePayExpressPaywallExperiment,
2013
- experimentFlagKey: APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY
2273
+ isEligible: isEligibleForApplePayExpressPaywall,
2274
+ returnUrl: "current_page" /* CURRENT_PAGE */,
2275
+ allowsPrintOffers: false
2014
2276
  },
2015
2277
  ["article_regwall" /* REGWALL */]: {
2016
2278
  isEligible: () => true,
2017
- enabled: false
2279
+ enabled: false,
2280
+ returnUrl: "current_page" /* CURRENT_PAGE */,
2281
+ allowsPrintOffers: false
2282
+ },
2283
+ ["free_trial_popup" /* FREE_TRIAL_POPUP */]: {
2284
+ isEligible: () => true,
2285
+ returnUrl: "current_page" /* CURRENT_PAGE */,
2286
+ allowsPrintOffers: false
2287
+ },
2288
+ ["subscribe" /* SUBSCRIBE */]: {
2289
+ isEligible: () => true,
2290
+ // Always-on after offer exclusions — host (sma-checkout) owns rollout toggle
2291
+ // The offers page is not a place to return to: the host keeps the article the user arrived from (or home).
2292
+ returnUrl: "host_managed" /* HOST_MANAGED */,
2293
+ allowsPrintOffers: true
2294
+ },
2295
+ ["sales_page" /* SALES_PAGE */]: {
2296
+ isEligible: () => true,
2297
+ // Host-owned page (sma-checkout), like /subscribe: the host keeps the user's return target.
2298
+ returnUrl: "host_managed" /* HOST_MANAGED */,
2299
+ // Print stays off until a sales page needs it; flip to true (and QA) to take print there.
2300
+ allowsPrintOffers: false
2018
2301
  }
2019
2302
  };
2020
- var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
2303
+ var DEFAULT_ENTRY_POINT = "dual_offer_banner" /* DUAL_OFFER_BANNER */;
2021
2304
  var TOTAL_LABEL = "The Economist";
2022
2305
  var DEFAULT_CURRENCY = "USD";
2023
2306
  var DEFAULT_TOTAL = "0.00";
2024
2307
  var SEL_CONTAINER = ".apple-pay-container";
2025
2308
  var SEL_BUTTON = ".apple-pay-btn";
2026
- var APPLE_PAY_EXCLUDED_VARIANTS = [
2027
- "bundle",
2028
- "insider_print"
2029
- ];
2309
+ var APPLE_PAY_EXCLUDED_VARIANTS = PRINT_VARIANTS2;
2310
+ var getExcludedVariants = (entryPoint) => {
2311
+ const config = ENTRY_POINT_CONFIG[entryPoint || DEFAULT_ENTRY_POINT] ?? ENTRY_POINT_CONFIG[DEFAULT_ENTRY_POINT];
2312
+ return PRINT_OFFERS_ENABLED && config.allowsPrintOffers ? NO_EXCLUSIONS : PRINT_VARIANTS2;
2313
+ };
2030
2314
  var ApplePayButton = class _ApplePayButton extends HTMLElement {
2031
2315
  static tag = "teg-apple-pay-button";
2032
2316
  static define() {
@@ -2036,26 +2320,18 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2036
2320
  * Creates and configures an ApplePayButton when the entry point allows it.
2037
2321
  *
2038
2322
  * - `DUAL_OFFER_BANNER` (or omitted): always-on after offer exclusions —
2039
- * no homepage/Safari gate here, no banners experiment read, and no banners
2040
- * `$exposure`.
2323
+ * no homepage/Safari gate here. Safari/Apple is enforced later by
2324
+ * `isApplePayAvailable()` on mount.
2041
2325
  * - `FREE_TRIAL_BANNER`: same always-on-after-exclusions gate as Dual; distinct
2042
2326
  * TEDL `entry_point` string (`free_trial_banner`) for wallet impression attribution.
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.
2327
+ * - `FREE_TRIAL_POPUP`: same always-on-after-exclusions gate. Distinct TEDL
2328
+ * `entry_point` (`free_trial_popup`).
2329
+ * - `PAYWALL`: always-on after offer exclusions + Safari/Apple placement
2330
+ * eligibility. No Amplitude experiment / `$exposure`.
2046
2331
  * - `REGWALL`: inert — always returns null.
2047
2332
  *
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 there is no
2051
- * experiment gate; `BYPASS_APPLE_PAY_CHECKS` only skips device checks in
2052
- * `isApplePayAvailable()` on mount.
2053
- *
2054
- * **Eligibility:**
2055
- * - `DUAL_OFFER_BANNER` / `FREE_TRIAL_BANNER` (or omitted): always eligible at
2056
- * this gate (homepage placement is host-owned; Safari/Apple is enforced
2057
- * later by `isApplePayAvailable()` on mount)
2058
- * - `PAYWALL`: Safari/Apple device only (no homepage) — article paywalls
2333
+ * `BYPASS_APPLE_PAY_CHECKS` skips placement eligibility here and device checks
2334
+ * in `isApplePayAvailable()` on mount (QA on non-Apple browsers).
2059
2335
  *
2060
2336
  * @param offer - The offer to display in the Apple Pay flow.
2061
2337
  * @param country - The user's country code.
@@ -2065,44 +2341,22 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2065
2341
  if (!offer) {
2066
2342
  return null;
2067
2343
  }
2068
- if (APPLE_PAY_EXCLUDED_VARIANTS.includes(offer.product?.variant)) {
2069
- return null;
2070
- }
2071
- const hasUrlParamFlag = new URLSearchParams(window.location.search).has(
2072
- FEATURE_APPLE_PAY_EXPRESS_CHECKOUT
2073
- );
2074
- const resolvedEntryPoint = entryPoint || "dual_offer_banner" /* DUAL_OFFER_BANNER */;
2344
+ const resolvedEntryPoint = entryPoint || DEFAULT_ENTRY_POINT;
2075
2345
  const config = ENTRY_POINT_CONFIG[resolvedEntryPoint];
2076
2346
  if (!config) {
2077
2347
  return null;
2078
2348
  }
2079
- const { isEligible: eligibilityCheck, experimentFlagKey } = config;
2349
+ if (getExcludedVariants(resolvedEntryPoint).includes(offer.product?.variant)) {
2350
+ return null;
2351
+ }
2352
+ const { isEligible: eligibilityCheck } = config;
2080
2353
  const isEligible = eligibilityCheck();
2081
2354
  if (config.enabled === false) {
2082
2355
  return null;
2083
2356
  }
2084
- if (!hasUrlParamFlag && !bypassApplePayChecks() && !isEligible) {
2357
+ if (!bypassApplePayChecks() && !isEligible) {
2085
2358
  return null;
2086
2359
  }
2087
- if (experimentFlagKey) {
2088
- const experimentValue = window.experimentIntegration?.getVariant?.(experimentFlagKey);
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
2360
  _ApplePayButton.define();
2107
2361
  const button = document.createElement(_ApplePayButton.tag);
2108
2362
  button.offer = offer;
@@ -2128,8 +2382,13 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2128
2382
  #readyPromise = null;
2129
2383
  #sessionData = null;
2130
2384
  #paymentOptions = null;
2385
+ /** URL of the page the button is on (sent to payment options). */
2131
2386
  #returnUrl = "";
2387
+ /** `checkout-redirect` to persist after purchase, per the entry point's `ReturnUrlPolicy`; `null` = leave it. */
2388
+ #checkoutRedirectUrl = null;
2132
2389
  #supportedBillingCountries = [];
2390
+ /** Print (bundle) offers only: countries the offer can be delivered to; `null` for offers without delivery. */
2391
+ #supportedDeliveryCountries = null;
2133
2392
  #entryPoint = "";
2134
2393
  // ─── Public API ─────────────────────────────────────────────────────────────
2135
2394
  get offer() {
@@ -2194,33 +2453,52 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2194
2453
  this.#sessionData = null;
2195
2454
  this.#paymentOptions = null;
2196
2455
  this.#returnUrl = "";
2456
+ this.#checkoutRedirectUrl = null;
2197
2457
  this.#supportedBillingCountries = [];
2458
+ this.#supportedDeliveryCountries = null;
2198
2459
  this.querySelector(SEL_CONTAINER)?.remove();
2199
2460
  }
2200
2461
  // ─── Render pipeline ────────────────────────────────────────────────────────
2201
2462
  async #run() {
2202
2463
  try {
2203
2464
  this.#renderTemplate();
2465
+ this.#captureReturnUrl();
2466
+ const requests = this.#startWalletRequests();
2204
2467
  if (await this.#checkAvailability()) return;
2205
2468
  if (this.#checkOffer()) return;
2206
- if (await this.#checkSession()) return;
2207
- this.#captureReturnUrl();
2208
2469
  this.#computeBillingCountries();
2209
- if (await this.#fetchAndCacheOptions()) return;
2470
+ if (this.#computeDeliveryCountries()) return;
2471
+ const [session, options] = await requests;
2472
+ if (this.#applySession(session)) return;
2473
+ if (this.#applyPaymentOptions(options)) return;
2210
2474
  this.#finishLoading();
2211
2475
  } catch {
2212
- this.style.display = "none";
2213
- this.querySelector(SEL_CONTAINER)?.remove();
2476
+ this.#hide();
2214
2477
  } finally {
2215
2478
  this.#rendering = false;
2216
2479
  }
2217
2480
  }
2481
+ /**
2482
+ * Stop the loading spinner before tear-down so Safari does not leave a GPU
2483
+ * ghost of `.apple-pay-btn.wap-loading::before` after the container is removed.
2484
+ */
2485
+ #hide() {
2486
+ const button = this.querySelector(SEL_BUTTON);
2487
+ if (button) {
2488
+ button.classList.remove("wap-loading");
2489
+ button.removeAttribute("aria-busy");
2490
+ button.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
2491
+ }
2492
+ this.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
2493
+ void this.offsetHeight;
2494
+ this.style.display = "none";
2495
+ this.querySelector(SEL_CONTAINER)?.remove();
2496
+ }
2218
2497
  /** Returns `true` (hide) when Apple Pay is unavailable on this device/browser. */
2219
2498
  async #checkAvailability() {
2220
2499
  const available = await isApplePayAvailable();
2221
2500
  if (!available) {
2222
- this.style.display = "none";
2223
- this.querySelector(SEL_CONTAINER)?.remove();
2501
+ this.#hide();
2224
2502
  return true;
2225
2503
  }
2226
2504
  return false;
@@ -2229,11 +2507,17 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2229
2507
  * Returns `true` (hide) when the user already has an active subscription or is B2B.
2230
2508
  * Session fetch errors are swallowed — the component continues as an anonymous user.
2231
2509
  */
2232
- async #checkSession() {
2233
- this.#sessionData = await this.#fetchSession();
2510
+ /** Starts the session and payment-options calls together (neither depends on the other). */
2511
+ #startWalletRequests() {
2512
+ if (!this.#offer || !isApplePayCapable()) {
2513
+ return Promise.resolve([null, null]);
2514
+ }
2515
+ return Promise.all([this.#fetchSession(), this.#fetchPaymentOptions()]);
2516
+ }
2517
+ #applySession(session) {
2518
+ this.#sessionData = session;
2234
2519
  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();
2520
+ this.#hide();
2237
2521
  return true;
2238
2522
  }
2239
2523
  return false;
@@ -2241,8 +2525,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2241
2525
  /** Returns `true` (hide) when no offer has been set before mount. */
2242
2526
  #checkOffer() {
2243
2527
  if (!this.#offer) {
2244
- this.style.display = "none";
2245
- this.querySelector(SEL_CONTAINER)?.remove();
2528
+ this.#hide();
2246
2529
  return true;
2247
2530
  }
2248
2531
  return false;
@@ -2250,6 +2533,11 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2250
2533
  /** Captures the current page URL once at mount for reuse across the session lifetime. */
2251
2534
  #captureReturnUrl() {
2252
2535
  this.#returnUrl = captureOriginUrl();
2536
+ const config = ENTRY_POINT_CONFIG[this.#entryPoint || DEFAULT_ENTRY_POINT] ?? ENTRY_POINT_CONFIG[DEFAULT_ENTRY_POINT];
2537
+ this.#checkoutRedirectUrl = resolveCheckoutRedirectUrl(
2538
+ config.returnUrl,
2539
+ this.#returnUrl
2540
+ );
2253
2541
  }
2254
2542
  /**
2255
2543
  * Computes supported billing countries once at mount.
@@ -2262,15 +2550,32 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2262
2550
  this.#offer.product?.variant ?? ""
2263
2551
  );
2264
2552
  }
2553
+ /**
2554
+ * Print (bundle) offers need a delivery address, which the Apple Pay sheet collects. Returns `true` (hide)
2555
+ * when the offer has no country it can be delivered to, because no valid address could ever be entered.
2556
+ */
2557
+ #computeDeliveryCountries() {
2558
+ const variant = this.#offer.product?.variant;
2559
+ if (!PRINT_VARIANTS2.includes(variant)) {
2560
+ this.#supportedDeliveryCountries = null;
2561
+ return false;
2562
+ }
2563
+ const countries = getSupportedDeliveryCountries(this.#country);
2564
+ if (countries.length === 0) {
2565
+ this.#hide();
2566
+ return true;
2567
+ }
2568
+ this.#supportedDeliveryCountries = countries;
2569
+ return false;
2570
+ }
2265
2571
  /**
2266
2572
  * Returns `true` (hide) when the wallet BFF reports Apple Pay is unavailable
2267
2573
  * for this offer. The response is cached and reused in `#initiateApplePay`.
2268
2574
  */
2269
- async #fetchAndCacheOptions() {
2270
- this.#paymentOptions = await this.#fetchPaymentOptions();
2575
+ #applyPaymentOptions(options) {
2576
+ this.#paymentOptions = options;
2271
2577
  if (!this.#paymentOptions?.options?.apple_pay) {
2272
- this.style.display = "none";
2273
- this.querySelector(SEL_CONTAINER)?.remove();
2578
+ this.#hide();
2274
2579
  return true;
2275
2580
  }
2276
2581
  return false;
@@ -2278,11 +2583,14 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2278
2583
  /** Injects the button template and wires click and confirm event listeners. */
2279
2584
  #renderTemplate() {
2280
2585
  this.style.removeProperty("display");
2281
- ensureApplePayLogoSymbol();
2282
2586
  const template = document.createElement("template");
2283
2587
  template.innerHTML = apple_pay_button_template_default;
2284
2588
  this.appendChild(template.content.cloneNode(true));
2285
2589
  const button = this.querySelector(SEL_BUTTON);
2590
+ const { caption, label } = getButtonCopy();
2591
+ this.querySelector(SEL_CONTAINER)?.setAttribute("aria-label", label);
2592
+ button.setAttribute("aria-label", label);
2593
+ this.querySelector(".apple-pay-btn__caption").textContent = caption;
2286
2594
  button.classList.add("wap-loading");
2287
2595
  button.setAttribute("disabled", "");
2288
2596
  button.setAttribute("aria-disabled", "true");
@@ -2370,16 +2678,25 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2370
2678
  totalAmount,
2371
2679
  totalLabel: TOTAL_LABEL,
2372
2680
  skuId,
2373
- returnUrl: this.#returnUrl,
2681
+ returnUrl: this.#checkoutRedirectUrl,
2374
2682
  userLoggedIn: sessionData.loggedIn,
2683
+ ...this.#supportedDeliveryCountries && {
2684
+ delivery: { supportedCountries: this.#supportedDeliveryCountries }
2685
+ },
2375
2686
  onPaymentAuthorized: async (event, session) => {
2376
2687
  const recaptchaToken = await recaptchaTokenPromise;
2377
2688
  return handlePaymentAuthorized(event, session, sessionData, {
2378
2689
  skuId,
2379
2690
  country,
2380
2691
  currency: offer.price?.currency_code ?? DEFAULT_CURRENCY,
2381
- returnUrl: this.#returnUrl,
2692
+ returnUrl: this.#checkoutRedirectUrl,
2382
2693
  supportedBillingCountries: this.#supportedBillingCountries,
2694
+ ...this.#supportedDeliveryCountries && {
2695
+ delivery: {
2696
+ offerCountry: country,
2697
+ supportedCountries: this.#supportedDeliveryCountries
2698
+ }
2699
+ },
2383
2700
  recaptchaToken
2384
2701
  });
2385
2702
  }
@@ -2403,7 +2720,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2403
2720
  );
2404
2721
  } catch {
2405
2722
  redirectToFallbackCheckout({
2406
- returnUrl: this.#returnUrl,
2723
+ returnUrl: this.#checkoutRedirectUrl,
2407
2724
  skuId,
2408
2725
  countryCode: country
2409
2726
  });
@@ -2412,5 +2729,6 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2412
2729
  };
2413
2730
  export {
2414
2731
  APPLE_PAY_EXCLUDED_VARIANTS,
2415
- ApplePayButton
2732
+ ApplePayButton,
2733
+ getExcludedVariants
2416
2734
  };