Skip to content

Instantly share code, notes, and snippets.

@coderforhire
Created April 22, 2012 01:28
Show Gist options
  • Save coderforhire/2440684 to your computer and use it in GitHub Desktop.
Save coderforhire/2440684 to your computer and use it in GitHub Desktop.
2012-04-22T01:25:40+00:00 app[web.1]: Completed 500 Internal Server Error in 116ms
2012-04-22T01:25:40+00:00 app[web.1]:
2012-04-22T01:25:40+00:00 app[web.1]: NoMethodError (undefined method `stripe_customer_token' for nil:NilClass):
2012-04-22T01:25:40+00:00 app[web.1]: app/models/purchase.rb:31:in `make_purchase'
2012-04-22T01:25:40+00:00 app[web.1]:
2012-04-22T01:25:40+00:00 app[web.1]: app/controllers/purchases_controller.rb:45:in `create'
2012-04-22T01:25:40+00:00 app[web.1]:
purchase_id | stripe_customer_token
cus_E4aIuWLN2XvtmA
(4 rows)
def create
@purchase = Purchase.new(params[:purchase])
@user = current_user
if @purchase.make_purchase
redirect_to root_path, :notice => "Thank you for subscribing!"
else
render :new
end
end
def make_purchase
if valid?
customer = Stripe::Customer.retrieve(user.stripe_customer_token)
customer.card = stripe_card_token
customer.save
customer = Stripe::Charge.create(customer: user.stripe_customer_token, description: user.email, amount: 500, currency: 'usd')
self.stripe_customer_token = customer.id
save!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment