Skip to content

Instantly share code, notes, and snippets.

@mattm
Created December 11, 2011 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattm/1457935 to your computer and use it in GitHub Desktop.
Save mattm/1457935 to your computer and use it in GitHub Desktop.
The Javascript:
function stripeResponseHandler(status, response) {
if (response.error) {
$("#stripe_error").html(response.error.message);
$('input[type=submit]').attr('disabled', false)
} else {
$("#subscription_stripe_card_token").val(response.id);
$("#new_subscription").get(0).submit();
}
}
The Ruby:
class Subscription < ActiveRecord::Base
belongs_to :user
attr_accessor :stripe_card_token
def save_with_payment
if valid?
customer = Stripe::Customer.create(description: user.email, plan: 'pro99', card: stripe_card_token)
self.stripe_customer_token = customer.id
self.plan = "pro99"
save!
end
# rescue Stripe::InvalidRequestError => e
# logger.error "Stripe error while creating customer: #{e.message}"
# errors.add :base, "There was a problem with your credit card."
# false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment