A little rough but seems to work, feedback appreciated: https://github.com/liliakai/discourse-chargebee
This plugin creates an endpoint that listens for Events from Chargebee. The migrations create a table for recording chargebee events, as well as adding a chargebee_id
field to users and invites.
After installing, generate an api key in Discourse for the system user and configure a webhook in Chargebee that points at <site_url>/chargebee?api_key=<api_key>
.
The intended use case is a paywalled Discourse instance using Chargebee as a third party billing service. Hence, the following event handlers:
When a customer is created, they are invited to Discourse. If they accept the invitation, their chargebee customer id is associated with the resulting Discourse user. This is handled by storing chargebee_id
on the invite and then cloning it over to the resulting User in an :after_create
hook.
When a subscription is cancelled, the corresponding Discourse User is suspended.
When a subscription is reactivated, the corresponding Discourse User is unsuspended.