Skip to content

Instantly share code, notes, and snippets.

@pnegri
Created February 10, 2014 15:50
Show Gist options
  • Save pnegri/8918290 to your computer and use it in GitHub Desktop.
Save pnegri/8918290 to your computer and use it in GitHub Desktop.
$("form").submit (evt) ->
form = $(this)
form.find("button .btn-danger").prop('disabled',true)
if ($('input[name=payment_method]:checked').val() == "credit_card" && $('input[name=credit_card_token]').val().length == 0)
evt.preventDefault()
$("#credit_card_details").removeClass("has-error")
name = $("#credit_card_details .credit_card_name").val().split(" ")
$("#credit_card_details .credit_card_first_name").val name.shift()
$("#credit_card_details .credit_card_last_name").val name.join(" ")
tokenResponseHandler = (data) ->
if (data.errors)
form.find("button .btn-danger").prop('disabled',false)
$("#credit_card_details").addClass("has-error")
else
$("#credit_card_token").val( data.id )
form.get(0).submit()
Iugu.createPaymentToken(this, tokenResponseHandler)
return true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment