Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Please save your file with .php extension. You can assign php value into js variable and pass it to PayPal. I have attached sample code below: I am passing amount value from php variable.`<script>
- var total_price= '<?php echo $total_price; ?>';
- paypal.Buttons({
- createOrder: function(data, actions) {
- return actions.order.create({
- purchase_units: [{
- amount: {
- value: total_price
- }
- }]
- });//insert JSON above this line
- },
- onApprove: function(data, actions) {
- return actions.order.capture().then(function(details) {
- alert('Transaction completed by ' + details.payer.name.given_name);
- // Call your server to save the transaction
- return fetch('/BurgerJoint/GetOrder.php', {
- method: 'post',
- headers: {
- 'content-type': 'application/json'
- },
- body: JSON.stringify({
- orderID: data.orderID
- })
- });
- });
- }
- }).render('#paypal-button-container');
- </script>`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement