
Public
Like
5
newStripeSubscriber
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of teams-payment-links branch: v5View latest version
This webhook listens for new subscribers to Val Town Pro from Stripe and sends the Val Town team a Discord notification.
We have an additional webhook in the core Val Town app that takes care of updating user's tier to let Pro users access premium features.
To create your own Stripe webhook that listens for new subscribers:
- Fork this HTTP val
- Create a new webhook in Stripe
- Add your val's HTTP endpoint URL into the Stripe webhook
- Select
invoice.payment_succeededas the event to listen to - Add your
stripe_sk_customer_readonlyto your Val Town Env Variables (you can find this on the left sidebar) - Add your webhook's signing secret as
STRIPE_WEBHOOK_SECRETto your Val Town Env Variables (you can find this on the left sidebar)
- Verifies the signature to make sure it's really from Stripe
- Filters for newly created subscriptions using
billing_reason === 'subscription_create' - Fetches customer details from Stripe
- Sends the Discord notification
We listen to the invoice.payment_succeeded event and filter for invoices where billing_reason === 'subscription_create'. This approach:
- Works for all subscription creation methods: Regular checkout, payment links, invoices, and trials
- Only fires when payment actually succeeds: Provides built-in fraud protection since the event only triggers after successful payment
- Single event type to monitor: Simpler webhook configuration compared to listening to multiple subscription events
- Reliable timing: Ensures we're notified when customers actually become paying subscribers, not just when they start the signup process
This event fires when:
- A new subscription is created via checkout and payment succeeds
- A new subscription is created via payment link and payment succeeds
- A trial period ends and the first payment goes through
By using this approach, we avoid false positives from fraudulent signups or incomplete checkouts while ensuring we catch all legitimate subscription creation methods.