Soldato
I have a cart.php which calculates a total amount owed into $toPay. I want this amount to then be charged in this script on the actual shop page (the keys are edited) -
How can I pass the variable in instead of '1.00'. I tried passing $toPay into $_SESSION['$toPay'] and then replacing 1.00 with <?php $_SESSION['$toPay'] ?> but then the Paypay button didn't show, so I assume that's not valid code.
Any ideas? Thanks.
**EDIT** For now I've got it working an older way where it diverts you all the way to Paypal. I would prefer to get this new way working if anyone can help, where it just uses a popup to take payment.
Also, in the onAuthorize, how would I get it to process success.php. Simply open <php include success.php ?> ? Can I do that in JS?
HTML:
<div id="paypal-button-container"></div>
<script>
paypal.Button.render({
env: 'sandbox', // sandbox | production
// Specify the style of the button
style: {
label: 'checkout',
size: 'small', // small | medium | large | responsive
shape: 'pill', // pill | rect
color: 'gold' // gold | blue | silver | black
},
// PayPal Client IDs - replace with your own
// Create a PayPal app: https://developer.paypal.com/developer/applications/create
client: {
sandbox: 'AZDxjDScFpQtjbyN_bDt4OgqaF4eYXlewfBP4-8aqX3PiV8e1GWU6E7M6R',
production: 'AUbmPNC-HX_OKAufXgkoiiUpieaFH4BRG69J9Bwy_XiqxW_9iWWzh3sMzB'
},
// Show the buyer a 'Pay Now' button in the checkout flow
commit: true,
// payment() is called when the button is clicked
payment: function(data, actions) {
// Make a call to the REST api to create the payment
return actions.payment.create({
payment: {
transactions: [{
amount: {
total: '1.00',
currency: 'GBP'
}
}]
}
});
},
// onAuthorize() is called when the buyer approves the payment
onAuthorize: function(data, actions) {
// Make a call to the REST api to execute the payment
return actions.payment.execute().then(function() {
window.alert('Payment Complete!');
});
}
}, '#paypal-button-container');
</script>
How can I pass the variable in instead of '1.00'. I tried passing $toPay into $_SESSION['$toPay'] and then replacing 1.00 with <?php $_SESSION['$toPay'] ?> but then the Paypay button didn't show, so I assume that's not valid code.
Any ideas? Thanks.
**EDIT** For now I've got it working an older way where it diverts you all the way to Paypal. I would prefer to get this new way working if anyone can help, where it just uses a popup to take payment.
Also, in the onAuthorize, how would I get it to process success.php. Simply open <php include success.php ?> ? Can I do that in JS?
Last edited: