@economist/web-apple-pay 1.5.0 → 1.6.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.
Files changed (33) hide show
  1. package/dist/index.js +963 -367
  2. package/dist/src/apple-pay-button.d.ts +13 -1
  3. package/dist/src/apple-pay-button.js +963 -367
  4. package/dist/src/apple-pay-button.stories.js +970 -383
  5. package/dist/src/apple-pay-modal.js +18 -316
  6. package/dist/src/apple-pay-modal.stories.js +963 -367
  7. package/dist/src/clients/payment-checkout/apple-session.d.ts +18 -0
  8. package/dist/src/clients/payment-checkout/apple-session.js +227 -0
  9. package/dist/src/clients/payment-checkout/billing-contact-details.d.ts +21 -0
  10. package/dist/src/clients/payment-checkout/billing-contact-details.js +109 -0
  11. package/dist/src/clients/payment-checkout/config.d.ts +1 -0
  12. package/dist/src/clients/payment-checkout/contact-validation.d.ts +21 -0
  13. package/dist/src/clients/payment-checkout/contact-validation.js +50 -0
  14. package/dist/src/clients/payment-checkout/index.d.ts +4 -0
  15. package/dist/src/clients/payment-checkout/index.js +25 -1
  16. package/dist/src/clients/payment-checkout/messages.d.ts +33 -0
  17. package/dist/src/clients/payment-checkout/messages.js +19 -0
  18. package/dist/src/clients/payment-checkout/payment-handler.d.ts +36 -0
  19. package/dist/src/clients/payment-checkout/payment-handler.js +375 -0
  20. package/dist/src/clients/payment-checkout/shipping-contact-details.d.ts +10 -0
  21. package/dist/src/clients/payment-checkout/shipping-contact-details.js +83 -0
  22. package/dist/src/clients/payment-checkout/types.d.ts +128 -0
  23. package/dist/src/index.d.ts +1 -1
  24. package/dist/src/index.js +963 -367
  25. package/dist/src/utils/billing-countries.d.ts +19 -0
  26. package/dist/src/utils/billing-countries.js +263 -0
  27. package/dist/src/utils/expressCheckoutRedirect.d.ts +55 -0
  28. package/dist/src/utils/expressCheckoutRedirect.js +46 -0
  29. package/dist/src/utils/expressCheckoutTracking.d.ts +64 -0
  30. package/dist/src/utils/expressCheckoutTracking.js +84 -0
  31. package/dist/src/utils/recaptcha.d.ts +22 -0
  32. package/dist/src/utils/recaptcha.js +54 -0
  33. package/package.json +2 -1
@@ -76,322 +76,7 @@ function ensureApplePayLogoSymbol() {
76
76
  }
77
77
 
