【问题标题】:ApplePay js - custom error message for completeShippingContactSelectionApplePay js - completeShippingContactSelection 的自定义错误消息
【发布时间】:2020-08-15 11:54:14
【问题描述】:

当送货地址无效时,我想向 ApplePay 添加自定义错误消息。我们有以下代码(显示一般错误消息)

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

根据Apple's documentation,他们在 ApplePay 版本 3(我们使用版本 3)上引入了新的错误类型。所以我尝试了以下代码:

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

但是我在运行时遇到错误 - TypeError type error。不显示错误。

如何显示自定义错误消息?

【问题讨论】:

    标签: applepay applepayjs


    【解决方案1】:

    提示:

    • type: pending 隐藏总数
    • label 应该是公司名称,例如“Something LCC”

    你可以尝试使用 ApplePayError 构造函数:

    const zipAppleError = new ApplePayError("shippingContactInvalid", "postalCode", "ZIP Code is invalid");
    
    applePay.session.completeShippingContactSelection({
      newShippingMethods: [],
      newTotal: { label: "error", amount: "1", type: "pending" },
      newLineItems: [],
      errors: [zipAppleError],
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-03
      • 1970-01-01
      • 2015-09-21
      • 2011-04-27
      • 2018-09-02
      • 2021-09-13
      • 2017-12-24
      • 1970-01-01
      相关资源
      最近更新 更多