Skip to content

Instantly share code, notes, and snippets.

@redhedded1
Created April 20, 2015 13:37
Show Gist options
  • Save redhedded1/6fa50fcb72ca9efb9a77 to your computer and use it in GitHub Desktop.
Save redhedded1/6fa50fcb72ca9efb9a77 to your computer and use it in GitHub Desktop.
stripe response token generation
Stripe.setPublishableKey('pk_test_5BzYDSKjzUu2BcVFyKoXpn8h');
function stripeResponseHandler(status, response) {
$form = $('#payment-form');
if (response.error) {
// re-enable the submit button
$('#pay-now-submit').removeAttr("disabled");
// show hidden div
document.getElementById('a_x200').style.display = 'block';
// show the errors on the form
$(".payment-errors").text(response.error.message);
$('html, body').animate({
scrollTop: $('#a_x200').offset().top - 50
}, 1000);
} else {
// token contains id, last4, and card type
var token = response.id;
// insert the token into the form so it gets submitted to the server
if($('[name=stripeToken]').length){
$('[name=stripeToken]').remove();
}
$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