Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1.  
  2. <!DOCTYPE html>
  3.  
  4. <head>
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <script src="https://www.paypalobjects.com/api/checkout.js"></script>
  8. </head>
  9.  
  10. <body>
  11. <div id="paypal-button-container"></div>
  12.  
  13. <script>
  14. paypal.Button.render({
  15.  
  16. env: 'sandbox', // sandbox | production
  17.  
  18. // Show the buyer a 'Pay Now' button in the checkout flow
  19. commit: true,
  20.  
  21. // payment() is called when the button is clicked
  22. payment: function() {
  23.  
  24. // Set up a url on your server to create the payment
  25. var CREATE_URL = '/demo/checkout/api/paypal/payment/create/';
  26.  
  27. // Make a call to your server to set up the payment
  28. return paypal.request.post(CREATE_URL)
  29. .then(function(res) {
  30. return res.paymentID;
  31. });
  32. },
  33.  
  34. // onAuthorize() is called when the buyer approves the payment
  35. onAuthorize: function(data, actions) {
  36.  
  37. // Set up a url on your server to execute the payment
  38. var EXECUTE_URL = '/demo/checkout/api/paypal/payment/execute/';
  39.  
  40. // Set up the data you need to pass to your server
  41. var data = {
  42. paymentID: data.paymentID,
  43. payerID: data.payerID
  44. };
  45.  
  46. // Make a call to your server to execute the payment
  47. return paypal.request.post(EXECUTE_URL, data)
  48. .then(function (res) {
  49. window.alert('Payment Complete!');
  50. });
  51. }
  52.  
  53. }, '#paypal-button-container');
  54. </script>
  55. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement