All threads / How do I add multiple subscriptions to one user ?
Ask A Question


You’re not receiving notifications from this thread.

How do I add multiple subscriptions to one user ?

Arnas Klasauskas asked in General

I'm able to assign multiple subscriptions to a user, but the problem is that everytime I assign a new subscription to a user, I'm overriding the subscription_id.

I can still show the user all his subscriptions through Stripe::Subscription.list(customer: current_user.stripe_id), but it's not possible to show a specific subscription, just the last one that was created.

How can I overcome this ?

Hey Arnas,

Try changing it so you have a Subscription belongs_to :user and a User has_many :subscriptions. Then use the association to handle the subscriptions in your app.

Hey Chris,
I'm currently working without a Model, therefore it's a bit tricky, but I guess I'll be able to handle this.

Just this last step isn't working fully to my intention...

if current_user.subscription_id?
subscription = customer.subscriptions.create(

This works when I add a new plan to the subscription, but it throws an error when I subscribe to the same plan twice. Stripe::InvalidRequestError (Cannot add multiple subscription items with the same plan: XXXXXX

Yeah, you can't subscribe to the same thing twice. You can use quantities if you need something like that.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 70,078+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.