Set up an Authorization Transaction

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.
  3. Calls PayPal to set up an authorization transaction.
  4. Handles any errors from the call.
  5. Returns a successful response to the client with the order ID.

Full parameters

For the full list of parameters and example responses, see create orders 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 createOrder function on your client. This function should call your server to create the order, and no longer call actions.order.create().

Note: PayPal recommends that you do not use jQuery's ajax() function as PayPal will expect your createOrder function to return a Promise, and jQuery's ajax() function does not return a Promise. Use fetch() to perform Ajax requests instead.

createOrder: function() {
  return fetch('/my-server/create-paypal-transaction', {
    method: 'post',
    headers: {
      'content-type': 'application/json'
    }
  }).then(function(res) {
    return res.json();
  }).then(function(data) {
    return data.id; // Use the key sent by your server's response, ex. 'id' or 'token'
  });
}

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