1

I'd like to add custom error message to ApplePay when shipping address is invalid. We have following code (that shows generic error message)

applePay.session.completeShippingContactSelection(
    ApplePaySession.STATUS_FAILURE,
    [],
    { label: "error", amount: "1" },
    [],
  );

According to Apple's documentation, they introduced new error type on ApplePay version 3 (we use version 3). So I tried following code:

applePay.session.completeShippingContactSelection(
    {
      errors: [ { code: "shippingContactInvalid", contactField: "postalCode", message: "ZIP Code is invalid" }],
      newShippingMethods: [],
      newTotal: { label: "error", amount: "1", type: "pending" },
      newLineItems: [],
    }
  );

However I get an error at runtime - TypeError type error. Error is not displayed.

How can I display custom error message?

Kazuki
  • 1,462
  • 14
  • 34

1 Answers1

0

Tips:

  • type: pending hides total
  • label should be a company name, like "Something LCC"

You can try to use ApplePayError constructor:

const zipAppleError = new ApplePayError("shippingContactInvalid", "postalCode", "ZIP Code is invalid");

applePay.session.completeShippingContactSelection({
  newShippingMethods: [],
  newTotal: { label: "error", amount: "1", type: "pending" },
  newLineItems: [],
  errors: [zipAppleError],
});
Marek Ka.
  • 327
  • 3
  • 14