Andrew Newby
Andrew Newby

Reputation: 5187

PayPal SDK causing "Order could not be captured" error after completing payment

OMG this PayPal system is doing my head in! I have the following code:

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

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

It gets into this bit fine:

onApprove: function(data, actions) {

But when it runs:

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

I get an error and it fails: (no money is taken)

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"

What does that even mean? This is an example of what I'm passing into purchase_units:

enter image description here

I'm so close to just calling it quits and saying "we are removing paypal".

UPDATE: In my searching, I keep coming up with people telling me that the issue is probably from PayPal that I'm using duplicated invoice_id's. I know that isn't the case, but maybe I'm passing it along wrong?

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

},

Upvotes: 0

Views: 1078

Answers (1)

Andrew Newby
Andrew Newby

Reputation: 5187

OK so I'm really hoping my pain will help someone else in the future. I spent hours going over this myself, and then more hours going over it with a PayPal support tech. The eventual solution was to wipe my browsers cache. A bit extreme, but it seems to have sorted it. I wish I'd thought of that before!

Upvotes: 4

Related Questions