• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
stevekrouse

stevekrouse

newStripeSubscriber

Notify the Val Town team when we get new subscribers
Public
Like
5
newStripeSubscriber
Home
Code
2
README.md
H
main.tsx
Environment variables
Branches
2
Pull requests
Remixes
13
History
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.
Sign up now
Code
/
README.md
Code
/
README.md
Search
…
Viewing readonly version of teams-payment-links branch: v5
View latest version
README.md

New Stripe Subscription Handler

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.

Setup

To create your own Stripe webhook that listens for new subscribers:

  1. Fork this HTTP val
  2. Create a new webhook in Stripe
  3. Add your val's HTTP endpoint URL into the Stripe webhook
  4. Select invoice.payment_succeeded as the event to listen to
  5. Add your stripe_sk_customer_readonly to your Val Town Env Variables (you can find this on the left sidebar)
  6. Add your webhook's signing secret as STRIPE_WEBHOOK_SECRET to your Val Town Env Variables (you can find this on the left sidebar)

How the code is structured

  1. Verifies the signature to make sure it's really from Stripe
  2. Filters for newly created subscriptions using billing_reason === 'subscription_create'
  3. Fetches customer details from Stripe
  4. Sends the Discord notification

Why we use invoice.payment_succeeded

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.

FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.