Include the following script on your shopping cart page: (For APMs, the layout must be vertical
and setting up the payment in the alternative payment method supported currency is required for the alternative payment method to render.)
paypal.Buttons({
env: 'sandbox', // sandbox | production
// Set style of buttons
style: {
layout: 'vertical', // horizontal | vertical <-Must be vertical for APMs
size: 'responsive', // medium | large | responsive
shape: 'pill', // pill | rect
color: 'gold', // gold | blue | silver | black,
fundingicons: false, // true | false,
tagline: false // true | false,
},
// payment() is called when the button is clicked
createOrder: function() {
return fetch('/my-server/create-paypal-transaction')
.then(function(res) {
return res.json();
}).then(function(data) {
return data.orderID;
});
},
// onAuthorize() is called when the buyer approves the payment
onApprove: function(data, actions) {
return fetch('/my-server/capture-paypal-transaction', {
body: JSON.stringify({
orderID: data.orderID
})
}).then(function(res) {
return res.json();
}).then(function(details) {
alert('Transaction funds captured from ' + details.payer_given_name);
});
}
}).render('#paypal-button-container');