We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 48690
    • 2 Posts
    I'm working through the stripe documentation and I'm trying to submit customer details in order to get a stripeToken sent back. I've looked at whats being sent and the credit card details leave fine however once (what I think is) the token comes back, my form refreshes and doesn't submit data to my database. I'm left with blank input fields.

    I'm using this in combination with logins registration snippet. Does anyone have any idea what's going wrong? I've spent hours on this and time is running out!

    Any help would be greatly appreciated!!

    Stripes submission script:

    <script type="text/javascript">
    // This identifies your website in the createToken call below
    Stripe.setPublishableKey('TESTKEY');
    
    var stripeResponseHandler = function(status, response) {
      var $form = $('#payment-form');
    
      if (response.error) {
        // Show the errors on the form
        $form.find('.payment-errors').text(response.error.message);
        $form.find('button').prop('disabled', false);
      } else {
        // token contains id, last4, and card type
        var token = response.id;
        // Insert the token into the form so it gets submitted to the server
        $form.append($('<input type="hidden" name="stripeToken" />').val(token));
        // and re-submit
        $form.get(0).submit();
      }
    };
    
    jQuery(function($) {
      $('#payment-form').submit(function(e) {
        var $form = $(this);
    
        // Disable the submit button to prevent repeated clicks
        $form.find('button').prop('disabled', true);
    
        Stripe.card.createToken($form, stripeResponseHandler);
    
        // Prevent the form from submitting with the default action
        return false;
      });
    });
    </script>    

    This question has been answered by snolan1. See the first response.

    • discuss.answer
      • 48690
      • 2 Posts
      I figured it out in the end, thought I'd post it here just incase anyone came across the same problem.
      In registration there's this line
        &submitVar=`registerbtn`


      Which requires submitting the form via the button.
      However stripe holds the submission and resubmits using the following line
       // and re-submit
          $form.get(0).submit();


      I just removed
        &submitVar=`registerbtn`
      and all was grand