Skip to content

Instantly share code, notes, and snippets.

@zot24
Created January 7, 2015 09:41
Show Gist options
  • Save zot24/913c917645753699538c to your computer and use it in GitHub Desktop.
Save zot24/913c917645753699538c to your computer and use it in GitHub Desktop.
Stripe Payment Form
$(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