78
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>`;
79
+ var apple_pay_modal_template_default = '<style>\n .apm-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n z-index: 97;\n background: rgba(13, 13, 13, 0.7);\n display: flex;\n align-items: center;\n justify-content: center;\n padding: var(--wall-gutter, 2rem);\n box-sizing: border-box;\n }\n\n .apm {\n position: relative;\n background: #fff;\n border-radius: 0.5rem 0.5rem 0 0;\n border: 0.0625rem solid #d9d9d9;\n padding: var(--mb-spacing-lg, 1.5rem);\n width: 25rem;\n max-width: 25rem;\n box-sizing: border-box;\n font-family: var(--mb-typeface-sans, var(--wall-type-system-sans));\n box-shadow: 0 0.25rem 1rem 0 rgba(13, 13, 13, 0.15);\n }\n\n .apm__close {\n position: absolute;\n top: 1.5rem;\n right: 1.3125rem;\n background: none;\n border: none;\n cursor: pointer;\n padding: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n }\n\n .apm__close:focus {\n outline: solid 0.125rem var(--focus-border-color, #121212);\n border-radius: 0.25rem;\n }\n\n .apm__offer-name {\n font-family: var(--mb-typeface-sans, var(--wall-type-system-sans));\n font-size: var(--mb-typestyle-title-3-size, 1.25rem);\n font-weight: 500;\n color: var(--mb-colour-greyscale-london-5, #0d0d0d);\n line-height: var(--mb-typestyle-title-3-leading, 1.75rem);\n font-style: normal;\n margin: 0 1.5rem 0.5rem 0;\n }\n\n .apm__due-today {\n color: #1a1a1a;\n font-family: var(--mb-typeface-sans, var(--wall-type-system-sans));\n font-size: var(--mb-typestyle-label-2-size, 0.9375rem);\n font-style: normal;\n font-weight: 400;\n line-height: var(--mb-typestyle-label-2-leading, 1.25rem);\n margin: 0 0 0.75rem 0;\n }\n\n .apm__rule {\n border: none;\n border-top: 0.0625rem solid #d9d9d9;\n margin: 0 0 1rem 0;\n }\n\n .apm__terms {\n color: #1a1a1a;\n font-family: var(--mb-typeface-sans, var(--wall-type-system-sans));\n font-size: var(--mb-typestyle-label-2-size, 0.9375rem);\n font-style: normal;\n font-weight: 400;\n line-height: var(--mb-typestyle-label-2-leading, 1.25rem);\n margin: 0 0 1rem 0;\n }\n\n .apm__terms-bullets {\n list-style: disc outside;\n padding-left: 1.25rem;\n margin: 0 0 0.75rem 0;\n }\n\n .apm__terms-bullets li {\n margin-bottom: 0.375rem;\n }\n\n .apm__terms-legal {\n margin: 0;\n }\n\n .apm__passive-terms {\n font-family: var(--wall-type-system-sans);\n font-size: 0.9375rem;\n color: #0d0d0d;\n line-height: 1.4;\n margin: 0 0 8px 0;\n }\n\n .apm__passive-terms a {\n color: #1a1a1a;\n font-weight: 700;\n text-decoration: underline;\n }\n\n .apm__checkbox-label {\n display: flex;\n align-items: flex-start;\n gap: var(--mb-spacing-sm, 0.5rem);\n font-family: var(--mb-typeface-sans, var(--wall-type-system-sans));\n font-size: var(--mb-typestyle-label-2-size, 0.9375rem);\n color: var(--mb-colour-greyscale-london-20, #1a1a1a);\n line-height: var(--mb-typestyle-label-2-leading, 1.25rem);\n cursor: pointer;\n margin: 0 0 1.5rem 0;\n }\n\n .apm__checkbox-label--error {\n margin-bottom: 0.25rem;\n }\n\n .apm__checkbox-wrapper {\n position: relative;\n flex-shrink: 0;\n width: 1.25rem;\n height: 1.25rem;\n margin-top: 0.0625rem;\n }\n\n .apm__checkbox-input {\n position: absolute;\n opacity: 0;\n width: 100%;\n height: 100%;\n cursor: pointer;\n margin: 0;\n z-index: 1;\n }\n\n .apm__checkbox-custom {\n position: absolute;\n top: 0;\n left: 0;\n width: 1.25rem;\n height: 1.25rem;\n pointer-events: none;\n }\n\n .apm__checkbox-custom svg {\n display: none;\n width: 1.25rem;\n height: 1.25rem;\n }\n\n .apm__checkbox-input:not(:checked) ~ .apm__checkbox-custom .svg-unchecked {\n display: block;\n }\n\n .apm__checkbox-input:checked ~ .apm__checkbox-custom .svg-checked {\n display: block;\n }\n\n .apm__checkbox-label--error\n .apm__checkbox-input:not(:checked)\n ~ .apm__checkbox-custom\n .svg-unchecked {\n display: none;\n }\n\n .apm__checkbox-label--error\n .apm__checkbox-input:not(:checked)\n ~ .apm__checkbox-custom\n .svg-error {\n display: block;\n }\n\n .apm__checkbox-input:focus-visible ~ .apm__checkbox-custom {\n outline: solid 0.125rem #c91d42;\n outline-offset: 0.125rem;\n border-radius: 0.25rem;\n }\n\n .apm__checkbox-label a {\n color: #1a1a1a;\n font-weight: 700;\n text-decoration: underline;\n }\n\n .apm__error {\n display: none;\n align-items: center;\n gap: 0.75rem;\n color: var(--mb-colour-greyscale-london-5, #0d0d0d);\n font-family: var(--mb-typeface-sans, var(--wall-type-system-sans));\n font-size: 1.0625rem;\n font-style: normal;\n font-weight: 500;\n line-height: 1.5rem;\n margin-bottom: 1rem;\n }\n\n .apm__error--visible {\n display: flex;\n }\n\n .apm__cta {\n display: flex;\n width: 100%;\n height: 2.75rem;\n padding: 0.375rem 1rem;\n justify-content: center;\n align-items: center;\n gap: 0.375rem;\n border-radius: 0.25rem;\n background: #000;\n border: none;\n cursor: pointer;\n color: #fff;\n text-align: center;\n font-family: var(\n --mb-typeface-sans,\n var(--wall-type-system-sans, system-ui, sans-serif)\n );\n font-size: 1.25rem;\n font-style: normal;\n font-weight: 500;\n line-height: normal;\n }\n\n .apm__cta svg {\n flex-shrink: 0;\n display: block;\n }\n\n @media (min-width: 22.5rem) and (max-width: 37.5rem) {\n .apm {\n width: 24.375rem;\n max-width: 24.375rem;\n }\n }\n\n @media (min-width: 37.5625rem) {\n .apm {\n border-radius: 0.5rem;\n }\n }\n\n @media (max-width: 22.4375rem) {\n .apm {\n width: 20rem;\n max-width: 20rem;\n }\n }\n\n @media (max-width: 26.1875rem) {\n .apm__cta {\n font-size: 1.125rem;\n }\n }\n</style>\n\n<div class="apm-overlay" id="apple-pay-modal-overlay">\n <div\n class="apm"\n role="dialog"\n aria-modal="true"\n aria-labelledby="apple-pay-modal-offer-name"\n id="apple-pay-modal"\n tabindex="-1"\n >\n <button class="apm__close" id="apple-pay-modal-close" aria-label="Close">\n <svg\n aria-hidden="true"\n xmlns="http://www.w3.org/2000/svg"\n width="24"\n height="24"\n viewBox="0 0 24 24"\n fill="none"\n >\n <g clip-path="url(#clip0_15712_93054)">\n <rect width="24" height="24" fill="white" fill-opacity="0.01" />\n <path\n fill-rule="evenodd"\n clip-rule="evenodd"\n d="M0 0H24V24H0V0Z"\n fill="white"\n fill-opacity="0.01"\n />\n <path\n fill-rule="evenodd"\n clip-rule="evenodd"\n 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"\n fill="#333333"\n />\n </g>\n <defs>\n <clipPath id="clip0_15712_93054">\n <rect width="24" height="24" fill="white" />\n </clipPath>\n </defs>\n </svg>\n </button>\n <p class="apm__offer-name" id="apple-pay-modal-offer-name"></p>\n <p class="apm__due-today" id="apple-pay-modal-due-today"></p>\n <hr class="apm__rule" />\n <div class="apm__terms" id="apple-pay-modal-terms"></div>\n <p class="apm__passive-terms" id="apple-pay-modal-passive-terms"></p>\n <label\n class="apm__checkbox-label"\n id="apple-pay-modal-checkbox-label"\n for="apple-pay-modal-checkbox"\n >\n <div class="apm__checkbox-wrapper">\n <input\n class="apm__checkbox-input"\n type="checkbox"\n id="apple-pay-modal-checkbox"\n />\n <span class="apm__checkbox-custom">\n <svg\n aria-hidden="true"\n class="svg-unchecked"\n width="24"\n height="24"\n viewBox="0 0 24 24"\n fill="none"\n xmlns="http://www.w3.org/2000/svg"\n >\n <path\n 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"\n fill="white"\n stroke="#595959"\n />\n </svg>\n <svg\n aria-hidden="true"\n class="svg-checked"\n width="24"\n height="24"\n viewBox="0 0 24 24"\n fill="none"\n xmlns="http://www.w3.org/2000/svg"\n >\n <g clip-path="url(#clip0_20014_9555)">\n <path\n 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"\n fill="#333333"\n />\n <path\n d="M10.2857 17L6 12.6814L7.20857 11.4635L10.2857 14.5557L16.7914 8L18 9.22649L10.2857 17Z"\n fill="white"\n />\n </g>\n <defs>\n <clipPath id="clip0_20014_9555">\n <path\n 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"\n fill="white"\n />\n </clipPath>\n </defs>\n </svg>\n <svg\n aria-hidden="true"\n class="svg-error"\n width="24"\n height="24"\n viewBox="0 0 24 24"\n fill="none"\n xmlns="http://www.w3.org/2000/svg"\n >\n <path\n 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"\n fill="white"\n stroke="#C91D42"\n stroke-width="2"\n />\n </svg>\n </span>\n </div>\n <span id="apple-pay-modal-checkbox-text"></span>\n </label>\n <div class="apm__error" id="apple-pay-modal-error" role="alert">\n <svg\n aria-hidden="true"\n width="20"\n height="20"\n viewBox="0 0 20 20"\n fill="none"\n xmlns="http://www.w3.org/2000/svg"\n >\n <path\n fill-rule="evenodd"\n clip-rule="evenodd"\n 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"\n fill="#C91D42"\n />\n </svg>\n Please accept the terms to continue\n </div>\n <button class="apm__cta" id="apple-pay-modal-cta">\n Continue with\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</div>\n\n';
395
80
 
396
81
  // src/apple-pay-modal.ts
397
82
  function getRenewalDateText(unit, duration) {
@@ -457,6 +142,12 @@ function getCheckboxTermsHtml(isNYT, isLoggedIn, autoRenewal) {
457
142
  }
458
143
  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
144
  }
145
+ function getPassiveTermsHtml(isNYT, isLoggedIn, autoRenewal) {
146
+ const accountClause = isLoggedIn ? " " : "\u2019ll get an account and ";
147
+ const autoRenewalClause = autoRenewal ? "above auto-renewal terms, " : "";
148
+ const nytPrefix = isNYT ? " your subscription to The Economist," : "";
149
+ return `By purchasing${nytPrefix} you${accountClause}agree to the ${autoRenewalClause}${TERMS_LINK} and acknowledge the ${PRIVACY_LINK}.`;
150
+ }
460
151
  function renewalPeriodText(unit, duration) {
461
152
  switch (unit) {
462
153
  case "week":
@@ -679,10 +370,21 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
679
370
  const errorElement = this.querySelector(
680
371
  "#apple-pay-modal-error"
681
372
  );
373
+ const passiveTermsElement = this.querySelector(
374
+ "#apple-pay-modal-passive-terms"
375
+ );
682
376
  if (!isUS) {
683
377
  checkboxLabel?.remove();
684
378
  errorElement?.remove();
379
+ if (passiveTermsElement) {
380
+ passiveTermsElement.innerHTML = getPassiveTermsHtml(
381
+ isOfferNYT,
382
+ isLoggedIn,
383
+ isAutoRenewal
384
+ );
385
+ }
685
386
  } else {
387
+ passiveTermsElement?.remove();
686
388
  checkbox?.addEventListener("change", () => {
687
389
  if (checkbox.checked) {
688
390
  errorElement?.classList.remove("apm__error--visible");
@@ -737,7 +439,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
737
439
  };
738
440
 
739
441
  // 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';
442
+ 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(--mb-typeface-sans, var(--wall-type-system-sans));\n font-size: 1.0625rem;\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
443
 
742
444
  // src/clients/payment-checkout/config.ts
743
445
  var runtimeConfig = null;
@@ -834,6 +536,27 @@ var apiFetch = async (path, options = {}) => {
834
536
  }
835
537
  return response.json();
836
538
  };
539
+ var getPaymentOptions = (data) => {
540
+ const { sku, countryCode, currencyCode, checkoutUrl } = data;
541
+ const params = new URLSearchParams({ checkoutUrl });
542
+ return apiFetch(
543
+ `/ecomb2c/v1/payment-options/sku/${sku}/${countryCode}/${currencyCode}?${params}`,
544
+ { method: "GET" }
545
+ );
546
+ };
547
+ var validateAppleMerchant = (data) => {
548
+ return apiFetch("/v1/wallet/validate-merchant", {
549
+ method: "POST",
550
+ body: JSON.stringify(data)
551
+ });
552
+ };
553
+ var performPurchase = (data) => {
554
+ return apiFetch("/v1/wallet/purchase", {
555
+ method: "POST",
556
+ body: JSON.stringify(data),
557
+ credentials: "include"
558
+ });
559
+ };
837
560
 
838
561
  // src/clients/payment-checkout/session.ts
839
562
  var getExpressCheckoutSession = () => {
@@ -843,9 +566,732 @@ var getExpressCheckoutSession = () => {
843
566
  });
844
567
  };
845
568
 
569
+ // src/utils/expressCheckoutRedirect.ts
570
+ var captureOriginUrl = () => window.location.href;
571
+ var buildQueryString = () => {
572
+ const countryCode = new URLSearchParams(window.location.search).get(
573
+ "country"
574
+ );
575
+ return countryCode ? `&country=${encodeURIComponent(countryCode)}` : "";
576
+ };
577
+ var decodeSku = (sku) => {
578
+ try {
579
+ return atob(sku.substring(sku.indexOf("-") + 1));
580
+ } catch {
581
+ return sku;
582
+ }
583
+ };
584
+ var redirectToCheckoutComplete = (params) => {
585
+ const url = new URL("/checkout/complete", window.location.origin);
586
+ url.searchParams.set("basketId", params.basketId);
587
+ if (params.queryString) {
588
+ const qs = params.queryString.startsWith("?") ? params.queryString.slice(1) : params.queryString;
589
+ new URLSearchParams(qs).forEach((v, k) => url.searchParams.set(k, v));
590
+ }
591
+ url.searchParams.set("lmo_offer", params.skuId);
592
+ url.searchParams.set("status", params.status);
593
+ url.searchParams.set("redirectToCheckout", "true");
594
+ url.searchParams.set("returnUrl", params.returnUrl);
595
+ return url.pathname + url.search;
596
+ };
597
+ var redirectToCheckoutFallback = (params) => {
598
+ const url = new URL(window.location.href);
599
+ url.pathname = "/checkout";
600
+ url.searchParams.set("lmo_offer", params.skuId);
601
+ if (params.inlineError)
602
+ url.searchParams.set("inlineError", params.inlineError);
603
+ if (params.email) url.searchParams.set("email", params.email);
604
+ if (params.emailError) url.searchParams.set("emailError", params.emailError);
605
+ url.searchParams.set("returnUrl", params.returnUrl);
606
+ return url.pathname + url.search;
607
+ };
608
+
609
+ // src/utils/recaptcha.ts
610
+ var loadRecaptchaScript = (siteKey) => {
611
+ return new Promise((resolve, reject) => {
612
+ if (typeof grecaptcha !== "undefined") return resolve();
613
+ const existingScript = document.querySelector(
614
+ 'script[src*="recaptcha/api.js"]'
615
+ );
616
+ if (existingScript) {
617
+ existingScript.addEventListener("load", () => resolve());
618
+ existingScript.addEventListener(
619
+ "error",
620
+ () => reject(new Error("Failed to load existing reCAPTCHA script"))
621
+ );
622
+ return;
623
+ }
624
+ const script = document.createElement("script");
625
+ script.src = `https://www.google.com/recaptcha/api.js?render=${siteKey}`;
626
+ script.async = true;
627
+ script.defer = true;
628
+ script.onload = () => resolve();
629
+ script.onerror = () => reject(new Error("Failed to load reCAPTCHA script"));
630
+ document.head.appendChild(script);
631
+ });
632
+ };
633
+ var getRecaptchaToken = async (action) => {
634
+ const siteKey = getApplePayConfig()?.recaptchaSiteKey;
635
+ if (!siteKey) {
636
+ throw new Error(
637
+ "[web-apple-pay] Missing recaptchaSiteKey. Call configureApplePay({ recaptchaSiteKey, ... }) before initiating Apple Pay."
638
+ );
639
+ }
640
+ await loadRecaptchaScript(siteKey);
641
+ return new Promise((resolve, reject) => {
642
+ grecaptcha.ready(() => {
643
+ grecaptcha.execute(siteKey, { action }).then(resolve).catch(reject);
644
+ });
645
+ });
646
+ };
647
+ var getPurchaseRecaptchaTokens = async () => {
648
+ const [checkEligibility, newBasket, registerUser] = await Promise.all([
649
+ getRecaptchaToken("checkEligibility"),
650
+ getRecaptchaToken("newBasket"),
651
+ getRecaptchaToken("registerUser")
652
+ ]);
653
+ return { checkEligibility, newBasket, registerUser };
654
+ };
655
+
656
+ // src/utils/expressCheckoutTracking.ts
657
+ var EXPRESS_CHECKOUT_EVENTS = {
658
+ /** Wallet button displayed */
659
+ IMPRESSION: "express_wallet_impression",
660
+ /** Wallet button clicked */
661
+ BUTTON_CLICK: "express_wallet_click",
662
+ /** Apple Pay sheet opened */
663
+ SHEET_OPEN: "wallet_payment_sheet_open",
664
+ /** Payment authorised by the user in the Apple Pay sheet */
665
+ AUTHORISED: "wallet_payment_authorised",
666
+ /** Purchase completed — BFF returned success */
667
+ SUCCESS: "wallet_payment_success",
668
+ /** Payment failed — BFF returned error */
669
+ FAILURE: "wallet_payment_failure",
670
+ /** Redirect to standard checkout (any fallback path) */
671
+ FALLBACK_CHECKOUT: "fallback_checkout"
672
+ };
673
+ var getDevice = () => {
674
+ const ua = navigator.userAgent;
675
+ if (/tablet|ipad/i.test(ua)) return "tablet";
676
+ if (/mobile|iphone|android/i.test(ua)) return "mobile";
677
+ return "desktop";
678
+ };
679
+ var emitTedlEvent = (event) => {
680
+ window.tedl = window.tedl ?? {};
681
+ window.tedl.events = window.tedl.events ?? [];
682
+ window.tedl.events.push(event);
683
+ };
684
+ var track = (action, extra) => {
685
+ emitTedlEvent({
686
+ name: "user.journey",
687
+ type: "checkout",
688
+ action,
689
+ info: "applepay",
690
+ ...extra
691
+ });
692
+ };
693
+ var trackExpressWalletImpression = (skuId, { entryPoint, country }) => {
694
+ track(EXPRESS_CHECKOUT_EVENTS.IMPRESSION, {
695
+ wallet_type: "apple_pay",
696
+ entry_point: entryPoint,
697
+ sku_id: skuId,
698
+ country,
699
+ device: getDevice()
700
+ });
701
+ };
702
+ var trackExpressWalletClick = (skuId) => {
703
+ track(EXPRESS_CHECKOUT_EVENTS.BUTTON_CLICK, { sku_id: skuId });
704
+ };
705
+ var trackWalletPaymentSheetOpen = (skuId) => {
706
+ track(EXPRESS_CHECKOUT_EVENTS.SHEET_OPEN, { sku_id: skuId });
707
+ };
708
+ var trackWalletPaymentAuthorised = (skuId) => {
709
+ track(EXPRESS_CHECKOUT_EVENTS.AUTHORISED, { sku_id: skuId });
710
+ };
711
+ var trackWalletPaymentSuccess = (skuId, basketId) => {
712
+ track(EXPRESS_CHECKOUT_EVENTS.SUCCESS, {
713
+ sku_id: skuId,
714
+ basket_id: basketId
715
+ });
716
+ };
717
+ var trackWalletPaymentFailure = (skuId, reason) => {
718
+ track(EXPRESS_CHECKOUT_EVENTS.FAILURE, {
719
+ sku_id: skuId,
720
+ failure_reason: reason
721
+ });
722
+ };
723
+ var trackFallbackCheckout = (skuId) => {
724
+ track(EXPRESS_CHECKOUT_EVENTS.FALLBACK_CHECKOUT, { sku_id: skuId });
725
+ };
726
+ var trackValidationFieldError = (field, errorType) => {
727
+ track(`validation_${field}_${errorType}`, {});
728
+ };
729
+
730
+ // src/clients/payment-checkout/messages.ts
731
+ var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
732
+ var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a valid email address.";
733
+ var MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
734
+ var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
735
+ var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
736
+ var MSG_RECAPTCHA_VALIDATION_FAILED = "Security check failed. Please try again.";
737
+ var MSG_EMAIL_COLLISION = "This email address is already linked to an account. Please log in, or try a different email address.";
738
+ var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
739
+
740
+ // src/clients/payment-checkout/apple-session.ts
741
+ function startApplePaySession(config) {
742
+ const paymentRequest = {
743
+ countryCode: config.countryCode,
744
+ currencyCode: config.currencyCode,
745
+ merchantCapabilities: ["supports3DS"],
746
+ supportedNetworks: config.supportedNetworks,
747
+ total: {
748
+ label: config.totalLabel,
749
+ amount: config.totalAmount
750
+ },
751
+ requiredBillingContactFields: ["postalAddress", "name"],
752
+ // Only request email from Apple Pay sheet if user is NOT logged in
753
+ ...!config.userLoggedIn && { requiredShippingContactFields: ["email"] }
754
+ };
755
+ const session = new ApplePaySession(3, paymentRequest);
756
+ session.onvalidatemerchant = async (event) => {
757
+ try {
758
+ const validationHost = new URL(event.validationURL).host;
759
+ if (!validationHost.endsWith("apple.com")) {
760
+ trackFallbackCheckout(config.skuId);
761
+ session.abort();
762
+ window.location.href = redirectToCheckoutFallback({
763
+ skuId: config.skuId,
764
+ returnUrl: config.returnUrl,
765
+ inlineError: MSG_PAYMENT_GENERIC_ERROR
766
+ });
767
+ return;
768
+ }
769
+ const recaptchaToken = await getRecaptchaToken("verifyMerchant");
770
+ const response = await validateAppleMerchant({
771
+ validationURL: event.validationURL,
772
+ recaptchaToken
773
+ });
774
+ if (!response?.merchantSession) {
775
+ trackFallbackCheckout(config.skuId);
776
+ session.abort();
777
+ window.location.href = redirectToCheckoutFallback({
778
+ skuId: config.skuId,
779
+ returnUrl: config.returnUrl,
780
+ inlineError: MSG_PAYMENT_GENERIC_ERROR
781
+ });
782
+ return;
783
+ }
784
+ session.completeMerchantValidation(response.merchantSession);
785
+ } catch {
786
+ trackFallbackCheckout(config.skuId);
787
+ session.abort();
788
+ window.location.href = redirectToCheckoutFallback({
789
+ skuId: config.skuId,
790
+ returnUrl: config.returnUrl,
791
+ inlineError: MSG_PAYMENT_GENERIC_ERROR
792
+ });
793
+ }
794
+ };
795
+ session.onpaymentauthorized = (event) => {
796
+ trackWalletPaymentAuthorised(config.skuId);
797
+ config.onPaymentAuthorized(event, session);
798
+ };
799
+ session.oncancel = () => {
800
+ config.onCancel?.();
801
+ };
802
+ trackWalletPaymentSheetOpen(config.skuId);
803
+ session.begin();
804
+ }
805
+
806
+ // src/clients/payment-checkout/contact-validation.ts
807
+ var pushFieldError = (errors, billingOrShippingContact = "billing", field, errorType, errorText) => {
808
+ const errorCode = billingOrShippingContact === "billing" ? "billingContactInvalid" : "shippingContactInvalid";
809
+ errors.push(new ApplePayError(errorCode, field, errorText));
810
+ trackValidationFieldError(field, errorType);
811
+ return "";
812
+ };
813
+ var pushRequiredFieldError = (errors, billingOrShippingContact = "billing", field) => {
814
+ return pushFieldError(
815
+ errors,
816
+ billingOrShippingContact,
817
+ field,
818
+ "required",
819
+ MSG_MISSING_REQUIRED_FIELD
820
+ );
821
+ };
822
+ var ContactValidationError = class extends Error {
823
+ constructor(errors) {
824
+ super(MSG_CONTACT_VALIDATION_INTERNAL);
825
+ this.errors = errors;
826
+ }
827
+ };
828
+
829
+ // src/clients/payment-checkout/billing-contact-details.ts
830
+ var countriesWithoutCityField = ["KY", "CK", "NR", "TC"];
831
+ var countriesRequiringAllFields = ["US", "CA", "GB"];
832
+ var resolveCountryConfig = (country) => {
833
+ const hasCityField = !countriesWithoutCityField.includes(country);
834
+ const requiresStateAndPostcode = countriesRequiringAllFields.includes(country);
835
+ return {
836
+ hasCityField,
837
+ requiresStateAndPostcode,
838
+ // if there is no city field, we require state and use it in place of city
839
+ requiresStateField: !hasCityField || requiresStateAndPostcode
840
+ };
841
+ };
842
+ var validateAddressFields = (errors, contact, { hasCityField, requiresStateAndPostcode, requiresStateField }) => {
843
+ const locality = !hasCityField ? contact.administrativeArea : contact.locality;
844
+ if (!contact.addressLines?.at(0)?.trim()) {
845
+ pushRequiredFieldError(errors, "billing", "addressLines");
846
+ }
847
+ if (!locality?.trim() && hasCityField) {
848
+ pushRequiredFieldError(errors, "billing", "locality");
849
+ }
850
+ if (!contact.administrativeArea?.trim() && requiresStateField) {
851
+ pushRequiredFieldError(errors, "billing", "administrativeArea");
852
+ }
853
+ if (!contact.postalCode?.trim() && requiresStateAndPostcode) {
854
+ pushRequiredFieldError(errors, "billing", "postalCode");
855
+ }
856
+ };
857
+ var validateNameFields = (errors, contact) => {
858
+ const firstName = contact.givenName?.trim() || "";
859
+ const lastName = contact.familyName?.trim() || "";
860
+ if (!firstName || !lastName) {
861
+ pushRequiredFieldError(errors, "billing", "name");
862
+ }
863
+ return { firstName, lastName };
864
+ };
865
+ var validateCountrySupport = (errors, country, supportedBillingCountries) => {
866
+ if (!supportedBillingCountries.includes(country)) {
867
+ pushFieldError(
868
+ errors,
869
+ "billing",
870
+ "countryCode",
871
+ "not-supported",
872
+ MSG_UNSUPPORTED_BILLING_COUNTRY
873
+ );
874
+ }
875
+ };
876
+ var billingContactDetails = (contact, supportedBillingCountries) => {
877
+ const errors = [];
878
+ const country = contact.countryCode?.toUpperCase() || pushRequiredFieldError(errors, "billing", "country");
879
+ const config = resolveCountryConfig(country);
880
+ validateAddressFields(errors, contact, config);
881
+ const { firstName, lastName } = validateNameFields(errors, contact);
882
+ validateCountrySupport(errors, country, supportedBillingCountries);
883
+ if (errors.length > 0) {
884
+ throw new ContactValidationError(errors);
885
+ }
886
+ return { firstName, lastName };
887
+ };
888
+
889
+ // src/clients/payment-checkout/shipping-contact-details.ts
890
+ var EMAIL_FORMAT_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
891
+ var shippingContactDetails = (shippingContact) => {
892
+ const errors = [];
893
+ let emailAddress = "";
894
+ if (shippingContact?.emailAddress === void 0 || shippingContact?.emailAddress === "") {
895
+ pushRequiredFieldError(errors, "shipping", "emailAddress");
896
+ } else {
897
+ emailAddress = shippingContact.emailAddress.trim();
898
+ if (emailAddress.length > 80) {
899
+ pushFieldError(
900
+ errors,
901
+ "shipping",
902
+ "emailAddress",
903
+ "format",
904
+ MSG_EMAIL_TOO_LONG
905
+ );
906
+ } else if (!EMAIL_FORMAT_REGEX.test(emailAddress)) {
907
+ pushFieldError(
908
+ errors,
909
+ "shipping",
910
+ "emailAddress",
911
+ "format",
912
+ MSG_EMAIL_WRONG_FORMAT
913
+ );
914
+ }
915
+ }
916
+ if (errors.length > 0) {
917
+ throw new ContactValidationError(errors);
918
+ }
919
+ return { emailAddress };
920
+ };
921
+
922
+ // src/clients/payment-checkout/payment-handler.ts
923
+ var MSG_ELIGIBILITY = "Something went wrong, please try again";
924
+ var MSG_REGISTRATION = "We couldn't create your account. Please enter your email or try a different login method.";
925
+ var failApplePaySession = (session, errors = []) => {
926
+ session.completePayment({
927
+ status: ApplePaySession.STATUS_FAILURE,
928
+ errors
929
+ });
930
+ };
931
+ function parseWalletApiError(err) {
932
+ const body = err instanceof ApiError ? err.body : err;
933
+ if (body && typeof body === "object" && "errorType" in body && "message" in body) {
934
+ return body;
935
+ }
936
+ return null;
937
+ }
938
+ function validateContacts(event, sessionData, supportedBillingCountries) {
939
+ billingContactDetails(
940
+ event.payment.billingContact,
941
+ supportedBillingCountries
942
+ );
943
+ if (!sessionData.loggedIn) {
944
+ return shippingContactDetails(event.payment.shippingContact).emailAddress;
945
+ }
946
+ return void 0;
947
+ }
948
+ function redirectFallback(skuId, returnUrl, options) {
949
+ trackFallbackCheckout(skuId);
950
+ window.location.href = redirectToCheckoutFallback({
951
+ skuId,
952
+ returnUrl,
953
+ ...options
954
+ });
955
+ }
956
+ var ERROR_HANDLERS = {
957
+ EMAIL_COLLISION: ({ skuId, returnUrl, validatedEmail }) => redirectFallback(skuId, returnUrl, {
958
+ emailError: MSG_EMAIL_COLLISION,
959
+ email: validatedEmail
960
+ }),
961
+ PAYMENT_DECLINED: ({ skuId, returnUrl }) => (
962
+ // Matches sma-checkout catch-all: always redirect with generic inlineError.
963
+ redirectFallback(skuId, returnUrl, { inlineError: MSG_PAYMENT_GENERIC_ERROR })
964
+ ),
965
+ ELIGIBILITY_REJECTED: ({ skuId, returnUrl }) => redirectFallback(skuId, returnUrl, { inlineError: MSG_ELIGIBILITY }),
966
+ REGISTRATION_FAILED: ({ skuId, returnUrl }) => redirectFallback(skuId, returnUrl, { inlineError: MSG_REGISTRATION }),
967
+ VALIDATION_ERROR: ({ skuId, returnUrl }) => redirectFallback(skuId, returnUrl, { inlineError: MSG_RECAPTCHA_VALIDATION_FAILED })
968
+ };
969
+ function handleStructuredError(ctx) {
970
+ const handler = ERROR_HANDLERS[ctx.walletError.errorType];
971
+ if (handler) {
972
+ handler(ctx);
973
+ } else {
974
+ redirectFallback(ctx.skuId, ctx.returnUrl, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
975
+ }
976
+ }
977
+ async function handlePaymentAuthorized(event, session, sessionData, config) {
978
+ const { skuId, returnUrl, queryString } = config;
979
+ let validatedEmail;
980
+ try {
981
+ validatedEmail = validateContacts(
982
+ event,
983
+ sessionData,
984
+ config.supportedBillingCountries
985
+ );
986
+ const result = await performPurchase({
987
+ applePayToken: event.payment.token,
988
+ skuId: config.skuId,
989
+ billingContact: event.payment.billingContact,
990
+ ...event.payment.shippingContact && {
991
+ shippingContact: event.payment.shippingContact
992
+ },
993
+ recaptchaTokens: config.recaptchaTokens
994
+ });
995
+ trackWalletPaymentSuccess(skuId, result.basketId);
996
+ session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
997
+ const userStatus = sessionData.loggedIn ? "lex" : "nex";
998
+ window.location.href = redirectToCheckoutComplete({
999
+ basketId: result.basketId,
1000
+ status: userStatus,
1001
+ skuId: decodeSku(skuId),
1002
+ returnUrl,
1003
+ queryString
1004
+ });
1005
+ } catch (err) {
1006
+ if (err instanceof ContactValidationError) {
1007
+ failApplePaySession(session, err.errors);
1008
+ return;
1009
+ }
1010
+ console.error("[web-apple-pay] onpaymentauthorized error", { skuId, err });
1011
+ const walletError = parseWalletApiError(err);
1012
+ trackWalletPaymentFailure(skuId, walletError?.errorType ?? "UNKNOWN");
1013
+ failApplePaySession(session);
1014
+ if (!walletError) {
1015
+ redirectFallback(skuId, returnUrl, { inlineError: MSG_PAYMENT_GENERIC_ERROR });
1016
+ return;
1017
+ }
1018
+ handleStructuredError({ skuId, returnUrl, validatedEmail, walletError });
1019
+ }
1020
+ }
1021
+
1022
+ // src/data/price-zones.json
1023
+ var price_zones_default = {
1024
+ "AS-AS": [
1025
+ "BD",
1026
+ "BT",
1027
+ "CK",
1028
+ "FJ",
1029
+ "ID",
1030
+ "KH",
1031
+ "KI",
1032
+ "LA",
1033
+ "LK",
1034
+ "MH",
1035
+ "MM",
1036
+ "MN",
1037
+ "MV",
1038
+ "NC",
1039
+ "NF",
1040
+ "NP",
1041
+ "NR",
1042
+ "PF",
1043
+ "PG",
1044
+ "PK",
1045
+ "PW",
1046
+ "SB",
1047
+ "TH",
1048
+ "TL",
1049
+ "TO",
1050
+ "TV",
1051
+ "VN",
1052
+ "VU",
1053
+ "WS"
1054
+ ],
1055
+ "AS-AU": ["AU"],
1056
+ "AS-CN": ["CN"],
1057
+ "AS-HK": ["HK", "MO"],
1058
+ "AS-IN": ["IN"],
1059
+ "AS-JP": ["JP"],
1060
+ "AS-KR": ["KR"],
1061
+ "AS-MY": ["MY"],
1062
+ "AS-NZ": ["NZ"],
1063
+ "AS-PH": ["PH"],
1064
+ "AS-SG": ["BN", "SG"],
1065
+ "AS-TW": ["TW"],
1066
+ "CE-AF": [
1067
+ "DZ",
1068
+ "AO",
1069
+ "BJ",
1070
+ "BW",
1071
+ "BF",
1072
+ "BI",
1073
+ "CM",
1074
+ "CV",
1075
+ "CF",
1076
+ "TD",
1077
+ "CG",
1078
+ "CD",
1079
+ "CI",
1080
+ "DJ",
1081
+ "EG",
1082
+ "GQ",
1083
+ "ER",
1084
+ "ET",
1085
+ "GA",
1086
+ "GM",
1087
+ "GH",
1088
+ "GN",
1089
+ "GW",
1090
+ "IL",
1091
+ "JO",
1092
+ "KE",
1093
+ "LB",
1094
+ "LS",
1095
+ "LR",
1096
+ "LY",
1097
+ "MG",
1098
+ "MW",
1099
+ "ML",
1100
+ "MR",
1101
+ "MU",
1102
+ "MA",
1103
+ "MZ",
1104
+ "NA",
1105
+ "NE",
1106
+ "NG",
1107
+ "PS",
1108
+ "RE",
1109
+ "RW",
1110
+ "ST",
1111
+ "SN",
1112
+ "SC",
1113
+ "SL",
1114
+ "ZA",
1115
+ "SZ",
1116
+ "TZ",
1117
+ "TG",
1118
+ "TN",
1119
+ "UG",
1120
+ "ZM",
1121
+ "ZW"
1122
+ ],
1123
+ "CE-CH": ["LI", "CH"],
1124
+ "CE-DK": ["FO", "GL", "DK"],
1125
+ "CE-EU": [
1126
+ "AL",
1127
+ "AD",
1128
+ "AM",
1129
+ "AT",
1130
+ "AZ",
1131
+ "BY",
1132
+ "BE",
1133
+ "BA",
1134
+ "BG",
1135
+ "HR",
1136
+ "CY",
1137
+ "CZ",
1138
+ "EE",
1139
+ "FI",
1140
+ "FR",
1141
+ "GE",
1142
+ "DE",
1143
+ "GI",
1144
+ "GR",
1145
+ "HU",
1146
+ "IS",
1147
+ "IE",
1148
+ "IT",
1149
+ "KZ",
1150
+ "XK",
1151
+ "KG",
1152
+ "LV",
1153
+ "LT",
1154
+ "LU",
1155
+ "MT",
1156
+ "MD",
1157
+ "MC",
1158
+ "ME",
1159
+ "NL",
1160
+ "PL",
1161
+ "PT",
1162
+ "MK",
1163
+ "RO",
1164
+ "RS",
1165
+ "SK",
1166
+ "SI",
1167
+ "ES",
1168
+ "TJ",
1169
+ "TR",
1170
+ "TM",
1171
+ "UA",
1172
+ "UZ"
1173
+ ],
1174
+ "CE-ME": ["AE", "BH", "KW", "OM", "QA", "SA"],
1175
+ "CE-NO": ["NO"],
1176
+ "CE-SE": ["SE"],
1177
+ "LA-LA": [
1178
+ "AI",
1179
+ "AG",
1180
+ "AR",
1181
+ "AW",
1182
+ "BS",
1183
+ "BB",
1184
+ "BZ",
1185
+ "BM",
1186
+ "BO",
1187
+ "BR",
1188
+ "KY",
1189
+ "CL",
1190
+ "CO",
1191
+ "CR",
1192
+ "DM",
1193
+ "DO",
1194
+ "EC",
1195
+ "SV",
1196
+ "FK",
1197
+ "GF",
1198
+ "GD",
1199
+ "GT",
1200
+ "GY",
1201
+ "HT",
1202
+ "HN",
1203
+ "JM",
1204
+ "MQ",
1205
+ "MX",
1206
+ "MS",
1207
+ "NI",
1208
+ "MP",
1209
+ "PA",
1210
+ "PY",
1211
+ "PE",
1212
+ "KN",
1213
+ "LC",
1214
+ "VC",
1215
+ "SR",
1216
+ "TT",
1217
+ "TC",
1218
+ "UY",
1219
+ "VG",
1220
+ "VI"
1221
+ ],
1222
+ "NA-CA": ["CA"],
1223
+ "NA-US": ["AS", "GU", "FM", "PR", "US"],
1224
+ "UK-UK": ["GB"]
1225
+ };
1226
+
1227
+ // src/data/eea-countries.json
1228
+ var eea_countries_default = [
1229
+ "AT",
1230
+ "BE",
1231
+ "BG",
1232
+ "HR",
1233
+ "CY",
1234
+ "CZ",
1235
+ "DK",
1236
+ "EE",
1237
+ "FO",
1238
+ "FI",
1239
+ "FR",
1240
+ "DE",
1241
+ "GR",
1242
+ "GL",
1243
+ "HU",
1244
+ "IS",
1245
+ "IE",
1246
+ "IT",
1247
+ "LV",
1248
+ "LI",
1249
+ "LT",
1250
+ "LU",
1251
+ "MT",
1252
+ "NL",
1253
+ "NO",
1254
+ "PL",
1255
+ "PT",
1256
+ "RO",
1257
+ "SK",
1258
+ "SI",
1259
+ "ES",
1260
+ "SE"
1261
+ ];
1262
+
1263
+ // src/utils/billing-countries.ts
1264
+ var priceZones = price_zones_default;
1265
+ var eeaCountries = eea_countries_default;
1266
+ var ALL_COUNTRY_CODES = Object.values(priceZones).flat();
1267
+ var getZoneByCountry = (country) => Object.keys(priceZones).find((key) => priceZones[key].includes(country)) ?? null;
1268
+ var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1269
+ if (offerVariant === "bundle" || offerVariant === "insider_print") {
1270
+ return [...ALL_COUNTRY_CODES];
1271
+ }
1272
+ const zone = getZoneByCountry(offerCountry);
1273
+ if (!zone) {
1274
+ return [...ALL_COUNTRY_CODES];
1275
+ }
1276
+ const zoneCountries = priceZones[zone];
1277
+ if (eeaCountries.includes(offerCountry)) {
1278
+ return Array.from(/* @__PURE__ */ new Set([...zoneCountries, ...eeaCountries]));
1279
+ }
1280
+ return [...zoneCountries];
1281
+ };
1282
+
846
1283
  // src/apple-pay-button.ts
847
1284
  var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
848
- var APPLE_PAY_EXCLUDED_VARIANTS = ["bundle", "insider_print"];
1285
+ var TOTAL_LABEL = "The Economist";
1286
+ var DEFAULT_CURRENCY = "USD";
1287
+ var DEFAULT_TOTAL = "0.00";
1288
+ var ERROR_INITIATE = "Failed to initiate Apple Pay session:";
1289
+ var SEL_CONTAINER = ".apple-pay-container";
1290
+ var SEL_BUTTON = ".apple-pay-btn";
1291
+ var APPLE_PAY_EXCLUDED_VARIANTS = [
1292
+ "bundle",
1293
+ "insider_print"
1294
+ ];
849
1295
  var ApplePayButton = class _ApplePayButton extends HTMLElement {
850
1296
  static tag = "teg-apple-pay-button";
851
1297
  static define() {
@@ -854,29 +1300,39 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
854
1300
  /**
855
1301
  * Creates and configures an ApplePayButton if the feature flag is present.
856
1302
  */
857
- static createIfEnabled(offer, country) {
858
- if (!offer) {
859
- return null;
860
- }
861
- const isExcludedVariant = APPLE_PAY_EXCLUDED_VARIANTS.includes(offer.product?.variant);
862
- if (isExcludedVariant) {
1303
+ static createIfEnabled(offer, country, entryPoint) {
1304
+ if (!offer) return null;
1305
+ if (APPLE_PAY_EXCLUDED_VARIANTS.includes(offer.product?.variant))
863
1306
  return null;
864
- }
865
- if (!new URLSearchParams(window.location.search).has(
866
- FEATURE_APPLE_PAY_EXPRESS_CHECKOUT
867
- )) {
1307
+ if (!new URLSearchParams(window.location.search).has(FEATURE_APPLE_PAY_EXPRESS_CHECKOUT))
868
1308
  return null;
869
- }
870
1309
  _ApplePayButton.define();
871
1310
  const button = document.createElement(_ApplePayButton.tag);
872
1311
  button.offer = offer;
873
1312
  button.country = country;
1313
+ button.entryPoint = entryPoint;
874
1314
  return button;
875
1315
  }
1316
+ /**
1317
+ * Fallback session used when the BFF is unreachable at page load.
1318
+ * Treats the user as anonymous (not logged in, new-eligible).
1319
+ * Matches the behaviour of sma-checkout when session fetch fails.
1320
+ */
1321
+ static #ANONYMOUS_SESSION = {
1322
+ loggedIn: false,
1323
+ userType: "new-eligible-user"
1324
+ };
1325
+ // ─── Private state ──────────────────────────────────────────────────────────
876
1326
  #offer = null;
877
1327
  #country = "";
878
1328
  #rendering = false;
879
1329
  #readyPromise = null;
1330
+ #sessionData = null;
1331
+ #paymentOptions = null;
1332
+ #returnUrl = "";
1333
+ #supportedBillingCountries = [];
1334
+ #entryPoint = "";
1335
+ // ─── Public API ─────────────────────────────────────────────────────────────
880
1336
  get offer() {
881
1337
  return this.#offer;
882
1338
  }
@@ -890,6 +1346,12 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
890
1346
  set country(value) {
891
1347
  this.#country = value;
892
1348
  }
1349
+ get entryPoint() {
1350
+ return this.#entryPoint;
1351
+ }
1352
+ set entryPoint(value) {
1353
+ this.#entryPoint = value;
1354
+ }
893
1355
  /**
894
1356
  * Awaitable contract for the component's current render lifecycle.
895
1357
  *
@@ -909,60 +1371,130 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
909
1371
  whenReady() {
910
1372
  return this.#readyPromise ?? Promise.resolve();
911
1373
  }
1374
+ // ─── Lifecycle ──────────────────────────────────────────────────────────────
912
1375
  async connectedCallback() {
913
- if (this.#rendering || this.querySelector(".apple-pay-container")) {
1376
+ if (this.#rendering || this.querySelector(SEL_CONTAINER)) {
914
1377
  return;
915
1378
  }
916
1379
  this.#rendering = true;
917
1380
  this.#readyPromise = this.#run();
918
1381
  await this.#readyPromise;
919
1382
  }
1383
+ /**
1384
+ * Resets all render state when the element is removed from the DOM.
1385
+ *
1386
+ * A shared library component cannot assume it won't be moved in the DOM
1387
+ * (e.g. lazy panels, SPA route changes). Resetting on disconnect means
1388
+ * reattach always triggers a fresh `#run()` — new session check, new payment
1389
+ * options fetch, fresh event listeners — preventing stale data from persisting
1390
+ * and eliminating the implicit reliance on the DOM as a render-state flag.
1391
+ */
1392
+ disconnectedCallback() {
1393
+ this.#rendering = false;
1394
+ this.#readyPromise = null;
1395
+ this.#sessionData = null;
1396
+ this.#paymentOptions = null;
1397
+ this.#returnUrl = "";
1398
+ this.#supportedBillingCountries = [];
1399
+ this.querySelector(SEL_CONTAINER)?.remove();
1400
+ }
1401
+ // ─── Render pipeline ────────────────────────────────────────────────────────
920
1402
  async #run() {
921
1403
  try {
922
- const available = await isApplePayAvailable();
923
- if (!available) {
924
- this.style.display = "none";
925
- return;
926
- }
927
- const sessionData = await this.#fetchSession();
928
- if (sessionData?.loggedIn && (sessionData.userType === "active-subscription" || sessionData.userType === "b2b-user")) {
929
- this.style.display = "none";
930
- return;
931
- }
932
- this.style.removeProperty("display");
933
- ensureApplePayLogoSymbol();
934
- const template = document.createElement("template");
935
- template.innerHTML = apple_pay_button_template_default;
936
- this.appendChild(template.content.cloneNode(true));
937
- this.#updateDisabledState();
938
- const button = this.querySelector(".apple-pay-btn");
939
- button.addEventListener("click", () => {
940
- if (!this.#offer) {
941
- return;
942
- }
943
- if (document.querySelector(ApplePayModal.tag)) {
944
- return;
945
- }
946
- ApplePayModal.define();
947
- const modal = document.createElement(ApplePayModal.tag);
948
- modal.offer = this.#offer;
949
- modal.country = this.#country;
950
- if (this.dataset.loggedIn !== void 0) {
951
- modal.dataset.loggedIn = this.dataset.loggedIn;
952
- }
953
- modal.open();
954
- });
1404
+ if (await this.#checkAvailability()) return;
1405
+ if (await this.#checkSession()) return;
1406
+ if (this.#checkOffer()) return;
1407
+ this.#captureReturnUrl();
1408
+ this.#computeBillingCountries();
1409
+ if (await this.#fetchAndCacheOptions()) return;
1410
+ this.#renderTemplate();
955
1411
  } catch {
956
1412
  this.style.display = "none";
957
1413
  } finally {
958
1414
  this.#rendering = false;
959
1415
  }
960
1416
  }
961
- #updateDisabledState() {
962
- const button = this.querySelector(".apple-pay-btn");
963
- if (!button) {
964
- return;
1417
+ /** Returns `true` (hide) when Apple Pay is unavailable on this device/browser. */
1418
+ async #checkAvailability() {
1419
+ const available = await isApplePayAvailable();
1420
+ if (!available) {
1421
+ this.style.display = "none";
1422
+ return true;
1423
+ }
1424
+ return false;
1425
+ }
1426
+ /**
1427
+ * Returns `true` (hide) when the user already has an active subscription or is B2B.
1428
+ * Session fetch errors are swallowed — the component continues as an anonymous user.
1429
+ */
1430
+ async #checkSession() {
1431
+ this.#sessionData = await this.#fetchSession();
1432
+ if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
1433
+ this.style.display = "none";
1434
+ return true;
1435
+ }
1436
+ return false;
1437
+ }
1438
+ /** Returns `true` (hide) when no offer has been set before mount. */
1439
+ #checkOffer() {
1440
+ if (!this.#offer) {
1441
+ this.style.display = "none";
1442
+ return true;
1443
+ }
1444
+ return false;
1445
+ }
1446
+ /** Captures the current page URL once at mount for reuse across the session lifetime. */
1447
+ #captureReturnUrl() {
1448
+ this.#returnUrl = captureOriginUrl();
1449
+ }
1450
+ /**
1451
+ * Computes supported billing countries once at mount.
1452
+ * Mirrors sma-checkout `billingCountryOptions()` — stable for the element's
1453
+ * connected lifetime; recalculated on reattach via `disconnectedCallback` reset.
1454
+ */
1455
+ #computeBillingCountries() {
1456
+ this.#supportedBillingCountries = getSupportedBillingCountries(
1457
+ this.#country,
1458
+ this.#offer.product?.variant ?? ""
1459
+ );
1460
+ }
1461
+ /**
1462
+ * Returns `true` (hide) when ecom services reports Apple Pay is unavailable
1463
+ * for this offer. The response is cached and reused in `#initiateApplePay`.
1464
+ */
1465
+ async #fetchAndCacheOptions() {
1466
+ this.#paymentOptions = await this.#fetchPaymentOptions();
1467
+ if (!this.#paymentOptions?.options.applePay) {
1468
+ this.style.display = "none";
1469
+ return true;
965
1470
  }
