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