JavaScript & PayPal Checkout Button Question
aaronesteban
Contributor
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
Oct-28-2021
07:16 PM
Hi PayPal community friends,
I am currently testing out the sandbox for the PayPal checkout integration using Javascript.
I see how to use the "Sandbox" mode versus using the "Live" mode when testing our buttons out in Javascript.
What I'm asking is how do I set the product's title so that the buyer can see exactly what they're about to purchase prior to clicking the "Pay Now" button to finalize the transaction?
Here is the code that I'm currently working with as shown below:
//HTML GOES HERE TO CONTAIN THE PAYPAL BUTTON
<div id="paypal-button-container"></div>
<script src="https://www.paypal.com/sdk/js?&client-id=[MY-CLIENT-ID-GOES-HERE]&merchant-id=[MY-MERCHANT-EMAIL-ADDRESS-GOES-HERE]¤cy=USD"></script>
paypal.Buttons({
style: {
layout: 'vertical',
color: 'gold',
shape: 'pill',
label: 'buynow'
},
// Sets up the transaction when a payment button is clicked
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: 50, // Can reference variables or functions. Example: `value: document.getElementById('...').value`
currency: 'USD'
},
}]
});
},
// Finalize the transaction after payer approval
onApprove: function(data, actions) {
return actions.order.capture().then(function(orderData) {
// Successful capture! For dev/demo purposes:
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
var transaction = orderData.purchase_units[0].payments.captures[0];
alert('Transaction '+ transaction.status + ': ' + transaction.id + '\n\nSee console for all available details');
// When ready to go live, remove the alert and show a success message within this page. For example:
// var element = document.getElementById('paypal-button-container');
// element.innerHTML = '';
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
actions.redirect('https://SomeWebsiteURLiWillForwardThemTo.com');
});
}
}).render('#paypal-button-container');
Labels:
- Labels:
-
Express Checkout
1 REPLY 1

Moderator
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nov-05-2021
07:12 AM
Hello,
Within the "purchase_units" object, you can add the variable "description" and the value would identify the product or service that you're selling.
The button code your using is based upon our REST API's, specifically our orders v2 API and you can view the API reference for that guide at the URL below.
https://developer.paypal.com/docs/api/orders/v2/#orders
I'm also providing the direct link for the "purchase_units" object here : https://developer.paypal.com/docs/api/orders/v2/#definition-purchase_unit_request
Thanks !
Was my post helpful? If so, please give me a kudos!
Within the "purchase_units" object, you can add the variable "description" and the value would identify the product or service that you're selling.
The button code your using is based upon our REST API's, specifically our orders v2 API and you can view the API reference for that guide at the URL below.
https://developer.paypal.com/docs/api/orders/v2/#orders
I'm also providing the direct link for the "purchase_units" object here : https://developer.paypal.com/docs/api/orders/v2/#definition-purchase_unit_request
Thanks !
Was my post helpful? If so, please give me a kudos!

Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
Related Content
- Selected Shipping Method amount not updating to cart for card payment in SDKs
- ExpressCheckout to REST API - Is Partner Program Now Required to Host Simple 3rd Party Transactions? in REST APIs
- Are there any restrictions to charge using only html, vanilla javascript and php with rest api? in REST APIs
- Compliance violation. flag based on the account origin ? in Sandbox Environment
- paypal.ApplePay().confirmOrder() returns applepay_payment_error. in SDKs