I’ve got an odd problem cropped up here with a subscriber.
They have no active subscriptions in under the Billing section;
In Stripe it shows as cancelled;
![]()
yet they cannot resubscribe… says already purchased;

Have I set something up incorrectly?
I’ve got an odd problem cropped up here with a subscriber.
They have no active subscriptions in under the Billing section;
In Stripe it shows as cancelled;
![]()
yet they cannot resubscribe… says already purchased;

Have I set something up incorrectly?
That looks like you might have your webhook endpoint improperly configured. When the subscription period ends, Stripe sends a webhook which the plugin uses to remove group membership, and remove the user from being an existing customer on that product (which allows the user to purchase again).
You’ll need to make sure this is configured per the OP here: Discourse Subscriptions
One way you to confirm from your server:
./launcher enter app
rails c
u = User.find_by_username(<username>)
c = DiscourseSubscriptions::Customer.where(user_id: u.id)
subscription = DiscourseSubscriptions::Subscription.where(customer_id: c.customer_id)
Be sure to replace <username> with the actual username of the user.
If subscription returns [], there’s another issue going on. But if it returns a value, that likely confirms the missing webhook.
To delete the DiscourseSubscriptions::Subscription entry so the user can purchase the product again:
Make sure subscription has only one value by running subscription.count. If the value returned is greater than 1, you’ll have to do a bit more digging to make sure you’re deleting the correct subscription instance. If you delete the wrong one, your subscriptions data will be in an inconsistent state and likely yield weird behavior.
Once you’ve confirmed there’s only one subscription, then you can run:
subscription.destroy_all
Keep in mind that subscription is the value returned from the initial set of queries we ran in the Rails console.
Hope that helps!
Thanks @justin
• got to the last line subscription and ran it… returned this;
NoMethodError: undefined method
customer_id' for #<DiscourseSubscriptions::Customer::ActiveRecord_Relation:0x000055be473772f0> from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.2/lib/active_record/relation/delegation.rb:110:inmethod_missing’
• Checked Stripe webhooks and it’s pointed to https://./s/hooks
• Events sent to webhook;
subscription_schedule.updated
subscription_schedule.expiring
subscription_schedule.created
subscription_schedule.canceled
• Stripe webhook log has one entry from setup date which looks to be establishing the events supported.
• I have an event entry in Stripe that is a cancellation of a subscription, but… the line entry says (effectively) “[subscription was canceled]” however when I click into the event, it says the event type is customer.subscription.deleted … which I notice is not listed in my webhooks event list.
Could the above be the problem?
Looks like the line should be DiscourseSubscriptions::Subscription instead of ::Customer. Try that and see what you get!
[2] pry(main)> c = DiscourseSubscriptions::Subscription.where(user_id: u.id)
=> #DiscourseSubscriptions::Subscription::ActiveRecord_Relation:0x8020
[3] pry(main)> subscription = DiscourseSubscriptions::Subscription.where(customer_id: c.customer_id)
NoMethodError: undefined methodcustomer_id' for #<DiscourseSubscriptions::Subscription::ActiveRecord_Relation:0x000055ec51164ca0> from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.2/lib/active_record/relation/delegation.rb:110:inmethod_missing’
Sorry, I misunderstood where this was happening.
Try this instead:
./launcher enter app
rails c
u = User.find_by_username(<username>)
c = DiscourseSubscriptions::Customer.find_by(user_id: u.id)
subscription = DiscourseSubscriptions::Subscription.where(customer_id: c[:customer_id])
Ah…
[3] pry(main)> subscription = DiscourseSubscriptions::Subscription.where(customer_id: c[:customer_id])
=>
Do you think the lack of subscription data has anything to do with the customer.subscription.deleted event being missing?
Is there anything I should explore next at this point?
I’m particularly interested in focusing on why the subscription page shows “purchased” while the active subscriptions section shows no active subs… is there some other place in the database where sub info is stored which might be cleared / empty under the active subs section but somehow a “purchased” boolean is still set to true somewhere … or something like that?
Is there anything else to try here?
Make sure in Stripe the purchase is fully cancelled and not waiting to be cancelled at the end of the period. You can also look under the Admin → Plugins → Discourse Subscriptions → Subscriptions area and look for this user’s username. If they have a subscription listed there, you can cancel it immediately.
Without further looking into your Discourse instance, I’m not sure how much further I can help.
yeah it’s not active under subscriptions in the plugin area, and also not on stripe either… the only thing that indicates anything is still active is if the user goes to the subscription page, they see a little green “purchased” checkmark and “go to billing”.

If I go to billing as the user in question, nothing;

So my question is - what in the database triggers that green checkmark and can it be cleared?
If this list includes the Stripe product id as per here:
Then the front end will display it as purchased. You may need to dig around the console with these queries to find out where it’s located. I almost guarantee there’s a record hanging around there yet.
حسنًا ، أعلم أنني أقوم بإحياء هذا الموضوع ولكن 1) هذا لا يزال مستمرًا دون حل ، و 2) وجدت بعض الوقت للتعمق في هذا مرة أخرى .. اتضح أنني كنت أحمقًا لم أتمكن من اتباع التعليمات. هذه هي الطريقة التي اكتشفت بها أنني أحمق ، ولماذا أنا الآن مستعد لحل هذا (ببعض المساعدة).
ما انتهى بي الأمر بفعله هو تصدير ملف CSV من Stripe لجميع الحسابات الملغاة. ركزت على مستخدم Discourse نفسه الذي تمت الإشارة إليه أعلاه في هذا الموضوع والذي كان مشتركًا ، وألغى ، ولكنه لم يتمكن بعد ذلك من إعادة الاشتراك لأن صفحة الاشتراك ظهرت على أنها “تم شراؤها” على الرغم من أن صفحة الاشتراكات النشطة الخاصة به لم تظهر أي اشتراكات. في بيانات CSV ، أظهر سجله على أنه “ملغى” مع البيانات التالية ؛
ثم قمت بالاتصال بحاوية التطبيق ، ودخلت إلى وحدة تحكم Ruby ، وبدأت في البحث. أولاً ، بحثت عن معرف العميل الخاص به في DiscourseSubscriptions::Customer ووجدته.
[3] pry(main)> DiscourseSubscriptions::Customer.where(customer_id: 'cus_JNWeiIWTs6YOwQ')
=> [#<DiscourseSubscriptions::Customer:0x000055db2d48eb40
id: 16,
customer_id: "cus_JNWeiIWTs6YOwQ",
product_id: "prod_JJbwYnKz0T5Z9h",
user_id: 3256,
created_at: Tue, 27 Apr 2021 07:45:07.455275000 UTC +00:00,
updated_at: Tue, 27 Apr 2021 07:45:07.455275000 UTC +00:00>]
بعد ذلك ، بحثت في DiscourseSubscriptions::Subscription لمعرفة ما إذا كان لهذا المستخدم أي اشتراكات ، واتضح نعم ، كان لديهم بالفعل ؛
[1] pry(main)> DiscourseSubscriptions::Subscription.where(external_id: 'sub_JNWejdDo4qhLG5')
=> [#<DiscourseSubscriptions::Subscription:0x000055854e1e1620
id: 16,
customer_id: 16,
external_id: "sub_JNWejdDo4qhLG5",
created_at: Tue, 27 Apr 2021 07:45:07.459681000 UTC +00:00,
updated_at: Tue, 27 Apr 2021 07:45:07.459681000 UTC +00:00>]
لذا ، يبدو أنه يمكنني ببساطة إزالة سجل الاشتراك هذا وإصلاح كل شيء .. لهذا المستخدم. الحقيقة هي أن كل مستخدم تم إلغاؤه قمت بالتحقق منه في تصدير CSV الخاص بي لا يزال لديه اشتراكات متبقية في النظام. من الواضح أن هناك انفصالًا ما / في مكان ما بين webhook الخاص بـ Stripe ومكون الاشتراك الإضافي .. أنا فقط لا أعرف أين / كيف.
أولاً ؛ كيف يمكنني بأمان إزالة بيانات سجل الاشتراك لمستخدم معين؟ اشرحها لي وكأنني في الخامسة .. أنا عند موجه وحدة تحكم Ruby .. كيف يمكنني التأكد من إزالة بيانات اشتراك المستخدم المستهدف فقط وعدم مسح بيانات اشتراك الجميع؟
ثانيًا ، كيف يمكنني استكشاف آلية webhook لإلغاء الاشتراك؟
كل مساعدتكم محل تقدير كبير!
تحديث:
حسنًا ، لقد تقدمت قليلاً .. تمكنت من فرز كيفية استخدام .delete_by لإزالة بيانات الاشتراك للمستخدم المستهدف فقط ؛
[1] pry(main)> DiscourseSubscriptions::Subscription.delete_by(external_id: 'sub_JNWejdDo4qhLG5')
[2] pry(main)> DiscourseSubscriptions::Subscription.where(external_id: 'sub_JNWejdDo4qhLG5')
=> []
ومع ذلك ، لا يزال سجل العميل يحتوي على product_id مرتبط ؛
[3] pry(main)> DiscourseSubscriptions::Customer.where(customer_id: 'cus_JNWeiIWTs6YOwQ')
=> [#<DiscourseSubscriptions::Customer:0x0000560ec18e4948
id: 16,
customer_id: "cus_JNWeiIWTs6YOwQ",
product_id: "prod_JJbwYnKz0T5Z9h",
user_id: 3256,
created_at: Tue, 27 Apr 2021 07:45:07.455275000 UTC +00:00,
updated_at: Tue, 27 Apr 2021 07:45:07.455275000 UTC +00:00>]
هذا يعني أنهم لا يزالون يرون علامة التحقق الخضراء ولا يمكنهم إعادة الاشتراك .. لذلك قمت بتطبيق “destroy_all” على كائن العميل .. ونجح الأمر! ولكن فقط لهذا المستخدم بالطبع ..
[4] pry(main)> DiscourseSubscriptions::Customer.where(customer_id: 'cus_JNWeiIWTs6YOwQ').destroy_all
=> [#<DiscourseSubscriptions::Customer:0x0000560ec19770e0
id: 16,
customer_id: "cus_JNWeiIWTs6YOwQ",
product_id: "prod_JJbwYnKz0T5Z9h",
user_id: 3256,
created_at: Tue, 27 Apr 2021 07:45:07.455275000 UTC +00:00,
updated_at: Tue, 27 Apr 2021 07:45:07.455275000 UTC +00:00>]
لذا الآن الأمر يتعلق فقط بتشخيص سبب عدم عمل webhook الخاص بـ Stripe للاشتراكات الملغاة.