Capture Transaction Funds

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 capture the order.
  4. Saves the capture ID to your database.
  5. Handles any errors from the call.
  6. Returns a successful response to the client.

For the full API reference, and example responses, see capture payment for order in the Orders API reference.

Note: Remember to swap the credentials and API URL from sandbox to live when going live with your integration.

On the client

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

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

Now your client and server are set up to call the PayPal Orders API to capture funds from a transaction.