@economist/web-apple-pay 2.0.0-beta.2 → 2.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +26 -8
  2. package/dist/index.js +647 -349
  3. package/dist/src/apple-pay-button.d.ts +18 -16
  4. package/dist/src/apple-pay-button.js +636 -340
  5. package/dist/src/apple-pay-button.stories.js +633 -339
  6. package/dist/src/apple-pay-modal.js +44 -39
  7. package/dist/src/apple-pay-modal.stories.js +633 -339
  8. package/dist/src/clients/payment-checkout/apple-session.d.ts +14 -1
  9. package/dist/src/clients/payment-checkout/apple-session.js +46 -11
  10. package/dist/src/clients/payment-checkout/billing-contact-details.js +43 -0
  11. package/dist/src/clients/payment-checkout/delivery-contact-details.d.ts +16 -0
  12. package/dist/src/clients/payment-checkout/delivery-contact-details.js +395 -0
  13. package/dist/src/clients/payment-checkout/detects.d.ts +5 -0
  14. package/dist/src/clients/payment-checkout/detects.js +18 -14
  15. package/dist/src/clients/payment-checkout/messages.d.ts +6 -0
  16. package/dist/src/clients/payment-checkout/messages.js +7 -1
  17. package/dist/src/clients/payment-checkout/payment-handler.d.ts +10 -1
  18. package/dist/src/clients/payment-checkout/payment-handler.js +397 -30
  19. package/dist/src/clients/payment-checkout/session.js +13 -1
  20. package/dist/src/clients/payment-checkout/types.d.ts +7 -0
  21. package/dist/src/constants.d.ts +7 -28
  22. package/dist/src/constants.js +3 -7
  23. package/dist/src/index.d.ts +2 -4
  24. package/dist/src/index.js +647 -349
  25. package/dist/src/types/offer.types.d.ts +1 -1
  26. package/dist/src/utils/address-rules.d.ts +23 -0
  27. package/dist/src/utils/address-rules.js +258 -0
  28. package/dist/src/utils/addressParityFlag.d.ts +13 -0
  29. package/dist/src/utils/addressParityFlag.js +5 -0
  30. package/dist/src/utils/applePayExpressEligibility.d.ts +5 -6
  31. package/dist/src/utils/applePayExpressEligibility.js +2 -2
  32. package/dist/src/utils/buttonCopyFlag.d.ts +22 -0
  33. package/dist/src/utils/buttonCopyFlag.js +12 -0
  34. package/dist/src/utils/delivery-countries.d.ts +9 -0
  35. package/dist/src/utils/delivery-countries.js +255 -0
  36. package/dist/src/utils/expressCheckoutRedirect.d.ts +20 -2
  37. package/dist/src/utils/expressCheckoutRedirect.js +13 -1
  38. package/dist/src/utils/expressCheckoutTracking.d.ts +0 -15
  39. package/dist/src/utils/expressCheckoutTracking.js +0 -27
  40. package/dist/src/utils/latin-characters.d.ts +3 -0
  41. package/dist/src/utils/latin-characters.js +10 -0
  42. package/dist/src/utils/printOffersFlag.d.ts +11 -0
  43. package/dist/src/utils/printOffersFlag.js +5 -0
  44. package/dist/src/utils/recaptcha.d.ts +3 -2
  45. package/dist/src/utils/recaptcha.js +17 -8
  46. package/package.json +1 -1
  47. package/dist/src/apple-pay-logo.d.ts +0 -1
  48. package/dist/src/apple-pay-logo.js +0 -14
  49. package/dist/src/types/experiment-integration.d.js +0 -0
  50. package/dist/src/utils/getExperimentKeyFromNextData.d.ts +0 -8
  51. package/dist/src/utils/getExperimentKeyFromNextData.js +0 -9
@@ -20,6 +20,12 @@ export declare const MSG_MISSING_REQUIRED_FIELD = "Missing required field";
20
20
  export declare const MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a valid email address.";
21
21
  /** Shown when the email address exceeds 80 characters (matches sma-checkout FormErrorMessages.MAX_80_CHARS). */
22
22
  export declare const MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
23
+ /** Shown when a name or address field has characters print fulfilment cannot render (sma-checkout SMA-3066). */
24
+ export declare const MSG_NON_LATIN_CHARACTERS = "Please use Latin characters only.";
25
+ /** Shown when a delivery address field exceeds its Commerce Services length limit. */
26
+ export declare const msgFieldTooLong: (label: string, max: number) => string;
27
+ /** Shown when the delivery country is not one the offer can be delivered to. */
28
+ export declare const MSG_UNSUPPORTED_DELIVERY_COUNTRY = "We can't deliver this print edition to that country. Try a different delivery address.";
23
29
  /** Shown when the billing country is not in the supported list for the offer. */
24
30
  export declare const MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
25
31
  /**
@@ -2,6 +2,9 @@
2
2
  var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
3
3
  var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a valid email address.";
4
4
  var MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
5
+ var MSG_NON_LATIN_CHARACTERS = "Please use Latin characters only.";
6
+ var msgFieldTooLong = (label, max) => `${label} must be ${max} characters or less`;
7
+ var MSG_UNSUPPORTED_DELIVERY_COUNTRY = "We can't deliver this print edition to that country. Try a different delivery address.";
5
8
  var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
6
9
  var BILLING_COUNTRY_MISMATCH_FALLBACK = "Country not supported for this purchase";
7
10
  var MSG_BILLING_COUNTRY_MISMATCH_REDIRECT = "This country isn\u2019t supported for this purchase. Try updating your billing address.";
@@ -26,7 +29,10 @@ export {
26
29
  MSG_EMAIL_TOO_LONG,
27
30
  MSG_EMAIL_WRONG_FORMAT,
28
31
  MSG_MISSING_REQUIRED_FIELD,
32
+ MSG_NON_LATIN_CHARACTERS,
29
33
  MSG_PAYMENT_GENERIC_ERROR,
30
34
  MSG_UNSUPPORTED_BILLING_COUNTRY,
31
- buildCountryMismatchMessage
35
+ MSG_UNSUPPORTED_DELIVERY_COUNTRY,
36
+ buildCountryMismatchMessage,
37
+ msgFieldTooLong
32
38
  };
@@ -18,8 +18,17 @@ export type PaymentHandlerConfig = {
18
18
  skuId: string;
19
19
  country: string;
20
20
  currency: string;
21
- returnUrl: string;
21
+ /** `checkout-redirect` to persist, or `null` to leave the host's value untouched. */
22
+ returnUrl: string | null;
22
23
  supportedBillingCountries: string[];
24
+ /**
25
+ * Print (bundle) offers: the delivery contact is validated and sent with the purchase. `offerCountry`
26
+ * selects the price zone whose address rules apply.
27
+ */
28
+ delivery?: {
29
+ offerCountry: string;
30
+ supportedCountries: string[];
31
+ };
23
32
  recaptchaToken: string;
24
33
  };
25
34
  export declare function handlePaymentAuthorized(event: ApplePayJS.ApplePayPaymentAuthorizedEvent, session: ApplePaySession, sessionData: SessionResponse, config: PaymentHandlerConfig): Promise<void>;
@@ -116,21 +116,10 @@ var trackValidationFieldError = (field, errorType) => {
116
116
  var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
117
117
  var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a valid email address.";
118
118
  var MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
119
+ var MSG_NON_LATIN_CHARACTERS = "Please use Latin characters only.";
120
+ var msgFieldTooLong = (label, max) => `${label} must be ${max} characters or less`;
121
+ var MSG_UNSUPPORTED_DELIVERY_COUNTRY = "We can't deliver this print edition to that country. Try a different delivery address.";
119
122
  var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
120
- var BILLING_COUNTRY_MISMATCH_FALLBACK = "Country not supported for this purchase";
121
- var MSG_BILLING_COUNTRY_MISMATCH_REDIRECT = "This country isn\u2019t supported for this purchase. Try updating your billing address.";
122
- var buildCountryMismatchMessage = (countryCode) => {
123
- if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
124
- try {
125
- const regionNames = new Intl.DisplayNames(["en"], { type: "region", fallback: "none" });
126
- const upper = countryCode.toUpperCase();
127
- const countryName = regionNames.of(upper);
128
- const isResolved = countryName && countryName !== upper && countryName !== "Unknown Region";
129
- return isResolved ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
130
- } catch {
131
- return BILLING_COUNTRY_MISMATCH_FALLBACK;
132
- }
133
- };
134
123
  var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
135
124
  var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
136
125
 
@@ -157,6 +146,16 @@ var ContactValidationError = class extends Error {
157
146
  }
158
147
  };
159
148
 
149
+ // src/utils/latin-characters.ts
150
+ var SUPPORTED_DIACRITICS = "\xE0\xE1\xE2\u0101\u0103\u0105\u0227\u01CE\u0201\u0203\xC0\xC1\xC2\u0100\u0102\u0104\u0226\u01CD\u0200\u0202\xE3\xE4\xC3\xC4\xE6\xC6\xE5\xC5\xE8\xE9\xEA\u1EBD\xEB\u0113\u0115\u0119\u0117\u011B\u0205\u0207\xC8\xC9\xCA\u1EBC\xCB\u0112\u0114\u0118\u0116\u011A\u0204\u0206\xEC\xED\xEE\u0129\xEF\u012B\u012D\u012F\u01D0\u0209\u020B\xCC\xCD\xCE\u0128\xCF\u012A\u012C\u012E\u01CF\u0208\u020A\xF2\xF3\xF4\xF5\u014D\u014F\u01EB\u022F\u0151\u01D2\u020D\u020F\xD2\xD3\xD4\xD5\u014C\u014E\u01EA\u022E\u0150\u01D1\u020C\u020E\xF6\xD6\xF8\xD8\u016F\xF9\xFA\xFB\u0169\u016B\u016D\u0173\u0171\u01D4\u0215\u0217\u016E\xD9\xDA\xDB\u0168\u016A\u016C\u0172\u0170\u01D3\u0214\u0216\xFC\xDC\u1EF3\xFD\u0177\u1EF9\xFF\u0233\u1E8F\u1EF2\xDD\u0176\u1EF8\u0178\u0232\u1E8E\xE7\xC7\u0107\u010D\u0106\u010C\xDF\xFE\xDE\xAA\u0159\u0155\u0158\u0154\u0142\u013E\u013A\u013C\u0141\u013D\u0139\u013B\xF1\u0144\u0148\u0146\xD1\u0143\u0147\u0145\u015B\u0161\u015A\u0160\u015F\u0219\u015E\u0218\u017A\u017C\u017E\u0179\u017B\u017D\u010F\xF0\u010E\xD0\u0165\u021B\u0164\u021A\u011F\u0123\u011E\u0122\u0137\u0136\u2019";
151
+ var LATIN_CHARACTERS_REGEX = new RegExp(
152
+ `^[\\x20-\\x7E${SUPPORTED_DIACRITICS}]*$`
153
+ );
154
+ var isLatinCharacters = (value) => LATIN_CHARACTERS_REGEX.test(value);
155
+
156
+ // src/utils/addressParityFlag.ts
157
+ var ADDRESS_PARITY_ENABLED = true;
158
+
160
159
  // src/clients/payment-checkout/billing-contact-details.ts
161
160
  var countriesWithoutCityField = ["KY", "CK", "NR", "TC"];
162
161
  var countriesRequiringAllFields = ["US", "CA", "GB"];
@@ -204,6 +203,35 @@ var validateCountrySupport = (errors, country, supportedBillingCountries) => {
204
203
  );
205
204
  }
206
205
  };
