Getting trxId from PayPal buttons API when sending the request

I’m working on the integration with PayPal using the Smart Payment Buttons, and I need to catch the trxId generated when the user presses the "Pay With PayPal", when I print the info on the console, I can see the value I need, but when debugging or trying to get the value of the var, I’m getting undefined all the times, what I’m missing?

Below there’s an image that explains the issue

My only guess so far is that there’s some sort of security that prevents from getting this value?

currentIssue

19 thoughts on “Getting trxId from PayPal buttons API when sending the request”

  1. There is no transaction at the time createOrder is called. The buyer hasn’t even signed in at that point, much less given their approval, much less there have been a successful capture.

    A transaction is only created after a successful capture.

                onApprove: function(data, actions) {
                    return actions.order.capture().then(function(details) {
                        console.log(details); //Transaction's ID will be within this object
                    });
                }
    

    The above captures on the client side. Do not capture on the client side and then send data to a server.

    If you need to do anything important with the transaction ID (such as store it in a database), you ought to be using a server-side integration instead. Create two routes, one for ‘Create Order’ and one for ‘Capture Order’, documented here. These routes should return JSON data.

    Pair your two routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server

    Reply

Leave a Comment