Skip to content

Instantly share code, notes, and snippets.

Forked from maccman/StripeTutorialPage.html
Last active October 10, 2019 23:10
Show Gist options
  • Save briancollins/6365455 to your computer and use it in GitHub Desktop.
Save briancollins/6365455 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Stripe Getting Started Form</title>
<!-- The required Stripe lib -->
<script type="text/javascript" src=""></script>
<!-- jQuery is used only for this example; it isn't required to use Stripe -->
<script type="text/javascript" src=""></script>
<script type="text/javascript">
// This identifies your website in the createToken call below
var stripeResponseHandler = function(status, response) {
var $form = $('#payment-form');
if (response.error) {
// Show the errors on the form
$form.find('button').prop('disabled', false);
} else {
// token contains id, last4, and card type
var token =;
// 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
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;
<h1>Charge $10 with Stripe</h1>
<form action="" method="POST" id="payment-form">
<span class="payment-errors"></span>
<div class="form-row">
<span>Card Number</span>
<input type="text" size="20" data-stripe="number"/>
<div class="form-row">
<input type="text" size="4" data-stripe="cvc"/>
<div class="form-row">
<span>Expiration (MM/YYYY)</span>
<input type="text" size="2" data-stripe="exp-month"/>
<span> / </span>
<input type="text" size="4" data-stripe="exp-year"/>
<button type="submit">Submit Payment</button>
Copy link

Can I use data-stripe="name" for cardholder name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment