Get Transaction Details

SDKLegacyLast updated: June 20th 2023, @ 6:44:12 pm


Note: This guide assumes you have completed a basic Smart Payment Buttons integration.

On the server

This code:

  1. Sets up your server to make calls to PayPal.
  2. Sets up your server to receive a call from the client with the order ID.
  3. Calls PayPal to get the order details.
  4. Handles any errors from the call.
  5. Validates the order details are as expected.
  6. Saves the order in your database.
  7. Returns a successful response to the client.

For the full list of order details you can retrieve from /v2/checkout/orders/, see show order details in the Orders API reference.

On the client

Next, change the onApprove function on your client. This function should call your server with the order ID, and no longer call actions.order.get().

onApprove: function(data) {
  return fetch('/my-server/get-paypal-transaction', {
    headers: {
      'content-type': 'application/json'
    },
    body: JSON.stringify({
      orderID: data.orderID
    })
  }).then(function(res) {
    return res.json();
  }).then(function(details) {
    alert('Transaction approved by ' + details.payer_given_name);

}

Now your client and server are set up to call the PayPal Orders API to get transaction details.