PayPal Checkout JS错误处理

问题描述 投票:0回答:1

我正在阅读PayPal Checkout文档的这一小部分: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');

有谁知道这些文件是否正确? PayPal checkout.js是否管理全局范围内的错误变量?如果没有,您如何正确实施本指南?

注意:交叉发布https://github.com/paypal/paypal-checkout/issues/790

javascript paypal
1个回答
1
投票

该文档不正确。 checkout.js代码为您处理一个/付款错误 - INSTRUMENT_DECLINED - 通过自动重新启动事务,您可以通过调用“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');

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

© www.soinside.com 2019 - 2024. All rights reserved.