Skip to content

Instantly share code, notes, and snippets.

@matthewarkin
Created February 22, 2016 02:55
Show Gist options
  • Save matthewarkin/e71ae514b62442ba5952 to your computer and use it in GitHub Desktop.
Save matthewarkin/e71ae514b62442ba5952 to your computer and use it in GitHub Desktop.
Stripe.card.createToken({
number: $('.card-number').val(),
cvc: $('.card-cvc').val(),
exp_month: $('.card-expiry-month').val(),
exp_year: $('.card-expiry-year').val()
}, 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 {
// response contains id and card, which contains additional card details
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 submit
$form.get(0).submit();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment