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

For the full list of parameters and example responses, see authorize payment for order in the Orders API reference.

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

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.authorize().

onApprove: function(data) {
  return fetch('/my-server/authorize-paypal-transaction', {
    method: 'post',
    headers: {
      'content-type': 'application/json'
    },
    body: JSON.stringify({
      orderID: data.orderID
    })
  }).then(function(res) {
    return res.json();
  }).then(function(details) {
    alert('Authorization created for ' + details.payer_given_name);
  });
}

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