1471
+ return false;
1472
+ }
1473
+ /** Injects the button template and wires click and confirm event listeners. */
1474
+ #renderTemplate() {
1475
+ this.style.removeProperty("display");
1476
+ ensureApplePayLogoSymbol();
1477
+ const template = document.createElement("template");
1478
+ template.innerHTML = apple_pay_button_template_default;
1479
+ this.appendChild(template.content.cloneNode(true));
1480
+ this.#updateDisabledState();
1481
+ trackExpressWalletImpression(this.#offer.sku_id, {
1482
+ entryPoint: this.#entryPoint,
1483
+ country: this.#country
1484
+ });
1485
+ const button = this.querySelector(SEL_BUTTON);
1486
+ button.addEventListener("click", () => {
1487
+ this.#openModal();
1488
+ });
1489
+ this.addEventListener("apple-pay-confirmed", (event) => {
1490
+ const { skuId, country } = event.detail;
1491
+ this.#initiateApplePay(skuId, country);
1492
+ });
1493
+ }
1494
+ // ─── Private helpers ────────────────────────────────────────────────────────
1495
+ #updateDisabledState() {
1496
+ const button = this.querySelector(SEL_BUTTON);
1497
+ if (!button) return;
966
1498
  if (this.#offer) {
967
1499
  button.removeAttribute("disabled");
968
1500
  button.removeAttribute("aria-disabled");
@@ -971,6 +1503,18 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
971
1503
  button.setAttribute("disabled", "");
972
1504
  button.setAttribute("aria-disabled", "true");
973
1505
  }
1506
+ #openModal() {
1507
+ if (!this.#offer || document.querySelector(ApplePayModal.tag)) return;
1508
+ trackExpressWalletClick(this.#offer.sku_id);
1509
+ ApplePayModal.define();
1510
+ const modal = document.createElement(ApplePayModal.tag);
1511
+ modal.offer = this.#offer;
1512
+ modal.country = this.#country;
1513
+ if (this.#sessionData?.loggedIn) {
1514
+ modal.dataset.loggedIn = "true";
1515
+ }
1516
+ modal.open();
1517
+ }
974
1518
  async #fetchSession() {
975
1519
  try {
976
1520
  return await getExpressCheckoutSession();
@@ -978,6 +1522,58 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
978
1522
  return null;
979
1523
  }
980
1524
  }
1525
+ async #fetchPaymentOptions() {
1526
+ try {
1527
+ return await getPaymentOptions({
1528
+ sku: this.#offer.sku_id,
1529
+ countryCode: this.#country,
1530
+ currencyCode: this.#offer.price?.currency_code ?? DEFAULT_CURRENCY,
1531
+ checkoutUrl: this.#returnUrl
1532
+ });
1533
+ } catch {
1534
+ return null;
1535
+ }
1536
+ }
1537
+ #buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokens) {
1538
+ const offer = this.#offer;
1539
+ const totalAmount = offer.price?.purchase ? `${offer.price.purchase}` : DEFAULT_TOTAL;
1540
+ return {
1541
+ countryCode: country,
1542
+ currencyCode: offer.price?.currency_code ?? DEFAULT_CURRENCY,
1543
+ supportedNetworks: paymentOptions.options.applePay.settings.supportedNetworks,
1544
+ totalAmount,
1545
+ totalLabel: TOTAL_LABEL,
1546
+ skuId,
1547
+ returnUrl: this.#returnUrl,
1548
+ userLoggedIn: sessionData.loggedIn,
1549
+ onPaymentAuthorized: (event, session) => handlePaymentAuthorized(event, session, sessionData, {
1550
+ skuId,
1551
+ country,
1552
+ returnUrl: this.#returnUrl,
1553
+ queryString: buildQueryString(),
1554
+ supportedBillingCountries: this.#supportedBillingCountries,
1555
+ recaptchaTokens
1556
+ })
1557
+ };
1558
+ }
1559
+ async #initiateApplePay(skuId, country) {
1560
+ try {
1561
+ const sessionData = this.#sessionData ?? _ApplePayButton.#ANONYMOUS_SESSION;
1562
+ const paymentOptions = this.#paymentOptions;
1563
+ const recaptchaTokens = await getPurchaseRecaptchaTokens();
1564
+ startApplePaySession(
1565
+ this.#buildSessionParams(
1566
+ skuId,
1567
+ country,
1568
+ sessionData,
1569
+ paymentOptions,
1570
+ recaptchaTokens
1571
+ )
1572
+ );
1573
+ } catch (error) {
1574
+ console.error(ERROR_INITIATE, error);
1575
+ }
1576
+ }
981
1577
  };
982
1578
  export {
983
1579
  APPLE_PAY_EXCLUDED_VARIANTS,