@economist/web-apple-pay 1.2.0 → 1.3.0
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 +21 -0
- package/dist/src/apple-pay-button.stories.js +1276 -0
- package/dist/src/apple-pay-modal.stories.js +1118 -0
- package/dist/src/stories/fixtures/offer.d.ts +2 -0
- package/dist/src/stories/fixtures/offer.js +28 -0
- package/dist/src/stories/utils/story-env.d.ts +11 -0
- package/dist/src/stories/utils/story-env.js +141 -0
- package/package.json +8 -1
|
@@ -0,0 +1,1276 @@
|
|
|
1
|
+
// src/utils/define.ts
|
|
2
|
+
var define = (component, instance) => {
|
|
3
|
+
if (!window.customElements.get(component)) {
|
|
4
|
+
window.customElements.define(component, instance);
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// src/utils/pricing.ts
|
|
9
|
+
var PRICE_CONSTANTS = {
|
|
10
|
+
CENTS_MULTIPLIER: 100,
|
|
11
|
+
DECIMAL_PLACES: 2,
|
|
12
|
+
NO_DECIMAL_PLACES: 0
|
|
13
|
+
};
|
|
14
|
+
function numberOfDecimalPoints(value) {
|
|
15
|
+
if (!value) {
|
|
16
|
+
return PRICE_CONSTANTS.NO_DECIMAL_PLACES;
|
|
17
|
+
}
|
|
18
|
+
return Number(value.toFixed(PRICE_CONSTANTS.DECIMAL_PLACES)) % 1 === 0 ? PRICE_CONSTANTS.NO_DECIMAL_PLACES : PRICE_CONSTANTS.DECIMAL_PLACES;
|
|
19
|
+
}
|
|
20
|
+
var priceFormatters = {
|
|
21
|
+
CAD: (price) => `C$${price}`,
|
|
22
|
+
SEK: (price) => `${price}Kr`,
|
|
23
|
+
AUD: (price) => `A$${price}`,
|
|
24
|
+
NZD: (price) => `NZ$${price}`,
|
|
25
|
+
HKD: (price) => `HK$${price}`,
|
|
26
|
+
DKK: (price) => `${price}Kr`,
|
|
27
|
+
NOK: (price) => `${price}Kr`,
|
|
28
|
+
CHF: (price) => `${price}Fr`,
|
|
29
|
+
SGD: (price) => `S$${price}`,
|
|
30
|
+
TWD: (price) => `TW$${price}`
|
|
31
|
+
};
|
|
32
|
+
function formatPrice(price, currencyCode, shouldFixDecimalPlaces = true, roundUp = false) {
|
|
33
|
+
if (price === void 0) {
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
const points = numberOfDecimalPoints(price);
|
|
37
|
+
const calculatedPrice = () => {
|
|
38
|
+
if (roundUp) {
|
|
39
|
+
return (Math.ceil(price * PRICE_CONSTANTS.CENTS_MULTIPLIER) / PRICE_CONSTANTS.CENTS_MULTIPLIER).toFixed(PRICE_CONSTANTS.DECIMAL_PLACES);
|
|
40
|
+
}
|
|
41
|
+
if (shouldFixDecimalPlaces) {
|
|
42
|
+
return (Math.round(price * PRICE_CONSTANTS.CENTS_MULTIPLIER) / PRICE_CONSTANTS.CENTS_MULTIPLIER).toFixed(PRICE_CONSTANTS.DECIMAL_PLACES);
|
|
43
|
+
}
|
|
44
|
+
return price;
|
|
45
|
+
};
|
|
46
|
+
const priceFixDecimal = calculatedPrice();
|
|
47
|
+
const priceFormatter = priceFormatters[currencyCode];
|
|
48
|
+
if (priceFormatter) {
|
|
49
|
+
const withCommas = Number(priceFixDecimal).toLocaleString("en", {
|
|
50
|
+
minimumFractionDigits: points
|
|
51
|
+
});
|
|
52
|
+
return priceFormatter(withCommas);
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
return Number(priceFixDecimal).toLocaleString("en", {
|
|
56
|
+
style: "currency",
|
|
57
|
+
currency: currencyCode,
|
|
58
|
+
minimumFractionDigits: points,
|
|
59
|
+
currencyDisplay: "narrowSymbol"
|
|
60
|
+
});
|
|
61
|
+
} catch {
|
|
62
|
+
return `${currencyCode} ${priceFixDecimal}`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
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="white"/></symbol></defs></svg>`;
|
|
75
|
+
document.body.prepend(tmp.firstElementChild);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/templates/apple-pay-modal.template.html
|
|
79
|
+
var apple_pay_modal_template_default = `<style>
|
|
80
|
+
.apm-overlay {
|
|
81
|
+
position: fixed;
|
|
82
|
+
top: 0;
|
|
83
|
+
left: 0;
|
|
84
|
+
width: 100%;
|
|
85
|
+
height: 100%;
|
|
86
|
+
z-index: 97;
|
|
87
|
+
background: rgba(13, 13, 13, 0.7);
|
|
88
|
+
display: flex;
|
|
89
|
+
align-items: center;
|
|
90
|
+
justify-content: center;
|
|
91
|
+
padding: var(--wall-gutter);
|
|
92
|
+
box-sizing: border-box;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.apm {
|
|
96
|
+
position: relative;
|
|
97
|
+
background: #fff;
|
|
98
|
+
border-radius: 8px 8px 0 0;
|
|
99
|
+
border: 1px solid #d9d9d9;
|
|
100
|
+
padding: 24px;
|
|
101
|
+
width: 400px;
|
|
102
|
+
max-width: 400px;
|
|
103
|
+
box-sizing: border-box;
|
|
104
|
+
font-family: var(--wall-type-system-sans);
|
|
105
|
+
box-shadow: 0 4px 16px 0 rgba(13, 13, 13, 0.15);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.apm__close {
|
|
109
|
+
position: absolute;
|
|
110
|
+
top: 24px;
|
|
111
|
+
right: 21px;
|
|
112
|
+
background: none;
|
|
113
|
+
border: none;
|
|
114
|
+
cursor: pointer;
|
|
115
|
+
padding: 0;
|
|
116
|
+
display: flex;
|
|
117
|
+
align-items: center;
|
|
118
|
+
justify-content: center;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.apm__close:focus {
|
|
122
|
+
outline: solid 2px var(--focus-border-color, #121212);
|
|
123
|
+
border-radius: 0.25rem;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.apm__offer-name {
|
|
127
|
+
font-family: var(--wall-type-system-sans);
|
|
128
|
+
font-size: 1.4375rem;
|
|
129
|
+
font-weight: 500;
|
|
130
|
+
color: #0d0d0d;
|
|
131
|
+
line-height: 28px;
|
|
132
|
+
font-style: normal;
|
|
133
|
+
margin: 0 1.5rem 0.5rem 0;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.apm__due-today {
|
|
137
|
+
color: #1a1a1a;
|
|
138
|
+
font-family: var(--wall-type-system-sans);
|
|
139
|
+
font-size: 15px;
|
|
140
|
+
font-style: normal;
|
|
141
|
+
font-weight: 400;
|
|
142
|
+
line-height: 20px;
|
|
143
|
+
margin: 0 0 1rem 0;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.apm__rule {
|
|
147
|
+
border: none;
|
|
148
|
+
border-top: 1px solid #d9d9d9;
|
|
149
|
+
margin: 0 0 1rem 0;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.apm__terms {
|
|
153
|
+
color: #1a1a1a;
|
|
154
|
+
font-family: var(--wall-type-system-sans);
|
|
155
|
+
font-size: 15px;
|
|
156
|
+
font-style: normal;
|
|
157
|
+
font-weight: 400;
|
|
158
|
+
line-height: 1.333;
|
|
159
|
+
margin: 0 0 1rem 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.apm__terms-bullets {
|
|
163
|
+
list-style: disc outside;
|
|
164
|
+
padding-left: 1.25rem;
|
|
165
|
+
margin: 0 0 0.75rem 0;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.apm__terms-bullets li {
|
|
169
|
+
margin-bottom: 0.375rem;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.apm__terms-legal {
|
|
173
|
+
margin: 0;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.apm__checkbox-label {
|
|
177
|
+
display: flex;
|
|
178
|
+
align-items: flex-start;
|
|
179
|
+
gap: 12px;
|
|
180
|
+
font-family: var(--wall-type-system-sans);
|
|
181
|
+
font-size: 0.9375rem;
|
|
182
|
+
color: #0d0d0d;
|
|
183
|
+
line-height: 1.4;
|
|
184
|
+
cursor: pointer;
|
|
185
|
+
margin: 0 0 8px 0;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.apm__checkbox-wrapper {
|
|
189
|
+
position: relative;
|
|
190
|
+
flex-shrink: 0;
|
|
191
|
+
width: 20px;
|
|
192
|
+
height: 20px;
|
|
193
|
+
margin-top: 1px;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.apm__checkbox-input {
|
|
197
|
+
position: absolute;
|
|
198
|
+
opacity: 0;
|
|
199
|
+
width: 100%;
|
|
200
|
+
height: 100%;
|
|
201
|
+
cursor: pointer;
|
|
202
|
+
margin: 0;
|
|
203
|
+
z-index: 1;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.apm__checkbox-custom {
|
|
207
|
+
position: absolute;
|
|
208
|
+
top: 0;
|
|
209
|
+
left: 0;
|
|
210
|
+
width: 20px;
|
|
211
|
+
height: 20px;
|
|
212
|
+
pointer-events: none;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.apm__checkbox-custom svg {
|
|
216
|
+
display: none;
|
|
217
|
+
width: 20px;
|
|
218
|
+
height: 20px;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.apm__checkbox-input:not(:checked)~.apm__checkbox-custom .svg-unchecked {
|
|
222
|
+
display: block;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.apm__checkbox-input:checked~.apm__checkbox-custom .svg-checked {
|
|
226
|
+
display: block;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.apm__checkbox-label--error .apm__checkbox-input:not(:checked)~.apm__checkbox-custom .svg-unchecked {
|
|
230
|
+
display: none;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.apm__checkbox-label--error .apm__checkbox-input:not(:checked)~.apm__checkbox-custom .svg-error {
|
|
234
|
+
display: block;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.apm__checkbox-input:focus-visible~.apm__checkbox-custom {
|
|
238
|
+
outline: solid 2px #c91d42;
|
|
239
|
+
outline-offset: 2px;
|
|
240
|
+
border-radius: 4px;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.apm__checkbox-label a {
|
|
244
|
+
color: #1a1a1a;
|
|
245
|
+
font-weight: 700;
|
|
246
|
+
text-decoration: underline;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
.apm__error {
|
|
250
|
+
display: none;
|
|
251
|
+
align-items: center;
|
|
252
|
+
gap: 12px;
|
|
253
|
+
color: #0d0d0d;
|
|
254
|
+
font-family: var(--wall-type-system-sans);
|
|
255
|
+
font-size: 17px;
|
|
256
|
+
font-style: normal;
|
|
257
|
+
font-weight: 500;
|
|
258
|
+
line-height: 24px;
|
|
259
|
+
margin-bottom: 16px;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
.apm__error--visible {
|
|
263
|
+
display: flex;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.apm__cta {
|
|
267
|
+
display: flex;
|
|
268
|
+
width: 100%;
|
|
269
|
+
height: 44px;
|
|
270
|
+
padding: 6px 16px;
|
|
271
|
+
justify-content: center;
|
|
272
|
+
align-items: center;
|
|
273
|
+
gap: 6px;
|
|
274
|
+
border-radius: 4px;
|
|
275
|
+
background: #000;
|
|
276
|
+
border: none;
|
|
277
|
+
cursor: pointer;
|
|
278
|
+
color: #fff;
|
|
279
|
+
text-align: center;
|
|
280
|
+
font-family: 'SF Pro', var(--wall-type-system-sans, system-ui, sans-serif);
|
|
281
|
+
font-size: 20px;
|
|
282
|
+
font-style: normal;
|
|
283
|
+
font-weight: 500;
|
|
284
|
+
line-height: normal;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
.apm__cta svg {
|
|
288
|
+
flex-shrink: 0;
|
|
289
|
+
display: block;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
@media (min-width: 360px) and (max-width: 600px) {
|
|
293
|
+
.apm {
|
|
294
|
+
width: 390px;
|
|
295
|
+
max-width: 390px;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
@media (min-width: 601px) {
|
|
300
|
+
.apm {
|
|
301
|
+
border-radius: 8px;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
@media (max-width: 359px) {
|
|
306
|
+
.apm {
|
|
307
|
+
width: 320px;
|
|
308
|
+
max-width: 320px;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
@media (max-width: 419px) {
|
|
313
|
+
.apm__cta {
|
|
314
|
+
font-size: 18px;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
</style>
|
|
318
|
+
|
|
319
|
+
<div class="apm-overlay" id="apple-pay-modal-overlay">
|
|
320
|
+
<div class="apm" role="dialog" aria-modal="true" aria-labelledby="apple-pay-modal-offer-name" id="apple-pay-modal"
|
|
321
|
+
tabindex="-1">
|
|
322
|
+
<button class="apm__close" id="apple-pay-modal-close" aria-label="Close">
|
|
323
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
|
|
324
|
+
<g clip-path="url(#clip0_15712_93054)">
|
|
325
|
+
<rect width="24" height="24" fill="white" fill-opacity="0.01" />
|
|
326
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M0 0H24V24H0V0Z" fill="white" fill-opacity="0.01" />
|
|
327
|
+
<path fill-rule="evenodd" clip-rule="evenodd"
|
|
328
|
+
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"
|
|
329
|
+
fill="#333333" />
|
|
330
|
+
</g>
|
|
331
|
+
<defs>
|
|
332
|
+
<clipPath id="clip0_15712_93054">
|
|
333
|
+
<rect width="24" height="24" fill="white" />
|
|
334
|
+
</clipPath>
|
|
335
|
+
</defs>
|
|
336
|
+
</svg>
|
|
337
|
+
</button>
|
|
338
|
+
<p class="apm__offer-name" id="apple-pay-modal-offer-name"></p>
|
|
339
|
+
<p class="apm__due-today" id="apple-pay-modal-due-today"></p>
|
|
340
|
+
<hr class="apm__rule" />
|
|
341
|
+
<div class="apm__terms" id="apple-pay-modal-terms"></div>
|
|
342
|
+
<label class="apm__checkbox-label" id="apple-pay-modal-checkbox-label" for="apple-pay-modal-checkbox">
|
|
343
|
+
<div class="apm__checkbox-wrapper">
|
|
344
|
+
<input class="apm__checkbox-input" type="checkbox" id="apple-pay-modal-checkbox" />
|
|
345
|
+
<span class="apm__checkbox-custom">
|
|
346
|
+
<svg class="svg-unchecked" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
|
347
|
+
xmlns="http://www.w3.org/2000/svg">
|
|
348
|
+
<path
|
|
349
|
+
d="M6 2.5H18C19.933 2.5 21.5 4.067 21.5 6V18C21.5 19.933 19.933 21.5 18 21.5H6C4.067 21.5 2.5 19.933 2.5 18V6C2.5 4.067 4.067 2.5 6 2.5Z"
|
|
350
|
+
fill="white" stroke="#595959" />
|
|
351
|
+
</svg>
|
|
352
|
+
<svg class="svg-checked" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
|
353
|
+
xmlns="http://www.w3.org/2000/svg">
|
|
354
|
+
<g clip-path="url(#clip0_20014_9555)">
|
|
355
|
+
<path
|
|
356
|
+
d="M2 6C2 3.79086 3.79086 2 6 2H18C20.2091 2 22 3.79086 22 6V18C22 20.2091 20.2091 22 18 22H6C3.79086 22 2 20.2091 2 18V6Z"
|
|
357
|
+
fill="#333333" />
|
|
358
|
+
<path d="M10.2857 17L6 12.6814L7.20857 11.4635L10.2857 14.5557L16.7914 8L18 9.22649L10.2857 17Z"
|
|
359
|
+
fill="white" />
|
|
360
|
+
</g>
|
|
361
|
+
<defs>
|
|
362
|
+
<clipPath id="clip0_20014_9555">
|
|
363
|
+
<path
|
|
364
|
+
d="M2 6C2 3.79086 3.79086 2 6 2H18C20.2091 2 22 3.79086 22 6V18C22 20.2091 20.2091 22 18 22H6C3.79086 22 2 20.2091 2 18V6Z"
|
|
365
|
+
fill="white" />
|
|
366
|
+
</clipPath>
|
|
367
|
+
</defs>
|
|
368
|
+
</svg>
|
|
369
|
+
<svg class="svg-error" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
|
370
|
+
xmlns="http://www.w3.org/2000/svg">
|
|
371
|
+
<path
|
|
372
|
+
d="M6 2.5H18C19.933 2.5 21.5 4.067 21.5 6V18C21.5 19.933 19.933 21.5 18 21.5H6C4.067 21.5 2.5 19.933 2.5 18V6C2.5 4.067 4.067 2.5 6 2.5Z"
|
|
373
|
+
fill="white" stroke="#C91D42" stroke-width="2" />
|
|
374
|
+
</svg>
|
|
375
|
+
</span>
|
|
376
|
+
</div>
|
|
377
|
+
<span id="apple-pay-modal-checkbox-text"></span>
|
|
378
|
+
</label>
|
|
379
|
+
<div class="apm__error" id="apple-pay-modal-error" role="alert">
|
|
380
|
+
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
381
|
+
<path fill-rule="evenodd" clip-rule="evenodd"
|
|
382
|
+
d="M10 2C5.58172 2 2 5.58172 2 10C2 14.4183 5.58172 18 10 18C14.4183 18 18 14.4183 18 10C18 5.58172 14.4183 2 10 2ZM0 10C0 4.47715 4.47715 0 10 0C15.5228 0 20 4.47715 20 10C20 15.5228 15.5228 20 10 20C4.47715 20 0 15.5228 0 10ZM11 13C11 13.5523 10.5523 14 10 14C9.44772 14 9 13.5523 9 13C9 12.4477 9.44772 12 10 12C10.5523 12 11 12.4477 11 13ZM10 6C10.5523 6 11 6.44772 11 7V10C11 10.5523 10.5523 11 10 11C9.44772 11 9 10.5523 9 10V7C9 6.44772 9.44772 6 10 6Z"
|
|
383
|
+
fill="#C91D42" />
|
|
384
|
+
</svg>
|
|
385
|
+
Please accept the terms to continue
|
|
386
|
+
</div>
|
|
387
|
+
<button class="apm__cta" id="apple-pay-modal-cta">
|
|
388
|
+
Continue with
|
|
389
|
+
<svg width="51" height="22" aria-label="Apple Pay" role="img">
|
|
390
|
+
<use href="#apple-pay-logo" />
|
|
391
|
+
</svg>
|
|
392
|
+
</button>
|
|
393
|
+
</div>
|
|
394
|
+
</div>`;
|
|
395
|
+
|
|
396
|
+
// src/apple-pay-modal.ts
|
|
397
|
+
function getRenewalDateText(unit, duration) {
|
|
398
|
+
const now = /* @__PURE__ */ new Date();
|
|
399
|
+
let date = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
400
|
+
switch (unit) {
|
|
401
|
+
case "week":
|
|
402
|
+
date.setDate(date.getDate() + duration * 7);
|
|
403
|
+
break;
|
|
404
|
+
case "month":
|
|
405
|
+
date.setMonth(date.getMonth() + duration);
|
|
406
|
+
if (date.getMonth() !== (now.getMonth() + duration) % 12) {
|
|
407
|
+
date = new Date(date.getFullYear(), date.getMonth(), 0);
|
|
408
|
+
}
|
|
409
|
+
break;
|
|
410
|
+
case "year":
|
|
411
|
+
date.setFullYear(date.getFullYear() + duration);
|
|
412
|
+
if (date.getMonth() !== now.getMonth()) {
|
|
413
|
+
date = new Date(date.getFullYear(), date.getMonth(), 0);
|
|
414
|
+
}
|
|
415
|
+
break;
|
|
416
|
+
default:
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
return date.toLocaleString("en-US", {
|
|
420
|
+
year: "numeric",
|
|
421
|
+
month: "long",
|
|
422
|
+
day: "numeric"
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
var MIN_TERM_DURATION_PATTERN = /^(\d+)\s+(\w+)s?$/;
|
|
426
|
+
function getMinTermDurationUnits(minTermContractLength) {
|
|
427
|
+
if (!minTermContractLength) {
|
|
428
|
+
return { duration: "", unit: "" };
|
|
429
|
+
}
|
|
430
|
+
const result = minTermContractLength.split(MIN_TERM_DURATION_PATTERN);
|
|
431
|
+
const [, duration = "", rawUnit = ""] = result;
|
|
432
|
+
return { duration, unit: rawUnit.replace(/s$/, "") };
|
|
433
|
+
}
|
|
434
|
+
function getOfferTypeText(offerType) {
|
|
435
|
+
switch (offerType) {
|
|
436
|
+
case "student":
|
|
437
|
+
return "student";
|
|
438
|
+
case "academic":
|
|
439
|
+
return "teacher/faculty";
|
|
440
|
+
default:
|
|
441
|
+
return "";
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
var TERMS_LINK = '<a href="https://www.economistgroup.com/terms-of-use" target="_blank" rel="noopener noreferrer">Terms and Conditions</a>';
|
|
445
|
+
var PRIVACY_LINK = '<a href="https://www.economistgroup.com/privacy-policy" target="_blank" rel="noopener noreferrer">Privacy Policy</a>';
|
|
446
|
+
function getCheckboxTermsHtml(isNYT, isLoggedIn, autoRenewal) {
|
|
447
|
+
const autoRenewalClause = autoRenewal ? " and auto-renewal terms above," : "";
|
|
448
|
+
if (isNYT) {
|
|
449
|
+
const base = `I accept The Economist ${TERMS_LINK} and auto-renewal terms above and acknowledge the ${PRIVACY_LINK}.`;
|
|
450
|
+
if (isLoggedIn) {
|
|
451
|
+
return base;
|
|
452
|
+
}
|
|
453
|
+
return `${base} I understand that by continuing, an account will be created for me if I don\u2019t already have one.`;
|
|
454
|
+
}
|
|
455
|
+
if (isLoggedIn) {
|
|
456
|
+
return `I accept the ${TERMS_LINK}${autoRenewalClause} and acknowledge the ${PRIVACY_LINK}.`;
|
|
457
|
+
}
|
|
458
|
+
return `I accept the ${TERMS_LINK}${autoRenewalClause} and acknowledge the ${PRIVACY_LINK}, and understand that by continuing, an account will be created for me if I don\u2019t already have one.`;
|
|
459
|
+
}
|
|
460
|
+
function renewalPeriodText(unit, duration) {
|
|
461
|
+
switch (unit) {
|
|
462
|
+
case "week":
|
|
463
|
+
return duration === 1 ? "weekly" : `every ${duration} weeks`;
|
|
464
|
+
case "month":
|
|
465
|
+
return duration === 1 ? "monthly" : `every ${duration} months`;
|
|
466
|
+
case "year":
|
|
467
|
+
return duration === 1 ? "annually" : `every ${duration} years`;
|
|
468
|
+
default:
|
|
469
|
+
return "";
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
function buildTermsContext(offer, country) {
|
|
473
|
+
const isUS = country === "US";
|
|
474
|
+
const isCA = country === "CA";
|
|
475
|
+
const isTaxIncluded = offer.price.tax?.inclusive;
|
|
476
|
+
const unit = offer.subscription_options?.renewal_interval?.unit ?? "";
|
|
477
|
+
const duration = offer.subscription_options?.renewal_interval?.duration ?? 1;
|
|
478
|
+
const isMinTermContract = offer.subscription_options?.min_term_contract || false;
|
|
479
|
+
const renewalPriceText = formatPrice(
|
|
480
|
+
isMinTermContract ? offer.price.pre_discount : offer.subscription_options?.renewal_price,
|
|
481
|
+
offer.price.currency_code,
|
|
482
|
+
!isMinTermContract
|
|
483
|
+
);
|
|
484
|
+
const offerTypeText = getOfferTypeText(offer.product?.offer_type);
|
|
485
|
+
const verificationText = offerTypeText ? `, pending ${offerTypeText} verification` : "";
|
|
486
|
+
const renewalDateText = getRenewalDateText(unit, duration);
|
|
487
|
+
return {
|
|
488
|
+
isUS,
|
|
489
|
+
isCA,
|
|
490
|
+
unit,
|
|
491
|
+
duration,
|
|
492
|
+
taxSuffix: isTaxIncluded ? "" : "*",
|
|
493
|
+
taxFootnote: isTaxIncluded ? "" : " *Plus any applicable sales tax.",
|
|
494
|
+
periodText: renewalPeriodText(unit, duration),
|
|
495
|
+
renewalPriceText,
|
|
496
|
+
renewalDateText,
|
|
497
|
+
renewalDateStr: `on ${renewalDateText}${verificationText}`,
|
|
498
|
+
verificationText,
|
|
499
|
+
usCancelNote: "Cancel auto-renewal at any time in My Account. To avoid being charged you must cancel at least 24 hrs before your renewal date. You\u2019ll still have full access until the end of your current billing period, when the cancellation will take effect.",
|
|
500
|
+
cancelAnytime: "Cancel auto-renewal at any time."
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
function freeTrialTerms(offer, ctx) {
|
|
504
|
+
const trialUnit = offer.subscription_options?.trial_period?.unit ?? ctx.unit;
|
|
505
|
+
const trialDuration = offer.subscription_options?.trial_period?.duration ?? 1;
|
|
506
|
+
const trialDateStr = `on ${getRenewalDateText(trialUnit, trialDuration)}${ctx.verificationText}`;
|
|
507
|
+
if (ctx.isUS) {
|
|
508
|
+
return `Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${trialDateStr} when your free trial ends, until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}`;
|
|
509
|
+
}
|
|
510
|
+
return `Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${trialDateStr} when your free trial ends, until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
|
|
511
|
+
}
|
|
512
|
+
function nytTerms(ctx) {
|
|
513
|
+
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.";
|
|
514
|
+
if (ctx.isUS) {
|
|
515
|
+
return `Your subscription to <em>The Economist</em> auto-renews ${ctx.periodText} until cancelled{{liSeparator}}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.renewalDateStr}{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}{{pSeparator}}${nytAccessText}`;
|
|
516
|
+
}
|
|
517
|
+
if (ctx.isCA) {
|
|
518
|
+
return `Your subscription to <em>The Economist</em> auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled.{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}{{pSeparator}}${nytAccessText}`;
|
|
519
|
+
}
|
|
520
|
+
return `Your subscription to <em>The Economist</em> auto-renews at ${ctx.renewalPriceText} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime} ${nytAccessText}`;
|
|
521
|
+
}
|
|
522
|
+
function minTermContractTerms(offer, ctx) {
|
|
523
|
+
const duePrice = formatPrice(offer.price.purchase, offer.price.currency_code);
|
|
524
|
+
const { duration: mtDuration, unit: mtUnit } = getMinTermDurationUnits(
|
|
525
|
+
offer.subscription_options?.min_term_contract_length
|
|
526
|
+
);
|
|
527
|
+
const contractLength = mtDuration && mtUnit ? `${mtDuration} ${mtUnit}` : "";
|
|
528
|
+
const initialContractText = contractLength ? `your initial ${contractLength} contract` : "your initial contract";
|
|
529
|
+
const mtRenewalDateText = mtUnit && mtDuration ? getRenewalDateText(mtUnit, Number(mtDuration)) : ctx.renewalDateText;
|
|
530
|
+
return `You\u2019ll be charged ${duePrice} a month for the duration of ${initialContractText}{{liSeparator}}Your subscription auto-renews annually at ${ctx.renewalPriceText} a month on ${mtRenewalDateText} until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}`;
|
|
531
|
+
}
|
|
532
|
+
function paidTrialTerms(offer, ctx) {
|
|
533
|
+
const trialUnit = offer.subscription_options?.trial_period?.unit ?? ctx.unit;
|
|
534
|
+
const trialDuration = offer.subscription_options?.trial_period?.duration ?? ctx.duration;
|
|
535
|
+
const trialDateText = getRenewalDateText(trialUnit, trialDuration);
|
|
536
|
+
if (ctx.isUS) {
|
|
537
|
+
return `Your subscription auto-renews ${ctx.periodText} until cancelled{{liSeparator}}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} on ${trialDateText} when your paid trial ends{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.usCancelNote}${ctx.taxFootnote}`;
|
|
538
|
+
}
|
|
539
|
+
return `Your subscription auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} on ${trialDateText} when your paid trial ends, until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
|
|
540
|
+
}
|
|
541
|
+
function autoRenewalTerms(ctx) {
|
|
542
|
+
if (ctx.isUS) {
|
|
543
|
+
return `Your subscription auto-renews ${ctx.periodText} until cancelled{{liSeparator}}Your subscription renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.renewalDateStr}{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal until cancelled. ${ctx.usCancelNote}${ctx.taxFootnote}`;
|
|
544
|
+
}
|
|
545
|
+
return `Your subscription auto-renews at ${ctx.renewalPriceText}${ctx.taxSuffix} ${ctx.periodText} ${ctx.renewalDateStr} until cancelled{{liSeparator}}You\u2019ll be charged the rate in effect at each renewal. ${ctx.cancelAnytime}${ctx.taxFootnote}`;
|
|
546
|
+
}
|
|
547
|
+
function noAutoRenewalTerms(ctx) {
|
|
548
|
+
if (ctx.isUS || ctx.isCA) {
|
|
549
|
+
return `Your subscription does not renew automatically${ctx.taxFootnote}{{liSeparator}}`;
|
|
550
|
+
}
|
|
551
|
+
return `Your subscription does not renew automatically{{liSeparator}}`;
|
|
552
|
+
}
|
|
553
|
+
function generateApplePayModalTerms(offer, country) {
|
|
554
|
+
const ctx = buildTermsContext(offer, country);
|
|
555
|
+
const opts = offer.subscription_options;
|
|
556
|
+
if (opts?.free_trial) {
|
|
557
|
+
return freeTrialTerms(offer, ctx);
|
|
558
|
+
}
|
|
559
|
+
if (offer.product?.offer_type === "bogof_nyt") {
|
|
560
|
+
return nytTerms(ctx);
|
|
561
|
+
}
|
|
562
|
+
if (opts?.auto_renewal && (opts?.min_term_contract || false)) {
|
|
563
|
+
return minTermContractTerms(offer, ctx);
|
|
564
|
+
}
|
|
565
|
+
if (opts?.auto_renewal && !opts?.free_trial && opts?.variable_term) {
|
|
566
|
+
return paidTrialTerms(offer, ctx);
|
|
567
|
+
}
|
|
568
|
+
if (opts?.auto_renewal) {
|
|
569
|
+
return autoRenewalTerms(ctx);
|
|
570
|
+
}
|
|
571
|
+
return noAutoRenewalTerms(ctx);
|
|
572
|
+
}
|
|
573
|
+
function renderTermsHtml(termsText) {
|
|
574
|
+
const renewalTextLists = termsText.split("{{liSeparator}}");
|
|
575
|
+
const lastPart = renewalTextLists.pop() || "";
|
|
576
|
+
const renewalTextParagraphs = lastPart.split("{{pSeparator}}");
|
|
577
|
+
const ulHtml = `<ul class="apm__terms-bullets">${renewalTextLists.map((value) => `<li>${value}</li>`).join("")}</ul>`;
|
|
578
|
+
const paragraphHtml = renewalTextParagraphs.filter(Boolean).map((value) => `<p class="apm__terms-legal">${value}</p>`).join("");
|
|
579
|
+
return ulHtml + paragraphHtml;
|
|
580
|
+
}
|
|
581
|
+
function getApplePayProductName(offer) {
|
|
582
|
+
const unit = offer.subscription_options?.renewal_interval?.unit ?? "";
|
|
583
|
+
const duration = offer.subscription_options?.renewal_interval?.duration ?? 1;
|
|
584
|
+
let intervalLabel = "";
|
|
585
|
+
switch (unit) {
|
|
586
|
+
case "year":
|
|
587
|
+
intervalLabel = duration === 1 ? "Annual" : `${duration} year`;
|
|
588
|
+
break;
|
|
589
|
+
case "month":
|
|
590
|
+
intervalLabel = duration === 1 ? "Monthly" : `${duration} month`;
|
|
591
|
+
break;
|
|
592
|
+
case "week":
|
|
593
|
+
intervalLabel = duration === 12 ? "Quarterly" : duration === 4 ? "4-week" : duration === 1 ? "Weekly" : `${duration} week`;
|
|
594
|
+
break;
|
|
595
|
+
default:
|
|
596
|
+
intervalLabel = "";
|
|
597
|
+
}
|
|
598
|
+
return [intervalLabel, offer.display_name ?? ""].filter(Boolean).join(" ");
|
|
599
|
+
}
|
|
600
|
+
var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
601
|
+
static tag = "teg-apple-pay-modal";
|
|
602
|
+
static define() {
|
|
603
|
+
define(_ApplePayModal.tag, _ApplePayModal);
|
|
604
|
+
}
|
|
605
|
+
#offer = null;
|
|
606
|
+
#country = "";
|
|
607
|
+
#triggerElement = null;
|
|
608
|
+
#keyHandler = null;
|
|
609
|
+
set offer(value) {
|
|
610
|
+
this.#offer = value;
|
|
611
|
+
}
|
|
612
|
+
get country() {
|
|
613
|
+
return this.#country;
|
|
614
|
+
}
|
|
615
|
+
set country(value) {
|
|
616
|
+
this.#country = value;
|
|
617
|
+
}
|
|
618
|
+
connectedCallback() {
|
|
619
|
+
if (this.querySelector(".apm-overlay")) {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
ensureApplePayLogoSymbol();
|
|
623
|
+
const template = document.createElement("template");
|
|
624
|
+
template.innerHTML = apple_pay_modal_template_default;
|
|
625
|
+
this.appendChild(template.content.cloneNode(true));
|
|
626
|
+
const offer = this.#offer;
|
|
627
|
+
const country = this.#country;
|
|
628
|
+
if (!offer) {
|
|
629
|
+
console.error("ApplePayModal: Missing or invalid offer data");
|
|
630
|
+
this.remove();
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
const offerNameElement = this.querySelector(
|
|
634
|
+
"#apple-pay-modal-offer-name"
|
|
635
|
+
);
|
|
636
|
+
const dueTodayElement = this.querySelector(
|
|
637
|
+
"#apple-pay-modal-due-today"
|
|
638
|
+
);
|
|
639
|
+
const termsElement = this.querySelector(
|
|
640
|
+
"#apple-pay-modal-terms"
|
|
641
|
+
);
|
|
642
|
+
if (offerNameElement) {
|
|
643
|
+
offerNameElement.textContent = getApplePayProductName(offer);
|
|
644
|
+
}
|
|
645
|
+
if (dueTodayElement) {
|
|
646
|
+
const taxSuffix = offer.price.purchase === 0 || offer.price.tax?.inclusive ? "" : "*";
|
|
647
|
+
const duePrice = formatPrice(
|
|
648
|
+
offer.price.purchase,
|
|
649
|
+
offer.price.currency_code
|
|
650
|
+
);
|
|
651
|
+
dueTodayElement.innerHTML = duePrice ? `Due today: <strong>${duePrice}${taxSuffix}</strong>` : "";
|
|
652
|
+
}
|
|
653
|
+
if (termsElement) {
|
|
654
|
+
termsElement.innerHTML = renderTermsHtml(
|
|
655
|
+
generateApplePayModalTerms(offer, country)
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
const isUS = country === "US";
|
|
659
|
+
const isLoggedIn = this.dataset.loggedIn === "true";
|
|
660
|
+
const isOfferNYT = offer.product?.offer_type === "bogof_nyt";
|
|
661
|
+
const isAutoRenewal = offer.subscription_options?.auto_renewal ?? true;
|
|
662
|
+
const checkboxTextElement = this.querySelector(
|
|
663
|
+
"#apple-pay-modal-checkbox-text"
|
|
664
|
+
);
|
|
665
|
+
if (checkboxTextElement) {
|
|
666
|
+
checkboxTextElement.innerHTML = getCheckboxTermsHtml(
|
|
667
|
+
isOfferNYT,
|
|
668
|
+
isLoggedIn,
|
|
669
|
+
isAutoRenewal
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
const checkboxLabel = this.querySelector(
|
|
673
|
+
"#apple-pay-modal-checkbox-label"
|
|
674
|
+
);
|
|
675
|
+
const checkbox = this.querySelector(
|
|
676
|
+
"#apple-pay-modal-checkbox"
|
|
677
|
+
);
|
|
678
|
+
const cta = this.querySelector("#apple-pay-modal-cta");
|
|
679
|
+
const errorElement = this.querySelector(
|
|
680
|
+
"#apple-pay-modal-error"
|
|
681
|
+
);
|
|
682
|
+
if (!isUS) {
|
|
683
|
+
checkboxLabel?.remove();
|
|
684
|
+
errorElement?.remove();
|
|
685
|
+
} else {
|
|
686
|
+
checkbox?.addEventListener("change", () => {
|
|
687
|
+
if (checkbox.checked) {
|
|
688
|
+
errorElement?.classList.remove("apm__error--visible");
|
|
689
|
+
checkboxLabel?.classList.remove("apm__checkbox-label--error");
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
cta?.addEventListener("click", () => {
|
|
694
|
+
if (isUS && checkbox && !checkbox.checked) {
|
|
695
|
+
errorElement?.classList.add("apm__error--visible");
|
|
696
|
+
checkboxLabel?.classList.add("apm__checkbox-label--error");
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
this.dispatchEvent(
|
|
700
|
+
new CustomEvent("apple-pay-confirmed", {
|
|
701
|
+
bubbles: true,
|
|
702
|
+
composed: true,
|
|
703
|
+
detail: { skuId: offer.sku_id, country }
|
|
704
|
+
})
|
|
705
|
+
);
|
|
706
|
+
this.close();
|
|
707
|
+
});
|
|
708
|
+
this.querySelector("#apple-pay-modal-close")?.addEventListener(
|
|
709
|
+
"click",
|
|
710
|
+
() => this.close()
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
open() {
|
|
714
|
+
this.#triggerElement = document.activeElement;
|
|
715
|
+
document.body.appendChild(this);
|
|
716
|
+
this.#keyHandler = (event) => {
|
|
717
|
+
if (event.key === "Escape") {
|
|
718
|
+
event.preventDefault();
|
|
719
|
+
event.stopPropagation();
|
|
720
|
+
event.stopImmediatePropagation();
|
|
721
|
+
this.close();
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
document.addEventListener("keydown", this.#keyHandler, { capture: true });
|
|
725
|
+
this.querySelector("#apple-pay-modal")?.focus();
|
|
726
|
+
}
|
|
727
|
+
close() {
|
|
728
|
+
if (this.#keyHandler) {
|
|
729
|
+
document.removeEventListener("keydown", this.#keyHandler, {
|
|
730
|
+
capture: true
|
|
731
|
+
});
|
|
732
|
+
this.#keyHandler = null;
|
|
733
|
+
}
|
|
734
|
+
this.remove();
|
|
735
|
+
this.#triggerElement?.focus();
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
// src/templates/apple-pay-button.template.html
|
|
740
|
+
var apple_pay_button_template_default = '<style>\n /* Use CSS variables for layout so parent walls can easily override placement and sizing */\n teg-apple-pay-button {\n display: block;\n margin: var(--apple-pay-margin, 0);\n width: 100%;\n height: 100%;\n }\n\n teg-apple-pay-button .apple-pay-container {\n display: flex;\n flex-direction: column;\n align-items: stretch;\n width: 100%;\n height: 100%;\n }\n\n teg-apple-pay-button .apple-pay-btn {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 0.375rem;\n width: 100%;\n min-width: 0;\n height: 100%;\n min-height: var(--apple-pay-height, 2.75rem);\n background-color: #000;\n color: #fff;\n border: none;\n border-radius: var(--apple-pay-border-radius, 1.375rem);\n cursor: pointer;\n font-family: var(--wall-type-system-sans, system-ui, sans-serif);\n font-size: 17px;\n font-weight: 500;\n }\n\n teg-apple-pay-button .apple-pay-btn svg {\n flex-shrink: 0;\n display: block;\n }\n</style>\n\n<div class="apple-pay-container" aria-label="Express checkout with Apple Pay">\n <button\n class="apple-pay-btn"\n type="button"\n aria-label="Pay with Apple Pay"\n data-analytics="paywall:apple-pay-checkout"\n >\n <svg width="51" height="22" aria-label="Apple Pay" role="img">\n <use href="#apple-pay-logo" />\n </svg>\n </button>\n</div>\n';
|
|
741
|
+
|
|
742
|
+
// src/clients/payment-checkout/config.ts
|
|
743
|
+
var runtimeConfig = null;
|
|
744
|
+
var configureApplePay = (config) => {
|
|
745
|
+
runtimeConfig = {
|
|
746
|
+
...config
|
|
747
|
+
};
|
|
748
|
+
};
|
|
749
|
+
var getApplePayConfig = () => runtimeConfig;
|
|
750
|
+
var resetApplePayConfig = () => {
|
|
751
|
+
runtimeConfig = null;
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
// src/clients/payment-checkout/detects.ts
|
|
755
|
+
var isAppleDeviceOrSafari = () => {
|
|
756
|
+
const isIOSOrMacTouchDevice = /iPad|iPhone|iPod/.test(navigator.userAgent) || navigator.maxTouchPoints > 1 && /Macintosh/.test(navigator.userAgent);
|
|
757
|
+
const isSafariBrowser = navigator.userAgent.indexOf("Safari") > -1 && navigator.userAgent.indexOf("Chrome") === -1;
|
|
758
|
+
return isIOSOrMacTouchDevice || isSafariBrowser;
|
|
759
|
+
};
|
|
760
|
+
var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null && getApplePayConfig()?.debugBypassEnabled === true;
|
|
761
|
+
var isApplePayAvailable = async () => {
|
|
762
|
+
if (bypassApplePayChecks()) {
|
|
763
|
+
return true;
|
|
764
|
+
}
|
|
765
|
+
if (!isAppleDeviceOrSafari()) {
|
|
766
|
+
return false;
|
|
767
|
+
}
|
|
768
|
+
const applePaySession = window.ApplePaySession;
|
|
769
|
+
if (!applePaySession) {
|
|
770
|
+
return false;
|
|
771
|
+
}
|
|
772
|
+
try {
|
|
773
|
+
if (typeof applePaySession.canMakePayments !== "function") {
|
|
774
|
+
return false;
|
|
775
|
+
}
|
|
776
|
+
if (!applePaySession.canMakePayments()) {
|
|
777
|
+
return false;
|
|
778
|
+
}
|
|
779
|
+
const merchantId = getApplePayConfig()?.merchantId;
|
|
780
|
+
if (!merchantId) {
|
|
781
|
+
console.warn(
|
|
782
|
+
"[web-apple-pay] Missing merchantId. Call configureApplePay({ merchantId, ... }) before rendering Apple Pay components."
|
|
783
|
+
);
|
|
784
|
+
return false;
|
|
785
|
+
}
|
|
786
|
+
return await applePaySession.canMakePaymentsWithActiveCard(merchantId);
|
|
787
|
+
} catch (error) {
|
|
788
|
+
console.error("Error checking Apple Pay active card status:", error);
|
|
789
|
+
return false;
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
|
|
793
|
+
// src/clients/payment-checkout/types.ts
|
|
794
|
+
var ApiError = class extends Error {
|
|
795
|
+
status;
|
|
796
|
+
body;
|
|
797
|
+
constructor(status, body) {
|
|
798
|
+
super(`API request failed with status ${status}`);
|
|
799
|
+
this.name = "ApiError";
|
|
800
|
+
this.status = status;
|
|
801
|
+
this.body = body;
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
// src/clients/payment-checkout/index.ts
|
|
806
|
+
var getWalletApiBaseUrl = () => {
|
|
807
|
+
const config = getApplePayConfig();
|
|
808
|
+
if (!config?.walletApiBaseUrl) {
|
|
809
|
+
throw new Error(
|
|
810
|
+
"[web-apple-pay] Missing walletApiBaseUrl. Call configureApplePay({ merchantId, walletApiBaseUrl, ... }) before making wallet API requests."
|
|
811
|
+
);
|
|
812
|
+
}
|
|
813
|
+
return config.walletApiBaseUrl;
|
|
814
|
+
};
|
|
815
|
+
var apiFetch = async (path, options = {}) => {
|
|
816
|
+
const baseUrl = getWalletApiBaseUrl();
|
|
817
|
+
const method = (options.method ?? "GET").toUpperCase();
|
|
818
|
+
const hasBody = options.body !== void 0 && options.body !== null;
|
|
819
|
+
const headers = new Headers(options.headers);
|
|
820
|
+
if (!headers.has("Accept")) {
|
|
821
|
+
headers.set("Accept", "application/json");
|
|
822
|
+
}
|
|
823
|
+
if (!headers.has("Content-Type")) {
|
|
824
|
+
if (hasBody || method !== "GET" && method !== "HEAD") {
|
|
825
|
+
headers.set("Content-Type", "application/json");
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
const response = await fetch(`${baseUrl}${path}`, {
|
|
829
|
+
...options,
|
|
830
|
+
headers
|
|
831
|
+
});
|
|
832
|
+
if (!response.ok) {
|
|
833
|
+
const contentType = response.headers.get("content-type") || "";
|
|
834
|
+
if (contentType.includes("application/json")) {
|
|
835
|
+
const errorBody = await response.json();
|
|
836
|
+
throw new ApiError(response.status, errorBody);
|
|
837
|
+
}
|
|
838
|
+
const errorText = await response.text();
|
|
839
|
+
throw new Error(
|
|
840
|
+
`API request failed: ${response.status} ${response.statusText} - ${errorText}`
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
return response.json();
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
// src/clients/payment-checkout/session.ts
|
|
847
|
+
var getExpressCheckoutSession = () => {
|
|
848
|
+
return apiFetch("/v1/wallet/session", {
|
|
849
|
+
method: "GET",
|
|
850
|
+
credentials: "include"
|
|
851
|
+
});
|
|
852
|
+
};
|
|
853
|
+
|
|
854
|
+
// src/apple-pay-button.ts
|
|
855
|
+
var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
|
|
856
|
+
var APPLE_PAY_EXCLUDED_VARIANTS = ["bundle", "insider_print"];
|
|
857
|
+
var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
858
|
+
static tag = "teg-apple-pay-button";
|
|
859
|
+
static define() {
|
|
860
|
+
define(_ApplePayButton.tag, _ApplePayButton);
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Creates and configures an ApplePayButton if the feature flag is present.
|
|
864
|
+
*/
|
|
865
|
+
static createIfEnabled(offer, country) {
|
|
866
|
+
if (!offer) {
|
|
867
|
+
return null;
|
|
868
|
+
}
|
|
869
|
+
const isExcludedVariant = APPLE_PAY_EXCLUDED_VARIANTS.includes(offer.product?.variant);
|
|
870
|
+
if (isExcludedVariant) {
|
|
871
|
+
return null;
|
|
872
|
+
}
|
|
873
|
+
if (!new URLSearchParams(window.location.search).has(
|
|
874
|
+
FEATURE_APPLE_PAY_EXPRESS_CHECKOUT
|
|
875
|
+
)) {
|
|
876
|
+
return null;
|
|
877
|
+
}
|
|
878
|
+
_ApplePayButton.define();
|
|
879
|
+
const button = document.createElement(_ApplePayButton.tag);
|
|
880
|
+
button.offer = offer;
|
|
881
|
+
button.country = country;
|
|
882
|
+
return button;
|
|
883
|
+
}
|
|
884
|
+
#offer = null;
|
|
885
|
+
#country = "";
|
|
886
|
+
#rendering = false;
|
|
887
|
+
get offer() {
|
|
888
|
+
return this.#offer;
|
|
889
|
+
}
|
|
890
|
+
set offer(value) {
|
|
891
|
+
this.#offer = value;
|
|
892
|
+
this.#updateDisabledState();
|
|
893
|
+
}
|
|
894
|
+
get country() {
|
|
895
|
+
return this.#country;
|
|
896
|
+
}
|
|
897
|
+
set country(value) {
|
|
898
|
+
this.#country = value;
|
|
899
|
+
}
|
|
900
|
+
async connectedCallback() {
|
|
901
|
+
if (this.#rendering || this.querySelector(".apple-pay-container")) {
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
this.#rendering = true;
|
|
905
|
+
try {
|
|
906
|
+
const available = await isApplePayAvailable();
|
|
907
|
+
if (!available) {
|
|
908
|
+
this.style.display = "none";
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
const sessionData = await this.#fetchSession();
|
|
912
|
+
if (sessionData?.loggedIn && (sessionData.userType === "active-subscription" || sessionData.userType === "b2b-user")) {
|
|
913
|
+
this.style.display = "none";
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
this.style.removeProperty("display");
|
|
917
|
+
ensureApplePayLogoSymbol();
|
|
918
|
+
const template = document.createElement("template");
|
|
919
|
+
template.innerHTML = apple_pay_button_template_default;
|
|
920
|
+
this.appendChild(template.content.cloneNode(true));
|
|
921
|
+
this.#updateDisabledState();
|
|
922
|
+
const button = this.querySelector(".apple-pay-btn");
|
|
923
|
+
button.addEventListener("click", () => {
|
|
924
|
+
if (!this.#offer) {
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
if (document.querySelector(ApplePayModal.tag)) {
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
ApplePayModal.define();
|
|
931
|
+
const modal = document.createElement(ApplePayModal.tag);
|
|
932
|
+
modal.offer = this.#offer;
|
|
933
|
+
modal.country = this.#country;
|
|
934
|
+
if (this.dataset.loggedIn !== void 0) {
|
|
935
|
+
modal.dataset.loggedIn = this.dataset.loggedIn;
|
|
936
|
+
}
|
|
937
|
+
modal.open();
|
|
938
|
+
});
|
|
939
|
+
} catch {
|
|
940
|
+
this.style.display = "none";
|
|
941
|
+
} finally {
|
|
942
|
+
this.#rendering = false;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
#updateDisabledState() {
|
|
946
|
+
const button = this.querySelector(".apple-pay-btn");
|
|
947
|
+
if (!button) {
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
if (this.#offer) {
|
|
951
|
+
button.removeAttribute("disabled");
|
|
952
|
+
button.removeAttribute("aria-disabled");
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
button.setAttribute("disabled", "");
|
|
956
|
+
button.setAttribute("aria-disabled", "true");
|
|
957
|
+
}
|
|
958
|
+
async #fetchSession() {
|
|
959
|
+
try {
|
|
960
|
+
return await getExpressCheckoutSession();
|
|
961
|
+
} catch {
|
|
962
|
+
return null;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
// src/index.ts
|
|
968
|
+
function defineApplePayElements() {
|
|
969
|
+
ApplePayButton.define();
|
|
970
|
+
ApplePayModal.define();
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
// src/stories/fixtures/offer.ts
|
|
974
|
+
var STORYBOOK_SAMPLE_OFFER = {
|
|
975
|
+
sku_id: "TEG-APPLEPAY-STORY-001",
|
|
976
|
+
display_name: "Economist Digital",
|
|
977
|
+
price: {
|
|
978
|
+
purchase: 12,
|
|
979
|
+
pre_discount: 24,
|
|
980
|
+
currency_code: "USD",
|
|
981
|
+
discounted: true,
|
|
982
|
+
tax: { inclusive: false }
|
|
983
|
+
},
|
|
984
|
+
product: {
|
|
985
|
+
type: "subscription",
|
|
986
|
+
variant: "digital",
|
|
987
|
+
offer_type: "standard"
|
|
988
|
+
},
|
|
989
|
+
subscription_options: {
|
|
990
|
+
free_trial: false,
|
|
991
|
+
renewal_interval: { duration: 1, unit: "month" },
|
|
992
|
+
renewal_price: 12,
|
|
993
|
+
auto_renewal: true,
|
|
994
|
+
variable_term: false,
|
|
995
|
+
display_name: "Monthly"
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
// src/stories/utils/story-env.ts
|
|
1000
|
+
var STORYBOOK_WALLET_BASE_URL = "https://storybook-wallet.economist.com";
|
|
1001
|
+
var STORYBOOK_SAFARI_UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15";
|
|
1002
|
+
var defaultSessionResponse = {
|
|
1003
|
+
loggedIn: false,
|
|
1004
|
+
userType: "new-eligible-user"
|
|
1005
|
+
};
|
|
1006
|
+
var resetStoryEnvironment = null;
|
|
1007
|
+
var createFetchMock = (sessionResponse, sessionStatus = 200) => {
|
|
1008
|
+
return async (input) => {
|
|
1009
|
+
const requestUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
1010
|
+
if (requestUrl.endsWith("/v1/wallet/session")) {
|
|
1011
|
+
if (sessionStatus >= 400) {
|
|
1012
|
+
return new Response("Session initialization failed", {
|
|
1013
|
+
status: sessionStatus,
|
|
1014
|
+
statusText: "Session Init Error"
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
return new Response(JSON.stringify(sessionResponse), {
|
|
1018
|
+
status: 200,
|
|
1019
|
+
headers: { "content-type": "application/json" }
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
return new Response("Not Found", {
|
|
1023
|
+
status: 404,
|
|
1024
|
+
statusText: "Not Found"
|
|
1025
|
+
});
|
|
1026
|
+
};
|
|
1027
|
+
};
|
|
1028
|
+
var applyApplePayStoryEnvironment = ({
|
|
1029
|
+
applePaySupported,
|
|
1030
|
+
sessionResponse = defaultSessionResponse,
|
|
1031
|
+
sessionStatus = 200,
|
|
1032
|
+
debugBypassEnabled = false,
|
|
1033
|
+
bypassApplePayChecks: bypassApplePayChecks2 = false
|
|
1034
|
+
}) => {
|
|
1035
|
+
if (resetStoryEnvironment) {
|
|
1036
|
+
resetStoryEnvironment();
|
|
1037
|
+
resetStoryEnvironment = null;
|
|
1038
|
+
}
|
|
1039
|
+
const originalFetch = globalThis.fetch;
|
|
1040
|
+
const originalHref = window.location.href;
|
|
1041
|
+
const originalUserAgent = navigator.userAgent;
|
|
1042
|
+
const originalMaxTouchPoints = navigator.maxTouchPoints;
|
|
1043
|
+
const originalApplePaySessionDescriptor = Object.getOwnPropertyDescriptor(
|
|
1044
|
+
window,
|
|
1045
|
+
"ApplePaySession"
|
|
1046
|
+
);
|
|
1047
|
+
const mockApplePaySession = {
|
|
1048
|
+
canMakePayments: () => applePaySupported,
|
|
1049
|
+
canMakePaymentsWithActiveCard: async () => applePaySupported
|
|
1050
|
+
};
|
|
1051
|
+
Object.defineProperty(window, "ApplePaySession", {
|
|
1052
|
+
configurable: true,
|
|
1053
|
+
writable: true,
|
|
1054
|
+
value: mockApplePaySession
|
|
1055
|
+
});
|
|
1056
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
1057
|
+
configurable: true,
|
|
1058
|
+
writable: true,
|
|
1059
|
+
value: STORYBOOK_SAFARI_UA
|
|
1060
|
+
});
|
|
1061
|
+
Object.defineProperty(navigator, "maxTouchPoints", {
|
|
1062
|
+
configurable: true,
|
|
1063
|
+
writable: true,
|
|
1064
|
+
value: 0
|
|
1065
|
+
});
|
|
1066
|
+
globalThis.fetch = createFetchMock(sessionResponse, sessionStatus);
|
|
1067
|
+
const nextUrl = new URL(window.location.href);
|
|
1068
|
+
if (bypassApplePayChecks2) {
|
|
1069
|
+
nextUrl.searchParams.set("BYPASS_APPLE_PAY_CHECKS", "1");
|
|
1070
|
+
} else {
|
|
1071
|
+
nextUrl.searchParams.delete("BYPASS_APPLE_PAY_CHECKS");
|
|
1072
|
+
}
|
|
1073
|
+
window.history.replaceState({}, "", nextUrl.toString());
|
|
1074
|
+
configureApplePay({
|
|
1075
|
+
merchantId: "merchant.com.economist.storybook",
|
|
1076
|
+
walletApiBaseUrl: STORYBOOK_WALLET_BASE_URL,
|
|
1077
|
+
debugBypassEnabled
|
|
1078
|
+
});
|
|
1079
|
+
resetStoryEnvironment = () => {
|
|
1080
|
+
resetApplePayConfig();
|
|
1081
|
+
globalThis.fetch = originalFetch;
|
|
1082
|
+
window.history.replaceState({}, "", originalHref);
|
|
1083
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
1084
|
+
configurable: true,
|
|
1085
|
+
writable: true,
|
|
1086
|
+
value: originalUserAgent
|
|
1087
|
+
});
|
|
1088
|
+
Object.defineProperty(navigator, "maxTouchPoints", {
|
|
1089
|
+
configurable: true,
|
|
1090
|
+
writable: true,
|
|
1091
|
+
value: originalMaxTouchPoints
|
|
1092
|
+
});
|
|
1093
|
+
if (originalApplePaySessionDescriptor) {
|
|
1094
|
+
Object.defineProperty(
|
|
1095
|
+
window,
|
|
1096
|
+
"ApplePaySession",
|
|
1097
|
+
originalApplePaySessionDescriptor
|
|
1098
|
+
);
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
delete window.ApplePaySession;
|
|
1102
|
+
};
|
|
1103
|
+
};
|
|
1104
|
+
var withApplePayStoryEnvironment = (options, renderFn) => (args) => {
|
|
1105
|
+
applyApplePayStoryEnvironment(options);
|
|
1106
|
+
return renderFn(args);
|
|
1107
|
+
};
|
|
1108
|
+
|
|
1109
|
+
// src/apple-pay-button.stories.ts
|
|
1110
|
+
var APPLE_PAY_BUTTON_TAG = "teg-apple-pay-button";
|
|
1111
|
+
var renderButton = ({ country, loggedIn }) => {
|
|
1112
|
+
defineApplePayElements();
|
|
1113
|
+
const container = document.createElement("div");
|
|
1114
|
+
container.style.padding = "24px";
|
|
1115
|
+
const button = document.createElement(
|
|
1116
|
+
APPLE_PAY_BUTTON_TAG
|
|
1117
|
+
);
|
|
1118
|
+
button.offer = STORYBOOK_SAMPLE_OFFER;
|
|
1119
|
+
button.country = country;
|
|
1120
|
+
button.dataset.loggedIn = String(loggedIn);
|
|
1121
|
+
container.appendChild(button);
|
|
1122
|
+
return container;
|
|
1123
|
+
};
|
|
1124
|
+
var meta = {
|
|
1125
|
+
title: "Web Apple Pay/ApplePayButton",
|
|
1126
|
+
tags: ["autodocs"],
|
|
1127
|
+
parameters: {
|
|
1128
|
+
docs: {
|
|
1129
|
+
inlineStories: false
|
|
1130
|
+
}
|
|
1131
|
+
},
|
|
1132
|
+
args: {
|
|
1133
|
+
country: "US",
|
|
1134
|
+
loggedIn: false
|
|
1135
|
+
},
|
|
1136
|
+
argTypes: {
|
|
1137
|
+
country: { control: "text" },
|
|
1138
|
+
loggedIn: { control: "boolean" }
|
|
1139
|
+
},
|
|
1140
|
+
render: renderButton
|
|
1141
|
+
};
|
|
1142
|
+
var apple_pay_button_stories_default = meta;
|
|
1143
|
+
var DefaultEligible = {
|
|
1144
|
+
render: withApplePayStoryEnvironment(
|
|
1145
|
+
{
|
|
1146
|
+
applePaySupported: true,
|
|
1147
|
+
debugBypassEnabled: true,
|
|
1148
|
+
bypassApplePayChecks: true
|
|
1149
|
+
},
|
|
1150
|
+
renderButton
|
|
1151
|
+
)
|
|
1152
|
+
};
|
|
1153
|
+
var NotSupported = {
|
|
1154
|
+
parameters: {
|
|
1155
|
+
docs: {
|
|
1156
|
+
disable: true
|
|
1157
|
+
}
|
|
1158
|
+
},
|
|
1159
|
+
render: withApplePayStoryEnvironment({ applePaySupported: false }, renderButton)
|
|
1160
|
+
};
|
|
1161
|
+
var SessionInitErrorFallback = {
|
|
1162
|
+
parameters: {
|
|
1163
|
+
docs: {
|
|
1164
|
+
disable: true
|
|
1165
|
+
}
|
|
1166
|
+
},
|
|
1167
|
+
render: withApplePayStoryEnvironment(
|
|
1168
|
+
{
|
|
1169
|
+
applePaySupported: true,
|
|
1170
|
+
sessionStatus: 500,
|
|
1171
|
+
debugBypassEnabled: true,
|
|
1172
|
+
bypassApplePayChecks: true
|
|
1173
|
+
},
|
|
1174
|
+
renderButton
|
|
1175
|
+
)
|
|
1176
|
+
};
|
|
1177
|
+
var LoggedInModalPropagation = {
|
|
1178
|
+
parameters: {
|
|
1179
|
+
docs: {
|
|
1180
|
+
disable: true
|
|
1181
|
+
}
|
|
1182
|
+
},
|
|
1183
|
+
args: {
|
|
1184
|
+
loggedIn: true
|
|
1185
|
+
},
|
|
1186
|
+
render: withApplePayStoryEnvironment(
|
|
1187
|
+
{
|
|
1188
|
+
applePaySupported: true,
|
|
1189
|
+
sessionResponse: {
|
|
1190
|
+
loggedIn: true,
|
|
1191
|
+
emailAddress: "storybook-user@economist.com",
|
|
1192
|
+
contactId: "STORYBOOK-CONT-1",
|
|
1193
|
+
userType: "new-eligible-user"
|
|
1194
|
+
},
|
|
1195
|
+
debugBypassEnabled: true,
|
|
1196
|
+
bypassApplePayChecks: true
|
|
1197
|
+
},
|
|
1198
|
+
renderButton
|
|
1199
|
+
)
|
|
1200
|
+
};
|
|
1201
|
+
var EligibleCAFlow = {
|
|
1202
|
+
parameters: {
|
|
1203
|
+
docs: {
|
|
1204
|
+
disable: true
|
|
1205
|
+
}
|
|
1206
|
+
},
|
|
1207
|
+
args: {
|
|
1208
|
+
country: "CA"
|
|
1209
|
+
},
|
|
1210
|
+
render: withApplePayStoryEnvironment(
|
|
1211
|
+
{
|
|
1212
|
+
applePaySupported: true,
|
|
1213
|
+
debugBypassEnabled: true,
|
|
1214
|
+
bypassApplePayChecks: true
|
|
1215
|
+
},
|
|
1216
|
+
renderButton
|
|
1217
|
+
)
|
|
1218
|
+
};
|
|
1219
|
+
var ActiveSubscriberHidden = {
|
|
1220
|
+
parameters: {
|
|
1221
|
+
docs: {
|
|
1222
|
+
disable: true
|
|
1223
|
+
}
|
|
1224
|
+
},
|
|
1225
|
+
args: {
|
|
1226
|
+
loggedIn: true
|
|
1227
|
+
},
|
|
1228
|
+
render: withApplePayStoryEnvironment(
|
|
1229
|
+
{
|
|
1230
|
+
applePaySupported: true,
|
|
1231
|
+
sessionResponse: {
|
|
1232
|
+
loggedIn: true,
|
|
1233
|
+
emailAddress: "subscriber@economist.com",
|
|
1234
|
+
contactId: "STORYBOOK-SUBSCRIBER-1",
|
|
1235
|
+
userType: "active-subscription"
|
|
1236
|
+
},
|
|
1237
|
+
debugBypassEnabled: true,
|
|
1238
|
+
bypassApplePayChecks: true
|
|
1239
|
+
},
|
|
1240
|
+
renderButton
|
|
1241
|
+
)
|
|
1242
|
+
};
|
|
1243
|
+
var B2BUserHidden = {
|
|
1244
|
+
parameters: {
|
|
1245
|
+
docs: {
|
|
1246
|
+
disable: true
|
|
1247
|
+
}
|
|
1248
|
+
},
|
|
1249
|
+
args: {
|
|
1250
|
+
loggedIn: true
|
|
1251
|
+
},
|
|
1252
|
+
render: withApplePayStoryEnvironment(
|
|
1253
|
+
{
|
|
1254
|
+
applePaySupported: true,
|
|
1255
|
+
sessionResponse: {
|
|
1256
|
+
loggedIn: true,
|
|
1257
|
+
emailAddress: "b2b-user@economist.com",
|
|
1258
|
+
contactId: "STORYBOOK-B2B-1",
|
|
1259
|
+
userType: "b2b-user"
|
|
1260
|
+
},
|
|
1261
|
+
debugBypassEnabled: true,
|
|
1262
|
+
bypassApplePayChecks: true
|
|
1263
|
+
},
|
|
1264
|
+
renderButton
|
|
1265
|
+
)
|
|
1266
|
+
};
|
|
1267
|
+
export {
|
|
1268
|
+
ActiveSubscriberHidden,
|
|
1269
|
+
B2BUserHidden,
|
|
1270
|
+
DefaultEligible,
|
|
1271
|
+
EligibleCAFlow,
|
|
1272
|
+
LoggedInModalPropagation,
|
|
1273
|
+
NotSupported,
|
|
1274
|
+
SessionInitErrorFallback,
|
|
1275
|
+
apple_pay_button_stories_default as default
|
|
1276
|
+
};
|