Video Course

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

Create a Token

Up Next

Stripe Validation

Autoplaying in 7 seconds!


To 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

157 posts

Co-founder of Slapping the keyboard until something good happens.