Created
January 7, 2015 09:41
-
-
Save zot24/913c917645753699538c to your computer and use it in GitHub Desktop.
Stripe Payment Form
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
$(document).ready -> | |
Stripe.setPublishableKey(window.stripe_pk); | |
stripeResponseHandler = (status, response) -> | |
if (response.error) | |
# re-enable the submit button | |
#$('.submit-button').removeAttr("disabled") | |
else | |
form$ = $("#formPaymentDetails") | |
# token contains id, last4, and card type | |
token = response['id'] | |
# insert the token into the form so it gets submitted to the server | |
form$.append("<input type='hidden' name='stripeToken' value='" + token + "'/>") | |
# and submit | |
form$.get(0).submit() | |
$("#formPaymentDetails").submit((event) -> | |
# disable the submit button to prevent repeated clicks | |
#$('.submit-button').attr("disabled", "disabled") | |
Stripe.createToken({ | |
number: $('#CardNumber').val(), | |
cvc: $('#CardCVN').val(), | |
exp_month: $('#CardExpiryMonth').val(), | |
exp_year: $('#CardExpiryYear').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