首页 > 解决方案 > 完成付款后,PayPal SDK 导致“无法捕获订单”错误

问题描述

天哪,这个 PayPal 系统让我大吃一惊!我有以下代码:

<script src="https://www.paypal.com/sdk/js?client-id=MY_CODE_HERE&vault=true"></script>

然后这个脚本:

paypal.Buttons({

  createOrder: function(data, actions) {

    return actions.order.create({
        purchase_units: [{
            amount: {
                value:    parseFloat( window.my_config.amount ),
                currency: 'USD',
            },
            description: window.my_config.description,
            invoice_id: invoice_id
        }]
      });
  },

  onApprove: function(data, actions) {

    return actions.order.capture().then(function(details) {

        console.log({ details: details });

        // do something here

      });

    $('#AJAXloadingWrapper').show();
  },
   onError: function (err) {
        // Show an error page here, when an error occurs
        console.log("ERROR")
        console.dir(err);
    }


}).render('#paypalWrapper');

它进入这一点很好:

onApprove: function(data, actions) {

但是当它运行时:

return actions.order.capture().then(function(details) {

我收到一个错误,但它失败了:(不拿钱)

Error
​
code: undefined
​
columnNumber: 55441
​
fileName: "https://www.paypal.com/sdk/js?client-id=xxxx&vault=true"
​
lineNumber: 2
​
message: "Order could not be captured"

那有什么意思?这是我要传递的一个示例purchase_units

在此处输入图像描述

我差一点就叫它退出并说“我们正在删除贝宝”。

更新:在我的搜索中,我不断有人告诉我,问题可能来自 PayPal,我正在使用重复的 invoice_id。我知道事实并非如此,但也许我传递错了?

return actions.order.create({
    purchase_units: [{
        amount: {
            value:    parseFloat( window.my_config.amount ),
            currency: 'USD',
        },
        description: window.my_config.description,
        invoice_id: invoice_id
    }]
  });

},

标签: paypalpaypal-rest-sdk

解决方案


好的,所以我真的希望我的痛苦将来能帮助其他人。我自己花了几个小时研究这个问题,然后用 PayPal 支持技术研究了更多时间。最终的解决方案是清除我的浏览器缓存。有点极端,但它似乎已经排序了。我希望我之前就想到了!


推荐阅读