I just tested your code here https://developer.paypal.com/demo/checkout/#/pattern/client and it works fine, I just took out your script with your client code. Just paste this in the code window <!DOCTYPE html>
<html lang="en">
<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" />
<title> PayPal Smart Payment Buttons Integration | Client Demo </title>
</head>
<body>
<!-- Set up a container element for the button -->
<div id="smart-button-container">
<div style="text-align: center;">
<div style="margin-bottom: 1.25rem;">
<p>AASDN Annual Membership</p>
<select id="item-options"><option value="Ordinary membership, including Journal" price="20">Ordinary membership, including Journal - 20 GBP</option><option value="Joint membership" price="25">Joint membership - 25 GBP</option><option value="Associate membership, senior citizens, students, unwaged, Journal not included" price="10">Associate membership, senior citizens, students, unwaged, Journal not included - 10 GBP</option><option value="Institutional membership (payable on publication of Journal) £25.00" price="25">Institutional membership (payable on publication of Journal) £25.00 - 25 GBP</option><option value="Overseas membership" price="29">Overseas membership - 29 GBP</option></select>
<select style="visibility: hidden" id="quantitySelect"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select>
</div>
<div id="paypal-button-container"></div>
</div>
</div>
<!-- Include the PayPal JavaScript SDK -->
<script src="https://www.paypal.com/sdk/js?client-id=test¤cy=GBP"></script>
<script>
function initPayPalButton() {
var shipping = 0;
var itemOptions = document.querySelector("#smart-button-container #item-options");
var quantity = parseInt(5);
var quantitySelect = document.querySelector("#smart-button-container #quantitySelect");
if (!isNaN(quantity)) {
quantitySelect.style.visibility = "visible";
}
var orderDescription = 'AASDN Annual Membership';
if(orderDescription === '') {
orderDescription = 'Item';
}
paypal.Buttons({
style: {
shape: 'rect',
color: 'gold',
layout: 'vertical',
label: 'paypal',
},
createOrder: function(data, actions) {
var selectedItemDescription = itemOptions.options[itemOptions.selectedIndex].value;
var selectedItemPrice = parseFloat(itemOptions.options[itemOptions.selectedIndex].getAttribute("price"));
var tax = (0 === 0) ? 0 : (selectedItemPrice * (parseFloat(0)/100));
if(quantitySelect.options.length > 0) {
quantity = parseInt(quantitySelect.options[quantitySelect.selectedIndex].value);
} else {
quantity = 1;
}
tax *= quantity;
tax = Math.round(tax * 100) / 100;
var priceTotal = quantity * selectedItemPrice + parseFloat(shipping) + tax;
priceTotal = Math.round(priceTotal * 100) / 100;
var itemTotalValue = Math.round((selectedItemPrice * quantity) * 100) / 100;
return actions.order.create({
purchase_units: [{
description: orderDescription,
amount: {
currency_code: 'GBP',
value: priceTotal,
breakdown: {
item_total: {
currency_code: 'GBP',
value: itemTotalValue,
},
shipping: {
currency_code: 'GBP',
value: shipping,
},
tax_total: {
currency_code: 'GBP',
value: tax,
}
}
},
items: [{
name: selectedItemDescription,
unit_amount: {
currency_code: 'GBP',
value: selectedItemPrice,
},
quantity: quantity
}]
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
},
onError: function(err) {
console.log(err);
},
}).render('#paypal-button-container');
}
initPayPalButton();
</script>
</body>
</html>
... View more