I am setting up a gated discourse forum for a car club, and am running into issues when getting a subscriber access to the site. I currently have some custom code which checks to see if the user is in a group - If not, they are redirected to our website, which has stripe buy links for each of the three memberships we offer.
Here is the code:
<script type="text/discourse-plugin" version="0.8.42"> api.onPageChange((url, title) => { const allowedGroups = ['Lite', 'Member', 'VIP', 'staff']; const isUserInAllowedGroup = api.getCurrentUser().groups.some(group => allowedGroups.includes(group.name)); if (!isUserInAllowedGroup) { window.location.href = "https://centralcoastdriversclub.webflow.io/select-a-plan"; } }); </script>
I have read through the docs on install, set up the three webhook events, and followed everything to a T, but I still cannot get it running smoothly. My first issue is that when I use the product buy links from Stripe on my website, the webhooks seem to give a 422 error with “email not found” for checkout.session.completed
and “customer not found” for customer.subscription.updated
. This of course does not create a subscription in discourse or add the user to the group. I would ideally like to be able to have a link from my website which takes people to the specific membership they are purchasing.
If I go test it through the forum URL /s/subscriptions
, members are added into discourse under the subscriptions tab, but unfortunately are still not added to their respective group. I also noticed that when going through Discourse, it uses a dynamic link which locks the email to the user’s account—interesting!
As you may have pieced together from my code and previous explanation, if the user isn’t added to the proper group, they aren’t able to view the forum as the code redirects them.
I must have missed something, but for the life of me can’t figure it out.
Any help is greatly appreciated—thanks in advance!