Created
December 11, 2011 02:58
-
-
Save mattm/1457935 to your computer and use it in GitHub Desktop.
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
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