Created
June 22, 2014 19:28
-
-
Save rocodev-tech/baa1395ff641960c5bf2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
jQuery ($) -> | |
$("#payment-form").submit (event) -> | |
$form = $(this) | |
# Disable the submit button to prevent repeated clicks | |
$form.find("button").prop "disabled", true | |
Stripe.createToken $form, stripeResponseHandler | |
# Prevent the form from submitting with the default action | |
false | |
return | |
stripeResponseHandler = (status, response) -> | |
$form = $("#payment-form") | |
if response.error | |
# Show the errors on the form | |
$form.find(".payment-errors").text response.error.message | |
$form.find("button").prop "disabled", false | |
else | |
# 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\" />").val(token) | |
# and submit | |
$form.get(0).submit() | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment