Skip to content

Instantly share code, notes, and snippets.

@brianweiner
Last active December 11, 2015 00:09
Show Gist options
  • Save brianweiner/4514705 to your computer and use it in GitHub Desktop.
Save brianweiner/4514705 to your computer and use it in GitHub Desktop.
stripe response handler
function stripeResponseHandler(status, response) {
if (response.error) {
...
// show the errors on the form
$(".payment-errors").text(response.error.message);
$(".submit-button").removeAttr("disabled");
} else {
var form$ = $("#payment-form");
// token contains id, last4, and card type
var token = response['id'];
// insert the token into the form so it gets submitted to the serverfunction stripeResponseHandler(status, response)
form$.append("<input type='hidden' name='stripeToken' value='" + 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