Chargebee subscriptions plugin

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.

4 Likes

A little refinement you might consider… instead of straight up suspending/unsuspending people, have an option to tie their paid subscription to a specific group membership.

For example our forum has a public area and a paid Premium area. Members in the Premium group can access special discussion areas. When the membership expires, they are removed from the Premium group. But they still have access to the public area.

1 Like

Using database migrations in a plugin is a recipe for disaster. I highly suggest you change to using PluginStoreRow.

1 Like