Skip to main content

Stripe payments course getting out of date

Site Feedback • Asked by Justin Mullis

Fallback

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.


Fallback

Yep, I'm working on a whole new version. Also going to include a shopping cart example!

I've been waiting a little bit to make sure that I cover any new API changes that they are making. I'm going to start recording the new version this week so it should be out shortly.

If only APIs didn't change... 😜


Fallback

Ok excellent, can't wait for the new version!


Fallback

Brilliant. I just happen to working on a project that needs to integrate payments. Looking forward to this.


Login or create an account to join the conversation.