I’m using the PayPal smart payment buttons to sell a single item on my website, but I can’t find in any of the documentation how to ask for quantity.
Is this even possible to do with the smart payment buttons API?
I just want to offer the customer the ability to change the quantity of the item they wish to buy. I don’t mind if it’s in the form or during the checkout stage within PayPal.
Here’s my code so far, it’s pretty standard as I’m trying to keep it simple:
<script>
// Render the PayPal button into #paypal-button-container
paypal.Buttons({
style: {
size: 'responsive',
shape: 'pill',
label: 'checkout',
},
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '8.99'
}
}]
});
},
// Finalize the transaction
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
}
}).render('#paypal-button-container');
</script>
2
Answers
To implement quantity field on your client. you have to breakdown the amount field and then add “item_total” and “items” field in the purchase units.
for your reference:
I have done this but without breaking out the bill.
I made the final price "amount" as the price multiplied by the quantity and in my database I am saving all the details of the bill.
This is my javascript code I used:
You can use Javascript instead of server code like this,
In both codes, values should be set before rendering the buttons, which means before loading the page.