Set up a 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:
- Sets up your server to make calls to PayPal.
- Sets up your server to receive a call from the client.
- Calls PayPal to create an order with intent to capture payment immediately.
- Handles any errors from the call.
- Returns a successful response to the client with the order ID.
Full parameters
For the full list of parameters and example responses, see create 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 createOrder
function on your client. This function calls your server to create the order, instead of actions.order.create()
.
Note: PayPal recommends that you do not use jQuery's
ajax()
function as PayPal will expect yourcreateOrder
function to return a Promise, and jQuery'sajax()
function does not return a Promise. Usefetch()
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.