Created
September 8, 2012 20:41
-
-
Save coderforhire/3679557 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
class Subscription < ActiveRecord::Base | |
belongs_to :user | |
attr_accessible :user_id, :stripe_card_token | |
def save_with_payment | |
if valid? | |
self.stripe_customer_token = customer.id | |
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 |
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
def create | |
@subscription = Subscription.new(params[:subscription]) | |
@user = User.new(params[:user]) | |
respond_to do |format| | |
if @user.save && @subscription.save_with_payment("1", @user) | |
@subscription.user_id = @user.id | |
@subscription.save | |
format.html { redirect_to pages_thankyou_url } | |
else | |
format.html { render action: "new" } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment