@economist/web-apple-pay 1.7.6 → 1.7.8

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.
@@ -71,7 +71,7 @@ function ensureApplePayLogoSymbol() {
71
71
  return;
72
72
  }
73
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="white"/></symbol></defs></svg>`;
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
75
  document.body.prepend(tmp.firstElementChild);
76
76
  }
77
77
 
@@ -109,16 +109,32 @@ var apple_pay_modal_template_default = `<style>
109
109
  position: absolute;
110
110
  top: 1.5rem;
111
111
  right: 1.3125rem;
112
- background: none;
112
+ background: transparent;
113
113
  border: none;
114
114
  cursor: pointer;
115
115
  padding: 0;
116
+ width: 1.5rem;
117
+ height: 1.5rem;
116
118
  display: flex;
117
119
  align-items: center;
118
120
  justify-content: center;
121
+ color: var(--mb-colour-greyscale-london-20, #1a1a1a);
122
+ transition:
123
+ background-color ease-in-out 0.2s,
124
+ color ease-in-out 0.2s;
125
+ }
126
+
127
+ .apm__close:hover {
128
+ color: var(--mb-colour-base-chicago-30, #333333);
129
+ }
130
+
131
+ .apm__close:active {
132
+ background-color: var(--mb-colour-base-chicago-90, #e6e6e6);
133
+ color: var(--mb-colour-base-chicago-30, #333333);
119
134
  }
120
135
 
121
136
  .apm__close:focus {
137
+ background-color: var(--mb-colour-base-chicago-90, #e6e6e6);
122
138
  outline: solid 0.125rem var(--focus-border-color, #121212);
123
139
  border-radius: 0.25rem;
124
140
  }
@@ -301,10 +317,6 @@ var apple_pay_modal_template_default = `<style>
301
317
  cursor: pointer;
302
318
  color: #fff;
303
319
  text-align: center;
304
- font-family: var(
305
- --mb-typeface-sans,
306
- var(--wall-type-system-sans, system-ui, sans-serif)
307
- );
308
320
  font-size: 1.25rem;
309
321
  font-style: normal;
310
322
  font-weight: 500;
@@ -421,7 +433,7 @@ var apple_pay_modal_template_default = `<style>
421
433
  fill-rule="evenodd"
422
434
  clip-rule="evenodd"
423
435
  d="M18.75 6.60964L17.3904 5.25L12 10.6404L6.60964 5.25L5.25 6.60964L10.6404 12L5.25 17.3904L6.60964 18.75L12 13.3596L17.3904 18.75L18.75 17.3904L13.3596 12L18.75 6.60964Z"
424
- fill="#333333"
436
+ fill="currentColor"
425
437
  />
426
438
  </g>
427
439
  <defs>
@@ -687,6 +699,8 @@ function renewalPeriodText(unit, duration) {
687
699
  return "";
688
700
  }
689
701
  }
702
+ var LI_SEPARATOR = "\0LI_SEP\0";
703
+ var P_SEPARATOR = "\0P_SEP\0";
690
704
  function buildTermsContext(offer, country) {
691
705
  const isUS = country === "US";
692
706
  const isCA = country === "CA";
@@ -723,19 +737,19 @@ function freeTrialTerms(offer, ctx) {
723
737
  const trialDuration = offer.subscription_options?.trial_period?.duration ?? 1;
724
738
  const trialDateStr = `on ${getRenewalDateText(trialUnit, trialDuration)}${ctx.verificationText}`;
725
739
  if (ctx.isUS) {
726
- return `Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${trialDateStr} when your free trial ends, until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}`;
740
+ return `Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${trialDateStr} when your free trial ends, until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}`;
727
741
  }
728
- return `Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${trialDateStr} when your free trial ends, until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
742
+ return `Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${trialDateStr} when your free trial ends, until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
729
743
  }
730
744
  function nytTerms(ctx) {
731
745
  const nytAccessText = "Your complimentary access to The New York Times is for one year only and does not auto-renew. We will send your instructions on how to redeem access to The New York Times by email.";
732
746
  if (ctx.isUS) {
733
- return `Your subscription to <em>The Economist</em> auto-renews ${ctx.periodText} until cancelled{{liSeparator}}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.renewalDateStr}{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}{{pSeparator}}${nytAccessText}`;
747
+ return `Your subscription to <em>The Economist</em> auto-renews ${ctx.periodText} until cancelled${LI_SEPARATOR}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.renewalDateStr}${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}${P_SEPARATOR}${nytAccessText}`;
734
748
  }
735
749
  if (ctx.isCA) {
736
- return `Your subscription to <em>The Economist</em> auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled.{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}{{pSeparator}}${nytAccessText}`;
750
+ return `Your subscription to <em>The Economist</em> auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled.${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}${P_SEPARATOR}${nytAccessText}`;
737
751
  }
738
- return `Your subscription to <em>The Economist</em> auto-renews at ${ctx.renewalPriceText} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime} ${nytAccessText}`;
752
+ return `Your subscription to <em>The Economist</em> auto-renews at ${ctx.renewalPriceText} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime} ${nytAccessText}`;
739
753
  }
740
754
  function minTermContractTerms(offer, ctx) {
741
755
  const duePrice = formatPrice(offer.price.purchase, offer.price.currency_code);
@@ -745,28 +759,28 @@ function minTermContractTerms(offer, ctx) {
745
759
  const contractLength = mtDuration && mtUnit ? `${mtDuration} ${mtUnit}` : "";
746
760
  const initialContractText = contractLength ? `your initial ${contractLength} contract` : "your initial contract";
747
761
  const mtRenewalDateText = mtUnit && mtDuration ? getRenewalDateText(mtUnit, Number(mtDuration)) : ctx.renewalDateText;
748
- return `You\u2019ll be charged ${duePrice} a month for the duration of ${initialContractText}{{liSeparator}}Your subscription auto-renews annually at ${ctx.renewalPriceText} a month on ${mtRenewalDateText} until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}`;
762
+ return `You\u2019ll be charged ${duePrice} a month for the duration of ${initialContractText}${LI_SEPARATOR}Your subscription auto-renews annually at ${ctx.renewalPriceText} a month on ${mtRenewalDateText} until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}`;
749
763
  }
750
764
  function paidTrialTerms(offer, ctx) {
751
765
  const trialUnit = offer.subscription_options?.trial_period?.unit ?? ctx.unit;
752
766
  const trialDuration = offer.subscription_options?.trial_period?.duration ?? ctx.duration;
753
767
  const trialDateText = getRenewalDateText(trialUnit, trialDuration);
754
768
  if (ctx.isUS) {
755
- return `Your subscription auto-renews ${ctx.periodText} until cancelled{{liSeparator}}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} on ${trialDateText} when your paid trial ends{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.usCancelNote}${ctx.taxFootnote}`;
769
+ return `Your subscription auto-renews ${ctx.periodText} until cancelled${LI_SEPARATOR}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} on ${trialDateText} when your paid trial ends${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.usCancelNote}${ctx.taxFootnote}`;
756
770
  }
757
- return `Your subscription auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} on ${trialDateText} when your paid trial ends, until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
771
+ return `Your subscription auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} on ${trialDateText} when your paid trial ends, until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
758
772
  }
759
773
  function autoRenewalTerms(ctx) {
760
774
  if (ctx.isUS) {
761
- return `Your subscription auto-renews ${ctx.periodText} until cancelled{{liSeparator}}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.renewalDateStr}{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}`;
775
+ return `Your subscription auto-renews ${ctx.periodText} until cancelled${LI_SEPARATOR}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.renewalDateStr}${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}`;
762
776
  }
763
- return `Your subscription auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
777
+ return `Your subscription auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
764
778
  }
765
779
  function noAutoRenewalTerms(ctx) {
766
780
  if (ctx.isUS || ctx.isCA) {
767
- return `Your subscription does not renew automatically${ctx.taxFootnote}{{liSeparator}}`;
781
+ return `Your subscription does not renew automatically${ctx.taxFootnote}${LI_SEPARATOR}`;
768
782
  }
769
- return `Your subscription does not renew automatically{{liSeparator}}`;
783
+ return `Your subscription does not renew automatically${LI_SEPARATOR}`;
770
784
  }
771
785
  function generateApplePayModalTerms(offer, country) {
772
786
  const ctx = buildTermsContext(offer, country);
@@ -789,9 +803,9 @@ function generateApplePayModalTerms(offer, country) {
789
803
  return noAutoRenewalTerms(ctx);
790
804
  }
791
805
  function renderTermsHtml(termsText) {
792
- const renewalTextLists = termsText.split("{{liSeparator}}");
806
+ const renewalTextLists = termsText.split(LI_SEPARATOR);
793
807
  const lastPart = renewalTextLists.pop() || "";
794
- const renewalTextParagraphs = lastPart.split("{{pSeparator}}");
808
+ const renewalTextParagraphs = lastPart.split(P_SEPARATOR);
795
809
  const ulHtml = `<ul class="apm__terms-bullets">${renewalTextLists.map((value) => `<li>${value}</li>`).join("")}</ul>`;
796
810
  const paragraphHtml = renewalTextParagraphs.filter(Boolean).map((value) => `<p class="apm__terms-legal">${value}</p>`).join("");
797
811
  return ulHtml + paragraphHtml;
@@ -945,7 +959,6 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
945
959
  cta.removeAttribute("aria-busy");
946
960
  }
947
961
  }).catch(() => {
948
- console.error("[web-apple-pay] apple-pay-modal: failed to pre-fetch reCAPTCHA tokens; CTA remains disabled");
949
962
  if (cta) {
950
963
  cta.removeAttribute("aria-busy");
951
964
  }
@@ -1034,8 +1047,8 @@ var apple_pay_button_template_default = `<style>
1034
1047
  min-width: 0;
1035
1048
  height: 100%;
1036
1049
  min-height: var(--apple-pay-height, 2.75rem);
1037
- background-color: #000;
1038
- color: #fff;
1050
+ background-color: var(--apple-pay-background-color, #000);
1051
+ color: var(--apple-pay-foreground-color, #fff);
1039
1052
  border: none;
1040
1053
  border-radius: var(--apple-pay-border-radius, 1.375rem);
1041
1054
  cursor: pointer;
@@ -1047,6 +1060,7 @@ var apple_pay_button_template_default = `<style>
1047
1060
  teg-apple-pay-button .apple-pay-btn svg {
1048
1061
  flex-shrink: 0;
1049
1062
  display: block;
1063
+ color: currentColor;
1050
1064
  }
1051
1065
 
1052
1066
  teg-apple-pay-button .apple-pay-btn.wap-loading {
@@ -1061,8 +1075,8 @@ var apple_pay_button_template_default = `<style>
1061
1075
  left: 50%;
1062
1076
  width: 1.25rem;
1063
1077
  height: 1.25rem;
1064
- border: 2px solid rgba(255, 255, 255, 0.25);
1065
- border-top-color: #fff;
1078
+ border: 2px solid var(--apple-pay-spinner-track-color, rgba(255, 255, 255, 0.25));
1079
+ border-top-color: var(--apple-pay-spinner-head-color, currentColor);
1066
1080
  border-radius: 50%;
1067
1081
  animation: wap-button-spinner 0.8s linear infinite;
1068
1082
  }
@@ -1130,15 +1144,11 @@ var isApplePayAvailable = async () => {
1130
1144
  }
1131
1145
  const merchantId = getApplePayConfig()?.merchantId;
1132
1146
  if (!merchantId) {
1133
- console.warn(
1134
- "[web-apple-pay] Missing merchantId. Call configureApplePay({ merchantId, ... }) before rendering Apple Pay components."
1135
- );
1136
1147
  return false;
1137
1148
  }
1138
1149
  const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
1139
1150
  return hasActiveCard;
1140
- } catch (error) {
1141
- console.error("Error checking Apple Pay active card status:", error);
1151
+ } catch {
1142
1152
  return false;
1143
1153
  }
1144
1154
  };
@@ -1226,13 +1236,25 @@ var getExpressCheckoutSession = () => {
1226
1236
  };
1227
1237
 
1228
1238
  // src/utils/expressCheckoutRedirect.ts
1229
- var captureOriginUrl = () => window.location.href;
1230
- var buildQueryString = () => {
1231
- const countryCode = new URLSearchParams(window.location.search).get(
1232
- "country"
1233
- );
1234
- return countryCode ? `&country=${encodeURIComponent(countryCode)}` : "";
1239
+ var CHECKOUT_REDIRECT_KEY = "checkout-redirect";
1240
+ var ALLOWED_REDIRECT_HOSTNAME = "economist.com";
1241
+ function isAllowedRedirectUrl(url) {
1242
+ if (url.startsWith("/")) return !url.startsWith("//");
1243
+ try {
1244
+ const { hostname } = new URL(url);
1245
+ return hostname === ALLOWED_REDIRECT_HOSTNAME || hostname.endsWith(`.${ALLOWED_REDIRECT_HOSTNAME}`);
1246
+ } catch {
1247
+ return false;
1248
+ }
1249
+ }
1250
+ var writeCheckoutRedirect = (originUrl) => {
1251
+ if (!isAllowedRedirectUrl(originUrl)) return;
1252
+ try {
1253
+ localStorage.setItem(CHECKOUT_REDIRECT_KEY, originUrl);
1254
+ } catch {
1255
+ }
1235
1256
  };
1257
+ var captureOriginUrl = () => window.location.href;
1236
1258
  var decodeSku = (sku) => {
1237
1259
  try {
1238
1260
  return atob(sku.substring(sku.indexOf("-") + 1));
@@ -1243,14 +1265,11 @@ var decodeSku = (sku) => {
1243
1265
  var redirectToCheckoutComplete = (params) => {
1244
1266
  const url = new URL("/checkout/complete", window.location.origin);
1245
1267
  url.searchParams.set("basketId", params.basketId);
1246
- if (params.queryString) {
1247
- const qs = params.queryString.startsWith("?") ? params.queryString.slice(1) : params.queryString;
1248
- new URLSearchParams(qs).forEach((v, k) => url.searchParams.set(k, v));
1249
- }
1250
1268
  url.searchParams.set("lmo_offer", params.skuId);
1251
1269
  url.searchParams.set("status", params.status);
1252
1270
  url.searchParams.set("redirectToCheckout", "true");
1253
- url.searchParams.set("returnUrl", params.returnUrl);
1271
+ if (params.email) url.searchParams.set("email", params.email);
1272
+ if (params.country) url.searchParams.set("country", params.country);
1254
1273
  return url.pathname + url.search;
1255
1274
  };
1256
1275
  var redirectToCheckoutFallback = (params) => {
@@ -1261,7 +1280,7 @@ var redirectToCheckoutFallback = (params) => {
1261
1280
  url.searchParams.set("inlineError", params.inlineError);
1262
1281
  if (params.email) url.searchParams.set("email", params.email);
1263
1282
  if (params.emailError) url.searchParams.set("emailError", params.emailError);
1264
- url.searchParams.set("returnUrl", params.returnUrl);
1283
+ if (params.country) url.searchParams.set("country", params.country);
1265
1284
  return url.pathname + url.search;
1266
1285
  };
1267
1286
 
@@ -1345,17 +1364,16 @@ var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a
1345
1364
  var MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
1346
1365
  var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
1347
1366
  var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
1348
- var MSG_RECAPTCHA_VALIDATION_FAILED = "Security check failed. Please try again.";
1349
- var MSG_EMAIL_COLLISION = "This email address is already linked to an account. Please log in, or try a different email address.";
1350
1367
  var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
1351
1368
 
1352
1369
  // src/clients/payment-checkout/apple-session.ts
1353
1370
  function redirectToFallbackCheckout(config) {
1371
+ writeCheckoutRedirect(config.returnUrl);
1354
1372
  trackFallbackCheckout(config.skuId);
1355
1373
  window.location.href = redirectToCheckoutFallback({
1356
1374
  skuId: config.skuId,
1357
- returnUrl: config.returnUrl,
1358
- inlineError: MSG_PAYMENT_GENERIC_ERROR
1375
+ inlineError: MSG_PAYMENT_GENERIC_ERROR,
1376
+ country: config.countryCode
1359
1377
  });
1360
1378
  }
1361
1379
  async function handleMerchantValidation(event, session, config) {
@@ -1377,8 +1395,7 @@ async function handleMerchantValidation(event, session, config) {
1377
1395
  return;
1378
1396
  }
1379
1397
  session.completeMerchantValidation(response.merchantSession);
1380
- } catch (err) {
1381
- console.error("[web-apple-pay] onvalidatemerchant: error during validation", err);
1398
+ } catch {
1382
1399
  session.abort();
1383
1400
  redirectToFallbackCheckout(config);
1384
1401
  }
@@ -1411,8 +1428,7 @@ function startApplePaySession(config) {
1411
1428
  };
1412
1429
  trackWalletPaymentSheetOpen(config.skuId);
1413
1430
  session.begin();
1414
- } catch (err) {
1415
- console.error("[web-apple-pay] startApplePaySession: failed to create session", err);
1431
+ } catch {
1416
1432
  redirectToFallbackCheckout(config);
1417
1433
  }
1418
1434
  }
@@ -1534,8 +1550,6 @@ var shippingContactDetails = (shippingContact) => {
1534
1550
  };
1535
1551
 
1536
1552
  // src/clients/payment-checkout/payment-handler.ts
1537
- var MSG_ELIGIBILITY = "Something went wrong, please try again";
1538
- var MSG_REGISTRATION = "We couldn't create your account. Please enter your email or try a different login method.";
1539
1553
  var failApplePaySession = (session, errors = []) => {
1540
1554
  session.completePayment({
1541
1555
  status: ApplePaySession.STATUS_FAILURE,
@@ -1559,37 +1573,42 @@ function validateContacts(event, sessionData, supportedBillingCountries) {
1559
1573
  }
1560
1574
  return void 0;
1561
1575
  }
1562
- function redirectFallback(skuId, returnUrl, options) {
1576
+ function redirectFallback(skuId, returnUrl, country, options) {
1577
+ writeCheckoutRedirect(returnUrl);
1563
1578
  trackFallbackCheckout(skuId);
1564
1579
  window.location.href = redirectToCheckoutFallback({
1565
1580
  skuId,
1566
- returnUrl,
1581
+ country,
1567
1582
  ...options
1568
1583
  });
1569
1584
  }
1570
1585
  var ERROR_HANDLERS = {
1571
- EMAIL_COLLISION: ({ skuId, returnUrl, validatedEmail }) => redirectFallback(skuId, returnUrl, {
1572
- emailError: MSG_EMAIL_COLLISION,
1586
+ // emailError flows as an inline field error on the email input.
1587
+ // email pre-populates the input so the user doesn't have to retype it.
1588
+ EMAIL_COLLISION: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
1589
+ emailError: walletError.message,
1573
1590
  email: validatedEmail
1574
1591
  }),
1575
- PAYMENT_DECLINED: ({ skuId, returnUrl }) => (
1576
- // Matches sma-checkout catch-all: always redirect with generic inlineError.
1577
- redirectFallback(skuId, returnUrl, { inlineError: MSG_PAYMENT_GENERIC_ERROR })
1578
- ),
1579
- ELIGIBILITY_REJECTED: ({ skuId, returnUrl }) => redirectFallback(skuId, returnUrl, { inlineError: MSG_ELIGIBILITY }),
1580
- REGISTRATION_FAILED: ({ skuId, returnUrl }) => redirectFallback(skuId, returnUrl, { inlineError: MSG_REGISTRATION }),
1581
- VALIDATION_ERROR: ({ skuId, returnUrl }) => redirectFallback(skuId, returnUrl, { inlineError: MSG_RECAPTCHA_VALIDATION_FAILED })
1592
+ PAYMENT_DECLINED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1593
+ ELIGIBILITY_REJECTED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1594
+ REGISTRATION_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1595
+ ACCOUNT_CREATION_FAILED: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
1596
+ emailError: walletError.message,
1597
+ email: validatedEmail
1598
+ }),
1599
+ VALIDATION_ERROR: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1600
+ RECAPTCHA_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message })
1582
1601
  };
1583
1602
  function handleStructuredError(ctx) {
1584
1603
  const handler = ERROR_HANDLERS[ctx.walletError.errorType];
1585
1604
  if (handler) {
1586
1605
  handler(ctx);
1587
1606
  } else {
1588
- redirectFallback(ctx.skuId, ctx.returnUrl, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
1607
+ redirectFallback(ctx.skuId, ctx.returnUrl, ctx.country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
1589
1608
  }
1590
1609
  }
1591
1610
  async function handlePaymentAuthorized(event, session, sessionData, config) {
1592
- const { skuId, returnUrl, queryString } = config;
1611
+ const { skuId, returnUrl, country } = config;
1593
1612
  let validatedEmail;
1594
1613
  try {
1595
1614
  validatedEmail = validateContacts(
@@ -1609,28 +1628,29 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1609
1628
  });
1610
1629
  trackWalletPaymentSuccess(skuId, result.basketId);
1611
1630
  session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
1631
+ const successEmail = sessionData.loggedIn ? sessionData.emailAddress : validatedEmail;
1612
1632
  const userStatus = sessionData.loggedIn ? "lex" : "nex";
1633
+ writeCheckoutRedirect(returnUrl);
1613
1634
  window.location.href = redirectToCheckoutComplete({
1614
1635
  basketId: result.basketId,
1615
1636
  status: userStatus,
1616
1637
  skuId: decodeSku(skuId),
1617
- returnUrl,
1618
- queryString
1638
+ email: successEmail,
1639
+ country
1619
1640
  });
1620
1641
  } catch (err) {
1621
1642
  if (err instanceof ContactValidationError) {
1622
1643
  failApplePaySession(session, err.errors);
1623
1644
  return;
1624
1645
  }
1625
- console.error("[web-apple-pay] onpaymentauthorized error", { skuId, err });
1626
1646
  const walletError = parseWalletApiError(err);
1627
1647
  trackWalletPaymentFailure(skuId, walletError?.errorType ?? "UNKNOWN");
1628
1648
  failApplePaySession(session);
1629
1649
  if (!walletError) {
1630
- redirectFallback(skuId, returnUrl, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
1650
+ redirectFallback(skuId, returnUrl, country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
1631
1651
  return;
1632
1652
  }
1633
- handleStructuredError({ skuId, returnUrl, validatedEmail, walletError });
1653
+ handleStructuredError({ skuId, returnUrl, country, validatedEmail, walletError });
1634
1654
  }
1635
1655
  }
1636
1656
 
@@ -1900,7 +1920,6 @@ var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
1900
1920
  var TOTAL_LABEL = "The Economist";
1901
1921
  var DEFAULT_CURRENCY = "USD";
1902
1922
  var DEFAULT_TOTAL = "0.00";
1903
- var ERROR_INITIATE = "Failed to initiate Apple Pay session:";
1904
1923
  var SEL_CONTAINER = ".apple-pay-container";
1905
1924
  var SEL_BUTTON = ".apple-pay-btn";
1906
1925
  var APPLE_PAY_EXCLUDED_VARIANTS = [
@@ -2032,8 +2051,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2032
2051
  this.#computeBillingCountries();
2033
2052
  if (await this.#fetchAndCacheOptions()) return;
2034
2053
  this.#finishLoading();
2035
- } catch (err) {
2036
- console.error("[web-apple-pay] #run: unexpected error, hiding button", err);
2054
+ } catch {
2037
2055
  this.style.display = "none";
2038
2056
  this.querySelector(SEL_CONTAINER)?.remove();
2039
2057
  } finally {
@@ -2172,8 +2190,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2172
2190
  */
2173
2191
  #scheduleRecaptchaTokens() {
2174
2192
  const attempt = getPurchaseRecaptchaTokens();
2175
- attempt.catch((err) => {
2176
- console.error("[web-apple-pay] reCAPTCHA token pre-fetch failed; will retry on modal open", err);
2193
+ attempt.catch(() => {
2177
2194
  if (this.#recaptchaTokensPromise === attempt) {
2178
2195
  this.#recaptchaTokensPromise = null;
2179
2196
  }
@@ -2216,7 +2233,6 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2216
2233
  country,
2217
2234
  currency: offer.price?.currency_code ?? DEFAULT_CURRENCY,
2218
2235
  returnUrl: this.#returnUrl,
2219
- queryString: buildQueryString(),
2220
2236
  supportedBillingCountries: this.#supportedBillingCountries,
2221
2237
  recaptchaTokens
2222
2238
  })
@@ -2235,8 +2251,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2235
2251
  recaptchaTokens
2236
2252
  )
2237
2253
  );
2238
- } catch (error) {
2239
- console.error(ERROR_INITIATE, error);
2254
+ } catch {
2240
2255
  }
2241
2256
  }
2242
2257
  };
@@ -6,7 +6,7 @@ function ensureApplePayLogoSymbol() {
6
6
  return;
7
7
  }
8
8
  const tmp = document.createElement("div");
9
- 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="white"/></symbol></defs></svg>`;
9
+ 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>`;
10
10
  document.body.prepend(tmp.firstElementChild);
11
11
  }
12
12
  export {
@@ -71,7 +71,7 @@ function ensureApplePayLogoSymbol() {
71
71
  return;
72
72
  }
73
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="white"/></symbol></defs></svg>`;
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
75
  document.body.prepend(tmp.firstElementChild);
76
76
  }
77
77
 
@@ -109,16 +109,32 @@ var apple_pay_modal_template_default = `<style>
109
109
  position: absolute;
110
110
  top: 1.5rem;
111
111
  right: 1.3125rem;
112
- background: none;
112
+ background: transparent;
113
113
  border: none;
114
114
  cursor: pointer;
115
115
  padding: 0;
116
+ width: 1.5rem;
117
+ height: 1.5rem;
116
118
  display: flex;
117
119
  align-items: center;
118
120
  justify-content: center;
121
+ color: var(--mb-colour-greyscale-london-20, #1a1a1a);
122
+ transition:
123
+ background-color ease-in-out 0.2s,
124
+ color ease-in-out 0.2s;
125
+ }
126
+
127
+ .apm__close:hover {
128
+ color: var(--mb-colour-base-chicago-30, #333333);
129
+ }
130
+
131
+ .apm__close:active {
132
+ background-color: var(--mb-colour-base-chicago-90, #e6e6e6);
133
+ color: var(--mb-colour-base-chicago-30, #333333);
119
134
  }
120
135
 
121
136
  .apm__close:focus {
137
+ background-color: var(--mb-colour-base-chicago-90, #e6e6e6);
122
138
  outline: solid 0.125rem var(--focus-border-color, #121212);
123
139
  border-radius: 0.25rem;
124
140
  }
@@ -301,10 +317,6 @@ var apple_pay_modal_template_default = `<style>
301
317
  cursor: pointer;
302
318
  color: #fff;
303
319
  text-align: center;
304
- font-family: var(
305
- --mb-typeface-sans,
306
- var(--wall-type-system-sans, system-ui, sans-serif)
307
- );
308
320
  font-size: 1.25rem;
309
321
  font-style: normal;
310
322
  font-weight: 500;
@@ -421,7 +433,7 @@ var apple_pay_modal_template_default = `<style>
421
433
  fill-rule="evenodd"
422
434
  clip-rule="evenodd"
423
435
  d="M18.75 6.60964L17.3904 5.25L12 10.6404L6.60964 5.25L5.25 6.60964L10.6404 12L5.25 17.3904L6.60964 18.75L12 13.3596L17.3904 18.75L18.75 17.3904L13.3596 12L18.75 6.60964Z"
424
- fill="#333333"
436
+ fill="currentColor"
425
437
  />
426
438
  </g>
427
439
  <defs>
@@ -679,6 +691,8 @@ function renewalPeriodText(unit, duration) {
679
691
  return "";
680
692
  }
681
693
  }
694
+ var LI_SEPARATOR = "\0LI_SEP\0";
695
+ var P_SEPARATOR = "\0P_SEP\0";
682
696
  function buildTermsContext(offer, country) {
683
697
  const isUS = country === "US";
684
698
  const isCA = country === "CA";
@@ -715,19 +729,19 @@ function freeTrialTerms(offer, ctx) {
715
729
  const trialDuration = offer.subscription_options?.trial_period?.duration ?? 1;
716
730
  const trialDateStr = `on ${getRenewalDateText(trialUnit, trialDuration)}${ctx.verificationText}`;
717
731
  if (ctx.isUS) {
718
- return `Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${trialDateStr} when your free trial ends, until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}`;
732
+ return `Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${trialDateStr} when your free trial ends, until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}`;
719
733
  }
720
- return `Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${trialDateStr} when your free trial ends, until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
734
+ return `Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${trialDateStr} when your free trial ends, until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
721
735
  }
722
736
  function nytTerms(ctx) {
723
737
  const nytAccessText = "Your complimentary access to The New York Times is for one year only and does not auto-renew. We will send your instructions on how to redeem access to The New York Times by email.";
724
738
  if (ctx.isUS) {
725
- return `Your subscription to <em>The Economist</em> auto-renews ${ctx.periodText} until cancelled{{liSeparator}}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.renewalDateStr}{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}{{pSeparator}}${nytAccessText}`;
739
+ return `Your subscription to <em>The Economist</em> auto-renews ${ctx.periodText} until cancelled${LI_SEPARATOR}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.renewalDateStr}${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}${P_SEPARATOR}${nytAccessText}`;
726
740
  }
727
741
  if (ctx.isCA) {
728
- return `Your subscription to <em>The Economist</em> auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled.{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}{{pSeparator}}${nytAccessText}`;
742
+ return `Your subscription to <em>The Economist</em> auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled.${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}${P_SEPARATOR}${nytAccessText}`;
729
743
  }
730
- return `Your subscription to <em>The Economist</em> auto-renews at ${ctx.renewalPriceText} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime} ${nytAccessText}`;
744
+ return `Your subscription to <em>The Economist</em> auto-renews at ${ctx.renewalPriceText} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime} ${nytAccessText}`;
731
745
  }
732
746
  function minTermContractTerms(offer, ctx) {
733
747
  const duePrice = formatPrice(offer.price.purchase, offer.price.currency_code);
@@ -737,28 +751,28 @@ function minTermContractTerms(offer, ctx) {
737
751
  const contractLength = mtDuration && mtUnit ? `${mtDuration} ${mtUnit}` : "";
738
752
  const initialContractText = contractLength ? `your initial ${contractLength} contract` : "your initial contract";
739
753
  const mtRenewalDateText = mtUnit && mtDuration ? getRenewalDateText(mtUnit, Number(mtDuration)) : ctx.renewalDateText;
740
- return `You\u2019ll be charged ${duePrice} a month for the duration of ${initialContractText}{{liSeparator}}Your subscription auto-renews annually at ${ctx.renewalPriceText} a month on ${mtRenewalDateText} until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}`;
754
+ return `You\u2019ll be charged ${duePrice} a month for the duration of ${initialContractText}${LI_SEPARATOR}Your subscription auto-renews annually at ${ctx.renewalPriceText} a month on ${mtRenewalDateText} until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}`;
741
755
  }
742
756
  function paidTrialTerms(offer, ctx) {
743
757
  const trialUnit = offer.subscription_options?.trial_period?.unit ?? ctx.unit;
744
758
  const trialDuration = offer.subscription_options?.trial_period?.duration ?? ctx.duration;
745
759
  const trialDateText = getRenewalDateText(trialUnit, trialDuration);
746
760
  if (ctx.isUS) {
747
- return `Your subscription auto-renews ${ctx.periodText} until cancelled{{liSeparator}}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} on ${trialDateText} when your paid trial ends{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.usCancelNote}${ctx.taxFootnote}`;
761
+ return `Your subscription auto-renews ${ctx.periodText} until cancelled${LI_SEPARATOR}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} on ${trialDateText} when your paid trial ends${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.usCancelNote}${ctx.taxFootnote}`;
748
762
  }
749
- return `Your subscription auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} on ${trialDateText} when your paid trial ends, until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
763
+ return `Your subscription auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} on ${trialDateText} when your paid trial ends, until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
750
764
  }
751
765
  function autoRenewalTerms(ctx) {
752
766
  if (ctx.isUS) {
753
- return `Your subscription auto-renews ${ctx.periodText} until cancelled{{liSeparator}}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.renewalDateStr}{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}`;
767
+ return `Your subscription auto-renews ${ctx.periodText} until cancelled${LI_SEPARATOR}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.renewalDateStr}${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}`;
754
768
  }
755
- return `Your subscription auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
769
+ return `Your subscription auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
756
770
  }
757
771
  function noAutoRenewalTerms(ctx) {
758
772
  if (ctx.isUS || ctx.isCA) {
759
- return `Your subscription does not renew automatically${ctx.taxFootnote}{{liSeparator}}`;
773
+ return `Your subscription does not renew automatically${ctx.taxFootnote}${LI_SEPARATOR}`;
760
774
  }
761
- return `Your subscription does not renew automatically{{liSeparator}}`;
775
+ return `Your subscription does not renew automatically${LI_SEPARATOR}`;
762
776
  }
763
777
  function generateApplePayModalTerms(offer, country) {
764
778
  const ctx = buildTermsContext(offer, country);
@@ -781,9 +795,9 @@ function generateApplePayModalTerms(offer, country) {
781
795
  return noAutoRenewalTerms(ctx);
782
796
  }
783
797
  function renderTermsHtml(termsText) {
784
- const renewalTextLists = termsText.split("{{liSeparator}}");
798
+ const renewalTextLists = termsText.split(LI_SEPARATOR);
785
799
  const lastPart = renewalTextLists.pop() || "";
786
- const renewalTextParagraphs = lastPart.split("{{pSeparator}}");
800
+ const renewalTextParagraphs = lastPart.split(P_SEPARATOR);
787
801
  const ulHtml = `<ul class="apm__terms-bullets">${renewalTextLists.map((value) => `<li>${value}</li>`).join("")}</ul>`;
788
802
  const paragraphHtml = renewalTextParagraphs.filter(Boolean).map((value) => `<p class="apm__terms-legal">${value}</p>`).join("");
789
803
  return ulHtml + paragraphHtml;
@@ -937,7 +951,6 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
937
951
  cta.removeAttribute("aria-busy");
938
952
  }
939
953
  }).catch(() => {
940
- console.error("[web-apple-pay] apple-pay-modal: failed to pre-fetch reCAPTCHA tokens; CTA remains disabled");
941
954
  if (cta) {
942
955
  cta.removeAttribute("aria-busy");
943
956
  }