@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.
- package/README.md +26 -8
- package/dist/index.js +647 -349
- package/dist/src/apple-pay-button.d.ts +18 -16
- package/dist/src/apple-pay-button.js +636 -340
- package/dist/src/apple-pay-button.stories.js +633 -339
- package/dist/src/apple-pay-modal.js +44 -39
- package/dist/src/apple-pay-modal.stories.js +633 -339
- package/dist/src/clients/payment-checkout/apple-session.d.ts +14 -1
- package/dist/src/clients/payment-checkout/apple-session.js +46 -11
- 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 +395 -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 +397 -30
- package/dist/src/clients/payment-checkout/session.js +13 -1
- package/dist/src/clients/payment-checkout/types.d.ts +7 -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 +647 -349
- package/dist/src/types/offer.types.d.ts +1 -1
- package/dist/src/utils/address-rules.d.ts +23 -0
- package/dist/src/utils/address-rules.js +258 -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/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 +0 -15
- package/dist/src/utils/expressCheckoutTracking.js +0 -27
- package/dist/src/utils/latin-characters.d.ts +3 -0
- package/dist/src/utils/latin-characters.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
|
@@ -10,10 +10,23 @@ export type ApplePaySessionConfig = {
|
|
|
10
10
|
totalAmount: string;
|
|
11
11
|
totalLabel: string;
|
|
12
12
|
skuId: string;
|
|
13
|
-
|
|
13
|
+
/** `checkout-redirect` to persist, or `null` to leave the host's value untouched. */
|
|
14
|
+
returnUrl: string | null;
|
|
14
15
|
userLoggedIn: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Print (bundle) offers: the sheet also collects the delivery contact (postal address, name, phone) and
|
|
18
|
+
* rejects addresses outside these countries before the user can authorise.
|
|
19
|
+
*/
|
|
20
|
+
delivery?: {
|
|
21
|
+
supportedCountries: string[];
|
|
22
|
+
};
|
|
15
23
|
onPaymentAuthorized: (event: ApplePayJS.ApplePayPaymentAuthorizedEvent, session: ApplePaySession) => Promise<void>;
|
|
16
24
|
onCancel?: () => void;
|
|
17
25
|
};
|
|
18
26
|
export declare function redirectToFallbackCheckout(config: Pick<ApplePaySessionConfig, 'returnUrl' | 'skuId' | 'countryCode'>): void;
|
|
27
|
+
/**
|
|
28
|
+
* Contact fields the sheet must collect as the shipping contact. Email only for anonymous users; print offers
|
|
29
|
+
* additionally need the delivery address, recipient name and phone.
|
|
30
|
+
*/
|
|
31
|
+
export declare const requiredShippingFields: (config: Pick<ApplePaySessionConfig, "userLoggedIn" | "delivery">) => ApplePayJS.ApplePayContactField[];
|
|
19
32
|
export declare function startApplePaySession(config: ApplePaySessionConfig): void;
|
|
@@ -74,7 +74,7 @@ function isAllowedRedirectUrl(url) {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
var writeCheckoutRedirect = (originUrl) => {
|
|
77
|
-
if (!isAllowedRedirectUrl(originUrl)) return;
|
|
77
|
+
if (originUrl === null || !isAllowedRedirectUrl(originUrl)) return;
|
|
78
78
|
try {
|
|
79
79
|
localStorage.setItem(CHECKOUT_REDIRECT_KEY, originUrl);
|
|
80
80
|
} catch {
|
|
@@ -100,15 +100,21 @@ var redirectToCheckoutFallback = (params) => {
|
|
|
100
100
|
};
|
|
101
101
|
|
|
102
102
|
// src/utils/recaptcha.ts
|
|
103
|
+
var findScriptForKey = (siteKey) => Array.from(
|
|
104
|
+
document.querySelectorAll(
|
|
105
|
+
'script[src*="recaptcha/api.js"]'
|
|
106
|
+
)
|
|
107
|
+
).find((script) => script.src.includes(`render=${siteKey}`));
|
|
108
|
+
var pendingLoads = /* @__PURE__ */ new Map();
|
|
103
109
|
var loadRecaptchaScript = (siteKey) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
const pending = pendingLoads.get(siteKey);
|
|
111
|
+
if (pending) return pending;
|
|
112
|
+
const ownScript = findScriptForKey(siteKey);
|
|
113
|
+
if (ownScript && typeof grecaptcha !== "undefined") return Promise.resolve();
|
|
114
|
+
const load = new Promise((resolve, reject) => {
|
|
115
|
+
if (ownScript) {
|
|
116
|
+
ownScript.addEventListener("load", () => resolve());
|
|
117
|
+
ownScript.addEventListener("error", () => {
|
|
112
118
|
reject(new Error("Failed to load existing reCAPTCHA script"));
|
|
113
119
|
});
|
|
114
120
|
return;
|
|
@@ -123,6 +129,9 @@ var loadRecaptchaScript = (siteKey) => {
|
|
|
123
129
|
};
|
|
124
130
|
document.head.appendChild(script);
|
|
125
131
|
});
|
|
132
|
+
pendingLoads.set(siteKey, load);
|
|
133
|
+
load.catch(() => pendingLoads.delete(siteKey));
|
|
134
|
+
return load;
|
|
126
135
|
};
|
|
127
136
|
var getRecaptchaToken = async (action) => {
|
|
128
137
|
const siteKey = getApplePayConfig()?.recaptchaSiteKey;
|
|
@@ -181,6 +190,7 @@ var trackFallbackCheckout = (skuId) => {
|
|
|
181
190
|
};
|
|
182
191
|
|
|
183
192
|
// src/clients/payment-checkout/messages.ts
|
|
193
|
+
var MSG_UNSUPPORTED_DELIVERY_COUNTRY = "We can't deliver this print edition to that country. Try a different delivery address.";
|
|
184
194
|
var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
|
|
185
195
|
|
|
186
196
|
// src/clients/payment-checkout/apple-session.ts
|
|
@@ -217,7 +227,12 @@ async function handleMerchantValidation(event, session, config) {
|
|
|
217
227
|
redirectToFallbackCheckout(config);
|
|
218
228
|
}
|
|
219
229
|
}
|
|
230
|
+
var requiredShippingFields = (config) => [
|
|
231
|
+
...config.delivery ? ["postalAddress", "name", "phone"] : [],
|
|
232
|
+
...config.userLoggedIn ? [] : ["email"]
|
|
233
|
+
];
|
|
220
234
|
function startApplePaySession(config) {
|
|
235
|
+
const shippingFields = requiredShippingFields(config);
|
|
221
236
|
const paymentRequest = {
|
|
222
237
|
countryCode: config.countryCode,
|
|
223
238
|
currencyCode: config.currencyCode,
|
|
@@ -228,14 +243,33 @@ function startApplePaySession(config) {
|
|
|
228
243
|
amount: config.totalAmount
|
|
229
244
|
},
|
|
230
245
|
requiredBillingContactFields: ["postalAddress", "name"],
|
|
231
|
-
|
|
232
|
-
|
|
246
|
+
...shippingFields.length > 0 && {
|
|
247
|
+
requiredShippingContactFields: shippingFields
|
|
248
|
+
}
|
|
233
249
|
};
|
|
234
250
|
try {
|
|
235
251
|
const session = new ApplePaySession(3, paymentRequest);
|
|
236
252
|
session.onvalidatemerchant = async (event) => {
|
|
237
253
|
await handleMerchantValidation(event, session, config);
|
|
238
254
|
};
|
|
255
|
+
const delivery = config.delivery;
|
|
256
|
+
if (delivery) {
|
|
257
|
+
session.onshippingcontactselected = (event) => {
|
|
258
|
+
const country = event.shippingContact.countryCode?.toUpperCase();
|
|
259
|
+
session.completeShippingContactSelection({
|
|
260
|
+
newTotal: paymentRequest.total,
|
|
261
|
+
...country && !delivery.supportedCountries.includes(country) && {
|
|
262
|
+
errors: [
|
|
263
|
+
new ApplePayError(
|
|
264
|
+
"shippingContactInvalid",
|
|
265
|
+
"countryCode",
|
|
266
|
+
MSG_UNSUPPORTED_DELIVERY_COUNTRY
|
|
267
|
+
)
|
|
268
|
+
]
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
}
|
|
239
273
|
session.onpaymentauthorized = (event) => {
|
|
240
274
|
trackWalletPaymentAuthorised(config.skuId);
|
|
241
275
|
config.onPaymentAuthorized(event, session).catch(() => {
|
|
@@ -254,5 +288,6 @@ function startApplePaySession(config) {
|
|
|
254
288
|
}
|
|
255
289
|
export {
|
|
256
290
|
redirectToFallbackCheckout,
|
|
291
|
+
requiredShippingFields,
|
|
257
292
|
startApplePaySession
|
|
258
293
|
};
|
|
@@ -19,6 +19,7 @@ var trackValidationFieldError = (field, errorType) => {
|
|
|
19
19
|
|
|
20
20
|
// src/clients/payment-checkout/messages.ts
|
|
21
21
|
var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
|
|
22
|
+
var MSG_NON_LATIN_CHARACTERS = "Please use Latin characters only.";
|
|
22
23
|
var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
|
|
23
24
|
var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
|
|
24
25
|
|
|
@@ -45,6 +46,16 @@ var ContactValidationError = class extends Error {
|
|
|
45
46
|
}
|
|
46
47
|
};
|
|
47
48
|
|
|
49
|
+
// src/utils/latin-characters.ts
|
|
50
|
+
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";
|
|
51
|
+
var LATIN_CHARACTERS_REGEX = new RegExp(
|
|
52
|
+
`^[\\x20-\\x7E${SUPPORTED_DIACRITICS}]*$`
|
|
53
|
+
);
|
|
54
|
+
var isLatinCharacters = (value) => LATIN_CHARACTERS_REGEX.test(value);
|
|
55
|
+
|
|
56
|
+
// src/utils/addressParityFlag.ts
|
|
57
|
+
var ADDRESS_PARITY_ENABLED = true;
|
|
58
|
+
|
|
48
59
|
// src/clients/payment-checkout/billing-contact-details.ts
|
|
49
60
|
var countriesWithoutCityField = ["KY", "CK", "NR", "TC"];
|
|
50
61
|
var countriesRequiringAllFields = ["US", "CA", "GB"];
|
|
@@ -92,6 +103,35 @@ var validateCountrySupport = (errors, country, supportedBillingCountries) => {
|
|
|
92
103
|
);
|
|
93
104
|
}
|
|
94
105
|
};
|
|
106
|
+
var validateLatinCharacters = (errors, contact, firstName, lastName) => {
|
|
107
|
+
if (!isLatinCharacters(firstName) || !isLatinCharacters(lastName)) {
|
|
108
|
+
pushFieldError(
|
|
109
|
+
errors,
|
|
110
|
+
"billing",
|
|
111
|
+
"name",
|
|
112
|
+
"format",
|
|
113
|
+
MSG_NON_LATIN_CHARACTERS
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
const addressFields = [
|
|
117
|
+
["addressLines", contact.addressLines?.at(0)],
|
|
118
|
+
["addressLines", contact.addressLines?.at(1)],
|
|
119
|
+
["locality", contact.locality],
|
|
120
|
+
["administrativeArea", contact.administrativeArea],
|
|
121
|
+
["postalCode", contact.postalCode]
|
|
122
|
+
];
|
|
123
|
+
for (const [field, value] of addressFields) {
|
|
124
|
+
if (value && !isLatinCharacters(value)) {
|
|
125
|
+
pushFieldError(
|
|
126
|
+
errors,
|
|
127
|
+
"billing",
|
|
128
|
+
field,
|
|
129
|
+
"format",
|
|
130
|
+
MSG_NON_LATIN_CHARACTERS
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
95
135
|
var billingContactDetails = (contact, supportedBillingCountries) => {
|
|
96
136
|
const errors = [];
|
|
97
137
|
const country = contact.countryCode?.toUpperCase() || pushRequiredFieldError(errors, "billing", "country");
|
|
@@ -99,6 +139,9 @@ var billingContactDetails = (contact, supportedBillingCountries) => {
|
|
|
99
139
|
validateAddressFields(errors, contact, config);
|
|
100
140
|
const { firstName, lastName } = validateNameFields(errors, contact);
|
|
101
141
|
validateCountrySupport(errors, country, supportedBillingCountries);
|
|
142
|
+
if (ADDRESS_PARITY_ENABLED) {
|
|
143
|
+
validateLatinCharacters(errors, contact, firstName, lastName);
|
|
144
|
+
}
|
|
102
145
|
if (errors.length > 0) {
|
|
103
146
|
throw new ContactValidationError(errors);
|
|
104
147
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apple Pay delivery (shipping) contact local validator for print (bundle) offers.
|
|
3
|
+
*
|
|
4
|
+
* For express checkout the delivery address comes from the Apple Pay sheet, not from sma-checkout's address
|
|
5
|
+
* form, so the same rules are applied here: required fields by zone, Commerce Services length limits, US zip
|
|
6
|
+
* and Canadian postcode formats, a phone number for India and China, delivery country restricted to the
|
|
7
|
+
* offer's zone, and Latin characters only (SMA-3066). Validation errors keep the sheet open with field-level
|
|
8
|
+
* messages, like the billing validator.
|
|
9
|
+
*/
|
|
10
|
+
export type DeliveryContactOptions = {
|
|
11
|
+
/** Offer country (selects the price zone whose rules apply). */
|
|
12
|
+
offerCountry: string;
|
|
13
|
+
/** Countries the offer can be delivered to. */
|
|
14
|
+
supportedDeliveryCountries: string[];
|
|
15
|
+
};
|
|
16
|
+
export declare const deliveryContactDetails: (contact: ApplePayJS.ApplePayPaymentContact | undefined, { offerCountry, supportedDeliveryCountries }: DeliveryContactOptions) => void;
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
// src/utils/expressCheckoutTracking.ts
|
|
2
|
+
var emitTedlEvent = (event) => {
|
|
3
|
+
window.tedl = window.tedl ?? {};
|
|
4
|
+
window.tedl.events = window.tedl.events ?? [];
|
|
5
|
+
window.tedl.events.push(event);
|
|
6
|
+
};
|
|
7
|
+
var track = (action, extra) => {
|
|
8
|
+
emitTedlEvent({
|
|
9
|
+
name: "user.journey",
|
|
10
|
+
type: "checkout",
|
|
11
|
+
action,
|
|
12
|
+
info: "applepay",
|
|
13
|
+
...extra
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var trackValidationFieldError = (field, errorType) => {
|
|
17
|
+
track(`validation_${field}_${errorType}`, {});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/clients/payment-checkout/messages.ts
|
|
21
|
+
var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
|
|
22
|
+
var MSG_NON_LATIN_CHARACTERS = "Please use Latin characters only.";
|
|
23
|
+
var msgFieldTooLong = (label, max) => `${label} must be ${max} characters or less`;
|
|
24
|
+
var MSG_UNSUPPORTED_DELIVERY_COUNTRY = "We can't deliver this print edition to that country. Try a different delivery address.";
|
|
25
|
+
var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
|
|
26
|
+
|
|
27
|
+
// src/clients/payment-checkout/contact-validation.ts
|
|
28
|
+
var pushFieldError = (errors, billingOrShippingContact = "billing", field, errorType, errorText) => {
|
|
29
|
+
const errorCode = billingOrShippingContact === "billing" ? "billingContactInvalid" : "shippingContactInvalid";
|
|
30
|
+
errors.push(new ApplePayError(errorCode, field, errorText));
|
|
31
|
+
trackValidationFieldError(field, errorType);
|
|
32
|
+
return "";
|
|
33
|
+
};
|
|
34
|
+
var pushRequiredFieldError = (errors, billingOrShippingContact = "billing", field) => {
|
|
35
|
+
return pushFieldError(
|
|
36
|
+
errors,
|
|
37
|
+
billingOrShippingContact,
|
|
38
|
+
field,
|
|
39
|
+
"required",
|
|
40
|
+
MSG_MISSING_REQUIRED_FIELD
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
var ContactValidationError = class extends Error {
|
|
44
|
+
constructor(errors) {
|
|
45
|
+
super(MSG_CONTACT_VALIDATION_INTERNAL);
|
|
46
|
+
this.errors = errors;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/data/price-zones.json
|
|
51
|
+
var price_zones_default = {
|
|
52
|
+
"AS-AS": [
|
|
53
|
+
"BD",
|
|
54
|
+
"BT",
|
|
55
|
+
"CK",
|
|
56
|
+
"FJ",
|
|
57
|
+
"ID",
|
|
58
|
+
"KH",
|
|
59
|
+
"KI",
|
|
60
|
+
"LA",
|
|
61
|
+
"LK",
|
|
62
|
+
"MH",
|
|
63
|
+
"MM",
|
|
64
|
+
"MN",
|
|
65
|
+
"MV",
|
|
66
|
+
"NC",
|
|
67
|
+
"NF",
|
|
68
|
+
"NP",
|
|
69
|
+
"NR",
|
|
70
|
+
"PF",
|
|
71
|
+
"PG",
|
|
72
|
+
"PK",
|
|
73
|
+
"PW",
|
|
74
|
+
"SB",
|
|
75
|
+
"TH",
|
|
76
|
+
"TL",
|
|
77
|
+
"TO",
|
|
78
|
+
"TV",
|
|
79
|
+
"VN",
|
|
80
|
+
"VU",
|
|
81
|
+
"WS"
|
|
82
|
+
],
|
|
83
|
+
"AS-AU": ["AU"],
|
|
84
|
+
"AS-CN": ["CN"],
|
|
85
|
+
"AS-HK": ["HK", "MO"],
|
|
86
|
+
"AS-IN": ["IN"],
|
|
87
|
+
"AS-JP": ["JP"],
|
|
88
|
+
"AS-KR": ["KR"],
|
|
89
|
+
"AS-MY": ["MY"],
|
|
90
|
+
"AS-NZ": ["NZ"],
|
|
91
|
+
"AS-PH": ["PH"],
|
|
92
|
+
"AS-SG": ["BN", "SG"],
|
|
93
|
+
"AS-TW": ["TW"],
|
|
94
|
+
"CE-AF": [
|
|
95
|
+
"DZ",
|
|
96
|
+
"AO",
|
|
97
|
+
"BJ",
|
|
98
|
+
"BW",
|
|
99
|
+
"BF",
|
|
100
|
+
"BI",
|
|
101
|
+
"CM",
|
|
102
|
+
"CV",
|
|
103
|
+
"CF",
|
|
104
|
+
"TD",
|
|
105
|
+
"CG",
|
|
106
|
+
"CD",
|
|
107
|
+
"CI",
|
|
108
|
+
"DJ",
|
|
109
|
+
"EG",
|
|
110
|
+
"GQ",
|
|
111
|
+
"ER",
|
|
112
|
+
"ET",
|
|
113
|
+
"GA",
|
|
114
|
+
"GM",
|
|
115
|
+
"GH",
|
|
116
|
+
"GN",
|
|
117
|
+
"GW",
|
|
118
|
+
"IL",
|
|
119
|
+
"JO",
|
|
120
|
+
"KE",
|
|
121
|
+
"LB",
|
|
122
|
+
"LS",
|
|
123
|
+
"LR",
|
|
124
|
+
"LY",
|
|
125
|
+
"MG",
|
|
126
|
+
"MW",
|
|
127
|
+
"ML",
|
|
128
|
+
"MR",
|
|
129
|
+
"MU",
|
|
130
|
+
"MA",
|
|
131
|
+
"MZ",
|
|
132
|
+
"NA",
|
|
133
|
+
"NE",
|
|
134
|
+
"NG",
|
|
135
|
+
"PS",
|
|
136
|
+
"RE",
|
|
137
|
+
"RW",
|
|
138
|
+
"ST",
|
|
139
|
+
"SN",
|
|
140
|
+
"SC",
|
|
141
|
+
"SL",
|
|
142
|
+
"ZA",
|
|
143
|
+
"SZ",
|
|
144
|
+
"TZ",
|
|
145
|
+
"TG",
|
|
146
|
+
"TN",
|
|
147
|
+
"UG",
|
|
148
|
+
"ZM",
|
|
149
|
+
"ZW"
|
|
150
|
+
],
|
|
151
|
+
"CE-CH": ["LI", "CH"],
|
|
152
|
+
"CE-DK": ["FO", "GL", "DK"],
|
|
153
|
+
"CE-EU": [
|
|
154
|
+
"AL",
|
|
155
|
+
"AD",
|
|
156
|
+
"AM",
|
|
157
|
+
"AT",
|
|
158
|
+
"AZ",
|
|
159
|
+
"BY",
|
|
160
|
+
"BE",
|
|
161
|
+
"BA",
|
|
162
|
+
"BG",
|
|
163
|
+
"HR",
|
|
164
|
+
"CY",
|
|
165
|
+
"CZ",
|
|
166
|
+
"EE",
|
|
167
|
+
"FI",
|
|
168
|
+
"FR",
|
|
169
|
+
"GE",
|
|
170
|
+
"DE",
|
|
171
|
+
"GI",
|
|
172
|
+
"GR",
|
|
173
|
+
"HU",
|
|
174
|
+
"IS",
|
|
175
|
+
"IE",
|
|
176
|
+
"IT",
|
|
177
|
+
"KZ",
|
|
178
|
+
"XK",
|
|
179
|
+
"KG",
|
|
180
|
+
"LV",
|
|
181
|
+
"LT",
|
|
182
|
+
"LU",
|
|
183
|
+
"MT",
|
|
184
|
+
"MD",
|
|
185
|
+
"MC",
|
|
186
|
+
"ME",
|
|
187
|
+
"NL",
|
|
188
|
+
"PL",
|
|
189
|
+
"PT",
|
|
190
|
+
"MK",
|
|
191
|
+
"RO",
|
|
192
|
+
"RS",
|
|
193
|
+
"SK",
|
|
194
|
+
"SI",
|
|
195
|
+
"ES",
|
|
196
|
+
"TJ",
|
|
197
|
+
"TR",
|
|
198
|
+
"TM",
|
|
199
|
+
"UA",
|
|
200
|
+
"UZ"
|
|
201
|
+
],
|
|
202
|
+
"CE-ME": ["AE", "BH", "KW", "OM", "QA", "SA"],
|
|
203
|
+
"CE-NO": ["NO"],
|
|
204
|
+
"CE-SE": ["SE"],
|
|
205
|
+
"LA-LA": [
|
|
206
|
+
"AI",
|
|
207
|
+
"AG",
|
|
208
|
+
"AR",
|
|
209
|
+
"AW",
|
|
210
|
+
"BS",
|
|
211
|
+
"BB",
|
|
212
|
+
"BZ",
|
|
213
|
+
"BM",
|
|
214
|
+
"BO",
|
|
215
|
+
"BR",
|
|
216
|
+
"KY",
|
|
217
|
+
"CL",
|
|
218
|
+
"CO",
|
|
219
|
+
"CR",
|
|
220
|
+
"DM",
|
|
221
|
+
"DO",
|
|
222
|
+
"EC",
|
|
223
|
+
"SV",
|
|
224
|
+
"FK",
|
|
225
|
+
"GF",
|
|
226
|
+
"GD",
|
|
227
|
+
"GT",
|
|
228
|
+
"GY",
|
|
229
|
+
"HT",
|
|
230
|
+
"HN",
|
|
231
|
+
"JM",
|
|
232
|
+
"MQ",
|
|
233
|
+
"MX",
|
|
234
|
+
"MS",
|
|
235
|
+
"NI",
|
|
236
|
+
"MP",
|
|
237
|
+
"PA",
|
|
238
|
+
"PY",
|
|
239
|
+
"PE",
|
|
240
|
+
"KN",
|
|
241
|
+
"LC",
|
|
242
|
+
"VC",
|
|
243
|
+
"SR",
|
|
244
|
+
"TT",
|
|
245
|
+
"TC",
|
|
246
|
+
"UY",
|
|
247
|
+
"VG",
|
|
248
|
+
"VI"
|
|
249
|
+
],
|
|
250
|
+
"NA-CA": ["CA"],
|
|
251
|
+
"NA-US": ["AS", "GU", "FM", "PR", "US"],
|
|
252
|
+
"UK-UK": ["GB"]
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// src/utils/address-rules.ts
|
|
256
|
+
var priceZones = price_zones_default;
|
|
257
|
+
var ADDRESS_LIMITS = {
|
|
258
|
+
address1: 35,
|
|
259
|
+
address2: 35,
|
|
260
|
+
city: 40,
|
|
261
|
+
state: 40,
|
|
262
|
+
postalCode: 20,
|
|
263
|
+
phone: 35
|
|
264
|
+
};
|
|
265
|
+
var zoneOf = (country) => Object.keys(priceZones).find((zone) => priceZones[zone].includes(country));
|
|
266
|
+
var COUNTRIES_REQUIRING_PHONE = ["IN", "CN"];
|
|
267
|
+
var requiredDeliveryFields = (offerCountry, country) => {
|
|
268
|
+
const zone = zoneOf(offerCountry);
|
|
269
|
+
const fields = ["address1", "city"];
|
|
270
|
+
if (zone === "AS-AU" || zone === "AS-JP" || zone === "NA-CA" || country === "US") {
|
|
271
|
+
fields.push("state");
|
|
272
|
+
}
|
|
273
|
+
if ((zone !== "AS-HK" || country === "MO") && zone !== "CE-AF" && zone !== "CE-ME") {
|
|
274
|
+
fields.push("postalCode");
|
|
275
|
+
}
|
|
276
|
+
if (COUNTRIES_REQUIRING_PHONE.includes(country)) fields.push("phone");
|
|
277
|
+
return fields;
|
|
278
|
+
};
|
|
279
|
+
var postalCodeFormatError = (offerCountry, postalCode) => {
|
|
280
|
+
if (!postalCode) return null;
|
|
281
|
+
const zone = zoneOf(offerCountry);
|
|
282
|
+
if (zone === "NA-US" && !/(^\d{5}$)|(^\d{5}-\d{4}$)/.test(postalCode)) {
|
|
283
|
+
return "Zip code must be a valid US zip code";
|
|
284
|
+
}
|
|
285
|
+
if (zone === "NA-CA" && !/^[A-Za-z]\d[A-Za-z][ -]?\d[A-Za-z]\d$/.test(postalCode)) {
|
|
286
|
+
return "Postal code must be a valid Canadian postal code";
|
|
287
|
+
}
|
|
288
|
+
return null;
|
|
289
|
+
};
|
|
290
|
+
var COUNTRY_CALLING_CODES = {
|
|
291
|
+
IN: "91",
|
|
292
|
+
CN: "86"
|
|
293
|
+
};
|
|
294
|
+
var normaliseDeliveryPhone = (raw, country) => {
|
|
295
|
+
const trimmed = raw?.trim() ?? "";
|
|
296
|
+
const digits = trimmed.replace(/[^0-9]+/g, "");
|
|
297
|
+
if (!digits) return void 0;
|
|
298
|
+
if (trimmed.startsWith("+")) return `+${digits}`;
|
|
299
|
+
const callingCode = COUNTRY_CALLING_CODES[country];
|
|
300
|
+
return callingCode ? `+${callingCode}${digits.replace(/^0+/, "")}` : void 0;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
// src/utils/latin-characters.ts
|
|
304
|
+
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";
|
|
305
|
+
var LATIN_CHARACTERS_REGEX = new RegExp(
|
|
306
|
+
`^[\\x20-\\x7E${SUPPORTED_DIACRITICS}]*$`
|
|
307
|
+
);
|
|
308
|
+
var isLatinCharacters = (value) => LATIN_CHARACTERS_REGEX.test(value);
|
|
309
|
+
|
|
310
|
+
// src/clients/payment-checkout/delivery-contact-details.ts
|
|
311
|
+
var APPLE_FIELD = {
|
|
312
|
+
address1: "addressLines",
|
|
313
|
+
city: "locality",
|
|
314
|
+
state: "administrativeArea",
|
|
315
|
+
postalCode: "postalCode",
|
|
316
|
+
phone: "phoneNumber"
|
|
317
|
+
};
|
|
318
|
+
var LABEL = {
|
|
319
|
+
address1: "Address line 1",
|
|
320
|
+
address2: "Address line 2",
|
|
321
|
+
city: "City",
|
|
322
|
+
state: "State",
|
|
323
|
+
postalCode: "Postcode",
|
|
324
|
+
phone: "Phone number"
|
|
325
|
+
};
|
|
326
|
+
var deliveryContactDetails = (contact, { offerCountry, supportedDeliveryCountries }) => {
|
|
327
|
+
const errors = [];
|
|
328
|
+
const fail = (field, type, message) => pushFieldError(errors, "shipping", field, type, message);
|
|
329
|
+
const country = contact?.countryCode?.trim().toUpperCase() ?? "";
|
|
330
|
+
const firstName = contact?.givenName?.trim() ?? "";
|
|
331
|
+
const lastName = contact?.familyName?.trim() ?? "";
|
|
332
|
+
const address1 = contact?.addressLines?.at(0)?.trim() ?? "";
|
|
333
|
+
const address2 = contact?.addressLines?.at(1)?.trim() ?? "";
|
|
334
|
+
const city = contact?.locality?.trim() ?? "";
|
|
335
|
+
const state = contact?.administrativeArea?.trim() ?? "";
|
|
336
|
+
const postalCode = contact?.postalCode?.trim() ?? "";
|
|
337
|
+
const phone = normaliseDeliveryPhone(contact?.phoneNumber, country) ?? "";
|
|
338
|
+
if (!country) {
|
|
339
|
+
pushRequiredFieldError(errors, "shipping", "country");
|
|
340
|
+
} else if (!supportedDeliveryCountries.includes(country)) {
|
|
341
|
+
fail("countryCode", "not-supported", MSG_UNSUPPORTED_DELIVERY_COUNTRY);
|
|
342
|
+
}
|
|
343
|
+
if (!firstName || !lastName) {
|
|
344
|
+
pushRequiredFieldError(errors, "shipping", "name");
|
|
345
|
+
}
|
|
346
|
+
const values = {
|
|
347
|
+
address1,
|
|
348
|
+
city,
|
|
349
|
+
state,
|
|
350
|
+
postalCode,
|
|
351
|
+
phone
|
|
352
|
+
};
|
|
353
|
+
for (const field of requiredDeliveryFields(offerCountry, country)) {
|
|
354
|
+
if (!values[field]) {
|
|
355
|
+
pushRequiredFieldError(errors, "shipping", APPLE_FIELD[field]);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
const limited = [
|
|
359
|
+
["address1", "addressLines", address1, ADDRESS_LIMITS.address1],
|
|
360
|
+
["address2", "addressLines", address2, ADDRESS_LIMITS.address2],
|
|
361
|
+
["city", "locality", city, ADDRESS_LIMITS.city],
|
|
362
|
+
["state", "administrativeArea", state, ADDRESS_LIMITS.state],
|
|
363
|
+
["postalCode", "postalCode", postalCode, ADDRESS_LIMITS.postalCode],
|
|
364
|
+
["phone", "phoneNumber", phone, ADDRESS_LIMITS.phone]
|
|
365
|
+
];
|
|
366
|
+
for (const [field, appleField, value, max] of limited) {
|
|
367
|
+
if (value.length > max) {
|
|
368
|
+
fail(appleField, "format", msgFieldTooLong(LABEL[field], max));
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
const formatError = postalCodeFormatError(offerCountry, postalCode);
|
|
372
|
+
if (formatError) {
|
|
373
|
+
fail("postalCode", "format", formatError);
|
|
374
|
+
}
|
|
375
|
+
const latin = [
|
|
376
|
+
["name", firstName],
|
|
377
|
+
["name", lastName],
|
|
378
|
+
["addressLines", address1],
|
|
379
|
+
["addressLines", address2],
|
|
380
|
+
["locality", city],
|
|
381
|
+
["administrativeArea", state],
|
|
382
|
+
["postalCode", postalCode]
|
|
383
|
+
];
|
|
384
|
+
for (const [field, value] of latin) {
|
|
385
|
+
if (!isLatinCharacters(value)) {
|
|
386
|
+
fail(field, "format", MSG_NON_LATIN_CHARACTERS);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (errors.length > 0) {
|
|
390
|
+
throw new ContactValidationError(errors);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
export {
|
|
394
|
+
deliveryContactDetails
|
|
395
|
+
};
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
export declare const isAppleDeviceOrSafari: () => boolean;
|
|
2
2
|
export declare const bypassApplePayChecks: () => boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Cheap synchronous part of the availability check: device, `ApplePaySession`, `canMakePayments()` and a
|
|
5
|
+
* configured merchant. `false` means Apple Pay can never work here, so no network call is worth making.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isApplePayCapable: () => boolean;
|
|
3
8
|
export declare const isApplePayAvailable: () => Promise<boolean>;
|
|
@@ -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
|
};
|