@economist/web-apple-pay 2.0.0-beta.1 → 2.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -12
- package/dist/index.js +661 -351
- package/dist/src/apple-pay-button.d.ts +21 -14
- package/dist/src/apple-pay-button.js +650 -343
- package/dist/src/apple-pay-button.stories.js +647 -342
- package/dist/src/apple-pay-modal.js +44 -39
- package/dist/src/apple-pay-modal.stories.js +647 -342
- package/dist/src/clients/payment-checkout/apple-session.d.ts +14 -1
- package/dist/src/clients/payment-checkout/apple-session.js +46 -11
- 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 +395 -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 +397 -30
- package/dist/src/clients/payment-checkout/session.js +13 -1
- package/dist/src/clients/payment-checkout/types.d.ts +7 -0
- package/dist/src/constants.d.ts +8 -28
- package/dist/src/constants.js +4 -7
- package/dist/src/index.d.ts +2 -4
- package/dist/src/index.js +661 -351
- package/dist/src/types/offer.types.d.ts +1 -1
- package/dist/src/utils/address-rules.d.ts +23 -0
- package/dist/src/utils/address-rules.js +258 -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 +7 -9
- package/dist/src/utils/applePayExpressEligibility.js +2 -2
- 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 +10 -16
- package/dist/src/utils/expressCheckoutTracking.js +5 -29
- package/dist/src/utils/latin-characters.d.ts +3 -0
- package/dist/src/utils/latin-characters.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
package/dist/index.js
CHANGED
|
@@ -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>
|
|
@@ -567,15 +564,21 @@ var configureApplePay = (config) => {
|
|
|
567
564
|
var getApplePayConfig = () => runtimeConfig;
|
|
568
565
|
|
|
569
566
|
// src/utils/recaptcha.ts
|
|
567
|
+
var findScriptForKey = (siteKey) => Array.from(
|
|
568
|
+
document.querySelectorAll(
|
|
569
|
+
'script[src*="recaptcha/api.js"]'
|
|
570
|
+
)
|
|
571
|
+
).find((script) => script.src.includes(`render=${siteKey}`));
|
|
572
|
+
var pendingLoads = /* @__PURE__ */ new Map();
|
|
570
573
|
var loadRecaptchaScript = (siteKey) => {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
if (
|
|
577
|
-
|
|
578
|
-
|
|
574
|
+
const pending = pendingLoads.get(siteKey);
|
|
575
|
+
if (pending) return pending;
|
|
576
|
+
const ownScript = findScriptForKey(siteKey);
|
|
577
|
+
if (ownScript && typeof grecaptcha !== "undefined") return Promise.resolve();
|
|
578
|
+
const load = new Promise((resolve, reject) => {
|
|
579
|
+
if (ownScript) {
|
|
580
|
+
ownScript.addEventListener("load", () => resolve());
|
|
581
|
+
ownScript.addEventListener("error", () => {
|
|
579
582
|
reject(new Error("Failed to load existing reCAPTCHA script"));
|
|
580
583
|
});
|
|
581
584
|
return;
|
|
@@ -590,6 +593,9 @@ var loadRecaptchaScript = (siteKey) => {
|
|
|
590
593
|
};
|
|
591
594
|
document.head.appendChild(script);
|
|
592
595
|
});
|
|
596
|
+
pendingLoads.set(siteKey, load);
|
|
597
|
+
load.catch(() => pendingLoads.delete(siteKey));
|
|
598
|
+
return load;
|
|
593
599
|
};
|
|
594
600
|
var getRecaptchaToken = async (action) => {
|
|
595
601
|
const siteKey = getApplePayConfig()?.recaptchaSiteKey;
|
|
@@ -854,7 +860,6 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
854
860
|
if (this.querySelector(".apm-overlay")) {
|
|
855
861
|
return;
|
|
856
862
|
}
|
|
857
|
-
ensureApplePayLogoSymbol();
|
|
858
863
|
const template = document.createElement("template");
|
|
859
864
|
template.innerHTML = apple_pay_modal_template_default;
|
|
860
865
|
this.appendChild(template.content.cloneNode(true));
|
|
@@ -1007,8 +1012,13 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
1007
1012
|
// src/templates/apple-pay-button.template.html
|
|
1008
1013
|
var apple_pay_button_template_default = `<style>
|
|
1009
1014
|
/*
|
|
1010
|
-
* Entry CTA:
|
|
1011
|
-
*
|
|
1015
|
+
* Entry CTA: caption + Apple Pay wordmark, built from text (no SVG), as in Figma (Play Global Spec 3268:39728):
|
|
1016
|
+
* black #0d0d0d, 4px radius, 40px high, 8px 16px padding, 4px gap.
|
|
1017
|
+
* Marber tokens (as bound in Figma): caption size label-2-size (15px), line height label-3-leading (24px);
|
|
1018
|
+
* glyph + "Pay" 17px (label-3-size) with auto line height; padding spacing-xs / spacing-md; gap + radius spacing-2xs;
|
|
1019
|
+
* background london-5. Expected content widths in Figma: caption 98px, wordmark 42px, button content 176px.
|
|
1020
|
+
* Caption: SF Pro Regular. Wordmark: the Apple glyph (U+F8FF, Regular) + "Pay" (Medium 510).
|
|
1021
|
+
* SF Pro is the system font on Apple devices, which are the only devices Apple Pay is shown on.
|
|
1012
1022
|
*/
|
|
1013
1023
|
teg-apple-pay-button {
|
|
1014
1024
|
display: block;
|
|
@@ -1033,46 +1043,45 @@ var apple_pay_button_template_default = `<style>
|
|
|
1033
1043
|
min-width: 0;
|
|
1034
1044
|
height: 100%;
|
|
1035
1045
|
min-height: var(--apple-pay-height, 2.5rem);
|
|
1036
|
-
|
|
1046
|
+
/* Figma button content: 8px 16px */
|
|
1047
|
+
padding: var(--mb-spacing-xs, 0.5rem) var(--mb-spacing-md, 1rem);
|
|
1037
1048
|
box-sizing: border-box;
|
|
1038
|
-
background-color: var(--apple-pay-background-color, #
|
|
1049
|
+
background-color: var(--apple-pay-background-color, var(--mb-colour-greyscale-london-5, #0d0d0d));
|
|
1039
1050
|
color: var(--apple-pay-foreground-color, #fff);
|
|
1040
1051
|
border: none;
|
|
1041
|
-
border-radius: var(--apple-pay-border-radius, 0.25rem);
|
|
1052
|
+
border-radius: var(--apple-pay-border-radius, var(--mb-spacing-2xs, 0.25rem));
|
|
1042
1053
|
cursor: pointer;
|
|
1043
|
-
/*
|
|
1044
|
-
font-family:
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
line
|
|
1054
|
+
/* Figma: SF Pro (system font on Apple devices), Regular 15 / 24 */
|
|
1055
|
+
font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro', system-ui, sans-serif;
|
|
1056
|
+
font-size: var(--mb-typestyle-label-2-size, 0.9375rem);
|
|
1057
|
+
font-weight: 400;
|
|
1058
|
+
font-variation-settings: 'wdth' 100;
|
|
1059
|
+
/* Figma letter spacing 0 */
|
|
1060
|
+
letter-spacing: 0;
|
|
1061
|
+
/* Figma caption: line height is the label-3-leading token (24px) */
|
|
1062
|
+
line-height: var(--mb-typestyle-label-3-leading, 1.5rem);
|
|
1051
1063
|
}
|
|
1052
1064
|
|
|
1053
1065
|
teg-apple-pay-button .apple-pay-btn__label {
|
|
1054
1066
|
display: inline-flex;
|
|
1055
1067
|
align-items: center;
|
|
1056
|
-
/*
|
|
1057
|
-
gap: 0;
|
|
1068
|
+
/* Figma: 4px between the caption and the wordmark */
|
|
1069
|
+
gap: var(--mb-spacing-2xs, 0.25rem);
|
|
1058
1070
|
white-space: nowrap;
|
|
1059
1071
|
}
|
|
1060
1072
|
|
|
1061
|
-
teg-apple-pay-button .apple-pay-
|
|
1062
|
-
|
|
1063
|
-
|
|
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) with AUTO line height (a 20px box centred in the 24px caption row),
|
|
1077
|
+
not the 24px leading token the caption uses. */
|
|
1078
|
+
font-size: var(--mb-typestyle-label-3-size, 1.0625rem);
|
|
1079
|
+
line-height: normal;
|
|
1064
1080
|
}
|
|
1065
1081
|
|
|
1066
|
-
teg-apple-pay-button .apple-pay-btn__logo {
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
/* Match caption font-size so mark aligns with text metrics */
|
|
1070
|
-
height: 1.05em;
|
|
1071
|
-
width: auto;
|
|
1072
|
-
aspect-ratio: 51 / 22;
|
|
1073
|
-
color: currentColor;
|
|
1074
|
-
/* Optical nudge \u2014 SVG viewBox sits slightly high vs EconomistSans caps */
|
|
1075
|
-
transform: translateY(0.06em);
|
|
1082
|
+
teg-apple-pay-button .apple-pay-btn__logo-word {
|
|
1083
|
+
font-weight: 510;
|
|
1084
|
+
font-variation-settings: 'wdth' 100;
|
|
1076
1085
|
}
|
|
1077
1086
|
|
|
1078
1087
|
teg-apple-pay-button .apple-pay-btn.wap-loading {
|
|
@@ -1109,6 +1118,7 @@ var apple_pay_button_template_default = `<style>
|
|
|
1109
1118
|
transform: translate(-50%, -50%) rotate(360deg);
|
|
1110
1119
|
}
|
|
1111
1120
|
}
|
|
1121
|
+
|
|
1112
1122
|
</style>
|
|
1113
1123
|
|
|
1114
1124
|
<div class="apple-pay-container" aria-label="Subscribe with Apple Pay">
|
|
@@ -1120,16 +1130,10 @@ var apple_pay_button_template_default = `<style>
|
|
|
1120
1130
|
>
|
|
1121
1131
|
<span class="apple-pay-btn__label"
|
|
1122
1132
|
><span class="apple-pay-btn__caption">Subscribe with</span
|
|
1123
|
-
><
|
|
1124
|
-
class="apple-pay-btn__logo"
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
viewBox="0 0 51 22"
|
|
1128
|
-
aria-hidden="true"
|
|
1129
|
-
role="img"
|
|
1130
|
-
>
|
|
1131
|
-
<use href="#apple-pay-logo" />
|
|
1132
|
-
</svg
|
|
1133
|
+
><span class="apple-pay-btn__logo" aria-hidden="true"
|
|
1134
|
+
><span class="apple-pay-btn__logo-glyph"></span
|
|
1135
|
+
><span class="apple-pay-btn__logo-word">Pay</span
|
|
1136
|
+
></span
|
|
1133
1137
|
></span>
|
|
1134
1138
|
<span class="apple-pay-btn__loading" aria-hidden="true">Loading...</span>
|
|
1135
1139
|
</button>
|
|
@@ -1143,7 +1147,7 @@ var isAppleDeviceOrSafari = () => {
|
|
|
1143
1147
|
return isIOSOrMacTouchDevice || isSafariBrowser;
|
|
1144
1148
|
};
|
|
1145
1149
|
var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null;
|
|
1146
|
-
var
|
|
1150
|
+
var isApplePayCapable = () => {
|
|
1147
1151
|
if (bypassApplePayChecks()) {
|
|
1148
1152
|
return true;
|
|
1149
1153
|
}
|
|
@@ -1155,18 +1159,21 @@ var isApplePayAvailable = async () => {
|
|
|
1155
1159
|
return false;
|
|
1156
1160
|
}
|
|
1157
1161
|
try {
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1162
|
+
return typeof applePaySession.canMakePayments === "function" && applePaySession.canMakePayments() && Boolean(getApplePayConfig()?.merchantId);
|
|
1163
|
+
} catch {
|
|
1164
|
+
return false;
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1167
|
+
var isApplePayAvailable = async () => {
|
|
1168
|
+
if (bypassApplePayChecks()) {
|
|
1169
|
+
return true;
|
|
1170
|
+
}
|
|
1171
|
+
if (!isApplePayCapable()) {
|
|
1172
|
+
return false;
|
|
1173
|
+
}
|
|
1174
|
+
try {
|
|
1175
|
+
const merchantId = getApplePayConfig().merchantId;
|
|
1176
|
+
return await window.ApplePaySession.canMakePaymentsWithActiveCard(merchantId);
|
|
1170
1177
|
} catch {
|
|
1171
1178
|
return false;
|
|
1172
1179
|
}
|
|
@@ -1247,11 +1254,23 @@ var performPurchase = (data) => {
|
|
|
1247
1254
|
};
|
|
1248
1255
|
|
|
1249
1256
|
// src/clients/payment-checkout/session.ts
|
|
1257
|
+
var inFlight = null;
|
|
1250
1258
|
var getExpressCheckoutSession = () => {
|
|
1251
|
-
|
|
1259
|
+
if (inFlight) {
|
|
1260
|
+
return inFlight;
|
|
1261
|
+
}
|
|
1262
|
+
const request = apiFetch("/v1/wallet/session", {
|
|
1252
1263
|
method: "GET",
|
|
1253
1264
|
credentials: "include"
|
|
1254
1265
|
});
|
|
1266
|
+
inFlight = request;
|
|
1267
|
+
const clear = () => {
|
|
1268
|
+
if (inFlight === request) {
|
|
1269
|
+
inFlight = null;
|
|
1270
|
+
}
|
|
1271
|
+
};
|
|
1272
|
+
request.then(clear, clear);
|
|
1273
|
+
return request;
|
|
1255
1274
|
};
|
|
1256
1275
|
|
|
1257
1276
|
// src/utils/expressCheckoutRedirect.ts
|
|
@@ -1266,8 +1285,13 @@ function isAllowedRedirectUrl(url) {
|
|
|
1266
1285
|
return false;
|
|
1267
1286
|
}
|
|
1268
1287
|
}
|
|
1288
|
+
var CHECKOUT_REDIRECT_BY_POLICY = {
|
|
1289
|
+
["current_page" /* CURRENT_PAGE */]: (currentPageUrl) => currentPageUrl,
|
|
1290
|
+
["host_managed" /* HOST_MANAGED */]: () => null
|
|
1291
|
+
};
|
|
1292
|
+
var resolveCheckoutRedirectUrl = (policy, currentPageUrl) => CHECKOUT_REDIRECT_BY_POLICY[policy](currentPageUrl);
|
|
1269
1293
|
var writeCheckoutRedirect = (originUrl) => {
|
|
1270
|
-
if (!isAllowedRedirectUrl(originUrl)) return;
|
|
1294
|
+
if (originUrl === null || !isAllowedRedirectUrl(originUrl)) return;
|
|
1271
1295
|
try {
|
|
1272
1296
|
localStorage.setItem(CHECKOUT_REDIRECT_KEY, originUrl);
|
|
1273
1297
|
} catch {
|
|
@@ -1303,19 +1327,6 @@ var redirectToCheckoutFallback = (params) => {
|
|
|
1303
1327
|
return url.pathname + url.search;
|
|
1304
1328
|
};
|
|
1305
1329
|
|
|
1306
|
-
// src/constants.ts
|
|
1307
|
-
var ApplePayEntryPoint = /* @__PURE__ */ ((ApplePayEntryPoint2) => {
|
|
1308
|
-
ApplePayEntryPoint2["PAYWALL"] = "article_paywall";
|
|
1309
|
-
ApplePayEntryPoint2["REGWALL"] = "article_regwall";
|
|
1310
|
-
ApplePayEntryPoint2["DUAL_OFFER_BANNER"] = "dual_offer_banner";
|
|
1311
|
-
return ApplePayEntryPoint2;
|
|
1312
|
-
})(ApplePayEntryPoint || {});
|
|
1313
|
-
var APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY = "apple-pay-express-checkout-on-paywalls";
|
|
1314
|
-
var APPLE_PAY_EXPRESS_VARIANTS = {
|
|
1315
|
-
CONTROL: "control",
|
|
1316
|
-
TREATMENT: "treatment"
|
|
1317
|
-
};
|
|
1318
|
-
|
|
1319
1330
|
// src/utils/expressCheckoutTracking.ts
|
|
1320
1331
|
var EXPRESS_CHECKOUT_EVENTS = {
|
|
1321
1332
|
/** Wallet button displayed */
|
|
@@ -1353,26 +1364,6 @@ var track = (action, extra) => {
|
|
|
1353
1364
|
...extra
|
|
1354
1365
|
});
|
|
1355
1366
|
};
|
|
1356
|
-
var trackApplePayExperimentExposure = (variant, experimentKey, flagKey) => {
|
|
1357
|
-
const isActiveVariant = variant === APPLE_PAY_EXPRESS_VARIANTS.CONTROL || variant === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
|
|
1358
|
-
if (!isActiveVariant) {
|
|
1359
|
-
return;
|
|
1360
|
-
}
|
|
1361
|
-
const exposures = window.__applePayExperimentExposures ?? {};
|
|
1362
|
-
window.__applePayExperimentExposures = exposures;
|
|
1363
|
-
const pathname = window.location?.pathname ?? "";
|
|
1364
|
-
const dedupeKey = `${pathname}:${flagKey}:${variant}`;
|
|
1365
|
-
if (exposures[dedupeKey]) {
|
|
1366
|
-
return;
|
|
1367
|
-
}
|
|
1368
|
-
exposures[dedupeKey] = true;
|
|
1369
|
-
emitTedlEvent({
|
|
1370
|
-
name: "$exposure",
|
|
1371
|
-
flag_key: flagKey,
|
|
1372
|
-
variant,
|
|
1373
|
-
...experimentKey ? { experiment_key: experimentKey } : {}
|
|
1374
|
-
});
|
|
1375
|
-
};
|
|
1376
1367
|
var trackExpressWalletImpression = (skuId, { entryPoint, country }) => {
|
|
1377
1368
|
track(EXPRESS_CHECKOUT_EVENTS.IMPRESSION, {
|
|
1378
1369
|
wallet_type: "apple_pay",
|
|
@@ -1382,8 +1373,11 @@ var trackExpressWalletImpression = (skuId, { entryPoint, country }) => {
|
|
|
1382
1373
|
device: getDevice()
|
|
1383
1374
|
});
|
|
1384
1375
|
};
|
|
1385
|
-
var trackExpressWalletClick = (skuId) => {
|
|
1386
|
-
track(EXPRESS_CHECKOUT_EVENTS.BUTTON_CLICK, {
|
|
1376
|
+
var trackExpressWalletClick = (skuId, { entryPoint } = {}) => {
|
|
1377
|
+
track(EXPRESS_CHECKOUT_EVENTS.BUTTON_CLICK, {
|
|
1378
|
+
sku_id: skuId,
|
|
1379
|
+
...entryPoint ? { entry_point: entryPoint } : {}
|
|
1380
|
+
});
|
|
1387
1381
|
};
|
|
1388
1382
|
var trackWalletPaymentSheetOpen = (skuId) => {
|
|
1389
1383
|
track(EXPRESS_CHECKOUT_EVENTS.SHEET_OPEN, { sku_id: skuId });
|
|
@@ -1414,21 +1408,10 @@ var trackValidationFieldError = (field, errorType) => {
|
|
|
1414
1408
|
var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
|
|
1415
1409
|
var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a valid email address.";
|
|
1416
1410
|
var MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
|
|
1411
|
+
var MSG_NON_LATIN_CHARACTERS = "Please use Latin characters only.";
|
|
1412
|
+
var msgFieldTooLong = (label, max) => `${label} must be ${max} characters or less`;
|
|
1413
|
+
var MSG_UNSUPPORTED_DELIVERY_COUNTRY = "We can't deliver this print edition to that country. Try a different delivery address.";
|
|
1417
1414
|
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
1415
|
var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
|
|
1433
1416
|
var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
|
|
1434
1417
|
|
|
@@ -1466,7 +1449,12 @@ async function handleMerchantValidation(event, session, config) {
|
|
|
1466
1449
|
redirectToFallbackCheckout(config);
|
|
1467
1450
|
}
|
|
1468
1451
|
}
|
|
1452
|
+
var requiredShippingFields = (config) => [
|
|
1453
|
+
...config.delivery ? ["postalAddress", "name", "phone"] : [],
|
|
1454
|
+
...config.userLoggedIn ? [] : ["email"]
|
|
1455
|
+
];
|
|
1469
1456
|
function startApplePaySession(config) {
|
|
1457
|
+
const shippingFields = requiredShippingFields(config);
|
|
1470
1458
|
const paymentRequest = {
|
|
1471
1459
|
countryCode: config.countryCode,
|
|
1472
1460
|
currencyCode: config.currencyCode,
|
|
@@ -1477,14 +1465,33 @@ function startApplePaySession(config) {
|
|
|
1477
1465
|
amount: config.totalAmount
|
|
1478
1466
|
},
|
|
1479
1467
|
requiredBillingContactFields: ["postalAddress", "name"],
|
|
1480
|
-
|
|
1481
|
-
|
|
1468
|
+
...shippingFields.length > 0 && {
|
|
1469
|
+
requiredShippingContactFields: shippingFields
|
|
1470
|
+
}
|
|
1482
1471
|
};
|
|
1483
1472
|
try {
|
|
1484
1473
|
const session = new ApplePaySession(3, paymentRequest);
|
|
1485
1474
|
session.onvalidatemerchant = async (event) => {
|
|
1486
1475
|
await handleMerchantValidation(event, session, config);
|
|
1487
1476
|
};
|
|
1477
|
+
const delivery = config.delivery;
|
|
1478
|
+
if (delivery) {
|
|
1479
|
+
session.onshippingcontactselected = (event) => {
|
|
1480
|
+
const country = event.shippingContact.countryCode?.toUpperCase();
|
|
1481
|
+
session.completeShippingContactSelection({
|
|
1482
|
+
newTotal: paymentRequest.total,
|
|
1483
|
+
...country && !delivery.supportedCountries.includes(country) && {
|
|
1484
|
+
errors: [
|
|
1485
|
+
new ApplePayError(
|
|
1486
|
+
"shippingContactInvalid",
|
|
1487
|
+
"countryCode",
|
|
1488
|
+
MSG_UNSUPPORTED_DELIVERY_COUNTRY
|
|
1489
|
+
)
|
|
1490
|
+
]
|
|
1491
|
+
}
|
|
1492
|
+
});
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1488
1495
|
session.onpaymentauthorized = (event) => {
|
|
1489
1496
|
trackWalletPaymentAuthorised(config.skuId);
|
|
1490
1497
|
config.onPaymentAuthorized(event, session).catch(() => {
|
|
@@ -1525,6 +1532,16 @@ var ContactValidationError = class extends Error {
|
|
|
1525
1532
|
}
|
|
1526
1533
|
};
|
|
1527
1534
|
|
|
1535
|
+
// src/utils/latin-characters.ts
|
|
1536
|
+
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";
|
|
1537
|
+
var LATIN_CHARACTERS_REGEX = new RegExp(
|
|
1538
|
+
`^[\\x20-\\x7E${SUPPORTED_DIACRITICS}]*$`
|
|
1539
|
+
);
|
|
1540
|
+
var isLatinCharacters = (value) => LATIN_CHARACTERS_REGEX.test(value);
|
|
1541
|
+
|
|
1542
|
+
// src/utils/addressParityFlag.ts
|
|
1543
|
+
var ADDRESS_PARITY_ENABLED = true;
|
|
1544
|
+
|
|
1528
1545
|
// src/clients/payment-checkout/billing-contact-details.ts
|
|
1529
1546
|
var countriesWithoutCityField = ["KY", "CK", "NR", "TC"];
|
|
1530
1547
|
var countriesRequiringAllFields = ["US", "CA", "GB"];
|
|
@@ -1572,6 +1589,35 @@ var validateCountrySupport = (errors, country, supportedBillingCountries) => {
|
|
|
1572
1589
|
);
|
|
1573
1590
|
}
|
|
1574
1591
|
};
|
|
1592
|
+
var validateLatinCharacters = (errors, contact, firstName, lastName) => {
|
|
1593
|
+
if (!isLatinCharacters(firstName) || !isLatinCharacters(lastName)) {
|
|
1594
|
+
pushFieldError(
|
|
1595
|
+
errors,
|
|
1596
|
+
"billing",
|
|
1597
|
+
"name",
|
|
1598
|
+
"format",
|
|
1599
|
+
MSG_NON_LATIN_CHARACTERS
|
|
1600
|
+
);
|
|
1601
|
+
}
|
|
1602
|
+
const addressFields = [
|
|
1603
|
+
["addressLines", contact.addressLines?.at(0)],
|
|
1604
|
+
["addressLines", contact.addressLines?.at(1)],
|
|
1605
|
+
["locality", contact.locality],
|
|
1606
|
+
["administrativeArea", contact.administrativeArea],
|
|
1607
|
+
["postalCode", contact.postalCode]
|
|
1608
|
+
];
|
|
1609
|
+
for (const [field, value] of addressFields) {
|
|
1610
|
+
if (value && !isLatinCharacters(value)) {
|
|
1611
|
+
pushFieldError(
|
|
1612
|
+
errors,
|
|
1613
|
+
"billing",
|
|
1614
|
+
field,
|
|
1615
|
+
"format",
|
|
1616
|
+
MSG_NON_LATIN_CHARACTERS
|
|
1617
|
+
);
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1575
1621
|
var billingContactDetails = (contact, supportedBillingCountries) => {
|
|
1576
1622
|
const errors = [];
|
|
1577
1623
|
const country = contact.countryCode?.toUpperCase() || pushRequiredFieldError(errors, "billing", "country");
|
|
@@ -1579,6 +1625,9 @@ var billingContactDetails = (contact, supportedBillingCountries) => {
|
|
|
1579
1625
|
validateAddressFields(errors, contact, config);
|
|
1580
1626
|
const { firstName, lastName } = validateNameFields(errors, contact);
|
|
1581
1627
|
validateCountrySupport(errors, country, supportedBillingCountries);
|
|
1628
|
+
if (ADDRESS_PARITY_ENABLED) {
|
|
1629
|
+
validateLatinCharacters(errors, contact, firstName, lastName);
|
|
1630
|
+
}
|
|
1582
1631
|
if (errors.length > 0) {
|
|
1583
1632
|
throw new ContactValidationError(errors);
|
|
1584
1633
|
}
|
|
@@ -1618,123 +1667,6 @@ var shippingContactDetails = (shippingContact) => {
|
|
|
1618
1667
|
return { emailAddress };
|
|
1619
1668
|
};
|
|
1620
1669
|
|
|
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
1670
|
// src/data/price-zones.json
|
|
1739
1671
|
var price_zones_default = {
|
|
1740
1672
|
"AS-AS": [
|
|
@@ -1940,6 +1872,254 @@ var price_zones_default = {
|
|
|
1940
1872
|
"UK-UK": ["GB"]
|
|
1941
1873
|
};
|
|
1942
1874
|
|
|
1875
|
+
// src/utils/address-rules.ts
|
|
1876
|
+
var priceZones = price_zones_default;
|
|
1877
|
+
var ADDRESS_LIMITS = {
|
|
1878
|
+
address1: 35,
|
|
1879
|
+
address2: 35,
|
|
1880
|
+
city: 40,
|
|
1881
|
+
state: 40,
|
|
1882
|
+
postalCode: 20,
|
|
1883
|
+
phone: 35
|
|
1884
|
+
};
|
|
1885
|
+
var zoneOf = (country) => Object.keys(priceZones).find((zone) => priceZones[zone].includes(country));
|
|
1886
|
+
var COUNTRIES_REQUIRING_PHONE = ["IN", "CN"];
|
|
1887
|
+
var requiredDeliveryFields = (offerCountry, country) => {
|
|
1888
|
+
const zone = zoneOf(offerCountry);
|
|
1889
|
+
const fields = ["address1", "city"];
|
|
1890
|
+
if (zone === "AS-AU" || zone === "AS-JP" || zone === "NA-CA" || country === "US") {
|
|
1891
|
+
fields.push("state");
|
|
1892
|
+
}
|
|
1893
|
+
if ((zone !== "AS-HK" || country === "MO") && zone !== "CE-AF" && zone !== "CE-ME") {
|
|
1894
|
+
fields.push("postalCode");
|
|
1895
|
+
}
|
|
1896
|
+
if (COUNTRIES_REQUIRING_PHONE.includes(country)) fields.push("phone");
|
|
1897
|
+
return fields;
|
|
1898
|
+
};
|
|
1899
|
+
var postalCodeFormatError = (offerCountry, postalCode) => {
|
|
1900
|
+
if (!postalCode) return null;
|
|
1901
|
+
const zone = zoneOf(offerCountry);
|
|
1902
|
+
if (zone === "NA-US" && !/(^\d{5}$)|(^\d{5}-\d{4}$)/.test(postalCode)) {
|
|
1903
|
+
return "Zip code must be a valid US zip code";
|
|
1904
|
+
}
|
|
1905
|
+
if (zone === "NA-CA" && !/^[A-Za-z]\d[A-Za-z][ -]?\d[A-Za-z]\d$/.test(postalCode)) {
|
|
1906
|
+
return "Postal code must be a valid Canadian postal code";
|
|
1907
|
+
}
|
|
1908
|
+
return null;
|
|
1909
|
+
};
|
|
1910
|
+
var COUNTRY_CALLING_CODES = {
|
|
1911
|
+
IN: "91",
|
|
1912
|
+
CN: "86"
|
|
1913
|
+
};
|
|
1914
|
+
var normaliseDeliveryPhone = (raw, country) => {
|
|
1915
|
+
const trimmed = raw?.trim() ?? "";
|
|
1916
|
+
const digits = trimmed.replace(/[^0-9]+/g, "");
|
|
1917
|
+
if (!digits) return void 0;
|
|
1918
|
+
if (trimmed.startsWith("+")) return `+${digits}`;
|
|
1919
|
+
const callingCode = COUNTRY_CALLING_CODES[country];
|
|
1920
|
+
return callingCode ? `+${callingCode}${digits.replace(/^0+/, "")}` : void 0;
|
|
1921
|
+
};
|
|
1922
|
+
|
|
1923
|
+
// src/clients/payment-checkout/delivery-contact-details.ts
|
|
1924
|
+
var APPLE_FIELD = {
|
|
1925
|
+
address1: "addressLines",
|
|
1926
|
+
city: "locality",
|
|
1927
|
+
state: "administrativeArea",
|
|
1928
|
+
postalCode: "postalCode",
|
|
1929
|
+
phone: "phoneNumber"
|
|
1930
|
+
};
|
|
1931
|
+
var LABEL = {
|
|
1932
|
+
address1: "Address line 1",
|
|
1933
|
+
address2: "Address line 2",
|
|
1934
|
+
city: "City",
|
|
1935
|
+
state: "State",
|
|
1936
|
+
postalCode: "Postcode",
|
|
1937
|
+
phone: "Phone number"
|
|
1938
|
+
};
|
|
1939
|
+
var deliveryContactDetails = (contact, { offerCountry, supportedDeliveryCountries }) => {
|
|
1940
|
+
const errors = [];
|
|
1941
|
+
const fail = (field, type, message) => pushFieldError(errors, "shipping", field, type, message);
|
|
1942
|
+
const country = contact?.countryCode?.trim().toUpperCase() ?? "";
|
|
1943
|
+
const firstName = contact?.givenName?.trim() ?? "";
|
|
1944
|
+
const lastName = contact?.familyName?.trim() ?? "";
|
|
1945
|
+
const address1 = contact?.addressLines?.at(0)?.trim() ?? "";
|
|
1946
|
+
const address2 = contact?.addressLines?.at(1)?.trim() ?? "";
|
|
1947
|
+
const city = contact?.locality?.trim() ?? "";
|
|
1948
|
+
const state = contact?.administrativeArea?.trim() ?? "";
|
|
1949
|
+
const postalCode = contact?.postalCode?.trim() ?? "";
|
|
1950
|
+
const phone = normaliseDeliveryPhone(contact?.phoneNumber, country) ?? "";
|
|
1951
|
+
if (!country) {
|
|
1952
|
+
pushRequiredFieldError(errors, "shipping", "country");
|
|
1953
|
+
} else if (!supportedDeliveryCountries.includes(country)) {
|
|
1954
|
+
fail("countryCode", "not-supported", MSG_UNSUPPORTED_DELIVERY_COUNTRY);
|
|
1955
|
+
}
|
|
1956
|
+
if (!firstName || !lastName) {
|
|
1957
|
+
pushRequiredFieldError(errors, "shipping", "name");
|
|
1958
|
+
}
|
|
1959
|
+
const values = {
|
|
1960
|
+
address1,
|
|
1961
|
+
city,
|
|
1962
|
+
state,
|
|
1963
|
+
postalCode,
|
|
1964
|
+
phone
|
|
1965
|
+
};
|
|
1966
|
+
for (const field of requiredDeliveryFields(offerCountry, country)) {
|
|
1967
|
+
if (!values[field]) {
|
|
1968
|
+
pushRequiredFieldError(errors, "shipping", APPLE_FIELD[field]);
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
const limited = [
|
|
1972
|
+
["address1", "addressLines", address1, ADDRESS_LIMITS.address1],
|
|
1973
|
+
["address2", "addressLines", address2, ADDRESS_LIMITS.address2],
|
|
1974
|
+
["city", "locality", city, ADDRESS_LIMITS.city],
|
|
1975
|
+
["state", "administrativeArea", state, ADDRESS_LIMITS.state],
|
|
1976
|
+
["postalCode", "postalCode", postalCode, ADDRESS_LIMITS.postalCode],
|
|
1977
|
+
["phone", "phoneNumber", phone, ADDRESS_LIMITS.phone]
|
|
1978
|
+
];
|
|
1979
|
+
for (const [field, appleField, value, max] of limited) {
|
|
1980
|
+
if (value.length > max) {
|
|
1981
|
+
fail(appleField, "format", msgFieldTooLong(LABEL[field], max));
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
const formatError = postalCodeFormatError(offerCountry, postalCode);
|
|
1985
|
+
if (formatError) {
|
|
1986
|
+
fail("postalCode", "format", formatError);
|
|
1987
|
+
}
|
|
1988
|
+
const latin = [
|
|
1989
|
+
["name", firstName],
|
|
1990
|
+
["name", lastName],
|
|
1991
|
+
["addressLines", address1],
|
|
1992
|
+
["addressLines", address2],
|
|
1993
|
+
["locality", city],
|
|
1994
|
+
["administrativeArea", state],
|
|
1995
|
+
["postalCode", postalCode]
|
|
1996
|
+
];
|
|
1997
|
+
for (const [field, value] of latin) {
|
|
1998
|
+
if (!isLatinCharacters(value)) {
|
|
1999
|
+
fail(field, "format", MSG_NON_LATIN_CHARACTERS);
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
if (errors.length > 0) {
|
|
2003
|
+
throw new ContactValidationError(errors);
|
|
2004
|
+
}
|
|
2005
|
+
};
|
|
2006
|
+
|
|
2007
|
+
// src/clients/payment-checkout/payment-handler.ts
|
|
2008
|
+
var failApplePaySession = (session, errors = []) => {
|
|
2009
|
+
session.completePayment({
|
|
2010
|
+
status: ApplePaySession.STATUS_FAILURE,
|
|
2011
|
+
errors
|
|
2012
|
+
});
|
|
2013
|
+
};
|
|
2014
|
+
function parseWalletApiError(err) {
|
|
2015
|
+
const body = err instanceof ApiError ? err.body : err;
|
|
2016
|
+
if (body && typeof body === "object" && "errorType" in body && "message" in body) {
|
|
2017
|
+
return body;
|
|
2018
|
+
}
|
|
2019
|
+
return null;
|
|
2020
|
+
}
|
|
2021
|
+
function validateContacts(event, sessionData, supportedBillingCountries, delivery) {
|
|
2022
|
+
billingContactDetails(
|
|
2023
|
+
event.payment.billingContact,
|
|
2024
|
+
supportedBillingCountries
|
|
2025
|
+
);
|
|
2026
|
+
if (delivery) {
|
|
2027
|
+
deliveryContactDetails(event.payment.shippingContact, {
|
|
2028
|
+
offerCountry: delivery.offerCountry,
|
|
2029
|
+
supportedDeliveryCountries: delivery.supportedCountries
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2032
|
+
if (!sessionData.loggedIn) {
|
|
2033
|
+
return shippingContactDetails(event.payment.shippingContact).emailAddress;
|
|
2034
|
+
}
|
|
2035
|
+
return void 0;
|
|
2036
|
+
}
|
|
2037
|
+
function redirectFallback(skuId, returnUrl, country, options) {
|
|
2038
|
+
writeCheckoutRedirect(returnUrl);
|
|
2039
|
+
trackFallbackCheckout(skuId);
|
|
2040
|
+
window.location.href = redirectToCheckoutFallback({
|
|
2041
|
+
skuId,
|
|
2042
|
+
country,
|
|
2043
|
+
...options
|
|
2044
|
+
});
|
|
2045
|
+
}
|
|
2046
|
+
var ERROR_HANDLERS = {
|
|
2047
|
+
// emailError flows as an inline field error on the email input.
|
|
2048
|
+
// email pre-populates the input so the user doesn't have to retype it.
|
|
2049
|
+
EMAIL_COLLISION: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
|
|
2050
|
+
emailError: walletError.message,
|
|
2051
|
+
email: validatedEmail
|
|
2052
|
+
}),
|
|
2053
|
+
PAYMENT_DECLINED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
|
|
2054
|
+
ELIGIBILITY_REJECTED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
|
|
2055
|
+
REGISTRATION_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
|
|
2056
|
+
ACCOUNT_CREATION_FAILED: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
|
|
2057
|
+
emailError: walletError.message,
|
|
2058
|
+
email: validatedEmail
|
|
2059
|
+
}),
|
|
2060
|
+
VALIDATION_ERROR: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
|
|
2061
|
+
RECAPTCHA_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message })
|
|
2062
|
+
};
|
|
2063
|
+
function handleStructuredError(ctx) {
|
|
2064
|
+
const handler = ERROR_HANDLERS[ctx.walletError.errorType];
|
|
2065
|
+
if (handler) {
|
|
2066
|
+
handler(ctx);
|
|
2067
|
+
} else {
|
|
2068
|
+
redirectFallback(ctx.skuId, ctx.returnUrl, ctx.country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
async function handlePaymentAuthorized(event, session, sessionData, config) {
|
|
2072
|
+
const { skuId, returnUrl, country } = config;
|
|
2073
|
+
let validatedEmail;
|
|
2074
|
+
try {
|
|
2075
|
+
validatedEmail = validateContacts(
|
|
2076
|
+
event,
|
|
2077
|
+
sessionData,
|
|
2078
|
+
config.supportedBillingCountries,
|
|
2079
|
+
config.delivery
|
|
2080
|
+
);
|
|
2081
|
+
const result = await performPurchase({
|
|
2082
|
+
applePayToken: event.payment.token,
|
|
2083
|
+
skuId: config.skuId,
|
|
2084
|
+
currency: config.currency,
|
|
2085
|
+
billingContact: event.payment.billingContact,
|
|
2086
|
+
...event.payment.shippingContact && {
|
|
2087
|
+
shippingContact: event.payment.shippingContact
|
|
2088
|
+
},
|
|
2089
|
+
...config.delivery && {
|
|
2090
|
+
supportedDeliveryCountries: config.delivery.supportedCountries
|
|
2091
|
+
},
|
|
2092
|
+
...ADDRESS_PARITY_ENABLED ? { strictAddressRules: true } : {},
|
|
2093
|
+
recaptchaToken: config.recaptchaToken
|
|
2094
|
+
});
|
|
2095
|
+
trackWalletPaymentSuccess(skuId, result.basketId);
|
|
2096
|
+
session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
2097
|
+
const successEmail = sessionData.loggedIn ? sessionData.emailAddress : validatedEmail;
|
|
2098
|
+
const userStatus = sessionData.loggedIn ? "lex" : "nex";
|
|
2099
|
+
writeCheckoutRedirect(returnUrl);
|
|
2100
|
+
window.location.href = redirectToCheckoutComplete({
|
|
2101
|
+
basketId: result.basketId,
|
|
2102
|
+
status: userStatus,
|
|
2103
|
+
skuId: decodeSku(skuId),
|
|
2104
|
+
email: successEmail,
|
|
2105
|
+
country
|
|
2106
|
+
});
|
|
2107
|
+
} catch (err) {
|
|
2108
|
+
if (err instanceof ContactValidationError) {
|
|
2109
|
+
failApplePaySession(session, err.errors);
|
|
2110
|
+
return;
|
|
2111
|
+
}
|
|
2112
|
+
const walletError = parseWalletApiError(err);
|
|
2113
|
+
trackWalletPaymentFailure(skuId, walletError?.errorType ?? "UNKNOWN");
|
|
2114
|
+
failApplePaySession(session);
|
|
2115
|
+
if (!walletError) {
|
|
2116
|
+
redirectFallback(skuId, returnUrl, country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
|
|
2117
|
+
return;
|
|
2118
|
+
}
|
|
2119
|
+
handleStructuredError({ skuId, returnUrl, country, validatedEmail, walletError });
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
|
|
1943
2123
|
// src/data/eea-countries.json
|
|
1944
2124
|
var eea_countries_default = [
|
|
1945
2125
|
"AT",
|
|
@@ -1977,10 +2157,10 @@ var eea_countries_default = [
|
|
|
1977
2157
|
];
|
|
1978
2158
|
|
|
1979
2159
|
// src/utils/billing-countries.ts
|
|
1980
|
-
var
|
|
2160
|
+
var priceZones2 = price_zones_default;
|
|
1981
2161
|
var eeaCountries = eea_countries_default;
|
|
1982
|
-
var ALL_COUNTRY_CODES = Object.values(
|
|
1983
|
-
var getZoneByCountry = (country) => Object.keys(
|
|
2162
|
+
var ALL_COUNTRY_CODES = Object.values(priceZones2).flat();
|
|
2163
|
+
var getZoneByCountry = (country) => Object.keys(priceZones2).find((key) => priceZones2[key].includes(country)) ?? null;
|
|
1984
2164
|
var getSupportedBillingCountries = (offerCountry, offerVariant) => {
|
|
1985
2165
|
if (offerVariant === "bundle" || offerVariant === "insider_print") {
|
|
1986
2166
|
return [...ALL_COUNTRY_CODES];
|
|
@@ -1989,50 +2169,143 @@ var getSupportedBillingCountries = (offerCountry, offerVariant) => {
|
|
|
1989
2169
|
if (!zone) {
|
|
1990
2170
|
return [...ALL_COUNTRY_CODES];
|
|
1991
2171
|
}
|
|
1992
|
-
const zoneCountries =
|
|
2172
|
+
const zoneCountries = priceZones2[zone];
|
|
1993
2173
|
if (eeaCountries.includes(offerCountry)) {
|
|
1994
2174
|
return Array.from(/* @__PURE__ */ new Set([...zoneCountries, ...eeaCountries]));
|
|
1995
2175
|
}
|
|
1996
2176
|
return [...zoneCountries];
|
|
1997
2177
|
};
|
|
1998
2178
|
|
|
1999
|
-
// src/
|
|
2000
|
-
var
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2179
|
+
// src/data/no-delivery-countries.json
|
|
2180
|
+
var no_delivery_countries_default = [
|
|
2181
|
+
"KH",
|
|
2182
|
+
"MM",
|
|
2183
|
+
"PK",
|
|
2184
|
+
"BI",
|
|
2185
|
+
"CV",
|
|
2186
|
+
"CF",
|
|
2187
|
+
"TD",
|
|
2188
|
+
"CG",
|
|
2189
|
+
"DJ",
|
|
2190
|
+
"EG",
|
|
2191
|
+
"GM",
|
|
2192
|
+
"GN",
|
|
2193
|
+
"GW",
|
|
2194
|
+
"LB",
|
|
2195
|
+
"LR",
|
|
2196
|
+
"LY",
|
|
2197
|
+
"ML",
|
|
2198
|
+
"MU",
|
|
2199
|
+
"RE",
|
|
2200
|
+
"SL",
|
|
2201
|
+
"AZ",
|
|
2202
|
+
"BY",
|
|
2203
|
+
"UA",
|
|
2204
|
+
"BM",
|
|
2205
|
+
"BO",
|
|
2206
|
+
"KY",
|
|
2207
|
+
"EC",
|
|
2208
|
+
"HN",
|
|
2209
|
+
"PA",
|
|
2210
|
+
"PE",
|
|
2211
|
+
"UY"
|
|
2212
|
+
];
|
|
2213
|
+
|
|
2214
|
+
// src/utils/delivery-countries.ts
|
|
2215
|
+
var priceZones3 = price_zones_default;
|
|
2216
|
+
var noDeliveryCountries = no_delivery_countries_default;
|
|
2217
|
+
var getSupportedDeliveryCountries = (offerCountry) => {
|
|
2218
|
+
const zone = Object.keys(priceZones3).find(
|
|
2219
|
+
(key) => priceZones3[key].includes(offerCountry)
|
|
2220
|
+
);
|
|
2221
|
+
if (!zone) return [];
|
|
2222
|
+
return priceZones3[zone].filter(
|
|
2223
|
+
(country) => !noDeliveryCountries.includes(country)
|
|
2224
|
+
);
|
|
2225
|
+
};
|
|
2226
|
+
|
|
2227
|
+
// src/utils/printOffersFlag.ts
|
|
2228
|
+
var PRINT_OFFERS_ENABLED = true;
|
|
2229
|
+
|
|
2230
|
+
// src/utils/buttonCopyFlag.ts
|
|
2231
|
+
var CONTINUE_WITH_COPY_ENABLED = true;
|
|
2232
|
+
var BUTTON_COPY = {
|
|
2233
|
+
subscribe: { caption: "Subscribe with", label: "Subscribe with Apple Pay" },
|
|
2234
|
+
continue: { caption: "Continue with", label: "Continue with Apple Pay" }
|
|
2004
2235
|
};
|
|
2236
|
+
var getButtonCopy = (enabled = CONTINUE_WITH_COPY_ENABLED) => enabled ? BUTTON_COPY.continue : BUTTON_COPY.subscribe;
|
|
2005
2237
|
|
|
2006
2238
|
// src/utils/applePayExpressEligibility.ts
|
|
2007
|
-
var
|
|
2008
|
-
|
|
2009
|
-
|
|
2239
|
+
var isEligibleForApplePayExpressPaywall = () => isAppleDeviceOrSafari();
|
|
2240
|
+
|
|
2241
|
+
// src/constants.ts
|
|
2242
|
+
var ApplePayEntryPoint = /* @__PURE__ */ ((ApplePayEntryPoint2) => {
|
|
2243
|
+
ApplePayEntryPoint2["PAYWALL"] = "article_paywall";
|
|
2244
|
+
ApplePayEntryPoint2["REGWALL"] = "article_regwall";
|
|
2245
|
+
ApplePayEntryPoint2["DUAL_OFFER_BANNER"] = "dual_offer_banner";
|
|
2246
|
+
ApplePayEntryPoint2["FREE_TRIAL_BANNER"] = "free_trial_banner";
|
|
2247
|
+
ApplePayEntryPoint2["FREE_TRIAL_POPUP"] = "free_trial_popup";
|
|
2248
|
+
ApplePayEntryPoint2["SUBSCRIBE"] = "subscribe";
|
|
2249
|
+
ApplePayEntryPoint2["SALES_PAGE"] = "sales_page";
|
|
2250
|
+
return ApplePayEntryPoint2;
|
|
2251
|
+
})(ApplePayEntryPoint || {});
|
|
2010
2252
|
|
|
2011
2253
|
// src/apple-pay-button.ts
|
|
2254
|
+
var PRINT_VARIANTS = ["bundle", "insider_print"];
|
|
2255
|
+
var NO_EXCLUSIONS = [];
|
|
2012
2256
|
var ENTRY_POINT_CONFIG = {
|
|
2013
2257
|
["dual_offer_banner" /* DUAL_OFFER_BANNER */]: {
|
|
2014
|
-
isEligible:
|
|
2015
|
-
|
|
2258
|
+
isEligible: () => true,
|
|
2259
|
+
returnUrl: "current_page" /* CURRENT_PAGE */,
|
|
2260
|
+
allowsPrintOffers: false
|
|
2261
|
+
},
|
|
2262
|
+
["free_trial_banner" /* FREE_TRIAL_BANNER */]: {
|
|
2263
|
+
isEligible: () => true,
|
|
2264
|
+
returnUrl: "current_page" /* CURRENT_PAGE */,
|
|
2265
|
+
allowsPrintOffers: false
|
|
2016
2266
|
},
|
|
2017
2267
|
["article_paywall" /* PAYWALL */]: {
|
|
2018
|
-
isEligible:
|
|
2019
|
-
|
|
2268
|
+
isEligible: isEligibleForApplePayExpressPaywall,
|
|
2269
|
+
returnUrl: "current_page" /* CURRENT_PAGE */,
|
|
2270
|
+
allowsPrintOffers: false
|
|
2020
2271
|
},
|
|
2021
2272
|
["article_regwall" /* REGWALL */]: {
|
|
2022
2273
|
isEligible: () => true,
|
|
2023
|
-
enabled: false
|
|
2274
|
+
enabled: false,
|
|
2275
|
+
returnUrl: "current_page" /* CURRENT_PAGE */,
|
|
2276
|
+
allowsPrintOffers: false
|
|
2277
|
+
},
|
|
2278
|
+
["free_trial_popup" /* FREE_TRIAL_POPUP */]: {
|
|
2279
|
+
isEligible: () => true,
|
|
2280
|
+
returnUrl: "current_page" /* CURRENT_PAGE */,
|
|
2281
|
+
allowsPrintOffers: false
|
|
2282
|
+
},
|
|
2283
|
+
["subscribe" /* SUBSCRIBE */]: {
|
|
2284
|
+
isEligible: () => true,
|
|
2285
|
+
// Always-on after offer exclusions — host (sma-checkout) owns rollout toggle
|
|
2286
|
+
// The offers page is not a place to return to: the host keeps the article the user arrived from (or home).
|
|
2287
|
+
returnUrl: "host_managed" /* HOST_MANAGED */,
|
|
2288
|
+
allowsPrintOffers: true
|
|
2289
|
+
},
|
|
2290
|
+
["sales_page" /* SALES_PAGE */]: {
|
|
2291
|
+
isEligible: () => true,
|
|
2292
|
+
// Host-owned page (sma-checkout), like /subscribe: the host keeps the user's return target.
|
|
2293
|
+
returnUrl: "host_managed" /* HOST_MANAGED */,
|
|
2294
|
+
// Print stays off until a sales page needs it; flip to true (and QA) to take print there.
|
|
2295
|
+
allowsPrintOffers: false
|
|
2024
2296
|
}
|
|
2025
2297
|
};
|
|
2026
|
-
var
|
|
2298
|
+
var DEFAULT_ENTRY_POINT = "dual_offer_banner" /* DUAL_OFFER_BANNER */;
|
|
2027
2299
|
var TOTAL_LABEL = "The Economist";
|
|
2028
2300
|
var DEFAULT_CURRENCY = "USD";
|
|
2029
2301
|
var DEFAULT_TOTAL = "0.00";
|
|
2030
2302
|
var SEL_CONTAINER = ".apple-pay-container";
|
|
2031
2303
|
var SEL_BUTTON = ".apple-pay-btn";
|
|
2032
|
-
var APPLE_PAY_EXCLUDED_VARIANTS =
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2304
|
+
var APPLE_PAY_EXCLUDED_VARIANTS = PRINT_VARIANTS;
|
|
2305
|
+
var getExcludedVariants = (entryPoint) => {
|
|
2306
|
+
const config = ENTRY_POINT_CONFIG[entryPoint || DEFAULT_ENTRY_POINT] ?? ENTRY_POINT_CONFIG[DEFAULT_ENTRY_POINT];
|
|
2307
|
+
return PRINT_OFFERS_ENABLED && config.allowsPrintOffers ? NO_EXCLUSIONS : PRINT_VARIANTS;
|
|
2308
|
+
};
|
|
2036
2309
|
var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
2037
2310
|
static tag = "teg-apple-pay-button";
|
|
2038
2311
|
static define() {
|
|
@@ -2041,22 +2314,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
2041
2314
|
/**
|
|
2042
2315
|
* Creates and configures an ApplePayButton when the entry point allows it.
|
|
2043
2316
|
*
|
|
2044
|
-
* - `DUAL_OFFER_BANNER` (or omitted): always-on after
|
|
2045
|
-
* no
|
|
2046
|
-
*
|
|
2047
|
-
*
|
|
2048
|
-
* `
|
|
2317
|
+
* - `DUAL_OFFER_BANNER` (or omitted): always-on after offer exclusions —
|
|
2318
|
+
* no homepage/Safari gate here. Safari/Apple is enforced later by
|
|
2319
|
+
* `isApplePayAvailable()` on mount.
|
|
2320
|
+
* - `FREE_TRIAL_BANNER`: same always-on-after-exclusions gate as Dual; distinct
|
|
2321
|
+
* TEDL `entry_point` string (`free_trial_banner`) for wallet impression attribution.
|
|
2322
|
+
* - `FREE_TRIAL_POPUP`: same always-on-after-exclusions gate. Distinct TEDL
|
|
2323
|
+
* `entry_point` (`free_trial_popup`).
|
|
2324
|
+
* - `PAYWALL`: always-on after offer exclusions + Safari/Apple placement
|
|
2325
|
+
* eligibility. No Amplitude experiment / `$exposure`.
|
|
2049
2326
|
* - `REGWALL`: inert — always returns null.
|
|
2050
2327
|
*
|
|
2051
|
-
*
|
|
2052
|
-
* `
|
|
2053
|
-
* treatment (and without inflating `$exposure`). For banners, the same URL
|
|
2054
|
-
* param / `BYPASS_APPLE_PAY_CHECKS` only bypass **eligibility**, not an
|
|
2055
|
-
* experiment gate.
|
|
2056
|
-
*
|
|
2057
|
-
* **Eligibility:**
|
|
2058
|
-
* - `DUAL_OFFER_BANNER` (or omitted): homepage + Safari/iPhone
|
|
2059
|
-
* - `PAYWALL`: Safari/Apple device only (no homepage) — article paywalls
|
|
2328
|
+
* `BYPASS_APPLE_PAY_CHECKS` skips placement eligibility here and device checks
|
|
2329
|
+
* in `isApplePayAvailable()` on mount (QA on non-Apple browsers).
|
|
2060
2330
|
*
|
|
2061
2331
|
* @param offer - The offer to display in the Apple Pay flow.
|
|
2062
2332
|
* @param country - The user's country code.
|
|
@@ -2066,46 +2336,22 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
2066
2336
|
if (!offer) {
|
|
2067
2337
|
return null;
|
|
2068
2338
|
}
|
|
2069
|
-
|
|
2070
|
-
return null;
|
|
2071
|
-
}
|
|
2072
|
-
const hasUrlParamFlag = new URLSearchParams(window.location.search).has(
|
|
2073
|
-
FEATURE_APPLE_PAY_EXPRESS_CHECKOUT
|
|
2074
|
-
);
|
|
2075
|
-
const resolvedEntryPoint = entryPoint || "dual_offer_banner" /* DUAL_OFFER_BANNER */;
|
|
2339
|
+
const resolvedEntryPoint = entryPoint || DEFAULT_ENTRY_POINT;
|
|
2076
2340
|
const config = ENTRY_POINT_CONFIG[resolvedEntryPoint];
|
|
2077
2341
|
if (!config) {
|
|
2078
2342
|
return null;
|
|
2079
2343
|
}
|
|
2080
|
-
|
|
2344
|
+
if (getExcludedVariants(resolvedEntryPoint).includes(offer.product?.variant)) {
|
|
2345
|
+
return null;
|
|
2346
|
+
}
|
|
2347
|
+
const { isEligible: eligibilityCheck } = config;
|
|
2081
2348
|
const isEligible = eligibilityCheck();
|
|
2082
2349
|
if (config.enabled === false) {
|
|
2083
2350
|
return null;
|
|
2084
2351
|
}
|
|
2085
|
-
if (!
|
|
2352
|
+
if (!bypassApplePayChecks() && !isEligible) {
|
|
2086
2353
|
return null;
|
|
2087
2354
|
}
|
|
2088
|
-
if (experimentFlagKey) {
|
|
2089
|
-
const experimentValue = window.experimentIntegration?.getVariant?.(
|
|
2090
|
-
experimentFlagKey
|
|
2091
|
-
);
|
|
2092
|
-
const isExperimentVariant = experimentValue === APPLE_PAY_EXPRESS_VARIANTS.CONTROL || experimentValue === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
|
|
2093
|
-
if (isExperimentVariant && isEligible && !bypassApplePayChecks() && !hasUrlParamFlag) {
|
|
2094
|
-
void isApplePayAvailable().then((available) => {
|
|
2095
|
-
if (available) {
|
|
2096
|
-
trackApplePayExperimentExposure(
|
|
2097
|
-
experimentValue,
|
|
2098
|
-
getExperimentKeyFromNextData(experimentFlagKey),
|
|
2099
|
-
experimentFlagKey
|
|
2100
|
-
);
|
|
2101
|
-
}
|
|
2102
|
-
});
|
|
2103
|
-
}
|
|
2104
|
-
const isTreatment = experimentValue === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
|
|
2105
|
-
if (!isTreatment && !hasUrlParamFlag) {
|
|
2106
|
-
return null;
|
|
2107
|
-
}
|
|
2108
|
-
}
|
|
2109
2355
|
_ApplePayButton.define();
|
|
2110
2356
|
const button = document.createElement(_ApplePayButton.tag);
|
|
2111
2357
|
button.offer = offer;
|
|
@@ -2131,8 +2377,13 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
2131
2377
|
#readyPromise = null;
|
|
2132
2378
|
#sessionData = null;
|
|
2133
2379
|
#paymentOptions = null;
|
|
2380
|
+
/** URL of the page the button is on (sent to payment options). */
|
|
2134
2381
|
#returnUrl = "";
|
|
2382
|
+
/** `checkout-redirect` to persist after purchase, per the entry point's `ReturnUrlPolicy`; `null` = leave it. */
|
|
2383
|
+
#checkoutRedirectUrl = null;
|
|
2135
2384
|
#supportedBillingCountries = [];
|
|
2385
|
+
/** Print (bundle) offers only: countries the offer can be delivered to; `null` for offers without delivery. */
|
|
2386
|
+
#supportedDeliveryCountries = null;
|
|
2136
2387
|
#entryPoint = "";
|
|
2137
2388
|
// ─── Public API ─────────────────────────────────────────────────────────────
|
|
2138
2389
|
get offer() {
|
|
@@ -2197,33 +2448,52 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
2197
2448
|
this.#sessionData = null;
|
|
2198
2449
|
this.#paymentOptions = null;
|
|
2199
2450
|
this.#returnUrl = "";
|
|
2451
|
+
this.#checkoutRedirectUrl = null;
|
|
2200
2452
|
this.#supportedBillingCountries = [];
|
|
2453
|
+
this.#supportedDeliveryCountries = null;
|
|
2201
2454
|
this.querySelector(SEL_CONTAINER)?.remove();
|
|
2202
2455
|
}
|
|
2203
2456
|
// ─── Render pipeline ────────────────────────────────────────────────────────
|
|
2204
2457
|
async #run() {
|
|
2205
2458
|
try {
|
|
2206
2459
|
this.#renderTemplate();
|
|
2460
|
+
this.#captureReturnUrl();
|
|
2461
|
+
const requests = this.#startWalletRequests();
|
|
2207
2462
|
if (await this.#checkAvailability()) return;
|
|
2208
2463
|
if (this.#checkOffer()) return;
|
|
2209
|
-
if (await this.#checkSession()) return;
|
|
2210
|
-
this.#captureReturnUrl();
|
|
2211
2464
|
this.#computeBillingCountries();
|
|
2212
|
-
if (
|
|
2465
|
+
if (this.#computeDeliveryCountries()) return;
|
|
2466
|
+
const [session, options] = await requests;
|
|
2467
|
+
if (this.#applySession(session)) return;
|
|
2468
|
+
if (this.#applyPaymentOptions(options)) return;
|
|
2213
2469
|
this.#finishLoading();
|
|
2214
2470
|
} catch {
|
|
2215
|
-
this
|
|
2216
|
-
this.querySelector(SEL_CONTAINER)?.remove();
|
|
2471
|
+
this.#hide();
|
|
2217
2472
|
} finally {
|
|
2218
2473
|
this.#rendering = false;
|
|
2219
2474
|
}
|
|
2220
2475
|
}
|
|
2476
|
+
/**
|
|
2477
|
+
* Stop the loading spinner before tear-down so Safari does not leave a GPU
|
|
2478
|
+
* ghost of `.apple-pay-btn.wap-loading::before` after the container is removed.
|
|
2479
|
+
*/
|
|
2480
|
+
#hide() {
|
|
2481
|
+
const button = this.querySelector(SEL_BUTTON);
|
|
2482
|
+
if (button) {
|
|
2483
|
+
button.classList.remove("wap-loading");
|
|
2484
|
+
button.removeAttribute("aria-busy");
|
|
2485
|
+
button.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
|
|
2486
|
+
}
|
|
2487
|
+
this.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
|
|
2488
|
+
void this.offsetHeight;
|
|
2489
|
+
this.style.display = "none";
|
|
2490
|
+
this.querySelector(SEL_CONTAINER)?.remove();
|
|
2491
|
+
}
|
|
2221
2492
|
/** Returns `true` (hide) when Apple Pay is unavailable on this device/browser. */
|
|
2222
2493
|
async #checkAvailability() {
|
|
2223
2494
|
const available = await isApplePayAvailable();
|
|
2224
2495
|
if (!available) {
|
|
2225
|
-
this
|
|
2226
|
-
this.querySelector(SEL_CONTAINER)?.remove();
|
|
2496
|
+
this.#hide();
|
|
2227
2497
|
return true;
|
|
2228
2498
|
}
|
|
2229
2499
|
return false;
|
|
@@ -2232,11 +2502,17 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
2232
2502
|
* Returns `true` (hide) when the user already has an active subscription or is B2B.
|
|
2233
2503
|
* Session fetch errors are swallowed — the component continues as an anonymous user.
|
|
2234
2504
|
*/
|
|
2235
|
-
|
|
2236
|
-
|
|
2505
|
+
/** Starts the session and payment-options calls together (neither depends on the other). */
|
|
2506
|
+
#startWalletRequests() {
|
|
2507
|
+
if (!this.#offer || !isApplePayCapable()) {
|
|
2508
|
+
return Promise.resolve([null, null]);
|
|
2509
|
+
}
|
|
2510
|
+
return Promise.all([this.#fetchSession(), this.#fetchPaymentOptions()]);
|
|
2511
|
+
}
|
|
2512
|
+
#applySession(session) {
|
|
2513
|
+
this.#sessionData = session;
|
|
2237
2514
|
if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
|
|
2238
|
-
this
|
|
2239
|
-
this.querySelector(SEL_CONTAINER)?.remove();
|
|
2515
|
+
this.#hide();
|
|
2240
2516
|
return true;
|
|
2241
2517
|
}
|
|
2242
2518
|
return false;
|
|
@@ -2244,8 +2520,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
2244
2520
|
/** Returns `true` (hide) when no offer has been set before mount. */
|
|
2245
2521
|
#checkOffer() {
|
|
2246
2522
|
if (!this.#offer) {
|
|
2247
|
-
this
|
|
2248
|
-
this.querySelector(SEL_CONTAINER)?.remove();
|
|
2523
|
+
this.#hide();
|
|
2249
2524
|
return true;
|
|
2250
2525
|
}
|
|
2251
2526
|
return false;
|
|
@@ -2253,6 +2528,11 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
2253
2528
|
/** Captures the current page URL once at mount for reuse across the session lifetime. */
|
|
2254
2529
|
#captureReturnUrl() {
|
|
2255
2530
|
this.#returnUrl = captureOriginUrl();
|
|
2531
|
+
const config = ENTRY_POINT_CONFIG[this.#entryPoint || DEFAULT_ENTRY_POINT] ?? ENTRY_POINT_CONFIG[DEFAULT_ENTRY_POINT];
|
|
2532
|
+
this.#checkoutRedirectUrl = resolveCheckoutRedirectUrl(
|
|
2533
|
+
config.returnUrl,
|
|
2534
|
+
this.#returnUrl
|
|
2535
|
+
);
|
|
2256
2536
|
}
|
|
2257
2537
|
/**
|
|
2258
2538
|
* Computes supported billing countries once at mount.
|
|
@@ -2265,15 +2545,32 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
2265
2545
|
this.#offer.product?.variant ?? ""
|
|
2266
2546
|
);
|
|
2267
2547
|
}
|
|
2548
|
+
/**
|
|
2549
|
+
* Print (bundle) offers need a delivery address, which the Apple Pay sheet collects. Returns `true` (hide)
|
|
2550
|
+
* when the offer has no country it can be delivered to, because no valid address could ever be entered.
|
|
2551
|
+
*/
|
|
2552
|
+
#computeDeliveryCountries() {
|
|
2553
|
+
const variant = this.#offer.product?.variant;
|
|
2554
|
+
if (!PRINT_VARIANTS.includes(variant)) {
|
|
2555
|
+
this.#supportedDeliveryCountries = null;
|
|
2556
|
+
return false;
|
|
2557
|
+
}
|
|
2558
|
+
const countries = getSupportedDeliveryCountries(this.#country);
|
|
2559
|
+
if (countries.length === 0) {
|
|
2560
|
+
this.#hide();
|
|
2561
|
+
return true;
|
|
2562
|
+
}
|
|
2563
|
+
this.#supportedDeliveryCountries = countries;
|
|
2564
|
+
return false;
|
|
2565
|
+
}
|
|
2268
2566
|
/**
|
|
2269
2567
|
* Returns `true` (hide) when the wallet BFF reports Apple Pay is unavailable
|
|
2270
2568
|
* for this offer. The response is cached and reused in `#initiateApplePay`.
|
|
2271
2569
|
*/
|
|
2272
|
-
|
|
2273
|
-
this.#paymentOptions =
|
|
2570
|
+
#applyPaymentOptions(options) {
|
|
2571
|
+
this.#paymentOptions = options;
|
|
2274
2572
|
if (!this.#paymentOptions?.options?.apple_pay) {
|
|
2275
|
-
this
|
|
2276
|
-
this.querySelector(SEL_CONTAINER)?.remove();
|
|
2573
|
+
this.#hide();
|
|
2277
2574
|
return true;
|
|
2278
2575
|
}
|
|
2279
2576
|
return false;
|
|
@@ -2281,11 +2578,14 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
2281
2578
|
/** Injects the button template and wires click and confirm event listeners. */
|
|
2282
2579
|
#renderTemplate() {
|
|
2283
2580
|
this.style.removeProperty("display");
|
|
2284
|
-
ensureApplePayLogoSymbol();
|
|
2285
2581
|
const template = document.createElement("template");
|
|
2286
2582
|
template.innerHTML = apple_pay_button_template_default;
|
|
2287
2583
|
this.appendChild(template.content.cloneNode(true));
|
|
2288
2584
|
const button = this.querySelector(SEL_BUTTON);
|
|
2585
|
+
const { caption, label } = getButtonCopy();
|
|
2586
|
+
this.querySelector(SEL_CONTAINER)?.setAttribute("aria-label", label);
|
|
2587
|
+
button.setAttribute("aria-label", label);
|
|
2588
|
+
this.querySelector(".apple-pay-btn__caption").textContent = caption;
|
|
2289
2589
|
button.classList.add("wap-loading");
|
|
2290
2590
|
button.setAttribute("disabled", "");
|
|
2291
2591
|
button.setAttribute("aria-disabled", "true");
|
|
@@ -2326,7 +2626,10 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
2326
2626
|
if (document.querySelector(ApplePayModal.tag)) {
|
|
2327
2627
|
return;
|
|
2328
2628
|
}
|
|
2329
|
-
trackExpressWalletClick(
|
|
2629
|
+
trackExpressWalletClick(
|
|
2630
|
+
this.#offer.sku_id,
|
|
2631
|
+
this.#entryPoint ? { entryPoint: this.#entryPoint } : void 0
|
|
2632
|
+
);
|
|
2330
2633
|
ApplePayModal.define();
|
|
2331
2634
|
const modal = document.createElement(ApplePayModal.tag);
|
|
2332
2635
|
modal.offer = this.#offer;
|
|
@@ -2370,16 +2673,25 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
2370
2673
|
totalAmount,
|
|
2371
2674
|
totalLabel: TOTAL_LABEL,
|
|
2372
2675
|
skuId,
|
|
2373
|
-
returnUrl: this.#
|
|
2676
|
+
returnUrl: this.#checkoutRedirectUrl,
|
|
2374
2677
|
userLoggedIn: sessionData.loggedIn,
|
|
2678
|
+
...this.#supportedDeliveryCountries && {
|
|
2679
|
+
delivery: { supportedCountries: this.#supportedDeliveryCountries }
|
|
2680
|
+
},
|
|
2375
2681
|
onPaymentAuthorized: async (event, session) => {
|
|
2376
2682
|
const recaptchaToken = await recaptchaTokenPromise;
|
|
2377
2683
|
return handlePaymentAuthorized(event, session, sessionData, {
|
|
2378
2684
|
skuId,
|
|
2379
2685
|
country,
|
|
2380
2686
|
currency: offer.price?.currency_code ?? DEFAULT_CURRENCY,
|
|
2381
|
-
returnUrl: this.#
|
|
2687
|
+
returnUrl: this.#checkoutRedirectUrl,
|
|
2382
2688
|
supportedBillingCountries: this.#supportedBillingCountries,
|
|
2689
|
+
...this.#supportedDeliveryCountries && {
|
|
2690
|
+
delivery: {
|
|
2691
|
+
offerCountry: country,
|
|
2692
|
+
supportedCountries: this.#supportedDeliveryCountries
|
|
2693
|
+
}
|
|
2694
|
+
},
|
|
2383
2695
|
recaptchaToken
|
|
2384
2696
|
});
|
|
2385
2697
|
}
|
|
@@ -2403,7 +2715,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
2403
2715
|
);
|
|
2404
2716
|
} catch {
|
|
2405
2717
|
redirectToFallbackCheckout({
|
|
2406
|
-
returnUrl: this.#
|
|
2718
|
+
returnUrl: this.#checkoutRedirectUrl,
|
|
2407
2719
|
skuId,
|
|
2408
2720
|
countryCode: country
|
|
2409
2721
|
});
|
|
@@ -2418,12 +2730,10 @@ function defineApplePayElements() {
|
|
|
2418
2730
|
}
|
|
2419
2731
|
export {
|
|
2420
2732
|
APPLE_PAY_EXCLUDED_VARIANTS,
|
|
2421
|
-
APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY,
|
|
2422
|
-
APPLE_PAY_EXPRESS_VARIANTS,
|
|
2423
2733
|
ApplePayButton,
|
|
2424
2734
|
ApplePayEntryPoint,
|
|
2425
2735
|
ApplePayModal,
|
|
2426
2736
|
configureApplePay,
|
|
2427
2737
|
defineApplePayElements,
|
|
2428
|
-
|
|
2738
|
+
getExcludedVariants
|
|
2429
2739
|
};
|