@economist/web-apple-pay 2.0.0-beta.2 → 2.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -12
- package/dist/index.js +681 -361
- package/dist/src/apple-pay-button.d.ts +18 -16
- package/dist/src/apple-pay-button.js +670 -352
- package/dist/src/apple-pay-button.stories.js +667 -351
- package/dist/src/apple-pay-modal.js +44 -39
- package/dist/src/apple-pay-modal.stories.js +667 -351
- package/dist/src/clients/payment-checkout/apple-session.d.ts +14 -1
- package/dist/src/clients/payment-checkout/apple-session.js +66 -17
- package/dist/src/clients/payment-checkout/billing-contact-details.js +43 -0
- package/dist/src/clients/payment-checkout/delivery-contact-details.d.ts +16 -0
- package/dist/src/clients/payment-checkout/delivery-contact-details.js +397 -0
- package/dist/src/clients/payment-checkout/detects.d.ts +5 -0
- package/dist/src/clients/payment-checkout/detects.js +18 -14
- package/dist/src/clients/payment-checkout/messages.d.ts +6 -0
- package/dist/src/clients/payment-checkout/messages.js +7 -1
- package/dist/src/clients/payment-checkout/payment-handler.d.ts +10 -1
- package/dist/src/clients/payment-checkout/payment-handler.js +414 -36
- package/dist/src/clients/payment-checkout/session.js +13 -1
- package/dist/src/clients/payment-checkout/types.d.ts +11 -0
- package/dist/src/constants.d.ts +7 -28
- package/dist/src/constants.js +3 -7
- package/dist/src/index.d.ts +2 -4
- package/dist/src/index.js +681 -361
- package/dist/src/types/offer.types.d.ts +1 -1
- package/dist/src/utils/address-rules.d.ts +29 -0
- package/dist/src/utils/address-rules.js +260 -0
- package/dist/src/utils/addressParityFlag.d.ts +13 -0
- package/dist/src/utils/addressParityFlag.js +5 -0
- package/dist/src/utils/applePayExpressEligibility.d.ts +5 -6
- package/dist/src/utils/applePayExpressEligibility.js +2 -2
- package/dist/src/utils/billing-countries.js +46 -37
- package/dist/src/utils/buttonCopyFlag.d.ts +22 -0
- package/dist/src/utils/buttonCopyFlag.js +12 -0
- package/dist/src/utils/delivery-countries.d.ts +9 -0
- package/dist/src/utils/delivery-countries.js +255 -0
- package/dist/src/utils/expressCheckoutRedirect.d.ts +20 -2
- package/dist/src/utils/expressCheckoutRedirect.js +13 -1
- package/dist/src/utils/expressCheckoutTracking.d.ts +13 -20
- package/dist/src/utils/expressCheckoutTracking.js +22 -37
- package/dist/src/utils/latin-characters.d.ts +3 -0
- package/dist/src/utils/latin-characters.js +10 -0
- package/dist/src/utils/price-zones.d.ts +7 -0
- package/dist/src/utils/price-zones.js +212 -0
- package/dist/src/utils/print-variants.d.ts +5 -0
- package/dist/src/utils/print-variants.js +10 -0
- package/dist/src/utils/printOffersFlag.d.ts +11 -0
- package/dist/src/utils/printOffersFlag.js +5 -0
- package/dist/src/utils/recaptcha.d.ts +3 -2
- package/dist/src/utils/recaptcha.js +17 -8
- package/package.json +1 -1
- package/dist/src/apple-pay-logo.d.ts +0 -1
- package/dist/src/apple-pay-logo.js +0 -14
- package/dist/src/types/experiment-integration.d.js +0 -0
- package/dist/src/utils/getExperimentKeyFromNextData.d.ts +0 -8
- package/dist/src/utils/getExperimentKeyFromNextData.js +0 -9
|
@@ -9,7 +9,7 @@ var isAppleDeviceOrSafari = () => {
|
|
|
9
9
|
return isIOSOrMacTouchDevice || isSafariBrowser;
|
|
10
10
|
};
|
|
11
11
|
var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null;
|
|
12
|
-
var
|
|
12
|
+
var isApplePayCapable = () => {
|
|
13
13
|
if (bypassApplePayChecks()) {
|
|
14
14
|
return true;
|
|
15
15
|
}
|
|
@@ -21,18 +21,21 @@ var isApplePayAvailable = async () => {
|
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
return typeof applePaySession.canMakePayments === "function" && applePaySession.canMakePayments() && Boolean(getApplePayConfig()?.merchantId);
|
|
25
|
+
} catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var isApplePayAvailable = async () => {
|
|
30
|
+
if (bypassApplePayChecks()) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if (!isApplePayCapable()) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const merchantId = getApplePayConfig().merchantId;
|
|
38
|
+
return await window.ApplePaySession.canMakePaymentsWithActiveCard(merchantId);
|
|
36
39
|
} catch {
|
|
37
40
|
return false;
|
|
38
41
|
}
|
|
@@ -40,5 +43,6 @@ var isApplePayAvailable = async () => {
|
|
|
40
43
|
export {
|
|
41
44
|
bypassApplePayChecks,
|
|
42
45
|
isAppleDeviceOrSafari,
|
|
43
|
-
isApplePayAvailable
|
|
46
|
+
isApplePayAvailable,
|
|
47
|
+
isApplePayCapable
|
|
44
48
|
};
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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>;
|
|
@@ -93,20 +93,26 @@ var track = (action, extra) => {
|
|
|
93
93
|
...extra
|
|
94
94
|
});
|
|
95
95
|
};
|
|
96
|
-
var
|
|
96
|
+
var withEntryPoint = ({ entryPoint } = {}) => entryPoint ? { entry_point: entryPoint } : {};
|
|
97
|
+
var trackWalletPaymentSuccess = (skuId, basketId, metadata) => {
|
|
97
98
|
track(EXPRESS_CHECKOUT_EVENTS.SUCCESS, {
|
|
98
99
|
sku_id: skuId,
|
|
99
|
-
basket_id: basketId
|
|
100
|
+
basket_id: basketId,
|
|
101
|
+
...withEntryPoint(metadata)
|
|
100
102
|
});
|
|
101
103
|
};
|
|
102
|
-
var trackWalletPaymentFailure = (skuId, reason) => {
|
|
104
|
+
var trackWalletPaymentFailure = (skuId, reason, metadata) => {
|
|
103
105
|
track(EXPRESS_CHECKOUT_EVENTS.FAILURE, {
|
|
104
106
|
sku_id: skuId,
|
|
105
|
-
failure_reason: reason
|
|
107
|
+
failure_reason: reason,
|
|
108
|
+
...withEntryPoint(metadata)
|
|
106
109
|
});
|
|
107
110
|
};
|
|
108
|
-
var trackFallbackCheckout = (skuId) => {
|
|
109
|
-
track(EXPRESS_CHECKOUT_EVENTS.FALLBACK_CHECKOUT, {
|
|
111
|
+
var trackFallbackCheckout = (skuId, metadata) => {
|
|
112
|
+
track(EXPRESS_CHECKOUT_EVENTS.FALLBACK_CHECKOUT, {
|
|
113
|
+
sku_id: skuId,
|
|
114
|
+
...withEntryPoint(metadata)
|
|
115
|
+
});
|
|
110
116
|
};
|
|
111
117
|
var trackValidationFieldError = (field, errorType) => {
|
|
112
118
|
track(`validation_${field}_${errorType}`, {});
|
|
@@ -116,21 +122,10 @@ var trackValidationFieldError = (field, errorType) => {
|
|
|
116
122
|
var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
|
|
117
123
|
var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a valid email address.";
|
|
118
124
|
var MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
|
|
125
|
+
var MSG_NON_LATIN_CHARACTERS = "Please use Latin characters only.";
|
|
126
|
+
var msgFieldTooLong = (label, max) => `${label} must be ${max} characters or less`;
|
|
127
|
+
var MSG_UNSUPPORTED_DELIVERY_COUNTRY = "We can't deliver this print edition to that country. Try a different delivery address.";
|
|
119
128
|
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
129
|
var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
|
|
135
130
|
var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
|
|
136
131
|
|
|
@@ -157,6 +152,16 @@ var ContactValidationError = class extends Error {
|
|
|
157
152
|
}
|
|
158
153
|
};
|
|
159
154
|
|
|
155
|
+
// src/utils/latin-characters.ts
|
|
156
|
+
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";
|
|
157
|
+
var LATIN_CHARACTERS_REGEX = new RegExp(
|
|
158
|
+
`^[\\x20-\\x7E${SUPPORTED_DIACRITICS}]*$`
|
|
159
|
+
);
|
|
160
|
+
var isLatinCharacters = (value) => LATIN_CHARACTERS_REGEX.test(value);
|
|
161
|
+
|
|
162
|
+
// src/utils/addressParityFlag.ts
|
|
163
|
+
var ADDRESS_PARITY_ENABLED = true;
|
|
164
|
+
|
|
160
165
|
// src/clients/payment-checkout/billing-contact-details.ts
|
|
161
166
|
var countriesWithoutCityField = ["KY", "CK", "NR", "TC"];
|
|
162
167
|
var countriesRequiringAllFields = ["US", "CA", "GB"];
|
|
@@ -204,6 +209,35 @@ var validateCountrySupport = (errors, country, supportedBillingCountries) => {
|
|
|
204
209
|
);
|
|
205
210
|
}
|
|
206
211
|
};
|
|
212
|
+
var validateLatinCharacters = (errors, contact, firstName, lastName) => {
|
|
213
|
+
if (!isLatinCharacters(firstName) || !isLatinCharacters(lastName)) {
|
|
214
|
+
pushFieldError(
|
|
215
|
+
errors,
|
|
216
|
+
"billing",
|
|
217
|
+
"name",
|
|
218
|
+
"format",
|
|
219
|
+
MSG_NON_LATIN_CHARACTERS
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
const addressFields = [
|
|
223
|
+
["addressLines", contact.addressLines?.at(0)],
|
|
224
|
+
["addressLines", contact.addressLines?.at(1)],
|
|
225
|
+
["locality", contact.locality],
|
|
226
|
+
["administrativeArea", contact.administrativeArea],
|
|
227
|
+
["postalCode", contact.postalCode]
|
|
228
|
+
];
|
|
229
|
+
for (const [field, value] of addressFields) {
|
|
230
|
+
if (value && !isLatinCharacters(value)) {
|
|
231
|
+
pushFieldError(
|
|
232
|
+
errors,
|
|
233
|
+
"billing",
|
|
234
|
+
field,
|
|
235
|
+
"format",
|
|
236
|
+
MSG_NON_LATIN_CHARACTERS
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
};
|
|
207
241
|
var billingContactDetails = (contact, supportedBillingCountries) => {
|
|
208
242
|
const errors = [];
|
|
209
243
|
const country = contact.countryCode?.toUpperCase() || pushRequiredFieldError(errors, "billing", "country");
|
|
@@ -211,6 +245,9 @@ var billingContactDetails = (contact, supportedBillingCountries) => {
|
|
|
211
245
|
validateAddressFields(errors, contact, config);
|
|
212
246
|
const { firstName, lastName } = validateNameFields(errors, contact);
|
|
213
247
|
validateCountrySupport(errors, country, supportedBillingCountries);
|
|
248
|
+
if (ADDRESS_PARITY_ENABLED) {
|
|
249
|
+
validateLatinCharacters(errors, contact, firstName, lastName);
|
|
250
|
+
}
|
|
214
251
|
if (errors.length > 0) {
|
|
215
252
|
throw new ContactValidationError(errors);
|
|
216
253
|
}
|
|
@@ -250,6 +287,345 @@ var shippingContactDetails = (shippingContact) => {
|
|
|
250
287
|
return { emailAddress };
|
|
251
288
|
};
|
|
252
289
|
|
|
290
|
+
// src/data/price-zones.json
|
|
291
|
+
var price_zones_default = {
|
|
292
|
+
"AS-AS": [
|
|
293
|
+
"BD",
|
|
294
|
+
"BT",
|
|
295
|
+
"CK",
|
|
296
|
+
"FJ",
|
|
297
|
+
"ID",
|
|
298
|
+
"KH",
|
|
299
|
+
"KI",
|
|
300
|
+
"LA",
|
|
301
|
+
"LK",
|
|
302
|
+
"MH",
|
|
303
|
+
"MM",
|
|
304
|
+
"MN",
|
|
305
|
+
"MV",
|
|
306
|
+
"NC",
|
|
307
|
+
"NF",
|
|
308
|
+
"NP",
|
|
309
|
+
"NR",
|
|
310
|
+
"PF",
|
|
311
|
+
"PG",
|
|
312
|
+
"PK",
|
|
313
|
+
"PW",
|
|
314
|
+
"SB",
|
|
315
|
+
"TH",
|
|
316
|
+
"TL",
|
|
317
|
+
"TO",
|
|
318
|
+
"TV",
|
|
319
|
+
"VN",
|
|
320
|
+
"VU",
|
|
321
|
+
"WS"
|
|
322
|
+
],
|
|
323
|
+
"AS-AU": ["AU"],
|
|
324
|
+
"AS-CN": ["CN"],
|
|
325
|
+
"AS-HK": ["HK", "MO"],
|
|
326
|
+
"AS-IN": ["IN"],
|
|
327
|
+
"AS-JP": ["JP"],
|
|
328
|
+
"AS-KR": ["KR"],
|
|
329
|
+
"AS-MY": ["MY"],
|
|
330
|
+
"AS-NZ": ["NZ"],
|
|
331
|
+
"AS-PH": ["PH"],
|
|
332
|
+
"AS-SG": ["BN", "SG"],
|
|
333
|
+
"AS-TW": ["TW"],
|
|
334
|
+
"CE-AF": [
|
|
335
|
+
"DZ",
|
|
336
|
+
"AO",
|
|
337
|
+
"BJ",
|
|
338
|
+
"BW",
|
|
339
|
+
"BF",
|
|
340
|
+
"BI",
|
|
341
|
+
"CM",
|
|
342
|
+
"CV",
|
|
343
|
+
"CF",
|
|
344
|
+
"TD",
|
|
345
|
+
"CG",
|
|
346
|
+
"CD",
|
|
347
|
+
"CI",
|
|
348
|
+
"DJ",
|
|
349
|
+
"EG",
|
|
350
|
+
"GQ",
|
|
351
|
+
"ER",
|
|
352
|
+
"ET",
|
|
353
|
+
"GA",
|
|
354
|
+
"GM",
|
|
355
|
+
"GH",
|
|
356
|
+
"GN",
|
|
357
|
+
"GW",
|
|
358
|
+
"IL",
|
|
359
|
+
"JO",
|
|
360
|
+
"KE",
|
|
361
|
+
"LB",
|
|
362
|
+
"LS",
|
|
363
|
+
"LR",
|
|
364
|
+
"LY",
|
|
365
|
+
"MG",
|
|
366
|
+
"MW",
|
|
367
|
+
"ML",
|
|
368
|
+
"MR",
|
|
369
|
+
"MU",
|
|
370
|
+
"MA",
|
|
371
|
+
"MZ",
|
|
372
|
+
"NA",
|
|
373
|
+
"NE",
|
|
374
|
+
"NG",
|
|
375
|
+
"PS",
|
|
376
|
+
"RE",
|
|
377
|
+
"RW",
|
|
378
|
+
"ST",
|
|
379
|
+
"SN",
|
|
380
|
+
"SC",
|
|
381
|
+
"SL",
|
|
382
|
+
"ZA",
|
|
383
|
+
"SZ",
|
|
384
|
+
"TZ",
|
|
385
|
+
"TG",
|
|
386
|
+
"TN",
|
|
387
|
+
"UG",
|
|
388
|
+
"ZM",
|
|
389
|
+
"ZW"
|
|
390
|
+
],
|
|
391
|
+
"CE-CH": ["LI", "CH"],
|
|
392
|
+
"CE-DK": ["FO", "GL", "DK"],
|
|
393
|
+
"CE-EU": [
|
|
394
|
+
"AL",
|
|
395
|
+
"AD",
|
|
396
|
+
"AM",
|
|
397
|
+
"AT",
|
|
398
|
+
"AZ",
|
|
399
|
+
"BY",
|
|
400
|
+
"BE",
|
|
401
|
+
"BA",
|
|
402
|
+
"BG",
|
|
403
|
+
"HR",
|
|
404
|
+
"CY",
|
|
405
|
+
"CZ",
|
|
406
|
+
"EE",
|
|
407
|
+
"FI",
|
|
408
|
+
"FR",
|
|
409
|
+
"GE",
|
|
410
|
+
"DE",
|
|
411
|
+
"GI",
|
|
412
|
+
"GR",
|
|
413
|
+
"HU",
|
|
414
|
+
"IS",
|
|
415
|
+
"IE",
|
|
416
|
+
"IT",
|
|
417
|
+
"KZ",
|
|
418
|
+
"XK",
|
|
419
|
+
"KG",
|
|
420
|
+
"LV",
|
|
421
|
+
"LT",
|
|
422
|
+
"LU",
|
|
423
|
+
"MT",
|
|
424
|
+
"MD",
|
|
425
|
+
"MC",
|
|
426
|
+
"ME",
|
|
427
|
+
"NL",
|
|
428
|
+
"PL",
|
|
429
|
+
"PT",
|
|
430
|
+
"MK",
|
|
431
|
+
"RO",
|
|
432
|
+
"RS",
|
|
433
|
+
"SK",
|
|
434
|
+
"SI",
|
|
435
|
+
"ES",
|
|
436
|
+
"TJ",
|
|
437
|
+
"TR",
|
|
438
|
+
"TM",
|
|
439
|
+
"UA",
|
|
440
|
+
"UZ"
|
|
441
|
+
],
|
|
442
|
+
"CE-ME": ["AE", "BH", "KW", "OM", "QA", "SA"],
|
|
443
|
+
"CE-NO": ["NO"],
|
|
444
|
+
"CE-SE": ["SE"],
|
|
445
|
+
"LA-LA": [
|
|
446
|
+
"AI",
|
|
447
|
+
"AG",
|
|
448
|
+
"AR",
|
|
449
|
+
"AW",
|
|
450
|
+
"BS",
|
|
451
|
+
"BB",
|
|
452
|
+
"BZ",
|
|
453
|
+
"BM",
|
|
454
|
+
"BO",
|
|
455
|
+
"BR",
|
|
456
|
+
"KY",
|
|
457
|
+
"CL",
|
|
458
|
+
"CO",
|
|
459
|
+
"CR",
|
|
460
|
+
"DM",
|
|
461
|
+
"DO",
|
|
462
|
+
"EC",
|
|
463
|
+
"SV",
|
|
464
|
+
"FK",
|
|
465
|
+
"GF",
|
|
466
|
+
"GD",
|
|
467
|
+
"GT",
|
|
468
|
+
"GY",
|
|
469
|
+
"HT",
|
|
470
|
+
"HN",
|
|
471
|
+
"JM",
|
|
472
|
+
"MQ",
|
|
473
|
+
"MX",
|
|
474
|
+
"MS",
|
|
475
|
+
"NI",
|
|
476
|
+
"MP",
|
|
477
|
+
"PA",
|
|
478
|
+
"PY",
|
|
479
|
+
"PE",
|
|
480
|
+
"KN",
|
|
481
|
+
"LC",
|
|
482
|
+
"VC",
|
|
483
|
+
"SR",
|
|
484
|
+
"TT",
|
|
485
|
+
"TC",
|
|
486
|
+
"UY",
|
|
487
|
+
"VG",
|
|
488
|
+
"VI"
|
|
489
|
+
],
|
|
490
|
+
"NA-CA": ["CA"],
|
|
491
|
+
"NA-US": ["AS", "GU", "FM", "PR", "US"],
|
|
492
|
+
"UK-UK": ["GB"]
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
// src/utils/price-zones.ts
|
|
496
|
+
var priceZones = price_zones_default;
|
|
497
|
+
var getZoneByCountry = (country) => Object.keys(priceZones).find((key) => priceZones[key].includes(country)) ?? null;
|
|
498
|
+
|
|
499
|
+
// src/utils/address-rules.ts
|
|
500
|
+
var ADDRESS_LIMITS = {
|
|
501
|
+
address1: 35,
|
|
502
|
+
address2: 35,
|
|
503
|
+
city: 40,
|
|
504
|
+
state: 40,
|
|
505
|
+
postalCode: 20,
|
|
506
|
+
phone: 35
|
|
507
|
+
};
|
|
508
|
+
var COUNTRIES_REQUIRING_PHONE = ["IN", "CN"];
|
|
509
|
+
var requiredDeliveryFields = (offerCountry, country) => {
|
|
510
|
+
const zone = getZoneByCountry(offerCountry);
|
|
511
|
+
const fields = ["address1", "city"];
|
|
512
|
+
if (zone === "AS-AU" || zone === "AS-JP" || zone === "NA-CA" || country === "US") {
|
|
513
|
+
fields.push("state");
|
|
514
|
+
}
|
|
515
|
+
if ((zone !== "AS-HK" || country === "MO") && zone !== "CE-AF" && zone !== "CE-ME") {
|
|
516
|
+
fields.push("postalCode");
|
|
517
|
+
}
|
|
518
|
+
if (COUNTRIES_REQUIRING_PHONE.includes(country)) fields.push("phone");
|
|
519
|
+
return fields;
|
|
520
|
+
};
|
|
521
|
+
var postalCodeFormatError = (offerCountry, postalCode) => {
|
|
522
|
+
if (!postalCode) return null;
|
|
523
|
+
const zone = getZoneByCountry(offerCountry);
|
|
524
|
+
if (zone === "NA-US" && !/(^\d{5}$)|(^\d{5}-\d{4}$)/.test(postalCode)) {
|
|
525
|
+
return "Zip code must be a valid US zip code";
|
|
526
|
+
}
|
|
527
|
+
if (zone === "NA-CA" && !/^[A-Za-z]\d[A-Za-z][ -]?\d[A-Za-z]\d$/.test(postalCode)) {
|
|
528
|
+
return "Postal code must be a valid Canadian postal code";
|
|
529
|
+
}
|
|
530
|
+
return null;
|
|
531
|
+
};
|
|
532
|
+
var COUNTRY_CALLING_CODES = {
|
|
533
|
+
IN: "91",
|
|
534
|
+
CN: "86"
|
|
535
|
+
};
|
|
536
|
+
var normaliseDeliveryPhone = (raw, country) => {
|
|
537
|
+
const trimmed = raw?.trim() ?? "";
|
|
538
|
+
const digits = trimmed.replace(/[^0-9]+/g, "");
|
|
539
|
+
if (!digits) return void 0;
|
|
540
|
+
if (trimmed.startsWith("+")) return `+${digits}`;
|
|
541
|
+
const callingCode = COUNTRY_CALLING_CODES[country];
|
|
542
|
+
return callingCode ? `+${callingCode}${digits.replace(/^0+/, "")}` : void 0;
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
// src/clients/payment-checkout/delivery-contact-details.ts
|
|
546
|
+
var APPLE_FIELD = {
|
|
547
|
+
address1: "addressLines",
|
|
548
|
+
city: "locality",
|
|
549
|
+
state: "administrativeArea",
|
|
550
|
+
postalCode: "postalCode",
|
|
551
|
+
phone: "phoneNumber"
|
|
552
|
+
};
|
|
553
|
+
var LABEL = {
|
|
554
|
+
address1: "Address line 1",
|
|
555
|
+
address2: "Address line 2",
|
|
556
|
+
city: "City",
|
|
557
|
+
state: "State",
|
|
558
|
+
postalCode: "Postcode",
|
|
559
|
+
phone: "Phone number"
|
|
560
|
+
};
|
|
561
|
+
var deliveryContactDetails = (contact, { offerCountry, supportedDeliveryCountries }) => {
|
|
562
|
+
const errors = [];
|
|
563
|
+
const fail = (field, type, message) => pushFieldError(errors, "shipping", field, type, message);
|
|
564
|
+
const country = contact?.countryCode?.trim().toUpperCase() ?? "";
|
|
565
|
+
const firstName = contact?.givenName?.trim() ?? "";
|
|
566
|
+
const lastName = contact?.familyName?.trim() ?? "";
|
|
567
|
+
const address1 = contact?.addressLines?.at(0)?.trim() ?? "";
|
|
568
|
+
const address2 = contact?.addressLines?.at(1)?.trim() ?? "";
|
|
569
|
+
const city = contact?.locality?.trim() ?? "";
|
|
570
|
+
const state = contact?.administrativeArea?.trim() ?? "";
|
|
571
|
+
const postalCode = contact?.postalCode?.trim() ?? "";
|
|
572
|
+
const phone = normaliseDeliveryPhone(contact?.phoneNumber, country) ?? "";
|
|
573
|
+
if (!country) {
|
|
574
|
+
pushRequiredFieldError(errors, "shipping", "country");
|
|
575
|
+
} else if (!supportedDeliveryCountries.includes(country)) {
|
|
576
|
+
fail("countryCode", "not-supported", MSG_UNSUPPORTED_DELIVERY_COUNTRY);
|
|
577
|
+
}
|
|
578
|
+
if (!firstName || !lastName) {
|
|
579
|
+
pushRequiredFieldError(errors, "shipping", "name");
|
|
580
|
+
}
|
|
581
|
+
const values = {
|
|
582
|
+
address1,
|
|
583
|
+
city,
|
|
584
|
+
state,
|
|
585
|
+
postalCode,
|
|
586
|
+
phone
|
|
587
|
+
};
|
|
588
|
+
for (const field of requiredDeliveryFields(offerCountry, country)) {
|
|
589
|
+
if (!values[field]) {
|
|
590
|
+
pushRequiredFieldError(errors, "shipping", APPLE_FIELD[field]);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
const limited = [
|
|
594
|
+
["address1", "addressLines", address1, ADDRESS_LIMITS.address1],
|
|
595
|
+
["address2", "addressLines", address2, ADDRESS_LIMITS.address2],
|
|
596
|
+
["city", "locality", city, ADDRESS_LIMITS.city],
|
|
597
|
+
["state", "administrativeArea", state, ADDRESS_LIMITS.state],
|
|
598
|
+
["postalCode", "postalCode", postalCode, ADDRESS_LIMITS.postalCode],
|
|
599
|
+
["phone", "phoneNumber", phone, ADDRESS_LIMITS.phone]
|
|
600
|
+
];
|
|
601
|
+
for (const [field, appleField, value, max] of limited) {
|
|
602
|
+
if (value.length > max) {
|
|
603
|
+
fail(appleField, "format", msgFieldTooLong(LABEL[field], max));
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
const formatError = postalCodeFormatError(offerCountry, postalCode);
|
|
607
|
+
if (formatError) {
|
|
608
|
+
fail("postalCode", "format", formatError);
|
|
609
|
+
}
|
|
610
|
+
const latin = [
|
|
611
|
+
["name", firstName],
|
|
612
|
+
["name", lastName],
|
|
613
|
+
["addressLines", address1],
|
|
614
|
+
["addressLines", address2],
|
|
615
|
+
["locality", city],
|
|
616
|
+
["administrativeArea", state],
|
|
617
|
+
["postalCode", postalCode]
|
|
618
|
+
];
|
|
619
|
+
for (const [field, value] of latin) {
|
|
620
|
+
if (!isLatinCharacters(value)) {
|
|
621
|
+
fail(field, "format", MSG_NON_LATIN_CHARACTERS);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
if (errors.length > 0) {
|
|
625
|
+
throw new ContactValidationError(errors);
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
|
|
253
629
|
// src/utils/expressCheckoutRedirect.ts
|
|
254
630
|
var CHECKOUT_REDIRECT_KEY = "checkout-redirect";
|
|
255
631
|
var ALLOWED_REDIRECT_HOSTNAME = "economist.com";
|
|
@@ -263,7 +639,7 @@ function isAllowedRedirectUrl(url) {
|
|
|
263
639
|
}
|
|
264
640
|
}
|
|
265
641
|
var writeCheckoutRedirect = (originUrl) => {
|
|
266
|
-
if (!isAllowedRedirectUrl(originUrl)) return;
|
|
642
|
+
if (originUrl === null || !isAllowedRedirectUrl(originUrl)) return;
|
|
267
643
|
try {
|
|
268
644
|
localStorage.setItem(CHECKOUT_REDIRECT_KEY, originUrl);
|
|
269
645
|
} catch {
|
|
@@ -312,11 +688,17 @@ function parseWalletApiError(err) {
|
|
|
312
688
|
}
|
|
313
689
|
return null;
|
|
314
690
|
}
|
|
315
|
-
function validateContacts(event, sessionData, supportedBillingCountries) {
|
|
691
|
+
function validateContacts(event, sessionData, supportedBillingCountries, delivery) {
|
|
316
692
|
billingContactDetails(
|
|
317
693
|
event.payment.billingContact,
|
|
318
694
|
supportedBillingCountries
|
|
319
695
|
);
|
|
696
|
+
if (delivery) {
|
|
697
|
+
deliveryContactDetails(event.payment.shippingContact, {
|
|
698
|
+
offerCountry: delivery.offerCountry,
|
|
699
|
+
supportedDeliveryCountries: delivery.supportedCountries
|
|
700
|
+
});
|
|
701
|
+
}
|
|
320
702
|
if (!sessionData.loggedIn) {
|
|
321
703
|
return shippingContactDetails(event.payment.shippingContact).emailAddress;
|
|
322
704
|
}
|
|
@@ -363,16 +745,24 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
|
|
|
363
745
|
validatedEmail = validateContacts(
|
|
364
746
|
event,
|
|
365
747
|
sessionData,
|
|
366
|
-
config.supportedBillingCountries
|
|
748
|
+
config.supportedBillingCountries,
|
|
749
|
+
config.delivery
|
|
367
750
|
);
|
|
368
751
|
const result = await performPurchase({
|
|
369
752
|
applePayToken: event.payment.token,
|
|
370
753
|
skuId: config.skuId,
|
|
754
|
+
// Offer/geo country — must not fall back to billing country on the BFF (print billing is unrestricted).
|
|
755
|
+
countryCode: config.country,
|
|
371
756
|
currency: config.currency,
|
|
372
757
|
billingContact: event.payment.billingContact,
|
|
758
|
+
supportedBillingCountries: config.supportedBillingCountries,
|
|
373
759
|
...event.payment.shippingContact && {
|
|
374
760
|
shippingContact: event.payment.shippingContact
|
|
375
761
|
},
|
|
762
|
+
...config.delivery && {
|
|
763
|
+
supportedDeliveryCountries: config.delivery.supportedCountries
|
|
764
|
+
},
|
|
765
|
+
...ADDRESS_PARITY_ENABLED ? { strictAddressRules: true } : {},
|
|
376
766
|
recaptchaToken: config.recaptchaToken
|
|
377
767
|
});
|
|
378
768
|
trackWalletPaymentSuccess(skuId, result.basketId);
|
|
@@ -389,19 +779,7 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
|
|
|
389
779
|
});
|
|
390
780
|
} catch (err) {
|
|
391
781
|
if (err instanceof ContactValidationError) {
|
|
392
|
-
|
|
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
|
-
}
|
|
782
|
+
failApplePaySession(session, err.errors);
|
|
405
783
|
return;
|
|
406
784
|
}
|
|
407
785
|
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
|
-
|
|
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
|
|
@@ -87,10 +87,21 @@ export type PurchaseRequest = {
|
|
|
87
87
|
* only provide a `skuId`. Frontend uses `skuId` directly — BFF must be aligned.
|
|
88
88
|
*/
|
|
89
89
|
skuId: string;
|
|
90
|
+
/** Offer/geo country for basket pricing and delivery zone rules (not the wallet billing country). */
|
|
91
|
+
countryCode: string;
|
|
90
92
|
currency: string;
|
|
91
93
|
billingContact: ApplePayPaymentContact;
|
|
92
94
|
/** Required if loggedIn: false — contains emailAddress from Apple Pay sheet. */
|
|
93
95
|
shippingContact?: ApplePayPaymentContact;
|
|
96
|
+
/** Countries the offer may be billed to (print is unrestricted; digital is price-zone limited). */
|
|
97
|
+
supportedBillingCountries: string[];
|
|
98
|
+
/**
|
|
99
|
+
* Print (bundle) offers only: the countries the offer can be delivered to. The BFF requires the delivery
|
|
100
|
+
* country to be in this list, same pattern as `supportedBillingCountries`.
|
|
101
|
+
*/
|
|
102
|
+
supportedDeliveryCountries?: string[];
|
|
103
|
+
/** Always sent: the BFF then applies the sma-checkout billing rules (Latin, truncation, PR). */
|
|
104
|
+
strictAddressRules?: boolean;
|
|
94
105
|
recaptchaToken: string;
|
|
95
106
|
};
|
|
96
107
|
export type PurchaseResponse = {
|