206
+ var validateLatinCharacters = (errors, contact, firstName, lastName) => {
207
+ if (!isLatinCharacters(firstName) || !isLatinCharacters(lastName)) {
208
+ pushFieldError(
209
+ errors,
210
+ "billing",
211
+ "name",
212
+ "format",
213
+ MSG_NON_LATIN_CHARACTERS
214
+ );
215
+ }
216
+ const addressFields = [
217
+ ["addressLines", contact.addressLines?.at(0)],
218
+ ["addressLines", contact.addressLines?.at(1)],
219
+ ["locality", contact.locality],
220
+ ["administrativeArea", contact.administrativeArea],
221
+ ["postalCode", contact.postalCode]
222
+ ];
223
+ for (const [field, value] of addressFields) {
224
+ if (value && !isLatinCharacters(value)) {
225
+ pushFieldError(
226
+ errors,
227
+ "billing",
228
+ field,
229
+ "format",
230
+ MSG_NON_LATIN_CHARACTERS
231
+ );
232
+ }
233
+ }
234
+ };
207
235
  var billingContactDetails = (contact, supportedBillingCountries) => {
208
236
  const errors = [];
209
237
  const country = contact.countryCode?.toUpperCase() || pushRequiredFieldError(errors, "billing", "country");
@@ -211,6 +239,9 @@ var billingContactDetails = (contact, supportedBillingCountries) => {
211
239
  validateAddressFields(errors, contact, config);
212
240
  const { firstName, lastName } = validateNameFields(errors, contact);
213
241
  validateCountrySupport(errors, country, supportedBillingCountries);
242
+ if (ADDRESS_PARITY_ENABLED) {
243
+ validateLatinCharacters(errors, contact, firstName, lastName);
244
+ }
214
245
  if (errors.length > 0) {
215
246
  throw new ContactValidationError(errors);
216
247
  }
@@ -250,6 +281,343 @@ var shippingContactDetails = (shippingContact) => {
250
281
  return { emailAddress };
251
282
  };
252
283
 
284
+ // src/data/price-zones.json
285
+ var price_zones_default = {
286
+ "AS-AS": [
287
+ "BD",
288
+ "BT",
289
+ "CK",
290
+ "FJ",
291
+ "ID",
292
+ "KH",
293
+ "KI",
294
+ "LA",
295
+ "LK",
296
+ "MH",
297
+ "MM",
298
+ "MN",
299
+ "MV",
300
+ "NC",
301
+ "NF",
302
+ "NP",
303
+ "NR",
304
+ "PF",
305
+ "PG",
306
+ "PK",
307
+ "PW",
308
+ "SB",
309
+ "TH",
310
+ "TL",
311
+ "TO",
312
+ "TV",
313
+ "VN",
314
+ "VU",
315
+ "WS"
316
+ ],
317
+ "AS-AU": ["AU"],
318
+ "AS-CN": ["CN"],
319
+ "AS-HK": ["HK", "MO"],
320
+ "AS-IN": ["IN"],
321
+ "AS-JP": ["JP"],
322
+ "AS-KR": ["KR"],
323
+ "AS-MY": ["MY"],
324
+ "AS-NZ": ["NZ"],
325
+ "AS-PH": ["PH"],
326
+ "AS-SG": ["BN", "SG"],
327
+ "AS-TW": ["TW"],
328
+ "CE-AF": [
329
+ "DZ",
330
+ "AO",
331
+ "BJ",
332
+ "BW",
333
+ "BF",
334
+ "BI",
335
+ "CM",
336
+ "CV",
337
+ "CF",
338
+ "TD",
339
+ "CG",
340
+ "CD",
341
+ "CI",
342
+ "DJ",
343
+ "EG",
344
+ "GQ",
345
+ "ER",
346
+ "ET",
347
+ "GA",
348
+ "GM",
349
+ "GH",
350
+ "GN",
351
+ "GW",
352
+ "IL",
353
+ "JO",
354
+ "KE",
355
+ "LB",
356
+ "LS",
357
+ "LR",
358
+ "LY",
359
+ "MG",
360
+ "MW",
361
+ "ML",
362
+ "MR",
363
+ "MU",
364
+ "MA",
365
+ "MZ",
366
+ "NA",
367
+ "NE",
368
+ "NG",
369
+ "PS",
370
+ "RE",
371
+ "RW",
372
+ "ST",
373
+ "SN",
374
+ "SC",
375
+ "SL",
376
+ "ZA",
377
+ "SZ",
378
+ "TZ",
379
+ "TG",
380
+ "TN",
381
+ "UG",
382
+ "ZM",
383
+ "ZW"
384
+ ],
385
+ "CE-CH": ["LI", "CH"],
386
+ "CE-DK": ["FO", "GL", "DK"],
387
+ "CE-EU": [
388
+ "AL",
389
+ "AD",
390
+ "AM",
391
+ "AT",
392
+ "AZ",
393
+ "BY",
394
+ "BE",
395
+ "BA",
396
+ "BG",
397
+ "HR",
398
+ "CY",
399
+ "CZ",
400
+ "EE",
401
+ "FI",
402
+ "FR",
403
+ "GE",
404
+ "DE",
405
+ "GI",
406
+ "GR",
407
+ "HU",
408
+ "IS",
409
+ "IE",
410
+ "IT",
411
+ "KZ",
412
+ "XK",
413
+ "KG",
414
+ "LV",
415
+ "LT",
416
+ "LU",
417
+ "MT",
418
+ "MD",
419
+ "MC",
420
+ "ME",
421
+ "NL",
422
+ "PL",
423
+ "PT",
424
+ "MK",
425
+ "RO",
426
+ "RS",
427
+ "SK",
428
+ "SI",
429
+ "ES",
430
+ "TJ",
431
+ "TR",
432
+ "TM",
433
+ "UA",
434
+ "UZ"
435
+ ],
436
+ "CE-ME": ["AE", "BH", "KW", "OM", "QA", "SA"],
437
+ "CE-NO": ["NO"],
438
+ "CE-SE": ["SE"],
439
+ "LA-LA": [
440
+ "AI",
441
+ "AG",
442
+ "AR",
443
+ "AW",
444
+ "BS",
445
+ "BB",
446
+ "BZ",
447
+ "BM",
448
+ "BO",
449
+ "BR",
450
+ "KY",
451
+ "CL",
452
+ "CO",
453
+ "CR",
454
+ "DM",
455
+ "DO",
456
+ "EC",
457
+ "SV",
458
+ "FK",
459
+ "GF",
460
+ "GD",
461
+ "GT",
462
+ "GY",
463
+ "HT",
464
+ "HN",
465
+ "JM",
466
+ "MQ",
467
+ "MX",
468
+ "MS",
469
+ "NI",
470
+ "MP",
471
+ "PA",
472
+ "PY",
473
+ "PE",
474
+ "KN",
475
+ "LC",
476
+ "VC",
477
+ "SR",
478
+ "TT",
479
+ "TC",
480
+ "UY",
481
+ "VG",
482
+ "VI"
483
+ ],
484
+ "NA-CA": ["CA"],
485
+ "NA-US": ["AS", "GU", "FM", "PR", "US"],
486
+ "UK-UK": ["GB"]
487
+ };
488
+
489
+ // src/utils/address-rules.ts
490
+ var priceZones = price_zones_default;
491
+ var ADDRESS_LIMITS = {
492
+ address1: 35,
493
+ address2: 35,
494
+ city: 40,
495
+ state: 40,
496
+ postalCode: 20,
497
+ phone: 35
498
+ };
499
+ var zoneOf = (country) => Object.keys(priceZones).find((zone) => priceZones[zone].includes(country));
500
+ var COUNTRIES_REQUIRING_PHONE = ["IN", "CN"];
501
+ var requiredDeliveryFields = (offerCountry, country) => {
502
+ const zone = zoneOf(offerCountry);
503
+ const fields = ["address1", "city"];
504
+ if (zone === "AS-AU" || zone === "AS-JP" || zone === "NA-CA" || country === "US") {
505
+ fields.push("state");
506
+ }
507
+ if ((zone !== "AS-HK" || country === "MO") && zone !== "CE-AF" && zone !== "CE-ME") {
508
+ fields.push("postalCode");
509
+ }
510
+ if (COUNTRIES_REQUIRING_PHONE.includes(country)) fields.push("phone");
511
+ return fields;
512
+ };
513
+ var postalCodeFormatError = (offerCountry, postalCode) => {
514
+ if (!postalCode) return null;
515
+ const zone = zoneOf(offerCountry);
516
+ if (zone === "NA-US" && !/(^\d{5}$)|(^\d{5}-\d{4}$)/.test(postalCode)) {
517
+ return "Zip code must be a valid US zip code";
518
+ }
519
+ if (zone === "NA-CA" && !/^[A-Za-z]\d[A-Za-z][ -]?\d[A-Za-z]\d$/.test(postalCode)) {
520
+ return "Postal code must be a valid Canadian postal code";
521
+ }
522
+ return null;
523
+ };
524
+ var COUNTRY_CALLING_CODES = {
525
+ IN: "91",
526
+ CN: "86"
527
+ };
528
+ var normaliseDeliveryPhone = (raw, country) => {
529
+ const trimmed = raw?.trim() ?? "";
530
+ const digits = trimmed.replace(/[^0-9]+/g, "");
531
+ if (!digits) return void 0;
532
+ if (trimmed.startsWith("+")) return `+${digits}`;
533
+ const callingCode = COUNTRY_CALLING_CODES[country];
534
+ return callingCode ? `+${callingCode}${digits.replace(/^0+/, "")}` : void 0;
535
+ };
536
+
537
+ // src/clients/payment-checkout/delivery-contact-details.ts
538
+ var APPLE_FIELD = {
539
+ address1: "addressLines",
540
+ city: "locality",
541
+ state: "administrativeArea",
542
+ postalCode: "postalCode",
543
+ phone: "phoneNumber"
544
+ };
545
+ var LABEL = {
546
+ address1: "Address line 1",
547
+ address2: "Address line 2",
548
+ city: "City",
549
+ state: "State",
550
+ postalCode: "Postcode",
551
+ phone: "Phone number"
552
+ };
553
+ var deliveryContactDetails = (contact, { offerCountry, supportedDeliveryCountries }) => {
554
+ const errors = [];
555
+ const fail = (field, type, message) => pushFieldError(errors, "shipping", field, type, message);
556
+ const country = contact?.countryCode?.trim().toUpperCase() ?? "";
557
+ const firstName = contact?.givenName?.trim() ?? "";
558
+ const lastName = contact?.familyName?.trim() ?? "";
559
+ const address1 = contact?.addressLines?.at(0)?.trim() ?? "";
560
+ const address2 = contact?.addressLines?.at(1)?.trim() ?? "";
561
+ const city = contact?.locality?.trim() ?? "";
562
+ const state = contact?.administrativeArea?.trim() ?? "";
563
+ const postalCode = contact?.postalCode?.trim() ?? "";
564
+ const phone = normaliseDeliveryPhone(contact?.phoneNumber, country) ?? "";
565
+ if (!country) {
566
+ pushRequiredFieldError(errors, "shipping", "country");
567
+ } else if (!supportedDeliveryCountries.includes(country)) {
568
+ fail("countryCode", "not-supported", MSG_UNSUPPORTED_DELIVERY_COUNTRY);
569
+ }
570
+ if (!firstName || !lastName) {
571
+ pushRequiredFieldError(errors, "shipping", "name");
572
+ }
573
+ const values = {
574
+ address1,
575
+ city,
576
+ state,
577
+ postalCode,
578
+ phone
579
+ };
580
+ for (const field of requiredDeliveryFields(offerCountry, country)) {
581
+ if (!values[field]) {
582
+ pushRequiredFieldError(errors, "shipping", APPLE_FIELD[field]);
583
+ }
584
+ }
585
+ const limited = [
586
+ ["address1", "addressLines", address1, ADDRESS_LIMITS.address1],
587
+ ["address2", "addressLines", address2, ADDRESS_LIMITS.address2],
588
+ ["city", "locality", city, ADDRESS_LIMITS.city],
589
+ ["state", "administrativeArea", state, ADDRESS_LIMITS.state],
590
+ ["postalCode", "postalCode", postalCode, ADDRESS_LIMITS.postalCode],
591
+ ["phone", "phoneNumber", phone, ADDRESS_LIMITS.phone]
592
+ ];
593
+ for (const [field, appleField, value, max] of limited) {
594
+ if (value.length > max) {
595
+ fail(appleField, "format", msgFieldTooLong(LABEL[field], max));
596
+ }
597
+ }
598
+ const formatError = postalCodeFormatError(offerCountry, postalCode);
599
+ if (formatError) {
600
+ fail("postalCode", "format", formatError);
601
+ }
602
+ const latin = [
603
+ ["name", firstName],
604
+ ["name", lastName],
605
+ ["addressLines", address1],
606
+ ["addressLines", address2],
607
+ ["locality", city],
608
+ ["administrativeArea", state],
609
+ ["postalCode", postalCode]
610
+ ];
611
+ for (const [field, value] of latin) {
612
+ if (!isLatinCharacters(value)) {
613
+ fail(field, "format", MSG_NON_LATIN_CHARACTERS);
614
+ }
615
+ }
616
+ if (errors.length > 0) {
617
+ throw new ContactValidationError(errors);
618
+ }
619
+ };
620
+
253
621
  // src/utils/expressCheckoutRedirect.ts
254
622
  var CHECKOUT_REDIRECT_KEY = "checkout-redirect";
255
623
  var ALLOWED_REDIRECT_HOSTNAME = "economist.com";
@@ -263,7 +631,7 @@ function isAllowedRedirectUrl(url) {
263
631
  }
264
632
  }
265
633
  var writeCheckoutRedirect = (originUrl) => {
266
- if (!isAllowedRedirectUrl(originUrl)) return;
634
+ if (originUrl === null || !isAllowedRedirectUrl(originUrl)) return;
267
635
  try {
268
636
  localStorage.setItem(CHECKOUT_REDIRECT_KEY, originUrl);
269
637
  } catch {
@@ -312,11 +680,17 @@ function parseWalletApiError(err) {
312
680
  }
313
681
  return null;
314
682
  }
315
- function validateContacts(event, sessionData, supportedBillingCountries) {
683
+ function validateContacts(event, sessionData, supportedBillingCountries, delivery) {
316
684
  billingContactDetails(
317
685
  event.payment.billingContact,
318
686
  supportedBillingCountries
319
687
  );
688
+ if (delivery) {
689
+ deliveryContactDetails(event.payment.shippingContact, {
690
+ offerCountry: delivery.offerCountry,
691
+ supportedDeliveryCountries: delivery.supportedCountries
692
+ });
693
+ }
320
694
  if (!sessionData.loggedIn) {
321
695
  return shippingContactDetails(event.payment.shippingContact).emailAddress;
322
696
  }
@@ -363,7 +737,8 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
363
737
  validatedEmail = validateContacts(
364
738
  event,
365
739
  sessionData,
366
- config.supportedBillingCountries
740
+ config.supportedBillingCountries,
741
+ config.delivery
367
742
  );
368
743
  const result = await performPurchase({
369
744
  applePayToken: event.payment.token,
@@ -373,6 +748,10 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
373
748
  ...event.payment.shippingContact && {
374
749
  shippingContact: event.payment.shippingContact
375
750
  },
751
+ ...config.delivery && {
752
+ supportedDeliveryCountries: config.delivery.supportedCountries
753
+ },
754
+ ...ADDRESS_PARITY_ENABLED ? { strictAddressRules: true } : {},
376
755
  recaptchaToken: config.recaptchaToken
377
756
  });
378
757
  trackWalletPaymentSuccess(skuId, result.basketId);
@@ -389,19 +768,7 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
389
768
  });
390
769
  } catch (err) {
391
770
  if (err instanceof ContactValidationError) {
392
- const isBillingCountryMismatch = err.errors.some(
393
- (e) => e.contactField === "countryCode"
394
- );
395
- if (isBillingCountryMismatch) {
396
- const countryCode = event.payment.billingContact?.countryCode;
397
- const userMessage = buildCountryMismatchMessage(countryCode);
398
- failApplePaySession(session, [
399
- new ApplePayError("billingContactInvalid", "countryCode", userMessage)
400
- ]);
401
- redirectFallback(skuId, returnUrl, country, { inlineError: MSG_BILLING_COUNTRY_MISMATCH_REDIRECT });
402
- } else {
403
- failApplePaySession(session, err.errors);
404
- }
771
+ failApplePaySession(session, err.errors);
405
772
  return;
406
773
  }
407
774
  const walletError = parseWalletApiError(err);
@@ -56,11 +56,23 @@ var apiFetch = async (path, options = {}) => {
56
56
  };
57
57
 
58
58
  // src/clients/payment-checkout/session.ts
59
+ var inFlight = null;
59
60
  var getExpressCheckoutSession = () => {
60
- return apiFetch("/v1/wallet/session", {
61
+ if (inFlight) {
62
+ return inFlight;
63
+ }
64
+ const request = apiFetch("/v1/wallet/session", {
61
65
  method: "GET",
62
66
  credentials: "include"
63
67
  });
68
+ inFlight = request;
69
+ const clear = () => {
70
+ if (inFlight === request) {
71
+ inFlight = null;
72
+ }
73
+ };
74
+ request.then(clear, clear);
75
+ return request;
64
76
  };
65
77
  export {
66
78
  getExpressCheckoutSession
@@ -91,6 +91,13 @@ export type PurchaseRequest = {
91
91
  billingContact: ApplePayPaymentContact;
92
92
  /** Required if loggedIn: false — contains emailAddress from Apple Pay sheet. */
93
93
  shippingContact?: ApplePayPaymentContact;
94
+ /**
95
+ * Print (bundle) offers only: the countries the offer can be delivered to. The BFF requires the delivery
96
+ * country to be in this list, same pattern as `supportedBillingCountries`.
97
+ */
98
+ supportedDeliveryCountries?: string[];
99
+ /** Sent when `ADDRESS_PARITY_ENABLED`: the BFF then applies the sma-checkout billing rules (Latin, truncation, PR). */
100
+ strictAddressRules?: boolean;
94
101
  recaptchaToken: string;
95
102
  };
96
103
  export type PurchaseResponse = {
@@ -2,32 +2,11 @@ export declare enum ApplePayEntryPoint {
2
2
  PAYWALL = "article_paywall",
3
3
  REGWALL = "article_regwall",
4
4
  DUAL_OFFER_BANNER = "dual_offer_banner",
5
- FREE_TRIAL_BANNER = "free_trial_banner"
5
+ FREE_TRIAL_BANNER = "free_trial_banner",
6
+ /** Post-registration free-trial popup. Not Amplitude-gated. */
7
+ FREE_TRIAL_POPUP = "free_trial_popup",
8
+ /** /subscribe offers page (sma-checkout). Not Amplitude-gated. */
9
+ SUBSCRIBE = "subscribe",
10
+ /** Sales pages in sma-checkout (Black Friday and other promotions). Not Amplitude-gated. */
11
+ SALES_PAGE = "sales_page"
6
12
  }
7
- /**
8
- * Amplitude experiment key for Apple Pay Express Checkout on article paywalls
9
- * (`ApplePayEntryPoint.PAYWALL`, e.g. single-offer-paywall / multi-offer paywall).
10
- *
11
- * Fail-closed when the variant is missing or not `treatment`; the QA URL param
12
- * `FEATURE_APPLE_PAY_EXPRESS_CHECKOUT` can show the button without treatment.
13
- * Eligibility for this flag ignores homepage and requires Safari/Apple device
14
- * (plus `isApplePayAvailable` before `$exposure`).
15
- *
16
- * Must match the Feature experiment key in Amplitude and host app constants
17
- * (Engagement / Insider / Podcasts) while those still bridge the experiment.
18
- */
19
- export declare const APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY = "apple-pay-express-checkout-on-paywalls";
20
- /**
21
- * Known Amplitude experiment flag keys for Apple Pay Express Checkout.
22
- * Narrowed so callers cannot pass an arbitrary typo'd string.
23
- */
24
- export type ApplePayExperimentFlagKey = typeof APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY;
25
- /**
26
- * Amplitude variant values for the Apple Pay Express Checkout experiment.
27
- * CONTROL → button hidden (baseline)
28
- * TREATMENT → button shown
29
- */
30
- export declare const APPLE_PAY_EXPRESS_VARIANTS: {
31
- readonly CONTROL: "control";
32
- readonly TREATMENT: "treatment";
33
- };
@@ -4,15 +4,11 @@ var ApplePayEntryPoint = /* @__PURE__ */ ((ApplePayEntryPoint2) => {
4
4
  ApplePayEntryPoint2["REGWALL"] = "article_regwall";
5
5
  ApplePayEntryPoint2["DUAL_OFFER_BANNER"] = "dual_offer_banner";
6
6
  ApplePayEntryPoint2["FREE_TRIAL_BANNER"] = "free_trial_banner";
7
+ ApplePayEntryPoint2["FREE_TRIAL_POPUP"] = "free_trial_popup";
8
+ ApplePayEntryPoint2["SUBSCRIBE"] = "subscribe";
9
+ ApplePayEntryPoint2["SALES_PAGE"] = "sales_page";
7
10
  return ApplePayEntryPoint2;
8
11
  })(ApplePayEntryPoint || {});
9
- var APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY = "apple-pay-express-checkout-on-paywalls";
10
- var APPLE_PAY_EXPRESS_VARIANTS = {
11
- CONTROL: "control",
12
- TREATMENT: "treatment"
13
- };
14
12
  export {
15
- APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY,
16
- APPLE_PAY_EXPRESS_VARIANTS,
17
13
  ApplePayEntryPoint
18
14
  };
@@ -1,9 +1,7 @@
1
- export { ApplePayButton, APPLE_PAY_EXCLUDED_VARIANTS, } from './apple-pay-button';
1
+ export { ApplePayButton, APPLE_PAY_EXCLUDED_VARIANTS, getExcludedVariants, } from './apple-pay-button';
2
2
  export { ApplePayModal } from './apple-pay-modal';
3
- export { ensureApplePayLogoSymbol } from './apple-pay-logo';
4
3
  export { configureApplePay } from './clients/payment-checkout/config';
5
- export { ApplePayEntryPoint, APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY, APPLE_PAY_EXPRESS_VARIANTS, } from './constants';
6
- export type { ApplePayExperimentFlagKey } from './constants';
4
+ export { ApplePayEntryPoint } from './constants';
7
5
  export type { ApplePayRuntimeConfig } from './clients/payment-checkout/config';
8
6
  export type { Offer } from './types/offer.types';
9
7
  export declare function defineApplePayElements(): void;