@economist/web-apple-pay 1.7.5 → 1.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +137 -85
- package/dist/src/apple-pay-button.js +137 -85
- package/dist/src/apple-pay-button.stories.js +137 -85
- package/dist/src/apple-pay-logo.js +1 -1
- package/dist/src/apple-pay-modal.js +63 -33
- package/dist/src/apple-pay-modal.stories.js +137 -85
- package/dist/src/clients/payment-checkout/apple-session.js +22 -3
- package/dist/src/clients/payment-checkout/messages.d.ts +13 -14
- package/dist/src/clients/payment-checkout/messages.js +0 -4
- package/dist/src/clients/payment-checkout/payment-handler.d.ts +0 -8
- package/dist/src/clients/payment-checkout/payment-handler.js +45 -27
- package/dist/src/clients/payment-checkout/types.d.ts +1 -1
- package/dist/src/index.js +137 -85
- package/dist/src/utils/expressCheckoutRedirect.d.ts +29 -7
- package/dist/src/utils/expressCheckoutRedirect.js +23 -7
- package/package.json +1 -1
|
@@ -71,7 +71,7 @@ function ensureApplePayLogoSymbol() {
|
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
73
|
const tmp = document.createElement("div");
|
|
74
|
-
tmp.innerHTML = `<svg aria-hidden="true" style="display:none" id="${LOGO_DEFS_ID}"><defs><symbol id="apple-pay-logo" viewBox="0 0 51 22"><path d="${LOGO_PATH}" fill="
|
|
74
|
+
tmp.innerHTML = `<svg aria-hidden="true" style="display:none" id="${LOGO_DEFS_ID}"><defs><symbol id="apple-pay-logo" viewBox="0 0 51 22"><path d="${LOGO_PATH}" fill="currentColor"/></symbol></defs></svg>`;
|
|
75
75
|
document.body.prepend(tmp.firstElementChild);
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -109,16 +109,32 @@ var apple_pay_modal_template_default = `<style>
|
|
|
109
109
|
position: absolute;
|
|
110
110
|
top: 1.5rem;
|
|
111
111
|
right: 1.3125rem;
|
|
112
|
-
background:
|
|
112
|
+
background: transparent;
|
|
113
113
|
border: none;
|
|
114
114
|
cursor: pointer;
|
|
115
115
|
padding: 0;
|
|
116
|
+
width: 1.5rem;
|
|
117
|
+
height: 1.5rem;
|
|
116
118
|
display: flex;
|
|
117
119
|
align-items: center;
|
|
118
120
|
justify-content: center;
|
|
121
|
+
color: var(--mb-colour-greyscale-london-20, #1a1a1a);
|
|
122
|
+
transition:
|
|
123
|
+
background-color ease-in-out 0.2s,
|
|
124
|
+
color ease-in-out 0.2s;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.apm__close:hover {
|
|
128
|
+
color: var(--mb-colour-base-chicago-30, #333333);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.apm__close:active {
|
|
132
|
+
background-color: var(--mb-colour-base-chicago-90, #e6e6e6);
|
|
133
|
+
color: var(--mb-colour-base-chicago-30, #333333);
|
|
119
134
|
}
|
|
120
135
|
|
|
121
136
|
.apm__close:focus {
|
|
137
|
+
background-color: var(--mb-colour-base-chicago-90, #e6e6e6);
|
|
122
138
|
outline: solid 0.125rem var(--focus-border-color, #121212);
|
|
123
139
|
border-radius: 0.25rem;
|
|
124
140
|
}
|
|
@@ -301,10 +317,6 @@ var apple_pay_modal_template_default = `<style>
|
|
|
301
317
|
cursor: pointer;
|
|
302
318
|
color: #fff;
|
|
303
319
|
text-align: center;
|
|
304
|
-
font-family: var(
|
|
305
|
-
--mb-typeface-sans,
|
|
306
|
-
var(--wall-type-system-sans, system-ui, sans-serif)
|
|
307
|
-
);
|
|
308
320
|
font-size: 1.25rem;
|
|
309
321
|
font-style: normal;
|
|
310
322
|
font-weight: 500;
|
|
@@ -320,28 +332,41 @@ var apple_pay_modal_template_default = `<style>
|
|
|
320
332
|
cursor: not-allowed;
|
|
321
333
|
}
|
|
322
334
|
|
|
323
|
-
.apm__cta
|
|
324
|
-
|
|
335
|
+
.apm__cta-content {
|
|
336
|
+
display: flex;
|
|
337
|
+
align-items: center;
|
|
338
|
+
gap: 0.375rem;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
.apm__cta-label {
|
|
342
|
+
display: inline-flex;
|
|
343
|
+
align-items: center;
|
|
344
|
+
gap: 0.375rem;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
.apm__cta-loading {
|
|
348
|
+
display: none;
|
|
325
349
|
}
|
|
326
350
|
|
|
327
|
-
.apm__cta[aria-busy="true"]::
|
|
351
|
+
.apm__cta[aria-busy="true"]::before {
|
|
328
352
|
content: '';
|
|
329
353
|
position: absolute;
|
|
330
|
-
left: 50%;
|
|
331
354
|
top: 50%;
|
|
332
|
-
|
|
333
|
-
margin-top: -0.625rem;
|
|
355
|
+
left: 50%;
|
|
334
356
|
width: 1.25rem;
|
|
335
357
|
height: 1.25rem;
|
|
336
|
-
border: 2px solid rgba(255, 255, 255, 0.
|
|
358
|
+
border: 2px solid rgba(255, 255, 255, 0.25);
|
|
337
359
|
border-top-color: #fff;
|
|
338
360
|
border-radius: 50%;
|
|
339
361
|
animation: apm-cta-spinner 0.8s linear infinite;
|
|
340
362
|
}
|
|
341
363
|
|
|
342
364
|
@keyframes apm-cta-spinner {
|
|
365
|
+
from {
|
|
366
|
+
transform: translate(-50%, -50%) rotate(0deg);
|
|
367
|
+
}
|
|
343
368
|
to {
|
|
344
|
-
transform: rotate(360deg);
|
|
369
|
+
transform: translate(-50%, -50%) rotate(360deg);
|
|
345
370
|
}
|
|
346
371
|
}
|
|
347
372
|
|
|
@@ -408,7 +433,7 @@ var apple_pay_modal_template_default = `<style>
|
|
|
408
433
|
fill-rule="evenodd"
|
|
409
434
|
clip-rule="evenodd"
|
|
410
435
|
d="M18.75 6.60964L17.3904 5.25L12 10.6404L6.60964 5.25L5.25 6.60964L10.6404 12L5.25 17.3904L6.60964 18.75L12 13.3596L17.3904 18.75L18.75 17.3904L13.3596 12L18.75 6.60964Z"
|
|
411
|
-
fill="
|
|
436
|
+
fill="currentColor"
|
|
412
437
|
/>
|
|
413
438
|
</g>
|
|
414
439
|
<defs>
|
|
@@ -518,11 +543,14 @@ var apple_pay_modal_template_default = `<style>
|
|
|
518
543
|
</div>
|
|
519
544
|
<button class="apm__cta" id="apple-pay-modal-cta" aria-label="Continue with Apple Pay">
|
|
520
545
|
<span class="apm__cta-content">
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
<
|
|
524
|
-
|
|
546
|
+
<span class="apm__cta-label">
|
|
547
|
+
Continue with
|
|
548
|
+
<svg width="51" height="22" aria-hidden="true" role="img">
|
|
549
|
+
<use href="#apple-pay-logo" />
|
|
550
|
+
</svg>
|
|
551
|
+
</span>
|
|
525
552
|
</span>
|
|
553
|
+
<span class="apm__cta-loading" aria-hidden="true">Loading...</span>
|
|
526
554
|
</button>
|
|
527
555
|
</div>
|
|
528
556
|
</div>
|
|
@@ -671,6 +699,8 @@ function renewalPeriodText(unit, duration) {
|
|
|
671
699
|
return "";
|
|
672
700
|
}
|
|
673
701
|
}
|
|
702
|
+
var LI_SEPARATOR = "\0LI_SEP\0";
|
|
703
|
+
var P_SEPARATOR = "\0P_SEP\0";
|
|
674
704
|
function buildTermsContext(offer, country) {
|
|
675
705
|
const isUS = country === "US";
|
|
676
706
|
const isCA = country === "CA";
|
|
@@ -707,19 +737,19 @@ function freeTrialTerms(offer, ctx) {
|
|
|
707
737
|
const trialDuration = offer.subscription_options?.trial_period?.duration ?? 1;
|
|
708
738
|
const trialDateStr = `on ${getRenewalDateText(trialUnit, trialDuration)}${ctx.verificationText}`;
|
|
709
739
|
if (ctx.isUS) {
|
|
710
|
-
return `Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${trialDateStr} when your free trial ends, until cancelled{
|
|
740
|
+
return `Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${trialDateStr} when your free trial ends, until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}`;
|
|
711
741
|
}
|
|
712
|
-
return `Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${trialDateStr} when your free trial ends, until cancelled{
|
|
742
|
+
return `Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${trialDateStr} when your free trial ends, until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
|
|
713
743
|
}
|
|
714
744
|
function nytTerms(ctx) {
|
|
715
745
|
const nytAccessText = "Your complimentary access to The New York Times is for one year only and does not auto-renew. We will send your instructions on how to redeem access to The New York Times by email.";
|
|
716
746
|
if (ctx.isUS) {
|
|
717
|
-
return `Your subscription to <em>The Economist</em> auto-renews ${ctx.periodText} until cancelled{
|
|
747
|
+
return `Your subscription to <em>The Economist</em> auto-renews ${ctx.periodText} until cancelled${LI_SEPARATOR}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.renewalDateStr}${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}${P_SEPARATOR}${nytAccessText}`;
|
|
718
748
|
}
|
|
719
749
|
if (ctx.isCA) {
|
|
720
|
-
return `Your subscription to <em>The Economist</em> auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled
|
|
750
|
+
return `Your subscription to <em>The Economist</em> auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled.${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}${P_SEPARATOR}${nytAccessText}`;
|
|
721
751
|
}
|
|
722
|
-
return `Your subscription to <em>The Economist</em> auto-renews at ${ctx.renewalPriceText} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled{
|
|
752
|
+
return `Your subscription to <em>The Economist</em> auto-renews at ${ctx.renewalPriceText} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime} ${nytAccessText}`;
|
|
723
753
|
}
|
|
724
754
|
function minTermContractTerms(offer, ctx) {
|
|
725
755
|
const duePrice = formatPrice(offer.price.purchase, offer.price.currency_code);
|
|
@@ -729,28 +759,28 @@ function minTermContractTerms(offer, ctx) {
|
|
|
729
759
|
const contractLength = mtDuration && mtUnit ? `${mtDuration} ${mtUnit}` : "";
|
|
730
760
|
const initialContractText = contractLength ? `your initial ${contractLength} contract` : "your initial contract";
|
|
731
761
|
const mtRenewalDateText = mtUnit && mtDuration ? getRenewalDateText(mtUnit, Number(mtDuration)) : ctx.renewalDateText;
|
|
732
|
-
return `You\u2019ll be charged ${duePrice} a month for the duration of ${initialContractText}{
|
|
762
|
+
return `You\u2019ll be charged ${duePrice} a month for the duration of ${initialContractText}${LI_SEPARATOR}Your subscription auto-renews annually at ${ctx.renewalPriceText} a month on ${mtRenewalDateText} until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}`;
|
|
733
763
|
}
|
|
734
764
|
function paidTrialTerms(offer, ctx) {
|
|
735
765
|
const trialUnit = offer.subscription_options?.trial_period?.unit ?? ctx.unit;
|
|
736
766
|
const trialDuration = offer.subscription_options?.trial_period?.duration ?? ctx.duration;
|
|
737
767
|
const trialDateText = getRenewalDateText(trialUnit, trialDuration);
|
|
738
768
|
if (ctx.isUS) {
|
|
739
|
-
return `Your subscription auto-renews ${ctx.periodText} until cancelled{
|
|
769
|
+
return `Your subscription auto-renews ${ctx.periodText} until cancelled${LI_SEPARATOR}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} on ${trialDateText} when your paid trial ends${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.usCancelNote}${ctx.taxFootnote}`;
|
|
740
770
|
}
|
|
741
|
-
return `Your subscription auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} on ${trialDateText} when your paid trial ends, until cancelled{
|
|
771
|
+
return `Your subscription auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} on ${trialDateText} when your paid trial ends, until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
|
|
742
772
|
}
|
|
743
773
|
function autoRenewalTerms(ctx) {
|
|
744
774
|
if (ctx.isUS) {
|
|
745
|
-
return `Your subscription auto-renews ${ctx.periodText} until cancelled{
|
|
775
|
+
return `Your subscription auto-renews ${ctx.periodText} until cancelled${LI_SEPARATOR}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.renewalDateStr}${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}`;
|
|
746
776
|
}
|
|
747
|
-
return `Your subscription auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled{
|
|
777
|
+
return `Your subscription auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled${LI_SEPARATOR}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
|
|
748
778
|
}
|
|
749
779
|
function noAutoRenewalTerms(ctx) {
|
|
750
780
|
if (ctx.isUS || ctx.isCA) {
|
|
751
|
-
return `Your subscription does not renew automatically${ctx.taxFootnote}{
|
|
781
|
+
return `Your subscription does not renew automatically${ctx.taxFootnote}${LI_SEPARATOR}`;
|
|
752
782
|
}
|
|
753
|
-
return `Your subscription does not renew automatically{
|
|
783
|
+
return `Your subscription does not renew automatically${LI_SEPARATOR}`;
|
|
754
784
|
}
|
|
755
785
|
function generateApplePayModalTerms(offer, country) {
|
|
756
786
|
const ctx = buildTermsContext(offer, country);
|
|
@@ -773,9 +803,9 @@ function generateApplePayModalTerms(offer, country) {
|
|
|
773
803
|
return noAutoRenewalTerms(ctx);
|
|
774
804
|
}
|
|
775
805
|
function renderTermsHtml(termsText) {
|
|
776
|
-
const renewalTextLists = termsText.split(
|
|
806
|
+
const renewalTextLists = termsText.split(LI_SEPARATOR);
|
|
777
807
|
const lastPart = renewalTextLists.pop() || "";
|
|
778
|
-
const renewalTextParagraphs = lastPart.split(
|
|
808
|
+
const renewalTextParagraphs = lastPart.split(P_SEPARATOR);
|
|
779
809
|
const ulHtml = `<ul class="apm__terms-bullets">${renewalTextLists.map((value) => `<li>${value}</li>`).join("")}</ul>`;
|
|
780
810
|
const paragraphHtml = renewalTextParagraphs.filter(Boolean).map((value) => `<p class="apm__terms-legal">${value}</p>`).join("");
|
|
781
811
|
return ulHtml + paragraphHtml;
|
|
@@ -1018,8 +1048,8 @@ var apple_pay_button_template_default = `<style>
|
|
|
1018
1048
|
min-width: 0;
|
|
1019
1049
|
height: 100%;
|
|
1020
1050
|
min-height: var(--apple-pay-height, 2.75rem);
|
|
1021
|
-
background-color: #000;
|
|
1022
|
-
color: #fff;
|
|
1051
|
+
background-color: var(--apple-pay-background-color, #000);
|
|
1052
|
+
color: var(--apple-pay-foreground-color, #fff);
|
|
1023
1053
|
border: none;
|
|
1024
1054
|
border-radius: var(--apple-pay-border-radius, 1.375rem);
|
|
1025
1055
|
cursor: pointer;
|
|
@@ -1031,6 +1061,7 @@ var apple_pay_button_template_default = `<style>
|
|
|
1031
1061
|
teg-apple-pay-button .apple-pay-btn svg {
|
|
1032
1062
|
flex-shrink: 0;
|
|
1033
1063
|
display: block;
|
|
1064
|
+
color: currentColor;
|
|
1034
1065
|
}
|
|
1035
1066
|
|
|
1036
1067
|
teg-apple-pay-button .apple-pay-btn.wap-loading {
|
|
@@ -1038,28 +1069,34 @@ var apple_pay_button_template_default = `<style>
|
|
|
1038
1069
|
cursor: default;
|
|
1039
1070
|
}
|
|
1040
1071
|
|
|
1041
|
-
teg-apple-pay-button .apple-pay-btn.wap-loading
|
|
1042
|
-
visibility: hidden;
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
teg-apple-pay-button .apple-pay-btn.wap-loading::after {
|
|
1072
|
+
teg-apple-pay-button .apple-pay-btn.wap-loading::before {
|
|
1046
1073
|
content: '';
|
|
1047
1074
|
position: absolute;
|
|
1048
|
-
left: 50%;
|
|
1049
1075
|
top: 50%;
|
|
1050
|
-
|
|
1051
|
-
margin-top: -0.625rem;
|
|
1076
|
+
left: 50%;
|
|
1052
1077
|
width: 1.25rem;
|
|
1053
1078
|
height: 1.25rem;
|
|
1054
|
-
border: 2px solid rgba(255, 255, 255, 0.
|
|
1055
|
-
border-top-color:
|
|
1079
|
+
border: 2px solid var(--apple-pay-spinner-track-color, rgba(255, 255, 255, 0.25));
|
|
1080
|
+
border-top-color: var(--apple-pay-spinner-head-color, currentColor);
|
|
1056
1081
|
border-radius: 50%;
|
|
1057
1082
|
animation: wap-button-spinner 0.8s linear infinite;
|
|
1058
1083
|
}
|
|
1059
1084
|
|
|
1085
|
+
teg-apple-pay-button .apple-pay-btn__logo {
|
|
1086
|
+
display: inline-flex;
|
|
1087
|
+
align-items: center;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
teg-apple-pay-button .apple-pay-btn__loading {
|
|
1091
|
+
display: none;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1060
1094
|
@keyframes wap-button-spinner {
|
|
1095
|
+
from {
|
|
1096
|
+
transform: translate(-50%, -50%) rotate(0deg);
|
|
1097
|
+
}
|
|
1061
1098
|
to {
|
|
1062
|
-
transform: rotate(360deg);
|
|
1099
|
+
transform: translate(-50%, -50%) rotate(360deg);
|
|
1063
1100
|
}
|
|
1064
1101
|
}
|
|
1065
1102
|
</style>
|
|
@@ -1071,9 +1108,12 @@ var apple_pay_button_template_default = `<style>
|
|
|
1071
1108
|
aria-label="Pay with Apple Pay"
|
|
1072
1109
|
data-analytics="paywall:apple-pay-checkout"
|
|
1073
1110
|
>
|
|
1074
|
-
<
|
|
1075
|
-
<
|
|
1076
|
-
|
|
1111
|
+
<span class="apple-pay-btn__logo">
|
|
1112
|
+
<svg width="51" height="22" aria-label="Apple Pay" role="img">
|
|
1113
|
+
<use href="#apple-pay-logo" />
|
|
1114
|
+
</svg>
|
|
1115
|
+
</span>
|
|
1116
|
+
<span class="apple-pay-btn__loading" aria-hidden="true">Loading...</span>
|
|
1077
1117
|
</button>
|
|
1078
1118
|
</div>
|
|
1079
1119
|
`;
|
|
@@ -1201,13 +1241,25 @@ var getExpressCheckoutSession = () => {
|
|
|
1201
1241
|
};
|
|
1202
1242
|
|
|
1203
1243
|
// src/utils/expressCheckoutRedirect.ts
|
|
1204
|
-
var
|
|
1205
|
-
var
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1244
|
+
var CHECKOUT_REDIRECT_KEY = "checkout-redirect";
|
|
1245
|
+
var ALLOWED_REDIRECT_HOSTNAME = "economist.com";
|
|
1246
|
+
function isAllowedRedirectUrl(url) {
|
|
1247
|
+
if (url.startsWith("/")) return !url.startsWith("//");
|
|
1248
|
+
try {
|
|
1249
|
+
const { hostname } = new URL(url);
|
|
1250
|
+
return hostname === ALLOWED_REDIRECT_HOSTNAME || hostname.endsWith(`.${ALLOWED_REDIRECT_HOSTNAME}`);
|
|
1251
|
+
} catch {
|
|
1252
|
+
return false;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
var writeCheckoutRedirect = (originUrl) => {
|
|
1256
|
+
if (!isAllowedRedirectUrl(originUrl)) return;
|
|
1257
|
+
try {
|
|
1258
|
+
localStorage.setItem(CHECKOUT_REDIRECT_KEY, originUrl);
|
|
1259
|
+
} catch {
|
|
1260
|
+
}
|
|
1210
1261
|
};
|
|
1262
|
+
var captureOriginUrl = () => window.location.href;
|
|
1211
1263
|
var decodeSku = (sku) => {
|
|
1212
1264
|
try {
|
|
1213
1265
|
return atob(sku.substring(sku.indexOf("-") + 1));
|
|
@@ -1218,14 +1270,11 @@ var decodeSku = (sku) => {
|
|
|
1218
1270
|
var redirectToCheckoutComplete = (params) => {
|
|
1219
1271
|
const url = new URL("/checkout/complete", window.location.origin);
|
|
1220
1272
|
url.searchParams.set("basketId", params.basketId);
|
|
1221
|
-
if (params.queryString) {
|
|
1222
|
-
const qs = params.queryString.startsWith("?") ? params.queryString.slice(1) : params.queryString;
|
|
1223
|
-
new URLSearchParams(qs).forEach((v, k) => url.searchParams.set(k, v));
|
|
1224
|
-
}
|
|
1225
1273
|
url.searchParams.set("lmo_offer", params.skuId);
|
|
1226
1274
|
url.searchParams.set("status", params.status);
|
|
1227
1275
|
url.searchParams.set("redirectToCheckout", "true");
|
|
1228
|
-
url.searchParams.set("
|
|
1276
|
+
if (params.email) url.searchParams.set("email", params.email);
|
|
1277
|
+
if (params.country) url.searchParams.set("country", params.country);
|
|
1229
1278
|
return url.pathname + url.search;
|
|
1230
1279
|
};
|
|
1231
1280
|
var redirectToCheckoutFallback = (params) => {
|
|
@@ -1236,7 +1285,7 @@ var redirectToCheckoutFallback = (params) => {
|
|
|
1236
1285
|
url.searchParams.set("inlineError", params.inlineError);
|
|
1237
1286
|
if (params.email) url.searchParams.set("email", params.email);
|
|
1238
1287
|
if (params.emailError) url.searchParams.set("emailError", params.emailError);
|
|
1239
|
-
url.searchParams.set("
|
|
1288
|
+
if (params.country) url.searchParams.set("country", params.country);
|
|
1240
1289
|
return url.pathname + url.search;
|
|
1241
1290
|
};
|
|
1242
1291
|
|
|
@@ -1320,17 +1369,16 @@ var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a
|
|
|
1320
1369
|
var MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
|
|
1321
1370
|
var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
|
|
1322
1371
|
var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
|
|
1323
|
-
var MSG_RECAPTCHA_VALIDATION_FAILED = "Security check failed. Please try again.";
|
|
1324
|
-
var MSG_EMAIL_COLLISION = "This email address is already linked to an account. Please log in, or try a different email address.";
|
|
1325
1372
|
var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
|
|
1326
1373
|
|
|
1327
1374
|
// src/clients/payment-checkout/apple-session.ts
|
|
1328
1375
|
function redirectToFallbackCheckout(config) {
|
|
1376
|
+
writeCheckoutRedirect(config.returnUrl);
|
|
1329
1377
|
trackFallbackCheckout(config.skuId);
|
|
1330
1378
|
window.location.href = redirectToCheckoutFallback({
|
|
1331
1379
|
skuId: config.skuId,
|
|
1332
|
-
|
|
1333
|
-
|
|
1380
|
+
inlineError: MSG_PAYMENT_GENERIC_ERROR,
|
|
1381
|
+
country: config.countryCode
|
|
1334
1382
|
});
|
|
1335
1383
|
}
|
|
1336
1384
|
async function handleMerchantValidation(event, session, config) {
|
|
@@ -1509,8 +1557,6 @@ var shippingContactDetails = (shippingContact) => {
|
|
|
1509
1557
|
};
|
|
1510
1558
|
|
|
1511
1559
|
// src/clients/payment-checkout/payment-handler.ts
|
|
1512
|
-
var MSG_ELIGIBILITY = "Something went wrong, please try again";
|
|
1513
|
-
var MSG_REGISTRATION = "We couldn't create your account. Please enter your email or try a different login method.";
|
|
1514
1560
|
var failApplePaySession = (session, errors = []) => {
|
|
1515
1561
|
session.completePayment({
|
|
1516
1562
|
status: ApplePaySession.STATUS_FAILURE,
|
|
@@ -1534,37 +1580,42 @@ function validateContacts(event, sessionData, supportedBillingCountries) {
|
|
|
1534
1580
|
}
|
|
1535
1581
|
return void 0;
|
|
1536
1582
|
}
|
|
1537
|
-
function redirectFallback(skuId, returnUrl, options) {
|
|
1583
|
+
function redirectFallback(skuId, returnUrl, country, options) {
|
|
1584
|
+
writeCheckoutRedirect(returnUrl);
|
|
1538
1585
|
trackFallbackCheckout(skuId);
|
|
1539
1586
|
window.location.href = redirectToCheckoutFallback({
|
|
1540
1587
|
skuId,
|
|
1541
|
-
|
|
1588
|
+
country,
|
|
1542
1589
|
...options
|
|
1543
1590
|
});
|
|
1544
1591
|
}
|
|
1545
1592
|
var ERROR_HANDLERS = {
|
|
1546
|
-
|
|
1547
|
-
|
|
1593
|
+
// emailError flows as an inline field error on the email input.
|
|
1594
|
+
// email pre-populates the input so the user doesn't have to retype it.
|
|
1595
|
+
EMAIL_COLLISION: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
|
|
1596
|
+
emailError: walletError.message,
|
|
1597
|
+
email: validatedEmail
|
|
1598
|
+
}),
|
|
1599
|
+
PAYMENT_DECLINED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
|
|
1600
|
+
ELIGIBILITY_REJECTED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
|
|
1601
|
+
REGISTRATION_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
|
|
1602
|
+
ACCOUNT_CREATION_FAILED: ({ skuId, returnUrl, country, validatedEmail, walletError }) => redirectFallback(skuId, returnUrl, country, {
|
|
1603
|
+
emailError: walletError.message,
|
|
1548
1604
|
email: validatedEmail
|
|
1549
1605
|
}),
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
redirectFallback(skuId, returnUrl, { inlineError: MSG_PAYMENT_GENERIC_ERROR })
|
|
1553
|
-
),
|
|
1554
|
-
ELIGIBILITY_REJECTED: ({ skuId, returnUrl }) => redirectFallback(skuId, returnUrl, { inlineError: MSG_ELIGIBILITY }),
|
|
1555
|
-
REGISTRATION_FAILED: ({ skuId, returnUrl }) => redirectFallback(skuId, returnUrl, { inlineError: MSG_REGISTRATION }),
|
|
1556
|
-
VALIDATION_ERROR: ({ skuId, returnUrl }) => redirectFallback(skuId, returnUrl, { inlineError: MSG_RECAPTCHA_VALIDATION_FAILED })
|
|
1606
|
+
VALIDATION_ERROR: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message }),
|
|
1607
|
+
RECAPTCHA_FAILED: ({ skuId, returnUrl, country, walletError }) => redirectFallback(skuId, returnUrl, country, { inlineError: walletError.message })
|
|
1557
1608
|
};
|
|
1558
1609
|
function handleStructuredError(ctx) {
|
|
1559
1610
|
const handler = ERROR_HANDLERS[ctx.walletError.errorType];
|
|
1560
1611
|
if (handler) {
|
|
1561
1612
|
handler(ctx);
|
|
1562
1613
|
} else {
|
|
1563
|
-
redirectFallback(ctx.skuId, ctx.returnUrl, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
|
|
1614
|
+
redirectFallback(ctx.skuId, ctx.returnUrl, ctx.country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
|
|
1564
1615
|
}
|
|
1565
1616
|
}
|
|
1566
1617
|
async function handlePaymentAuthorized(event, session, sessionData, config) {
|
|
1567
|
-
const { skuId, returnUrl,
|
|
1618
|
+
const { skuId, returnUrl, country } = config;
|
|
1568
1619
|
let validatedEmail;
|
|
1569
1620
|
try {
|
|
1570
1621
|
validatedEmail = validateContacts(
|
|
@@ -1584,13 +1635,15 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
|
|
|
1584
1635
|
});
|
|
1585
1636
|
trackWalletPaymentSuccess(skuId, result.basketId);
|
|
1586
1637
|
session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
1638
|
+
const successEmail = sessionData.loggedIn ? sessionData.emailAddress : validatedEmail;
|
|
1587
1639
|
const userStatus = sessionData.loggedIn ? "lex" : "nex";
|
|
1640
|
+
writeCheckoutRedirect(returnUrl);
|
|
1588
1641
|
window.location.href = redirectToCheckoutComplete({
|
|
1589
1642
|
basketId: result.basketId,
|
|
1590
1643
|
status: userStatus,
|
|
1591
1644
|
skuId: decodeSku(skuId),
|
|
1592
|
-
|
|
1593
|
-
|
|
1645
|
+
email: successEmail,
|
|
1646
|
+
country
|
|
1594
1647
|
});
|
|
1595
1648
|
} catch (err) {
|
|
1596
1649
|
if (err instanceof ContactValidationError) {
|
|
@@ -1602,10 +1655,10 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
|
|
|
1602
1655
|
trackWalletPaymentFailure(skuId, walletError?.errorType ?? "UNKNOWN");
|
|
1603
1656
|
failApplePaySession(session);
|
|
1604
1657
|
if (!walletError) {
|
|
1605
|
-
redirectFallback(skuId, returnUrl, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
|
|
1658
|
+
redirectFallback(skuId, returnUrl, country, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
|
|
1606
1659
|
return;
|
|
1607
1660
|
}
|
|
1608
|
-
handleStructuredError({ skuId, returnUrl, validatedEmail, walletError });
|
|
1661
|
+
handleStructuredError({ skuId, returnUrl, country, validatedEmail, walletError });
|
|
1609
1662
|
}
|
|
1610
1663
|
}
|
|
1611
1664
|
|
|
@@ -2191,7 +2244,6 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
2191
2244
|
country,
|
|
2192
2245
|
currency: offer.price?.currency_code ?? DEFAULT_CURRENCY,
|
|
2193
2246
|
returnUrl: this.#returnUrl,
|
|
2194
|
-
queryString: buildQueryString(),
|
|
2195
2247
|
supportedBillingCountries: this.#supportedBillingCountries,
|
|
2196
2248
|
recaptchaTokens
|
|
2197
2249
|
})
|
|
@@ -6,7 +6,7 @@ function ensureApplePayLogoSymbol() {
|
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
8
|
const tmp = document.createElement("div");
|
|
9
|
-
tmp.innerHTML = `<svg aria-hidden="true" style="display:none" id="${LOGO_DEFS_ID}"><defs><symbol id="apple-pay-logo" viewBox="0 0 51 22"><path d="${LOGO_PATH}" fill="
|
|
9
|
+
tmp.innerHTML = `<svg aria-hidden="true" style="display:none" id="${LOGO_DEFS_ID}"><defs><symbol id="apple-pay-logo" viewBox="0 0 51 22"><path d="${LOGO_PATH}" fill="currentColor"/></symbol></defs></svg>`;
|
|
10
10
|
document.body.prepend(tmp.firstElementChild);
|
|
11
11
|
}
|
|
12
12
|
export {
|