PayPal 集成 400 Bad Request / Order couldn't be captured

PayPal integration 400 Bad Request / Order could not be captured

我正在尝试集成 PayPal,但出现以下错误

您可以在此处使用任何 PayPal 沙盒买家帐户测试代码: Codepen

这是我使用的代码

    paypal.Buttons({
  createOrder: function (data, actions) {
    // This function sets up the details of the transaction, including the amount and line item details.
    return actions.order.create({
      purchase_units: [{
        amount: {
          value: '5.00'
        }
      }]
    });
  },
  onApprove: function (data, actions) {
    // This function captures the funds from the transaction.
    return actions.order.capture().then(details => {
      // This function shows a transaction success message to your buyer.
      alert('Transaction completed by ' + details.payer.name.given_name);
    });
  }
}).render('#paypal-button-container');

关于错误的更多信息

从“网络”选项卡测试您的 Codepen,您得到一个 COMPLIANCE_VIOLATION -- 可能是由于您正在测试的帐户的国家/地区没有在沙盒中正确设置。

尝试使用不同的国家/地区在沙盒中进行测试。在 https://www.paypal.com/signin?intent=developer&returnUri=https%3A%2F%2Fdeveloper.paypal.com%2Fdeveloper%2Faccounts%2F 创建一个新的企业帐户,然后使用新的 ClientID/Secret 创建一个新的 REST 应用程序。