How do I see if a user is subscribed to a particular plan?
https://github.com/pay-rails/pay#checking-a-users-subscription-status
current_account.subscribed?(plan: "x")
thanks for the reply. When I try from the console I get an undefined error.
[3] pry(main)> user = User.find_by(email: 'ssnape@example.com')
[3] pry(main)> user = User.find_by(email: 'ssnape@example.com')
User Load (0.9ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 LIMIT $2 [["email", "ssnape@example.com"], ["LIMIT", 1]]
=> #<User id: 3, email: "ssnape@example.com", first_name: "Severus", last_name: "Snape", time_zone: "Eastern Time (US & Canada)", accepted_terms_at: "2020-03-29 19:38:37", accepted_privacy_at: "2020-03-29 19:38:37", announcements_read_at: nil, admin: false, created_at: "2020-03-29 19:38:37", updated_at: "2020-03-29 20:16:47", rank_id: 1, current_student: true, terms_of_service: nil>
[4] pry(main)> user.on_trial_or_subscribed?
/Users/bryan.stewart/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/pry-0.12.2/lib/pry/exceptions.rb:28: warning: $SAFE will become a normal global variable in Ruby 3.0
NoMethodError: undefined method `on_trial_or_subscribed?' for #<User:0x00007fe508a03bc0>
from /Users/bryan.stewart/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activemodel-6.0.2.1/lib/active_model/attribute_methods.rb:431:in `method_missing'
[5] pry(main)>
Use Team or Account, not User. https://jumpstartrails.com/docs/billing
Fixed up! Thanks Chris! I just ended up using the code from the billing page, which displays the plan name. I then checked that value against the name of the plan that I wanted to verify. I suppose that leaves just one issue I am having left. (were you able to catch the post i have about ConnectionReset coming from larger files with activestorage?)
I tried checking if a user is subscribed to a certain plan adding this line:
<% if current_account.subscribed?(plan: "basic") %>
but I get:
unknown keyword: :plan
Extracted source (around line #137):135 136 137 138 139 140 | <h1 class="h3 text-white">Próximas clases 🔎</h1> </div> <% if current_account.subscribed?(plan: "basic") %> <div class="flex justify-between items-center"> <p class="mb-6 text-white">Hola 👋. Aquí puedes ver todas las clases disponibles de esta semana. Cada domingo se actualiza la lista 😍.</p> </div>
Anyone knows how can I do it?
Thanks
Thanks
I was getting this as well. plan: does not work for me, I have to use processor_plan and use the plan code from Stripe. so something like this
<% if current_account.subscribed?(processor_plan: "price_JKLhhJ6ifeiPwlQ52007YBq") %>
and my plan name is always set to default for some reason.
current_account.subscription.plan.name
however if an account has more than one subscription (or I noticed, had a former subscription and then changed it, for example, changed from monthly to annual). then you need to know which subscription:
however if an account has more than one subscription (or I noticed, had a former subscription and then changed it, for example, changed from monthly to annual). then you need to know which subscription:
current_account.subscriptions.count # false current_account.subscription[0].active? # true current_account.subscription[1].active? # false
but you can't do:
current_account.subscriptions.active?
(I would have thought that would give me all active subscriptions). So you sort of have to loop through the subscriptions and get a handle on a active one. Once you have it, you can do:
current_account.subscriptions[0].plan.name
I also noticed that
current_account.on_trial_or_subscribed? # false
when there is more than one subscription even when one of those subscriptions is active (!!)
Notifications
You’re not receiving notifications from this thread.