Justin Mullis
Joined
Activity
Ok excellent, can't wait for the new version!
Chris just wanted to mention that the Stripe master course is getting a little out of date (mostly just API changes on Stripe's end). Maybe a good idea to enable commenting on each section/video in the course so people can see there what they need to change.
To start, it looks like you can pass the Stripe token as the "source" when creating a customer. Passing it when creating a subscription gives me an invalid parameter error from the Stripe gem.
I updated my user.rb from
def stripe_customer
if stripe_id?
Stripe::Customer.retrieve(stripe_id)
else
stripe_customer = Stripe::Customer.create(email: email)
update(stripe_id: stripe_customer.id)
stripe_customer
end
end
to
def stripe_customer(stripeToken = nil)
if stripe_id?
Stripe::Customer.retrieve(stripe_id)
else
stripe_customer = Stripe::Customer.create(email: email, source: stripeToken)
update(stripe_id: stripe_customer.id)
stripe_customer
end
end
And then the controller code for subscription create goes from
customer = current_user.stripe_customer
subscription = customer.subscriptions.create(
source: params[:stripeToken],
plan: params[:plan]
)
to
customer = current_user.stripe_customer(params[:stripeToken])
subscription = Stripe::Subscription.create({
customer: customer.id,
items: [{plan: params[:plan]}],
})
I think the code is a little gross looking following the changes, since stripeToken needs to be passed to the model to create the Stripe customer. But its working now.