Subscriptions: Deleted data in Stripe, now plugin errors

Hi,

I’m currently trying out this plugin for future usage on my instance and had an issue.

My Stripe account is new and not verified which means it’s using test data that I can wipe on the Stripe dashboard > Developers.
The issue is that wiping the data on Stripe doesn’t delete the same data on the forum instance. This can result in a crash of the Billing > Payment page of a user.

Step to reproduce

  1. Create a subscription plan
  2. Subscribe a user to the plan. Stripe will give him a customer_id such as cus_abcd1234567890
  3. Wipe the data on the Stripe dashboard
  4. Retry to open the user’s Billing page will result to a crash while loading /s/user/payment with the following response text in the web browser console:
    {\"errors\":[\"No such customer: 'cus_abcd1234567890'\"]}

After exploring the database of my instance, I can find previous data from multiple wipes I did in the following tables:

  • discourse_subscriptions_customers : causes a crash for user billing page
  • discourse_subscriptions_products
  • discourse_subscriptions_subscriptions

The last 2 tables don’t seem to trigger a crash. However, they still contain expired data.

Manually deleting the problematic row(s) in discourse_subscriptions_customers fixes the crash of the user. But having to do it via SQL request is complicated and dangerous, especially for inexperienced users.

It can be also noted that this issue doesn’t occur when manually deleting the user info from Stripe dashboard. Stripe still keep archived info about him and mark him as “permanently deleted”.

Proposed solutions

If possible, make a way for Stripe to let Discourse know that the test data was wiped, and it should delete the data in those tables.

Or,

In the plugin options, create a button to “wipe the test data” with a big red warning label to make sure the admin knows what he’s doing.

This seems like a bit of an edge case, and not something I’m at this time interested in handling in the plugin. To fix the errors you’re seeing, you’ll have to do this from inside the container:

rails c
DiscourseSubscriptions::Customer.destroy_all
DiscourseSubscriptions::Products.destroy_all
DiscourseSubscriptions::Subscriptions.destroy_all

This will reset all the local models, which are used to compare to Stripe.

My recommendation going forward: delete data from Discourse versus from Stripe. If model records don’t exist in Discourse, it won’t pull in the data from Stripe.

4 Likes

A post was split to a new topic: Issue with /s/user/payments

Thanks for the suggestion. I tested it and it works beside a small typo: there’s no s at the end of ::Product and ::Subscription. Otherwise, it can’t find them.

Corrected commands:

rails c
DiscourseSubscriptions::Customer.destroy_all
DiscourseSubscriptions::Product.destroy_all
DiscourseSubscriptions::Subscription.destroy_all
3 Likes

You’re right - my bad there!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.