User can't repurchase a subscription product after canceling

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!

2 Likes