Created
April 20, 2015 13:37
-
-
Save redhedded1/6fa50fcb72ca9efb9a77 to your computer and use it in GitHub Desktop.
stripe response token generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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