Smart Buttons - Include Item details

wnevets
Contributor
Contributor

Hi,

 

I have achieved this button script so far (below), but need to add an item ID number and description (or name) of the item which will be included in the order details for myself and the customer's receipt. I have tried various things but none work. Can anyone help please?

 

<script>
paypal.Buttons({
style: {
shape: 'rect',
color: 'blue',
layout: 'vertical',
label: 'pay',

},
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '18.00',
currency: 'GBP',
}
}],
application_context: {
shipping_preference: 'NO_SHIPPING'
}
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Thank you ' + details.payer.name.given_name + ', please click OK to continue'),
window.location.href = 'https://www.my-domain-name.com/thankyou';
});
}
}).render('#paypal-button-container'); // Display payment options on your web page
</script>

Login to Me Too
5 REPLIES 5

SteveStuartDJ
Contributor
Contributor

It looks like you're missing your Client ID?
Here's a copy of mine as an example:
<div id="smart-button-container">
<div style="text-align: center;">
<div id="paypal-button-container"></div>
</div>
</div>
<script src="https://www.paypal.com/sdk/js?client-id=AZXJHo2Qp14Diln5yFwIbYGV7gydOBtTzLJVX0ow2yzANTUbqSAgCdFI4jEV..." data-sdk-integration-source="button-factory"></script>
<script>
function initPayPalButton() {
paypal.Buttons({
style: {
shape: 'pill',
color: 'gold',
layout: 'vertical',
label: 'buynow',

},
Also, your original question as to the product information, here's a copy of mine as an example:
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{"description":"Cartoons","amount":{"currency_code":"GBP","value":3}}]
});
},

This may be of help, I'm no techie, but sometimes examples can help? Steve

Login to Me Too

triecy25
Member
Member

Hello @SteveStuartDJ , 

 

Hoping you can assist me as well.  

 

The problem I am having is now that I have installed the smart buttons; I am no longer receiving notifications to my shopify store.  The payment is going to my PayPal but I am then having to email the customer to find out what they ordered because of the different variants.

 

I believe this is the section that is messed up 😞

 

// Finalize the transaction
onApprove: function(data, actions) {
return actions.order.capture().then(function(orderData) {
// Successful capture! For 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');

// Replace the above to show a success message within this page, e.g.
// const element = document.getElementById('paypal-button-container');
// element.innerHTML = '';
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');

Login to Me Too

wnevets
Contributor
Contributor

Further to Steve's reply, I did a little experimenting with inverted commas "" or not, and this did work, so kudos to Steve:

 

createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
description:"Cartoons",
amount: {
value: '18.00',
currency: 'GBP',
}
}]

Login to Me Too

SteveStuartDJ
Contributor
Contributor

Brilliant, so there's my good deed for the day! 

Login to Me Too

wnevets
Contributor
Contributor

Kudos without inverted commas """"""""!!!!!!!

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.