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