Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5.  
  6. <title>Charge</title>
  7. </head>
  8. <body>
  9.  
  10. <form action="charge.php/?id=4" method="POST" id="payment-form">
  11. <table>
  12. <tr>
  13. <td>Name: </td>
  14. <td><input id="name" type="text"></td>
  15. </tr>
  16. <tr>
  17. <td>Email: </td>
  18. <td><input id="email" type="text"></td>
  19. </tr>
  20. <tr>
  21. <td>Credit Card Number: </td>
  22. <td><input id="cc-number" type="text"></td>
  23. </tr>
  24. <tr>
  25. <td>Expiration Month: </td>
  26. <td><input id="cc-month" type="text"></td>
  27. </tr>
  28. <tr>
  29. <td>Expiration Year: </td>
  30. <td><input id="cc-year" type="text"></td>
  31. </tr>
  32. <tr>
  33. <td>CVV: </td>
  34. <td><input id="cc-cvv" type="text"></td>
  35. </tr>
  36. <tr>
  37. <td>Postal Code: </td>
  38. <td><input id="postal_code" type="text"></td>
  39. </tr>
  40. <tr>
  41. <td></td>
  42. <td><input type="submit" class="submit" value="Submit Payment"></td>
  43. </tr>
  44. </table>
  45. </form>
  46. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  47. <script type="text/javascript" src="https://static.wepay.com/min/js/tokenization.v2.js"></script>
  48. <script>
  49. $(function() {
  50. WePay.set_endpoint("production");
  51. var client_id = 184547;
  52. var $form = $('#payment-form');
  53. var d = document;
  54. d.id = d.getElementById,
  55. valueById = function(id) {
  56. return d.id(id).value;
  57. };
  58. $form.submit(function(event) {
  59. // Disable the submit button to prevent repeated clicks:
  60. $form.find('.submit').prop('disabled', true);
  61.  
  62. // Request a token from Stripe:
  63. response = WePay.credit_card.create({
  64. "client_id": client_id,
  65. "user_name": valueById('name'),
  66. "email": valueById('email'),
  67. "cc_number": valueById('cc-number'),
  68. "cvv": valueById('cc-cvv'),
  69. "expiration_month": valueById('cc-month'),
  70. "expiration_year": valueById('cc-year'),
  71. "address": {
  72. "postal_code": valueById('postal_code')
  73. }
  74. }, function(data) {
  75.  
  76.  
  77. if (data.error) {
  78. console.log(data);
  79.  
  80. } else {
  81. console.log(data.credit_card_id);
  82. // call your own app's API to save the token inside the data;
  83. // show a success page
  84.  
  85. var $form = $('#payment-form');
  86. var $token = data.credit_card_id;
  87. $form.append($('<input type="hidden" name="wepayToken">').val($token));
  88. $form.get(0).submit();
  89.  
  90. }
  91. });
  92.  
  93. // Prevent the form from being submitted:
  94. return false;
  95. });
  96. });
  97.  
  98.  
  99. </script>
  100.  
  101.  
  102.  
  103. </body>
  104. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement