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

stevekrouse

newStripeSubscriber

Public
Like
5
newStripeSubscriber
Home
Code
2
README.md
H
main.tsx
Branches
1
Pull requests
Remixes
12
History
Environment variables
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
/
Code
/
Search
main.tsx
https://stevekrouse--3aecfd381bcc11f0a237569c3dd06744.web.val.run
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 notifcation.

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 customer.subscription.updated as the event to listen to (more on this below)
  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
  3. Sends the Discord message

Which Stripe event type to listen to

Stripe 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 fraudsters testing stolen credit cards using our service. We started getting lots of notifications for new subscriptions that never actually became active. 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 successfuly created 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:

Create val
event.data.previous_attributes.status === 'incomplete' && event.data.object.status === 'active'

Migrated from folder: Archive/prod/newStripeSubscriber

HTTP
  • main.tsx
    stevekrouse--3a…44.web.val.run
Code
README.md
H
main.tsx
FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
ExploreDocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.