代码之家  ›  专栏  ›  技术社区  ›  vicatcu

PayPal Checkout JS错误处理

  •  0
  • vicatcu  · 技术社区  · 7 年前

    我正在阅读PayPal结帐文档的这一小部分: https://developer.paypal.com/docs/checkout/how-to/customize-flow/#manage-funding-source-failure .这里包括以下代码片段:

    paypal.Button.render({
      //Configure environment
      env: 'production', // To test, set to `sandbox`
      payment: function () {
        // Set up the payment here, when the buyer clicks on the button
      },
      onAuthorize: function (data, actions) {
        // Call your server to execute the payment
        if (error === 'INSTRUMENT_DECLINED') {
          actions.restart();
        }
      }
    }, '#paypal-button');
    

    有人知道这些文件是否正确吗?贝宝结账。js是否管理全局范围内的错误变量?如果没有,您如何正确实施本指南?

    注:交叉张贴 https://github.com/paypal/paypal-checkout/issues/790

    1 回复  |  直到 7 年前
        1
  •  0
  •   Paul Goldman    7 年前

    那份文件不正确。结账。js代码通过自动重新启动事务来为您处理一个/支付错误(INSTRUMENT_谢绝了),您可以通过调用“actions.restart()”自行完成。

    所有其他错误消息,包括HTTP错误,都会转到需要设置的错误消息处理程序。例如:

    paypal.Button.render({
    env: 'sandbox',
    payment: function () {
      // Set up the payment here, when the buyer clicks on the button
    },
    onAuthorize: function (data, actions) {
      // Execute the payment here, when the buyer approves the transaction
    },
    onError: function (err) {
      // Show an error page here, when an error occurs
    }
    }, '#paypal-button');
    

    请注意,如果您正在进行服务器集成,那么服务器将处理错误,而不是按钮。

    推荐文章