@economist/web-apple-pay 1.9.1 → 1.9.2

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 CHANGED
@@ -1382,6 +1382,20 @@ 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 MSG_BILLING_COUNTRY_MISMATCH_REDIRECT = "This country isn\u2019t supported for this purchase. Try updating your billing address.";
1387
+ var buildCountryMismatchMessage = (countryCode) => {
1388
+ if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
1389
+ try {
1390
+ const regionNames = new Intl.DisplayNames(["en"], { type: "region", fallback: "none" });
1391
+ const upper = countryCode.toUpperCase();
1392
+ const countryName = regionNames.of(upper);
1393
+ const isResolved = countryName && countryName !== upper && countryName !== "Unknown Region";
1394
+ return isResolved ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
1395
+ } catch {
1396
+ return BILLING_COUNTRY_MISMATCH_FALLBACK;
1397
+ }
1398
+ };
1385
1399
  var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
1386
1400
  var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
1387
1401
 
@@ -1662,7 +1676,19 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1662
1676
  });
1663
1677
  } catch (err) {
1664
1678
  if (err instanceof ContactValidationError) {
1665
- failApplePaySession(session, err.errors);
1679
+ const isBillingCountryMismatch = err.errors.some(
1680
+ (e) => e.contactField === "countryCode"
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: MSG_BILLING_COUNTRY_MISMATCH_REDIRECT });
1689
+ } else {
1690
+ failApplePaySession(session, err.errors);
1691
+ }
1666
1692
  return;
1667
1693
  }
1668
1694
  const walletError = parseWalletApiError(err);
@@ -1377,6 +1377,20 @@ 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 MSG_BILLING_COUNTRY_MISMATCH_REDIRECT = "This country isn\u2019t supported for this purchase. Try updating your billing address.";
1382
+ var buildCountryMismatchMessage = (countryCode) => {
1383
+ if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
1384
+ try {
1385
+ const regionNames = new Intl.DisplayNames(["en"], { type: "region", fallback: "none" });
1386
+ const upper = countryCode.toUpperCase();
1387
+ const countryName = regionNames.of(upper);
1388
+ const isResolved = countryName && countryName !== upper && countryName !== "Unknown Region";
1389
+ return isResolved ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
1390
+ } catch {
1391
+ return BILLING_COUNTRY_MISMATCH_FALLBACK;
1392
+ }
1393
+ };
1380
1394
  var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
1381
1395
  var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
1382
1396
 
@@ -1657,7 +1671,19 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1657
1671
  });
1658
1672
  } catch (err) {
1659
1673
  if (err instanceof ContactValidationError) {
1660
- failApplePaySession(session, err.errors);
1674
+ const isBillingCountryMismatch = err.errors.some(
1675
+ (e) => e.contactField === "countryCode"
1676
+ );
1677
+ if (isBillingCountryMismatch) {
1678
+ const countryCode = event.payment.billingContact?.countryCode;
1679
+ const userMessage = buildCountryMismatchMessage(countryCode);
1680
+ failApplePaySession(session, [
1681
+ new ApplePayError("billingContactInvalid", "countryCode", userMessage)
1682
+ ]);
1683
+ redirectFallback(skuId, returnUrl, country, { inlineError: MSG_BILLING_COUNTRY_MISMATCH_REDIRECT });
1684
+ } else {
1685
+ failApplePaySession(session, err.errors);
1686
+ }
1661
1687
  return;
1662
1688
  }
1663
1689
  const walletError = parseWalletApiError(err);
@@ -1385,6 +1385,20 @@ 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 MSG_BILLING_COUNTRY_MISMATCH_REDIRECT = "This country isn\u2019t supported for this purchase. Try updating your billing address.";
1390
+ var buildCountryMismatchMessage = (countryCode) => {
1391
+ if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
1392
+ try {
1393
+ const regionNames = new Intl.DisplayNames(["en"], { type: "region", fallback: "none" });
1394
+ const upper = countryCode.toUpperCase();
1395
+ const countryName = regionNames.of(upper);
1396
+ const isResolved = countryName && countryName !== upper && countryName !== "Unknown Region";
1397
+ return isResolved ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
1398
+ } catch {
1399
+ return BILLING_COUNTRY_MISMATCH_FALLBACK;
1400
+ }
1401
+ };
1388
1402
  var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
1389
1403
  var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
1390
1404
 
@@ -1665,7 +1679,19 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1665
1679
  });
1666
1680
  } catch (err) {
1667
1681
  if (err instanceof ContactValidationError) {
1668
- failApplePaySession(session, err.errors);
1682
+ const isBillingCountryMismatch = err.errors.some(
1683
+ (e) => e.contactField === "countryCode"
1684
+ );
1685
+ if (isBillingCountryMismatch) {
1686
+ const countryCode = event.payment.billingContact?.countryCode;
1687
+ const userMessage = buildCountryMismatchMessage(countryCode);
1688
+ failApplePaySession(session, [
1689
+ new ApplePayError("billingContactInvalid", "countryCode", userMessage)
1690
+ ]);
1691
+ redirectFallback(skuId, returnUrl, country, { inlineError: MSG_BILLING_COUNTRY_MISMATCH_REDIRECT });
1692
+ } else {
1693
+ failApplePaySession(session, err.errors);
1694
+ }
1669
1695
  return;
1670
1696
  }
1671
1697
  const walletError = parseWalletApiError(err);
@@ -1377,6 +1377,20 @@ 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 MSG_BILLING_COUNTRY_MISMATCH_REDIRECT = "This country isn\u2019t supported for this purchase. Try updating your billing address.";
1382
+ var buildCountryMismatchMessage = (countryCode) => {
1383
+ if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
1384
+ try {
1385
+ const regionNames = new Intl.DisplayNames(["en"], { type: "region", fallback: "none" });
1386
+ const upper = countryCode.toUpperCase();
1387
+ const countryName = regionNames.of(upper);
1388
+ const isResolved = countryName && countryName !== upper && countryName !== "Unknown Region";
1389
+ return isResolved ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
1390
+ } catch {
1391
+ return BILLING_COUNTRY_MISMATCH_FALLBACK;
1392
+ }
1393
+ };
1380
1394
  var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
1381
1395
  var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
1382
1396
 
@@ -1657,7 +1671,19 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1657
1671
  });
