title: How to use Stripe checkout with AJAX
body: <p>I have a button that I am using for Stripe checkout (it pops up the Stripe form). What I would like to do is use Ajax to send the inputs to my backend (using a route) and then store that information. How would I do this?</p>
  
  <p>Current code below:  </p>
  
  <pre><code>&lt;div class="button_row"&gt;
  {{ Form::button('Pay $1', array( 
          'id' =&gt; 'customButton',
          'class' =&gt; 'button',
          )); }}
  &lt;/div&gt;
  
  &lt;script src="https://checkout.stripe.com/checkout.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;
    var handler = StripeCheckout.configure({
      key: '*****************',
      image: '/assets/images/1024icon.png',
      token: function(token) {
        // Use the token to create the charge with a server-side script.
        // You can access the token ID with `token.id`
      }
    });
  
    $('#customButton').on('click', function(e) {
      // Open Checkout with further options
      handler.open({
        name: 'Test',
        description: 'Test',
        amount: 100
      });
      e.preventDefault();
    });
  
    // Close Checkout on page navigation
    $(window).on('popstate', function() {
      handler.close();
    });
  &lt;/script&gt;
  </code></pre>
  
  <p>Backend Controller Function:</p>
  
  <pre><code>public function stripe_pay() {
      // Use the config for the stripe secret key
      Stripe::setApiKey(Config::get('stripe.stripe.secret'));
  
      // Get the credit card details submitted by the form
      $token = Input::get('stripeToken');
  
      // Create the charge on Stripe's servers - this will charge the user's card
      try {
          $charge = Stripe_Charge::create(array(
            "amount" =&gt; 500, // amount in cents
            "currency" =&gt; "usd",
            "card"  =&gt; $token,
            "description" =&gt; 'Charge for my product')
          );
  
      } catch(Stripe_CardError $e) {
          $e_json = $e-&gt;getJsonBody();
          $error = $e_json['error'];
          // The card has been declined
          // redirect back to checkout page
          return Redirect::to('/artists/'.$artist_id)
              -&gt;withInput()-&gt;with('stripe_errors',$error['message']);
      }
      // Maybe add an entry to your DB that the charge was successful, or at least Log the charge or errors
      // Stripe charge was successfull, continue by redirecting to a page with a thank you message
  }
  </code></pre>