@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
|
@@ -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;
|
|
@@ -170,17 +179,28 @@ var track = (action, extra) => {
|
|
|
170
179
|
...extra
|
|
171
180
|
});
|
|
172
181
|
};
|
|
173
|
-
var
|
|
174
|
-
|
|
182
|
+
var withEntryPoint = ({ entryPoint } = {}) => entryPoint ? { entry_point: entryPoint } : {};
|
|
183
|
+
var trackWalletPaymentSheetOpen = (skuId, metadata) => {
|
|
184
|
+
track(EXPRESS_CHECKOUT_EVENTS.SHEET_OPEN, {
|
|
185
|
+
sku_id: skuId,
|
|
186
|
+
...withEntryPoint(metadata)
|
|
187
|
+
});
|
|
175
188
|
};
|
|
176
|
-
var trackWalletPaymentAuthorised = (skuId) => {
|
|
177
|
-
track(EXPRESS_CHECKOUT_EVENTS.AUTHORISED, {
|
|
189
|
+
var trackWalletPaymentAuthorised = (skuId, metadata) => {
|
|
190
|
+
track(EXPRESS_CHECKOUT_EVENTS.AUTHORISED, {
|
|
191
|
+
sku_id: skuId,
|
|
192
|
+
...withEntryPoint(metadata)
|
|
193
|
+
});
|
|
178
194
|
};
|
|
179
|
-
var trackFallbackCheckout = (skuId) => {
|
|
180
|
-
track(EXPRESS_CHECKOUT_EVENTS.FALLBACK_CHECKOUT, {
|
|
195
|
+
var trackFallbackCheckout = (skuId, metadata) => {
|
|
196
|
+
track(EXPRESS_CHECKOUT_EVENTS.FALLBACK_CHECKOUT, {
|
|
197
|
+
sku_id: skuId,
|
|
198
|
+
...withEntryPoint(metadata)
|
|
199
|
+
});
|
|
181
200
|
};
|
|
182
201
|
|
|
183
202
|
// src/clients/payment-checkout/messages.ts
|
|
203
|
+
var MSG_UNSUPPORTED_DELIVERY_COUNTRY = "We can't deliver this print edition to that country. Try a different delivery address.";
|
|
184
204
|
var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
|
|
185
205
|
|
|
186
206
|
// src/clients/payment-checkout/apple-session.ts
|
|
@@ -217,7 +237,12 @@ async function handleMerchantValidation(event, session, config) {
|
|
|
217
237
|
redirectToFallbackCheckout(config);
|
|
218
238
|
}
|
|
219
239
|
}
|
|
240
|
+
var requiredShippingFields = (config) => [
|
|
241
|
+
...config.delivery ? ["postalAddress", "name", "phone"] : [],
|
|
242
|
+
...config.userLoggedIn ? [] : ["email"]
|
|
243
|
+
];
|
|
220
244
|
function startApplePaySession(config) {
|
|
245
|
+
const shippingFields = requiredShippingFields(config);
|
|
221
246
|
const paymentRequest = {
|
|
222
247
|
countryCode: config.countryCode,
|
|
223
248
|
currencyCode: config.currencyCode,
|
|
@@ -228,14 +253,37 @@ function startApplePaySession(config) {
|
|
|
228
253
|
amount: config.totalAmount
|
|
229
254
|
},
|
|
230
255
|
requiredBillingContactFields: ["postalAddress", "name"],
|
|
231
|
-
|
|
232
|
-
|
|
256
|
+
...shippingFields.length > 0 && {
|
|
257
|
+
requiredShippingContactFields: shippingFields
|
|
258
|
+
},
|
|
259
|
+
// Restrict the shipping country picker for print; onshippingcontactselected still validates as a backstop.
|
|
260
|
+
...config.delivery && config.delivery.supportedCountries.length > 0 && {
|
|
261
|
+
supportedCountries: config.delivery.supportedCountries
|
|
262
|
+
}
|
|
233
263
|
};
|
|
234
264
|
try {
|
|
235
265
|
const session = new ApplePaySession(3, paymentRequest);
|
|
236
266
|
session.onvalidatemerchant = async (event) => {
|
|
237
267
|
await handleMerchantValidation(event, session, config);
|
|
238
268
|
};
|
|
269
|
+
const delivery = config.delivery;
|
|
270
|
+
if (delivery) {
|
|
271
|
+
session.onshippingcontactselected = (event) => {
|
|
272
|
+
const country = event.shippingContact.countryCode?.toUpperCase();
|
|
273
|
+
session.completeShippingContactSelection({
|
|
274
|
+
newTotal: paymentRequest.total,
|
|
275
|
+
...country && !delivery.supportedCountries.includes(country) && {
|
|
276
|
+
errors: [
|
|
277
|
+
new ApplePayError(
|
|
278
|
+
"shippingContactInvalid",
|
|
279
|
+
"countryCode",
|
|
280
|
+
MSG_UNSUPPORTED_DELIVERY_COUNTRY
|
|
281
|
+
)
|
|
282
|
+
]
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
}
|
|
239
287
|
session.onpaymentauthorized = (event) => {
|
|
240
288
|
trackWalletPaymentAuthorised(config.skuId);
|
|
241
289
|
config.onPaymentAuthorized(event, session).catch(() => {
|
|
@@ -254,5 +302,6 @@ function startApplePaySession(config) {
|
|
|
254
302
|
}
|
|
255
303
|
export {
|
|
256
304
|
redirectToFallbackCheckout,
|
|
305
|
+
requiredShippingFields,
|
|
257
306
|
startApplePaySession
|
|
258
307
|
};
|
|
@@ -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,397 @@
|
|
|
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/price-zones.ts
|
|
256
|
+
var priceZones = price_zones_default;
|
|
257
|
+
var getZoneByCountry = (country) => Object.keys(priceZones).find((key) => priceZones[key].includes(country)) ?? null;
|
|
258
|
+
|
|
259
|
+
// src/utils/address-rules.ts
|
|
260
|
+
var ADDRESS_LIMITS = {
|
|
261
|
+
address1: 35,
|
|
262
|
+
address2: 35,
|
|
263
|
+
city: 40,
|
|
264
|
+
state: 40,
|
|
265
|
+
postalCode: 20,
|
|
266
|
+
phone: 35
|
|
267
|
+
};
|
|
268
|
+
var COUNTRIES_REQUIRING_PHONE = ["IN", "CN"];
|
|
269
|
+
var requiredDeliveryFields = (offerCountry, country) => {
|
|
270
|
+
const zone = getZoneByCountry(offerCountry);
|
|
271
|
+
const fields = ["address1", "city"];
|
|
272
|
+
if (zone === "AS-AU" || zone === "AS-JP" || zone === "NA-CA" || country === "US") {
|
|
273
|
+
fields.push("state");
|
|
274
|
+
}
|
|
275
|
+
if ((zone !== "AS-HK" || country === "MO") && zone !== "CE-AF" && zone !== "CE-ME") {
|
|
276
|
+
fields.push("postalCode");
|
|
277
|
+
}
|
|
278
|
+
if (COUNTRIES_REQUIRING_PHONE.includes(country)) fields.push("phone");
|
|
279
|
+
return fields;
|
|
280
|
+
};
|
|
281
|
+
var postalCodeFormatError = (offerCountry, postalCode) => {
|
|
282
|
+
if (!postalCode) return null;
|
|
283
|
+
const zone = getZoneByCountry(offerCountry);
|
|
284
|
+
if (zone === "NA-US" && !/(^\d{5}$)|(^\d{5}-\d{4}$)/.test(postalCode)) {
|
|
285
|
+
return "Zip code must be a valid US zip code";
|
|
286
|
+
}
|
|
287
|
+
if (zone === "NA-CA" && !/^[A-Za-z]\d[A-Za-z][ -]?\d[A-Za-z]\d$/.test(postalCode)) {
|
|
288
|
+
return "Postal code must be a valid Canadian postal code";
|
|
289
|
+
}
|
|
290
|
+
return null;
|
|
291
|
+
};
|
|
292
|
+
var COUNTRY_CALLING_CODES = {
|
|
293
|
+
IN: "91",
|
|
294
|
+
CN: "86"
|
|
295
|
+
};
|
|
296
|
+
var normaliseDeliveryPhone = (raw, country) => {
|
|
297
|
+
const trimmed = raw?.trim() ?? "";
|
|
298
|
+
const digits = trimmed.replace(/[^0-9]+/g, "");
|
|
299
|
+
if (!digits) return void 0;
|
|
300
|
+
if (trimmed.startsWith("+")) return `+${digits}`;
|
|
301
|
+
const callingCode = COUNTRY_CALLING_CODES[country];
|
|
302
|
+
return callingCode ? `+${callingCode}${digits.replace(/^0+/, "")}` : void 0;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// src/utils/latin-characters.ts
|
|
306
|
+
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";
|
|
307
|
+
var LATIN_CHARACTERS_REGEX = new RegExp(
|
|
308
|
+
`^[\\x20-\\x7E${SUPPORTED_DIACRITICS}]*$`
|
|
309
|
+
);
|
|
310
|
+
var isLatinCharacters = (value) => LATIN_CHARACTERS_REGEX.test(value);
|
|
311
|
+
|
|
312
|
+
// src/clients/payment-checkout/delivery-contact-details.ts
|
|
313
|
+
var APPLE_FIELD = {
|
|
314
|
+
address1: "addressLines",
|
|
315
|
+
city: "locality",
|
|
316
|
+
state: "administrativeArea",
|
|
317
|
+
postalCode: "postalCode",
|
|
318
|
+
phone: "phoneNumber"
|
|
319
|
+
};
|
|
320
|
+
var LABEL = {
|
|
321
|
+
address1: "Address line 1",
|
|
322
|
+
address2: "Address line 2",
|
|
323
|
+
city: "City",
|
|
324
|
+
state: "State",
|
|
325
|
+
postalCode: "Postcode",
|
|
326
|
+
phone: "Phone number"
|
|
327
|
+
};
|
|
328
|
+
var deliveryContactDetails = (contact, { offerCountry, supportedDeliveryCountries }) => {
|
|
329
|
+
const errors = [];
|
|
330
|
+
const fail = (field, type, message) => pushFieldError(errors, "shipping", field, type, message);
|
|
331
|
+
const country = contact?.countryCode?.trim().toUpperCase() ?? "";
|
|
332
|
+
const firstName = contact?.givenName?.trim() ?? "";
|
|
333
|
+
const lastName = contact?.familyName?.trim() ?? "";
|
|
334
|
+
const address1 = contact?.addressLines?.at(0)?.trim() ?? "";
|
|
335
|
+
const address2 = contact?.addressLines?.at(1)?.trim() ?? "";
|
|
336
|
+
const city = contact?.locality?.trim() ?? "";
|
|
337
|
+
const state = contact?.administrativeArea?.trim() ?? "";
|
|
338
|
+
const postalCode = contact?.postalCode?.trim() ?? "";
|
|
339
|
+
const phone = normaliseDeliveryPhone(contact?.phoneNumber, country) ?? "";
|
|
340
|
+
if (!country) {
|
|
341
|
+
pushRequiredFieldError(errors, "shipping", "country");
|
|
342
|
+
} else if (!supportedDeliveryCountries.includes(country)) {
|
|
343
|
+
fail("countryCode", "not-supported", MSG_UNSUPPORTED_DELIVERY_COUNTRY);
|
|
344
|
+
}
|
|
345
|
+
if (!firstName || !lastName) {
|
|
346
|
+
pushRequiredFieldError(errors, "shipping", "name");
|
|
347
|
+
}
|
|
348
|
+
const values = {
|
|
349
|
+
address1,
|
|
350
|
+
city,
|
|
351
|
+
state,
|
|
352
|
+
postalCode,
|
|
353
|
+
phone
|
|
354
|
+
};
|
|
355
|
+
for (const field of requiredDeliveryFields(offerCountry, country)) {
|
|
356
|
+
if (!values[field]) {
|
|
357
|
+
pushRequiredFieldError(errors, "shipping", APPLE_FIELD[field]);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
const limited = [
|
|
361
|
+
["address1", "addressLines", address1, ADDRESS_LIMITS.address1],
|
|
362
|
+
["address2", "addressLines", address2, ADDRESS_LIMITS.address2],
|
|
363
|
+
["city", "locality", city, ADDRESS_LIMITS.city],
|
|
364
|
+
["state", "administrativeArea", state, ADDRESS_LIMITS.state],
|
|
365
|
+
["postalCode", "postalCode", postalCode, ADDRESS_LIMITS.postalCode],
|
|
366
|
+
["phone", "phoneNumber", phone, ADDRESS_LIMITS.phone]
|
|
367
|
+
];
|
|
368
|
+
for (const [field, appleField, value, max] of limited) {
|
|
369
|
+
if (value.length > max) {
|
|
370
|
+
fail(appleField, "format", msgFieldTooLong(LABEL[field], max));
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const formatError = postalCodeFormatError(offerCountry, postalCode);
|
|
374
|
+
if (formatError) {
|
|
375
|
+
fail("postalCode", "format", formatError);
|
|
376
|
+
}
|
|
377
|
+
const latin = [
|
|
378
|
+
["name", firstName],
|
|
379
|
+
["name", lastName],
|
|
380
|
+
["addressLines", address1],
|
|
381
|
+
["addressLines", address2],
|
|
382
|
+
["locality", city],
|
|
383
|
+
["administrativeArea", state],
|
|
384
|
+
["postalCode", postalCode]
|
|
385
|
+
];
|
|
386
|
+
for (const [field, value] of latin) {
|
|
387
|
+
if (!isLatinCharacters(value)) {
|
|
388
|
+
fail(field, "format", MSG_NON_LATIN_CHARACTERS);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (errors.length > 0) {
|
|
392
|
+
throw new ContactValidationError(errors);
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
export {
|
|
396
|
+
deliveryContactDetails
|
|
397
|
+
};
|
|
@@ -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>;
|