Problem with 500 error with subscriptions

I’m assuming it’s only for this one site? You aren’t seeing this on other sites? Yes, there is a “bug” where we shouldn’t return a 500, but there is likely some “bad” data somewhere like a missing plan or something. Maybe it got removed in stripe and never got updated in the plugin db.

Can you run these rails console commands to help me debug?

Stripe.api_key = SiteSetting.discourse_subscriptions_secret_key
user = User.find_by(username: 'xxx')
customer = DiscourseSubscriptions::Customer.find_by(user_id: user.id)
subs = ::Stripe::Subscription.list(customer: stripe_customer_id, status: 'all')[:data]
subs.count # note how many subscriptions they have
subscription = subs.first # change this and run the below lines for each sub
price_id = subscription[:items][:data].first[:price][:id]
plans = ::Stripe::Price.list(expand: ['data.product'], limit: 100)
plan = plans[:data].find { |p| p[:id] == price_id }
plan

I’m thinking either plans or plan will return nil, but that will help us narrow down where the issue is. Could you let me know how many subscriptions they have and if there are any missing plans for them?

Likely a code fix I’ll make is to just not return any subscriptions for these users if there is an error, but if they actually have a subscription that isn’t really solving the issue. Maybe I’ll have it return an error that says something like a subscription has been found but there is an error loading the plan details for it, please reach out to an admin for help.