Smart Payment Button - Variable amount
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Below is the sample code for the smart button provided by paypal, it would be really helpful if the sample code isn't hard coded the amount (not real life applicable). I've edited to take a value from a combo box and can't put this value to replace the hard coded '0.01' value. I've bolded the section of the area that I need fixed. Appreciate the help. Thanks.
<!DOCTYPE html>
<head>
<!-- Add meta tags for mobile and IE -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
Top Up Amount :
<select id="PaymentAmount" class="autocomplete">
<option value="50">USD50</option>
<option value="100">USD100</option>
</select>
<!-- Set up a container element for the button -->
<div id="paypal-button-container"></div>
<!-- Include the PayPal JavaScript SDK -->
<script>
// Render the PayPal button into #paypal-button-container
var sel = document.getElementById('PaymentAmount');
paypal.Buttons({
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '0.01' // How to pass in the variable sel.Value()
}
}]
});
},
// 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>
</body>
- Labels:
-
PayPal Buttons
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
You have set variable sel to be the element 'PaymentAmount' rather than the value contained there. Use: var sel = document.getElementById('PaymentAmount').value; instead. Then just replace '0.01' with sel. Might have to try with and without the pair of single quotes.
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- Zettle refunds and Zettle vs Here in Merchant Products and Services Archives
- Sufficient Evidence for Virtual Goods Sale Dispute? in Managing Risk and Fraud Archives
- How to get item description at Activities Download? in Reporting Archives
- Process monthly invoices for customers in Merchant Products and Services Archives
- payment stuck on invoice ? in Managing Risk and Fraud Archives