1658
1672
  } catch (err) {
1659
1673
  if (err instanceof ContactValidationError) {
1660
- failApplePaySession(session, err.errors);
1674
+ const isBillingCountryMismatch = err.errors.some(
1675
+ (e) => e.contactField === "countryCode"
1676
+ );
1677
+ if (isBillingCountryMismatch) {
1678
+ const countryCode = event.payment.billingContact?.countryCode;
1679
+ const userMessage = buildCountryMismatchMessage(countryCode);
1680
+ failApplePaySession(session, [
1681
+ new ApplePayError("billingContactInvalid", "countryCode", userMessage)
1682
+ ]);
1683
+ redirectFallback(skuId, returnUrl, country, { inlineError: MSG_BILLING_COUNTRY_MISMATCH_REDIRECT });
1684
+ } else {
1685
+ failApplePaySession(session, err.errors);
1686
+ }
1661
1687
  return;
1662
1688
  }
1663
1689
  const walletError = parseWalletApiError(err);
@@ -22,6 +22,25 @@ 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
+ * User-facing message shown as an inlineError on the checkout redirect page
32
+ * when the billing country does not match the offer price zone.
33
+ */
34
+ export declare const MSG_BILLING_COUNTRY_MISMATCH_REDIRECT = "This country isn\u2019t supported for this purchase. Try updating your billing address.";
35
+ /**
36
+ * Builds a short, user-facing message for a billing country mismatch, suitable
37
+ * for Apple's native payment sheet (~50 char limit).
38
+ *
39
+ * Returns `"[Country] address required"` (e.g. "Taiwan address required") when
40
+ * the country code resolves to a name, otherwise falls back to
41
+ * BILLING_COUNTRY_MISMATCH_FALLBACK.
42
+ */
43
+ export declare const buildCountryMismatchMessage: (countryCode: string | undefined) => string;
25
44
  /**
26
45
  * Generic fallback error shown to the user when merchant validation or the
27
46
  * purchase call fails. Redirected as an inlineError on the checkout fallback page.
@@ -3,13 +3,30 @@ 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 MSG_BILLING_COUNTRY_MISMATCH_REDIRECT = "This country isn\u2019t supported for this purchase. Try updating your billing address.";
8
+ var buildCountryMismatchMessage = (countryCode) => {
9
+ if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
10
+ try {
11
+ const regionNames = new Intl.DisplayNames(["en"], { type: "region", fallback: "none" });
12
+ const upper = countryCode.toUpperCase();
13
+ const countryName = regionNames.of(upper);
14
+ const isResolved = countryName && countryName !== upper && countryName !== "Unknown Region";
15
+ return isResolved ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
16
+ } catch {
17
+ return BILLING_COUNTRY_MISMATCH_FALLBACK;
18
+ }
19
+ };
6
20
  var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
7
21
  var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
8
22
  export {
23
+ BILLING_COUNTRY_MISMATCH_FALLBACK,
24
+ MSG_BILLING_COUNTRY_MISMATCH_REDIRECT,
9
25
  MSG_CONTACT_VALIDATION_INTERNAL,
10
26
  MSG_EMAIL_TOO_LONG,
11
27
  MSG_EMAIL_WRONG_FORMAT,
12
28
  MSG_MISSING_REQUIRED_FIELD,
13
29
  MSG_PAYMENT_GENERIC_ERROR,
14
- MSG_UNSUPPORTED_BILLING_COUNTRY
30
+ MSG_UNSUPPORTED_BILLING_COUNTRY,
31
+ buildCountryMismatchMessage
15
32
  };
@@ -117,6 +117,20 @@ 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 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
+ };
120
134
  var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
121
135
  var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
122
136
 
@@ -375,7 +389,19 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
375
389
  });
376
390
  } catch (err) {
377
391
  if (err instanceof ContactValidationError) {
378
- failApplePaySession(session, err.errors);
392
+ const isBillingCountryMismatch = err.errors.some(
393
+ (e) => e.contactField === "countryCode"
394
+ );
395
+ if (isBillingCountryMismatch) {
396
+ const countryCode = event.payment.billingContact?.countryCode;
397
+ const userMessage = buildCountryMismatchMessage(countryCode);
398
+ failApplePaySession(session, [
399
+ new ApplePayError("billingContactInvalid", "countryCode", userMessage)
400
+ ]);
401
+ redirectFallback(skuId, returnUrl, country, { inlineError: MSG_BILLING_COUNTRY_MISMATCH_REDIRECT });
402
+ } else {
403
+ failApplePaySession(session, err.errors);
404
+ }
379
405
  return;
380
406
  }
381
407
  const walletError = parseWalletApiError(err);
package/dist/src/index.js CHANGED
@@ -1382,6 +1382,20 @@ 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 MSG_BILLING_COUNTRY_MISMATCH_REDIRECT = "This country isn\u2019t supported for this purchase. Try updating your billing address.";
1387
+ var buildCountryMismatchMessage = (countryCode) => {
1388
+ if (!countryCode) return BILLING_COUNTRY_MISMATCH_FALLBACK;
1389
+ try {
1390
+ const regionNames = new Intl.DisplayNames(["en"], { type: "region", fallback: "none" });
1391
+ const upper = countryCode.toUpperCase();
1392
+ const countryName = regionNames.of(upper);
1393
+ const isResolved = countryName && countryName !== upper && countryName !== "Unknown Region";
1394
+ return isResolved ? `${countryName} address required` : BILLING_COUNTRY_MISMATCH_FALLBACK;
1395
+ } catch {
1396
+ return BILLING_COUNTRY_MISMATCH_FALLBACK;
1397
+ }
1398
+ };
1385
1399
  var MSG_PAYMENT_GENERIC_ERROR = "Something went wrong. Please check your payment and billing details and try again or contact us.";
1386
1400
  var MSG_CONTACT_VALIDATION_INTERNAL = "Could not validate Apple Pay contact";
1387
1401
 
@@ -1662,7 +1676,19 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1662
1676
  });
1663
1677
  } catch (err) {
1664
1678
  if (err instanceof ContactValidationError) {
1665
- failApplePaySession(session, err.errors);
1679
+ const isBillingCountryMismatch = err.errors.some(
1680
+ (e) => e.contactField === "countryCode"
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: MSG_BILLING_COUNTRY_MISMATCH_REDIRECT });
1689
+ } else {
1690
+ failApplePaySession(session, err.errors);
1691
+ }
1666
1692
  return;
1667
1693
  }
1668
1694
  const walletError = parseWalletApiError(err);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@economist/web-apple-pay",
3
3
  "description": "Web component package for Apple Pay checkout UI",
4
- "version": "1.9.1",
4
+ "version": "1.9.2",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",