khaled mahmoud
khaled mahmoud

Reputation: 97

PayPal integration 400 Bad Request / Order could not be captured

I'm trying to integrate PayPal and I get the error below

You can test the code here with any PayPal sandbox buyer account: Codepen

Here is the code I'm using

    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');

more about the error

more about the error

more about the error

Upvotes: 1

Views: 679

Answers (1)

Preston PHX
Preston PHX

Reputation: 30379

Testing your Codepen from the Network tab, you are getting a COMPLIANCE_VIOLATION -- probably due to the country of the account you are testing with not being properly set up in sandbox.

Try simply using a different country for your testing within sandbox. Create a new business account at https://www.paypal.com/signin?intent=developer&returnUri=https%3A%2F%2Fdeveloper.paypal.com%2Fdeveloper%2Faccounts%2F , and then create a new REST app with a new ClientID/Secret for it.

Upvotes: 4

Related Questions