Build a Monthly Subscription App with Laravel Cashier: Lesson 23 of 36

Create a Token

Up Next

Stripe Validation

Autoplaying in 7 seconds!



Table of Contents

    o create a token from a user's credit card information, we'll use the Stripe.js library.

    Here is the code to process our form:

    // target the form
      // on form submission, create a token
      $('#subscribe-form').submit(function(e) {
        var form = $(this);
        // disable the form button
        form.find('button').prop('disabled', true);
        // use the stripe library. create a single use token
        Stripe.card.createToken(form, function(status, response) {
          // if there are errors, show them
          if (response.error) {
            form.find('.stripe-errors').text(response.error.message).addClass('alert alert-danger');
            form.find('button').prop('disabled', false);
          } else {
            // if there are no errors...
            // append the token to the form
            form.append($('<input type="hidden" name="cc_token">').val(;
            // submit the form

    Chris Sevilleja

    173 posts

    Founder of Google Developer Expert in Web Technologies. Slapping the keyboard until something good happens.