@economist/web-apple-pay 1.7.5 → 1.7.7

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.
package/dist/index.js CHANGED
@@ -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;
@@ -320,28 +332,41 @@ var apple_pay_modal_template_default = `<style>
320
332
  cursor: not-allowed;
321
333
  }
322
334
 
323
- .apm__cta[aria-busy="true"] > * {
324
- visibility: hidden;
335
+ .apm__cta-content {
336
+ display: flex;
337
+ align-items: center;
338
+ gap: 0.375rem;
339
+ }
340
+
341
+ .apm__cta-label {
342
+ display: inline-flex;
343
+ align-items: center;
344
+ gap: 0.375rem;
345
+ }
346
+
347
+ .apm__cta-loading {
348
+ display: none;
325
349
  }
326
350
 
327
- .apm__cta[aria-busy="true"]::after {
351
+ .apm__cta[aria-busy="true"]::before {
328
352
  content: '';
329
353
  position: absolute;
330
- left: 50%;
331
354
  top: 50%;
332
- margin-left: -0.625rem;
333
- margin-top: -0.625rem;
355
+ left: 50%;
334
356
  width: 1.25rem;
335
357
  height: 1.25rem;
336
- border: 2px solid rgba(255, 255, 255, 0.2);
358
+ border: 2px solid rgba(255, 255, 255, 0.25);
337
359
  border-top-color: #fff;
338
360
  border-radius: 50%;
339
361
  animation: apm-cta-spinner 0.8s linear infinite;
340
362
  }
341
363
 
342
364
  @keyframes apm-cta-spinner {
365
+ from {
366
+ transform: translate(-50%, -50%) rotate(0deg);
367
+ }
343
368
  to {
344
- transform: rotate(360deg);
369
+ transform: translate(-50%, -50%) rotate(360deg);
345
370
  }
346
371
  }
347
372
 
@@ -408,7 +433,7 @@ var apple_pay_modal_template_default = `<style>
408
433
  fill-rule="evenodd"
409
434
  clip-rule="evenodd"
410
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"
411
- fill="#333333"
436
+ fill="currentColor"
412
437
  />
413
438
  </g>
414
439
  <defs>
@@ -518,11 +543,14 @@ var apple_pay_modal_template_default = `<style>
518
543
  </div>
519
544
  <button class="apm__cta" id="apple-pay-modal-cta" aria-label="Continue with Apple Pay">
520
545
  <span class="apm__cta-content">
521
- Continue with
522
- <svg width="51" height="22" aria-hidden="true" role="img">
523
- <use href="#apple-pay-logo" />
524
- </svg>
546
+ <span class="apm__cta-label">
547
+ Continue with
548
+ <svg width="51" height="22" aria-hidden="true" role="img">
549
+ <use href="#apple-pay-logo" />
550
+ </svg>
551
+ </span>
525
552
  </span>
553
+ <span class="apm__cta-loading" aria-hidden="true">Loading...</span>
526
554
  </button>
527
555
  </div>
528
556
  </div>
@@ -668,6 +696,8 @@ function renewalPeriodText(unit, duration) {
668
696
  return "";
669
697
  }
670
698
  }
699
+ var LI_SEPARATOR = "\0LI_SEP\0";
700
+ var P_SEPARATOR = "\0P_SEP\0";
671
701
  function buildTermsContext(offer, country) {
672
702
  const isUS = country === "US";
673
703
  const isCA = country === "CA";
@@ -704,19 +734,19 @@ function freeTrialTerms(offer, ctx) {
704
734
  const trialDuration = offer.subscription_options?.trial_period?.duration ?? 1;
705
735
  const trialDateStr = `on ${getRenewalDateText(trialUnit, trialDuration)}${ctx.verificationText}`;
706
736
  if (ctx.isUS) {
707
- 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}`;
737
+ 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}`;
708
738
  }
709
- 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}`;
739
+ 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}`;
710
740
  }
711
741
  function nytTerms(ctx) {
712
742
  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.";
713
743
  if (ctx.isUS) {
714
- 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}`;
744
+ 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}`;
715
745
  }
716
746
  if (ctx.isCA) {
717
- 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}`;
747
+ 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}`;
718
748
  }
719
- 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}`;
749
+ 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}`;
720
750
  }
721
751
  function minTermContractTerms(offer, ctx) {
722
752
  const duePrice = formatPrice(offer.price.purchase, offer.price.currency_code);
@@ -726,28 +756,28 @@ function minTermContractTerms(offer, ctx) {
726
756
  const contractLength = mtDuration && mtUnit ? `${mtDuration} ${mtUnit}` : "";
727
757
  const initialContractText = contractLength ? `your initial ${contractLength} contract` : "your initial contract";
728
758
  const mtRenewalDateText = mtUnit && mtDuration ? getRenewalDateText(mtUnit, Number(mtDuration)) : ctx.renewalDateText;
729
- 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}`;
759
+ 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}`;
730
760
  }
731
761
  function paidTrialTerms(offer, ctx) {
732
762
  const trialUnit = offer.subscription_options?.trial_period?.unit ?? ctx.unit;
733
763
  const trialDuration = offer.subscription_options?.trial_period?.duration ?? ctx.duration;
734
764
  const trialDateText = getRenewalDateText(trialUnit, trialDuration);
735
765
  if (ctx.isUS) {
736
- 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}`;
766
+ 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}`;
737
767
  }
738
- 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}`;
768
+ 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}`;
739
769
  }
740
770
  function autoRenewalTerms(ctx) {
741
771
  if (ctx.isUS) {
742
- 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}`;
772
+ 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}`;
743
773
  }
744
- 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}`;
774
+ 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}`;
745
775
  }
746
776
  function noAutoRenewalTerms(ctx) {
747
777
  if (ctx.isUS || ctx.isCA) {
748
- return `Your subscription does not renew automatically${ctx.taxFootnote}{{liSeparator}}`;
778
+ return `Your subscription does not renew automatically${ctx.taxFootnote}${LI_SEPARATOR}`;
749
779
  }
750
- return `Your subscription does not renew automatically{{liSeparator}}`;
780
+ return `Your subscription does not renew automatically${LI_SEPARATOR}`;
751
781
  }
752
782
  function generateApplePayModalTerms(offer, country) {
753
783
  const ctx = buildTermsContext(offer, country);
@@ -770,9 +800,9 @@ function generateApplePayModalTerms(offer, country) {
770
800
  return noAutoRenewalTerms(ctx);
771
801
  }
772
802
  function renderTermsHtml(termsText) {
773
- const renewalTextLists = termsText.split("{{liSeparator}}");
803
+ const renewalTextLists = termsText.split(LI_SEPARATOR);
774
804
  const lastPart = renewalTextLists.pop() || "";
775
- const renewalTextParagraphs = lastPart.split("{{pSeparator}}");
805
+ const renewalTextParagraphs = lastPart.split(P_SEPARATOR);
776
806
  const ulHtml = `<ul class="apm__terms-bullets">${renewalTextLists.map((value) => `<li>${value}</li>`).join("")}</ul>`;
777
807
  const paragraphHtml = renewalTextParagraphs.filter(Boolean).map((value) => `<p class="apm__terms-legal">${value}</p>`).join("");
778
808
  return ulHtml + paragraphHtml;
@@ -1015,8 +1045,8 @@ var apple_pay_button_template_default = `<style>
1015
1045
  min-width: 0;
1016
1046
  height: 100%;
1017
1047
  min-height: var(--apple-pay-height, 2.75rem);
1018
- background-color: #000;
1019
- color: #fff;
1048
+ background-color: var(--apple-pay-background-color, #000);
1049
+ color: var(--apple-pay-foreground-color, #fff);
1020
1050
  border: none;
1021
1051
  border-radius: var(--apple-pay-border-radius, 1.375rem);
1022
1052
  cursor: pointer;
@@ -1028,6 +1058,7 @@ var apple_pay_button_template_default = `<style>
1028
1058
  teg-apple-pay-button .apple-pay-btn svg {
1029
1059
  flex-shrink: 0;
1030
1060
  display: block;
1061
+ color: currentColor;
1031
1062
  }
1032
1063
 
1033
1064
  teg-apple-pay-button .apple-pay-btn.wap-loading {
@@ -1035,28 +1066,34 @@ var apple_pay_button_template_default = `<style>
1035
1066
  cursor: default;
1036
1067
  }
1037
1068
 
1038
- teg-apple-pay-button .apple-pay-btn.wap-loading svg {
1039
- visibility: hidden;
1040
- }
1041
-
1042
- teg-apple-pay-button .apple-pay-btn.wap-loading::after {
1069
+ teg-apple-pay-button .apple-pay-btn.wap-loading::before {
1043
1070
  content: '';
1044
1071
  position: absolute;
1045
- left: 50%;
1046
1072
  top: 50%;
1047
- margin-left: -0.625rem;
1048
- margin-top: -0.625rem;
1073
+ left: 50%;
1049
1074
  width: 1.25rem;
1050
1075
  height: 1.25rem;
1051
- border: 2px solid rgba(255, 255, 255, 0.2);
1052
- border-top-color: #fff;
1076
+ border: 2px solid var(--apple-pay-spinner-track-color, rgba(255, 255, 255, 0.25));
1077
+ border-top-color: var(--apple-pay-spinner-head-color, currentColor);
1053
1078
  border-radius: 50%;
1054
1079
  animation: wap-button-spinner 0.8s linear infinite;
1055
1080
  }
1056
1081
 
1082
+ teg-apple-pay-button .apple-pay-btn__logo {
1083
+ display: inline-flex;
1084
+ align-items: center;
1085
+ }
1086
+
1087
+ teg-apple-pay-button .apple-pay-btn__loading {
1088
+ display: none;
1089
+ }
1090
+
1057
1091
  @keyframes wap-button-spinner {
1092
+ from {
1093
+ transform: translate(-50%, -50%) rotate(0deg);
1094
+ }
1058
1095
  to {
1059
- transform: rotate(360deg);
1096
+ transform: translate(-50%, -50%) rotate(360deg);
1060
1097
  }
1061
1098
  }
1062
1099
  </style>
@@ -1068,9 +1105,12 @@ var apple_pay_button_template_default = `<style>
1068
1105
  aria-label="Pay with Apple Pay"
1069
1106
  data-analytics="paywall:apple-pay-checkout"
1070
1107
  >
1071
- <svg width="51" height="22" aria-label="Apple Pay" role="img">
1072
- <use href="#apple-pay-logo" />
1073
- </svg>
1108
+ <span class="apple-pay-btn__logo">
1109
+ <svg width="51" height="22" aria-label="Apple Pay" role="img">
1110
+ <use href="#apple-pay-logo" />
1111
+ </svg>
1112
+ </span>
1113
+ <span class="apple-pay-btn__loading" aria-hidden="true">Loading...</span>
1074
1114
  </button>
1075
1115
  </div>
1076
1116
  `;
@@ -1198,13 +1238,25 @@ var getExpressCheckoutSession = () => {
1198
1238
  };
1199
1239
 
1200
1240
  // src/utils/expressCheckoutRedirect.ts
1201
- var captureOriginUrl = () => window.location.href;
1202
- var buildQueryString = () => {
1203
- const countryCode = new URLSearchParams(window.location.search).get(
1204
- "country"
1205
- );
1206
- return countryCode ? `&country=${encodeURIComponent(countryCode)}` : "";
1241
+ var CHECKOUT_REDIRECT_KEY = "checkout-redirect";
1242
+ var ALLOWED_REDIRECT_HOSTNAME = "economist.com";
1243
+ function isAllowedRedirectUrl(url) {
1244
+ if (url.startsWith("/")) return !url.startsWith("//");
1245
+ try {
1246
+ const { hostname } = new URL(url);
1247
+ return hostname === ALLOWED_REDIRECT_HOSTNAME || hostname.endsWith(`.${ALLOWED_REDIRECT_HOSTNAME}`);
1248
+ } catch {
1249
+ return false;
1250
+ }
1251
+ }
1252
+ var writeCheckoutRedirect = (originUrl) => {
1253
+ if (!isAllowedRedirectUrl(originUrl)) return;
1254
+ try {
1255
+ localStorage.setItem(CHECKOUT_REDIRECT_KEY, originUrl);
1256
+ } catch {
1257
+ }
1207
1258
  };
1259
+ var captureOriginUrl = () => window.location.href;
1208
1260
  var decodeSku = (sku) => {
1209
1261
  try {
1210
1262
  return atob(sku.substring(sku.indexOf("-") + 1));
@@ -1215,14 +1267,11 @@ var decodeSku = (sku) => {
1215
1267
  var redirectToCheckoutComplete = (params) => {
1216
1268
  const url = new URL("/checkout/complete", window.location.origin);
1217
1269
  url.searchParams.set("basketId", params.basketId);
1218
- if (params.queryString) {
1219
- const qs = params.queryString.startsWith("?") ? params.queryString.slice(1) : params.queryString;
1220
- new URLSearchParams(qs).forEach((v, k) => url.searchParams.set(k, v));
1221
- }
1222
1270
  url.searchParams.set("lmo_offer", params.skuId);
1223
1271
  url.searchParams.set("status", params.status);
1224
1272
  url.searchParams.set("redirectToCheckout", "true");
1225
- url.searchParams.set("returnUrl", params.returnUrl);
1273
+ if (params.email) url.searchParams.set("email", params.email);
1274
+ if (params.country) url.searchParams.set("country", params.country);
1226
1275
  return url.pathname + url.search;
1227
1276
  };
1228
1277
  var redirectToCheckoutFallback = (params) => {
@@ -1233,7 +1282,7 @@ var redirectToCheckoutFallback = (params) => {
1233
1282
  url.searchParams.set("inlineError", params.inlineError);
1234
1283
  if (params.email) url.searchParams.set("email", params.email);
1235
1284
  if (params.emailError) url.searchParams.set("emailError", params.emailError);
1236
- url.searchParams.set("returnUrl", params.returnUrl);
1285
+ if (params.country) url.searchParams.set("country", params.country);
1237
1286
  return url.pathname + url.search;
1238
1287
  };
1239
1288
 
@@ -1317,17 +1366,16 @@ var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a
1317
1366
  var MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
1318
1367
  var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
1319
1368
  var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
1320
- var MSG_RECAPTCHA_VALIDATION_FAILED = "Security check failed. Please try again.";
1321
- var MSG_EMAIL_COLLISION = "This email address is already linked to an account. Please log in, or try a different email address.";
1322
1369
  var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
1323
1370
 
1324
1371
  // src/clients/payment-checkout/apple-session.ts
1325
1372
  function redirectToFallbackCheckout(config) {
1373
+ writeCheckoutRedirect(config.returnUrl);
1326
1374
  trackFallbackCheckout(config.skuId);
1327
1375
  window.location.href = redirectToCheckoutFallback({
1328
1376
  skuId: config.skuId,
1329
- returnUrl: config.returnUrl,
1330
- inlineError: MSG_PAYMENT_GENERIC_ERROR
1377
+ inlineError: MSG_PAYMENT_GENERIC_ERROR,
1378
+ country: config.countryCode
1331
1379
  });
1332
1380
  }
1333
1381
  async function handleMerchantValidation(event, session, config) {
@@ -1506,8 +1554,6 @@ var shippingContactDetails = (shippingContact) => {
1506
1554
  };
1507
1555
 
1508
1556
  // src/clients/payment-checkout/payment-handler.ts
1509
- var MSG_ELIGIBILITY = "Something went wrong, please try again";
1510
- var MSG_REGISTRATION = "We couldn't create your account. Please enter your email or try a different login method.";
1511
1557
  var failApplePaySession = (session, errors = []) => {
1512
1558
  session.completePayment({
1513
1559
  status: ApplePaySession.STATUS_FAILURE,
@@ -1531,37 +1577,42 @@ function validateContacts(event, sessionData, supportedBillingCountries) {
1531
1577
  }
1532
1578
  return void 0;
1533
1579
  }
1534
- function redirectFallback(skuId, returnUrl, options) {
1580
+ function redirectFallback(skuId, returnUrl, country, options) {
1581
+ writeCheckoutRedirect(returnUrl);
1535
1582
  trackFallbackCheckout(skuId);
1536
1583
  window.location.href = redirectToCheckoutFallback({
1537
1584
  skuId,
1538
- returnUrl,
1585
+ country,
1539
1586
  ...options
1540
1587
  });
1541
1588
  }
1542
1589
  var ERROR_HANDLERS = {
1543
- EMAIL_COLLISION: ({ skuId, returnUrl, validatedEmail }) => redirectFallback(skuId, returnUrl, {
1544
- emailError: MSG_EMAIL_COLLISION,
1590
+ // emailError flows as an inline field error on the email input.
1591
+ // email pre-populates the input so the user doesn't have to retype it.
1592
+ EMAIL_COLLISION: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
1593
+ emailError: walletError.message,
1594
+ email: validatedEmail
1595
+ }),
1596
+ PAYMENT_DECLINED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1597
+ ELIGIBILITY_REJECTED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1598
+ REGISTRATION_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1599
+ ACCOUNT_CREATION_FAILED: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
1600
+ emailError: walletError.message,
1545
1601
  email: validatedEmail
1546
1602
  }),
1547
- PAYMENT_DECLINED: ({ skuId, returnUrl }) => (
1548
- // Matches sma-checkout catch-all: always redirect with generic inlineError.
1549
- redirectFallback(skuId, returnUrl, { inlineError: MSG_PAYMENT_GENERIC_ERROR })
1550
- ),
1551
- ELIGIBILITY_REJECTED: ({ skuId, returnUrl }) => redirectFallback(skuId, returnUrl, { inlineError: MSG_ELIGIBILITY }),
1552
- REGISTRATION_FAILED: ({ skuId, returnUrl }) => redirectFallback(skuId, returnUrl, { inlineError: MSG_REGISTRATION }),
1553
- VALIDATION_ERROR: ({ skuId, returnUrl }) => redirectFallback(skuId, returnUrl, { inlineError: MSG_RECAPTCHA_VALIDATION_FAILED })
1603
+ VALIDATION_ERROR: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
1604
+ RECAPTCHA_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message })
1554
1605
  };
1555
1606
  function handleStructuredError(ctx) {
1556
1607
  const handler = ERROR_HANDLERS[ctx.walletError.errorType];
1557
1608
  if (handler) {
1558
1609
  handler(ctx);
1559
1610
  } else {
1560
- redirectFallback(ctx.skuId, ctx.returnUrl, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
1611
+ redirectFallback(ctx.skuId, ctx.returnUrl, ctx.country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
1561
1612
  }
1562
1613
  }
1563
1614
  async function handlePaymentAuthorized(event, session, sessionData, config) {
1564
- const { skuId, returnUrl, queryString } = config;
1615
+ const { skuId, returnUrl, country } = config;
1565
1616
  let validatedEmail;
1566
1617
  try {
1567
1618
  validatedEmail = validateContacts(
@@ -1581,13 +1632,15 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1581
1632
  });
1582
1633
  trackWalletPaymentSuccess(skuId, result.basketId);
1583
1634
  session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
1635
+ const successEmail = sessionData.loggedIn ? sessionData.emailAddress : validatedEmail;
1584
1636
  const userStatus = sessionData.loggedIn ? "lex" : "nex";
1637
+ writeCheckoutRedirect(returnUrl);
1585
1638
  window.location.href = redirectToCheckoutComplete({
1586
1639
  basketId: result.basketId,
1587
1640
  status: userStatus,
1588
1641
  skuId: decodeSku(skuId),
1589
- returnUrl,
1590
- queryString
1642
+ email: successEmail,
1643
+ country
1591
1644
  });
1592
1645
  } catch (err) {
1593
1646
  if (err instanceof ContactValidationError) {
@@ -1599,10 +1652,10 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1599
1652
  trackWalletPaymentFailure(skuId, walletError?.errorType ?? "UNKNOWN");
1600
1653
  failApplePaySession(session);
1601
1654
  if (!walletError) {
1602
- redirectFallback(skuId, returnUrl, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
1655
+ redirectFallback(skuId, returnUrl, country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
1603
1656
  return;
1604
1657
  }
1605
- handleStructuredError({ skuId, returnUrl, validatedEmail, walletError });
1658
+ handleStructuredError({ skuId, returnUrl, country, validatedEmail, walletError });
1606
1659
  }
1607
1660
  }
1608
1661
 
@@ -2188,7 +2241,6 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2188
2241
  country,
2189
2242
  currency: offer.price?.currency_code ?? DEFAULT_CURRENCY,
2190
2243
  returnUrl: this.#returnUrl,
2191
- queryString: buildQueryString(),
2192
2244
  supportedBillingCountries: this.#supportedBillingCountries,
2193
2245
  recaptchaTokens
2194
2246
  })