This val processes new subscriptions to komorebi's individual personal use license by sending a notifcation to the community Discord server.
customer.subscription.updated as the only event to listen to (more on this below)STRIPE_READ_ONLY_API_KEY to your Val Town Env VariablesSTRIPE_WEBHOOK_SECRET to your Val Town Env VariablesSTRIPE_DISCORD_WEBHOOK_URL to your Val Town Env VariablesStripe sends webhooks for many different kinds of events. Relevant for us here are:
customer.subscription.created (what we used to listen for)customer.subscription.updated (what we're currently listening for)The issue with customer.subscription.created is that it triggers too early,
before the user's payment actually goes through. This is a problem
because in early Nov 2024 we started getting credit card fraudsters
testing cards using our service. We started getting lots of notifications
for new subscriptions that never actually became active.
Note: if anyone knows good ways to prevent that sort of behavior at the root, please let me know by commenting on this val!
In order to only get notified on a valid subscription, we now subscribe
to customer.subscription.updated. This event happens on any subscription change,
including renewals and cancellations, so now we have to filter those events
to only get new subscriptions, ie where:
event.data.previous_attributes.status === 'incomplete' && event.data.object.status === 'active'