@economist/web-apple-pay 0.1.3-beta.49 → 0.1.3-beta.50
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/dist/index.js +25 -3
- package/dist/src/apple-pay-button.js +25 -3
- package/dist/src/apple-pay-button.stories.js +25 -3
- package/dist/src/apple-pay-modal.stories.js +25 -3
- package/dist/src/clients/payment-checkout/messages.d.ts +14 -0
- package/dist/src/clients/payment-checkout/messages.js +14 -1
- package/dist/src/clients/payment-checkout/payment-handler.js +24 -1
- package/dist/src/index.js +25 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1382,6 +1382,17 @@ var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
|
|
|
1382
1382
|
var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a valid email address.";
|
|
1383
1383
|
var MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
|
|
1384
1384
|
var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
|
|
1385
|
+
var BILLING_COUNTRY_MISMATCH_FALLBACK = "Country not supported for this purchase";
|
|
1386
|
+
var buildCountryMismatchMessage = (countryCode) => {
|
|
1387
|
+
if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
1388
|
+
try {
|
|
1389
|
+
const regionNames = new Intl.DisplayNames(["en"], { type: "region" });
|
|
1390
|
+
const countryName = regionNames.of(countryCode.toUpperCase());
|
|
1391
|
+
return countryName ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
1392
|
+
} catch {
|
|
1393
|
+
return BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1385
1396
|
var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
|
|
1386
1397
|
var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
|
|
1387
1398
|
|
|
@@ -1662,7 +1673,19 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
|
|
|
1662
1673
|
});
|
|
1663
1674
|
} catch (err) {
|
|
1664
1675
|
if (err instanceof ContactValidationError) {
|
|
1665
|
-
|
|
1676
|
+
const isBillingCountryMismatch = err.errors.some(
|
|
1677
|
+
(e) => e.message === MSG_UNSUPPORTED_BILLING_COUNTRY
|
|
1678
|
+
);
|
|
1679
|
+
if (isBillingCountryMismatch) {
|
|
1680
|
+
const countryCode = event.payment.billingContact?.countryCode;
|
|
1681
|
+
const userMessage = buildCountryMismatchMessage(countryCode);
|
|
1682
|
+
failApplePaySession(session, [
|
|
1683
|
+
new ApplePayError("billingContactInvalid", "countryCode", userMessage)
|
|
1684
|
+
]);
|
|
1685
|
+
redirectFallback(skuId, returnUrl, country, { inlineError: userMessage });
|
|
1686
|
+
} else {
|
|
1687
|
+
failApplePaySession(session, err.errors);
|
|
1688
|
+
}
|
|
1666
1689
|
return;
|
|
1667
1690
|
}
|
|
1668
1691
|
const walletError = parseWalletApiError(err);
|
|
@@ -1952,7 +1975,6 @@ var APPLE_PAY_EXPRESS_VARIANTS = {
|
|
|
1952
1975
|
|
|
1953
1976
|
// src/apple-pay-button.ts
|
|
1954
1977
|
var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
|
|
1955
|
-
var APPLE_PAY_EXPRESS_GATING_DISABLED = true;
|
|
1956
1978
|
var TOTAL_LABEL = "The Economist";
|
|
1957
1979
|
var DEFAULT_CURRENCY = "USD";
|
|
1958
1980
|
var DEFAULT_TOTAL = "0.00";
|
|
@@ -2000,7 +2022,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
2000
2022
|
const hasUrlParamFlag = new URLSearchParams(window.location.search).has(
|
|
2001
2023
|
FEATURE_APPLE_PAY_EXPRESS_CHECKOUT
|
|
2002
2024
|
);
|
|
2003
|
-
if (!
|
|
2025
|
+
if (!isTreatment && !hasUrlParamFlag) {
|
|
2004
2026
|
return null;
|
|
2005
2027
|
}
|
|
2006
2028
|
_ApplePayButton.define();
|
|
@@ -1377,6 +1377,17 @@ var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
|
|
|
1377
1377
|
var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a valid email address.";
|
|
1378
1378
|
var MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
|
|
1379
1379
|
var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
|
|
1380
|
+
var BILLING_COUNTRY_MISMATCH_FALLBACK = "Country not supported for this purchase";
|
|
1381
|
+
var buildCountryMismatchMessage = (countryCode) => {
|
|
1382
|
+
if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
1383
|
+
try {
|
|
1384
|
+
const regionNames = new Intl.DisplayNames(["en"], { type: "region" });
|
|
1385
|
+
const countryName = regionNames.of(countryCode.toUpperCase());
|
|
1386
|
+
return countryName ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
1387
|
+
} catch {
|
|
1388
|
+
return BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
1389
|
+
}
|
|
1390
|
+
};
|
|
1380
1391
|
var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
|
|
1381
1392
|
var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
|
|
1382
1393
|
|
|
@@ -1657,7 +1668,19 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
|
|
|
1657
1668
|
});
|
|
1658
1669
|
} catch (err) {
|
|
1659
1670
|
if (err instanceof ContactValidationError) {
|
|
1660
|
-
|
|
1671
|
+
const isBillingCountryMismatch = err.errors.some(
|
|
1672
|
+
(e) => e.message === MSG_UNSUPPORTED_BILLING_COUNTRY
|
|
1673
|
+
);
|
|
1674
|
+
if (isBillingCountryMismatch) {
|
|
1675
|
+
const countryCode = event.payment.billingContact?.countryCode;
|
|
1676
|
+
const userMessage = buildCountryMismatchMessage(countryCode);
|
|
1677
|
+
failApplePaySession(session, [
|
|
1678
|
+
new ApplePayError("billingContactInvalid", "countryCode", userMessage)
|
|
1679
|
+
]);
|
|
1680
|
+
redirectFallback(skuId, returnUrl, country, { inlineError: userMessage });
|
|
1681
|
+
} else {
|
|
1682
|
+
failApplePaySession(session, err.errors);
|
|
1683
|
+
}
|
|
1661
1684
|
return;
|
|
1662
1685
|
}
|
|
1663
1686
|
const walletError = parseWalletApiError(err);
|
|
@@ -1941,7 +1964,6 @@ var APPLE_PAY_EXPRESS_VARIANTS = {
|
|
|
1941
1964
|
|
|
1942
1965
|
// src/apple-pay-button.ts
|
|
1943
1966
|
var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
|
|
1944
|
-
var APPLE_PAY_EXPRESS_GATING_DISABLED = true;
|
|
1945
1967
|
var TOTAL_LABEL = "The Economist";
|
|
1946
1968
|
var DEFAULT_CURRENCY = "USD";
|
|
1947
1969
|
var DEFAULT_TOTAL = "0.00";
|
|
@@ -1989,7 +2011,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1989
2011
|
const hasUrlParamFlag = new URLSearchParams(window.location.search).has(
|
|
1990
2012
|
FEATURE_APPLE_PAY_EXPRESS_CHECKOUT
|
|
1991
2013
|
);
|
|
1992
|
-
if (!
|
|
2014
|
+
if (!isTreatment && !hasUrlParamFlag) {
|
|
1993
2015
|
return null;
|
|
1994
2016
|
}
|
|
1995
2017
|
_ApplePayButton.define();
|
|
@@ -1385,6 +1385,17 @@ var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
|
|
|
1385
1385
|
var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a valid email address.";
|
|
1386
1386
|
var MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
|
|
1387
1387
|
var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
|
|
1388
|
+
var BILLING_COUNTRY_MISMATCH_FALLBACK = "Country not supported for this purchase";
|
|
1389
|
+
var buildCountryMismatchMessage = (countryCode) => {
|
|
1390
|
+
if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
1391
|
+
try {
|
|
1392
|
+
const regionNames = new Intl.DisplayNames(["en"], { type: "region" });
|
|
1393
|
+
const countryName = regionNames.of(countryCode.toUpperCase());
|
|
1394
|
+
return countryName ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
1395
|
+
} catch {
|
|
1396
|
+
return BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
1397
|
+
}
|
|
1398
|
+
};
|
|
1388
1399
|
var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
|
|
1389
1400
|
var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
|
|
1390
1401
|
|
|
@@ -1665,7 +1676,19 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
|
|
|
1665
1676
|
});
|
|
1666
1677
|
} catch (err) {
|
|
1667
1678
|
if (err instanceof ContactValidationError) {
|
|
1668
|
-
|
|
1679
|
+
const isBillingCountryMismatch = err.errors.some(
|
|
1680
|
+
(e) => e.message === MSG_UNSUPPORTED_BILLING_COUNTRY
|
|
1681
|
+
);
|
|
1682
|
+
if (isBillingCountryMismatch) {
|
|
1683
|
+
const countryCode = event.payment.billingContact?.countryCode;
|
|
1684
|
+
const userMessage = buildCountryMismatchMessage(countryCode);
|
|
1685
|
+
failApplePaySession(session, [
|
|
1686
|
+
new ApplePayError("billingContactInvalid", "countryCode", userMessage)
|
|
1687
|
+
]);
|
|
1688
|
+
redirectFallback(skuId, returnUrl, country, { inlineError: userMessage });
|
|
1689
|
+
} else {
|
|
1690
|
+
failApplePaySession(session, err.errors);
|
|
1691
|
+
}
|
|
1669
1692
|
return;
|
|
1670
1693
|
}
|
|
1671
1694
|
const walletError = parseWalletApiError(err);
|
|
@@ -1949,7 +1972,6 @@ var APPLE_PAY_EXPRESS_VARIANTS = {
|
|
|
1949
1972
|
|
|
1950
1973
|
// src/apple-pay-button.ts
|
|
1951
1974
|
var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
|
|
1952
|
-
var APPLE_PAY_EXPRESS_GATING_DISABLED = true;
|
|
1953
1975
|
var TOTAL_LABEL = "The Economist";
|
|
1954
1976
|
var DEFAULT_CURRENCY = "USD";
|
|
1955
1977
|
var DEFAULT_TOTAL = "0.00";
|
|
@@ -1997,7 +2019,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1997
2019
|
const hasUrlParamFlag = new URLSearchParams(window.location.search).has(
|
|
1998
2020
|
FEATURE_APPLE_PAY_EXPRESS_CHECKOUT
|
|
1999
2021
|
);
|
|
2000
|
-
if (!
|
|
2022
|
+
if (!isTreatment && !hasUrlParamFlag) {
|
|
2001
2023
|
return null;
|
|
2002
2024
|
}
|
|
2003
2025
|
_ApplePayButton.define();
|
|
@@ -1377,6 +1377,17 @@ var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
|
|
|
1377
1377
|
var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a valid email address.";
|
|
1378
1378
|
var MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
|
|
1379
1379
|
var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
|
|
1380
|
+
var BILLING_COUNTRY_MISMATCH_FALLBACK = "Country not supported for this purchase";
|
|
1381
|
+
var buildCountryMismatchMessage = (countryCode) => {
|
|
1382
|
+
if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
1383
|
+
try {
|
|
1384
|
+
const regionNames = new Intl.DisplayNames(["en"], { type: "region" });
|
|
1385
|
+
const countryName = regionNames.of(countryCode.toUpperCase());
|
|
1386
|
+
return countryName ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
1387
|
+
} catch {
|
|
1388
|
+
return BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
1389
|
+
}
|
|
1390
|
+
};
|
|
1380
1391
|
var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
|
|
1381
1392
|
var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
|
|
1382
1393
|
|
|
@@ -1657,7 +1668,19 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
|
|
|
1657
1668
|
});
|
|
1658
1669
|
} catch (err) {
|
|
1659
1670
|
if (err instanceof ContactValidationError) {
|
|
1660
|
-
|
|
1671
|
+
const isBillingCountryMismatch = err.errors.some(
|
|
1672
|
+
(e) => e.message === MSG_UNSUPPORTED_BILLING_COUNTRY
|
|
1673
|
+
);
|
|
1674
|
+
if (isBillingCountryMismatch) {
|
|
1675
|
+
const countryCode = event.payment.billingContact?.countryCode;
|
|
1676
|
+
const userMessage = buildCountryMismatchMessage(countryCode);
|
|
1677
|
+
failApplePaySession(session, [
|
|
1678
|
+
new ApplePayError("billingContactInvalid", "countryCode", userMessage)
|
|
1679
|
+
]);
|
|
1680
|
+
redirectFallback(skuId, returnUrl, country, { inlineError: userMessage });
|
|
1681
|
+
} else {
|
|
1682
|
+
failApplePaySession(session, err.errors);
|
|
1683
|
+
}
|
|
1661
1684
|
return;
|
|
1662
1685
|
}
|
|
1663
1686
|
const walletError = parseWalletApiError(err);
|
|
@@ -1941,7 +1964,6 @@ var APPLE_PAY_EXPRESS_VARIANTS = {
|
|
|
1941
1964
|
|
|
1942
1965
|
// src/apple-pay-button.ts
|
|
1943
1966
|
var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
|
|
1944
|
-
var APPLE_PAY_EXPRESS_GATING_DISABLED = true;
|
|
1945
1967
|
var TOTAL_LABEL = "The Economist";
|
|
1946
1968
|
var DEFAULT_CURRENCY = "USD";
|
|
1947
1969
|
var DEFAULT_TOTAL = "0.00";
|
|
@@ -1989,7 +2011,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1989
2011
|
const hasUrlParamFlag = new URLSearchParams(window.location.search).has(
|
|
1990
2012
|
FEATURE_APPLE_PAY_EXPRESS_CHECKOUT
|
|
1991
2013
|
);
|
|
1992
|
-
if (!
|
|
2014
|
+
if (!isTreatment && !hasUrlParamFlag) {
|
|
1993
2015
|
return null;
|
|
1994
2016
|
}
|
|
1995
2017
|
_ApplePayButton.define();
|
|
@@ -22,6 +22,20 @@ export declare const MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look righ
|
|
|
22
22
|
export declare const MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
|
|
23
23
|
/** Shown when the billing country is not in the supported list for the offer. */
|
|
24
24
|
export declare const MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
|
|
25
|
+
/**
|
|
26
|
+
* Fallback user-facing message for billing country mismatch when the country
|
|
27
|
+
* name cannot be resolved from the country code.
|
|
28
|
+
*/
|
|
29
|
+
export declare const BILLING_COUNTRY_MISMATCH_FALLBACK = "Country not supported for this purchase";
|
|
30
|
+
/**
|
|
31
|
+
* Builds a short, user-facing message for a billing country mismatch, suitable
|
|
32
|
+
* for Apple's native payment sheet (~50 char limit).
|
|
33
|
+
*
|
|
34
|
+
* Returns `"[Country] address required"` (e.g. "Taiwan address required") when
|
|
35
|
+
* the country code resolves to a name, otherwise falls back to
|
|
36
|
+
* BILLING_COUNTRY_MISMATCH_FALLBACK.
|
|
37
|
+
*/
|
|
38
|
+
export declare const buildCountryMismatchMessage: (countryCode: string | undefined) => string;
|
|
25
39
|
/**
|
|
26
40
|
* Generic fallback error shown to the user when merchant validation or the
|
|
27
41
|
* purchase call fails. Redirected as an inlineError on the checkout fallback page.
|
|
@@ -3,13 +3,26 @@ 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
5
|
var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
|
|
6
|
+
var BILLING_COUNTRY_MISMATCH_FALLBACK = "Country not supported for this purchase";
|
|
7
|
+
var buildCountryMismatchMessage = (countryCode) => {
|
|
8
|
+
if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
9
|
+
try {
|
|
10
|
+
const regionNames = new Intl.DisplayNames(["en"], { type: "region" });
|
|
11
|
+
const countryName = regionNames.of(countryCode.toUpperCase());
|
|
12
|
+
return countryName ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
13
|
+
} catch {
|
|
14
|
+
return BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
6
17
|
var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
|
|
7
18
|
var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
|
|
8
19
|
export {
|
|
20
|
+
BILLING_COUNTRY_MISMATCH_FALLBACK,
|
|
9
21
|
MSG_CONTACT_VALIDATION_INTERNAL,
|
|
10
22
|
MSG_EMAIL_TOO_LONG,
|
|
11
23
|
MSG_EMAIL_WRONG_FORMAT,
|
|
12
24
|
MSG_MISSING_REQUIRED_FIELD,
|
|
13
25
|
MSG_PAYMENT_GENERIC_ERROR,
|
|
14
|
-
MSG_UNSUPPORTED_BILLING_COUNTRY
|
|
26
|
+
MSG_UNSUPPORTED_BILLING_COUNTRY,
|
|
27
|
+
buildCountryMismatchMessage
|
|
15
28
|
};
|
|
@@ -117,6 +117,17 @@ var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
|
|
|
117
117
|
var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a valid email address.";
|
|
118
118
|
var MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
|
|
119
119
|
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 buildCountryMismatchMessage = (countryCode) => {
|
|
122
|
+
if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
123
|
+
try {
|
|
124
|
+
const regionNames = new Intl.DisplayNames(["en"], { type: "region" });
|
|
125
|
+
const countryName = regionNames.of(countryCode.toUpperCase());
|
|
126
|
+
return countryName ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
127
|
+
} catch {
|
|
128
|
+
return BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
120
131
|
var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
|
|
121
132
|
var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
|
|
122
133
|
|
|
@@ -375,7 +386,19 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
|
|
|
375
386
|
});
|
|
376
387
|
} catch (err) {
|
|
377
388
|
if (err instanceof ContactValidationError) {
|
|
378
|
-
|
|
389
|
+
const isBillingCountryMismatch = err.errors.some(
|
|
390
|
+
(e) => e.message === MSG_UNSUPPORTED_BILLING_COUNTRY
|
|
391
|
+
);
|
|
392
|
+
if (isBillingCountryMismatch) {
|
|
393
|
+
const countryCode = event.payment.billingContact?.countryCode;
|
|
394
|
+
const userMessage = buildCountryMismatchMessage(countryCode);
|
|
395
|
+
failApplePaySession(session, [
|
|
396
|
+
new ApplePayError("billingContactInvalid", "countryCode", userMessage)
|
|
397
|
+
]);
|
|
398
|
+
redirectFallback(skuId, returnUrl, country, { inlineError: userMessage });
|
|
399
|
+
} else {
|
|
400
|
+
failApplePaySession(session, err.errors);
|
|
401
|
+
}
|
|
379
402
|
return;
|
|
380
403
|
}
|
|
381
404
|
const walletError = parseWalletApiError(err);
|
package/dist/src/index.js
CHANGED
|
@@ -1382,6 +1382,17 @@ var MSG_MISSING_REQUIRED_FIELD = "Missing required field";
|
|
|
1382
1382
|
var MSG_EMAIL_WRONG_FORMAT = "That email doesn\u2019t look right. Please enter a valid email address.";
|
|
1383
1383
|
var MSG_EMAIL_TOO_LONG = "This field must be 80 characters or less.";
|
|
1384
1384
|
var MSG_UNSUPPORTED_BILLING_COUNTRY = "Billing country does not match offer price zone";
|
|
1385
|
+
var BILLING_COUNTRY_MISMATCH_FALLBACK = "Country not supported for this purchase";
|
|
1386
|
+
var buildCountryMismatchMessage = (countryCode) => {
|
|
1387
|
+
if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
1388
|
+
try {
|
|
1389
|
+
const regionNames = new Intl.DisplayNames(["en"], { type: "region" });
|
|
1390
|
+
const countryName = regionNames.of(countryCode.toUpperCase());
|
|
1391
|
+
return countryName ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
1392
|
+
} catch {
|
|
1393
|
+
return BILLING_COUNTRY_MISMATCH_FALLBACK;
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1385
1396
|
var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
|
|
1386
1397
|
var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
|
|
1387
1398
|
|
|
@@ -1662,7 +1673,19 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
|
|
|
1662
1673
|
});
|
|
1663
1674
|
} catch (err) {
|
|
1664
1675
|
if (err instanceof ContactValidationError) {
|
|
1665
|
-
|
|
1676
|
+
const isBillingCountryMismatch = err.errors.some(
|
|
1677
|
+
(e) => e.message === MSG_UNSUPPORTED_BILLING_COUNTRY
|
|
1678
|
+
);
|
|
1679
|
+
if (isBillingCountryMismatch) {
|
|
1680
|
+
const countryCode = event.payment.billingContact?.countryCode;
|
|
1681
|
+
const userMessage = buildCountryMismatchMessage(countryCode);
|
|
1682
|
+
failApplePaySession(session, [
|
|
1683
|
+
new ApplePayError("billingContactInvalid", "countryCode", userMessage)
|
|
1684
|
+
]);
|
|
1685
|
+
redirectFallback(skuId, returnUrl, country, { inlineError: userMessage });
|
|
1686
|
+
} else {
|
|
1687
|
+
failApplePaySession(session, err.errors);
|
|
1688
|
+
}
|
|
1666
1689
|
return;
|
|
1667
1690
|
}
|
|
1668
1691
|
const walletError = parseWalletApiError(err);
|
|
@@ -1952,7 +1975,6 @@ var APPLE_PAY_EXPRESS_VARIANTS = {
|
|
|
1952
1975
|
|
|
1953
1976
|
// src/apple-pay-button.ts
|
|
1954
1977
|
var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
|
|
1955
|
-
var APPLE_PAY_EXPRESS_GATING_DISABLED = true;
|
|
1956
1978
|
var TOTAL_LABEL = "The Economist";
|
|
1957
1979
|
var DEFAULT_CURRENCY = "USD";
|
|
1958
1980
|
var DEFAULT_TOTAL = "0.00";
|
|
@@ -2000,7 +2022,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
2000
2022
|
const hasUrlParamFlag = new URLSearchParams(window.location.search).has(
|
|
2001
2023
|
FEATURE_APPLE_PAY_EXPRESS_CHECKOUT
|
|
2002
2024
|
);
|
|
2003
|
-
if (!
|
|
2025
|
+
if (!isTreatment && !hasUrlParamFlag) {
|
|
2004
2026
|
return null;
|
|
2005
2027
|
}
|
|
2006
2028
|
_ApplePayButton.define();
|
package/package.json
CHANGED