×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: HTML
Posted by: tharun pt
Added: Jan 1, 2016 12:43 PM
Views: 2
Tags: stripeform
stripeForm
  1.   <head>
  2.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
  3.     <!---->
  4.     </script>
  5.     <script type="text/javascript" src="https://js.stripe.com/v2/">
  6.     <!---->
  7.     </script>
  8.    
  9.   </head>
  10.   <body>
  11.     <form id="payment-form" action="" method="post">
  12.       <div class="form-row">
  13.         <label>
  14.         <span>Card Number</span> <input type="text" data-stripe="number" size="20">
  15.         </label>
  16.       </div>
  17.       <div class="form-row">
  18.         <label>
  19.         <span>CVC</span> <input type="text" data-stripe="cvc" size="4"> </label>
  20.       </div>
  21.       <div class="form-row">
  22.         <label>
  23.         <span>Expiration (MM/YYYY)</span> <input type="text" data-stripe="exp-month" size="2">
  24.         </label> <span>/ </span><input type="text" data-stripe="exp-year" size="4">
  25.       </div>
  26.       <button type="submit">
  27.       Submit Payment</button>
  28.     </form>
  29.     <script type="text/javascript">
  30.     <!--// This identifies your website in the createToken call below
  31.  Stripe.setPublishableKey('pk_test_6pRNASCoBOKtIshFeQd4XMUh');
  32.  // ...
  33.  
  34.  
  35. jQuery(function($) {
  36.  $('#payment-form').submit(function(event) {
  37.    var $form = $(this);
  38.    // Disable the submit button to prevent repeated clicks
  39.    $form.find('button').prop('disabled', true);
  40.  
  41.    Stripe.card.createToken($form, stripeResponseHandler);
  42.  
  43.    // Prevent the form from submitting with the default action
  44.    return false;
  45.  });
  46. });
  47.  
  48. function stripeResponseHandler(status, response) {
  49.  var $form = $('#payment-form');
  50.  
  51.  if (response.error) {
  52.    // Show the errors on the form
  53.    $form.find('.payment-errors').text(response.error.message);
  54.    $form.find('button').prop('disabled', false);
  55.  } else {
  56.    // response contains id and card, which contains additional card details
  57.    var token = response.id;
  58.    // Insert the token into the form so it gets submitted to the server
  59.    $form.append($('<input type="hidden" name="stripeToken" />').val(token));
  60.    // and submit
  61.    $form.get(0).submit();
  62.  }
  63. };-->
  64.     </script>
  65.   </body>
  66. </html>
  67.