Skip to content

Instantly share code, notes, and snippets.

@Poincare
Created May 7, 2012 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Poincare/2625346 to your computer and use it in GitHub Desktop.
Save Poincare/2625346 to your computer and use it in GitHub Desktop.
function stripeResponseHandler(status, response) {
if (response.error) {
$(".payment-errors").text(response.error.message);
}
else {
var form$ = $("#stripe-form");
var token = response['id'];
form$.append("<input type='hidden' name='stripeToken' value='" + token + "'/>");
form$.get(0).submit();
}
}
$(document).ready(function() {
$("#stripe-form").submit(function(event) {
$('.submit').attr("disabled", "disabled");
Stripe.createToken({
number: $('.credit-number').val(),
cvc: $('.credit-security').val(),
exp_month: $('.card-expiry-month').val(),
exp_year: $('.card-expiry-year').val()
}, stripeResponseHandler);
// prevent the form from submitting with the default action
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment