
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: v3View 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 webhook signature to ensure it's really from Stripe
- Checks if the event is a new subscription by looking for
invoice.payment_succeededwithbilling_reason === "subscription_create" - Fetches the customer details from Stripe
- Sends a Discord notification with the customer's email
We listen to invoice.payment_succeeded events and filter for billing_reason === "subscription_create" because:
- Works for all subscription methods: Covers standard checkout, payment links, invoices, and trials ending
- Payment confirmation: Only fires when payment actually succeeds, preventing notifications for failed fraud attempts
- Simpler implementation: Single event type to monitor, no need to track status transitions
- More reliable: Catches the moment when a customer becomes a paying subscriber, regardless of how they signed up
This approach ensures we get notified exactly once per new paying customer, at the moment their first payment goes through.