Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. 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>
  2. var total_price= '<?php echo $total_price; ?>';
  3. paypal.Buttons({
  4. createOrder: function(data, actions) {
  5. return actions.order.create({
  6. purchase_units: [{
  7. amount: {
  8. value: total_price
  9. }
  10. }]
  11. });//insert JSON above this line
  12. },
  13. onApprove: function(data, actions) {
  14. return actions.order.capture().then(function(details) {
  15. alert('Transaction completed by ' + details.payer.name.given_name);
  16. // Call your server to save the transaction
  17. return fetch('/BurgerJoint/GetOrder.php', {
  18. method: 'post',
  19. headers: {
  20. 'content-type': 'application/json'
  21. },
  22. body: JSON.stringify({
  23. orderID: data.orderID
  24. })
  25. });
  26. });
  27. }
  28. }).render('#paypal-button-container');
  29. </script>`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement