/**Get script from magic paypal button (https://www.paypal.com/buttons/smart) and insert in html file.
Remove the script tags from the functions and paste functions below the getPaypalUi();
<script src="https://www.paypal.com/sdk/js?client-id=AayjFILjN_mSN-KKC0vMOgPJZ1cGu0lYbY98aBNewHVkd7qbsUR_KejGQX_sXRNdSTB7ZQiCVW5pyVaR¤cy=USD" data-sdk-integration-source="button-factory"></script>
**/
/**
getPaypalUi() returns the Ui in text form
**/
var itemName='';
var itemPrice=0;
function setPaypalItem(name,price){
itemName=name;
itemPrice=price;}
function getPaypalUi(){
return "<hr><div id='smart-button-container'><div style='text-align: center;'><div id='paypal-button-container'></div></div></div>";}
function initPayPalButton() {
paypal.Buttons({
style: {
shape: 'rect',
color: 'gold',
layout: 'vertical',
label: 'paypal',
},
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{"description": itemName,"amount":{"currency_code":"USD","value":itemPrice}}]
});
},
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');
}