• Blog
  • Docs
  • Pricing
  • Weโ€™re hiring!
Log inSign up
dcm31

dcm31

stripe-sub-template

Stripe subscription paywall template with Google auth
Public
Like
stripe-sub-template
Home
Code
7
pages
3
README.md
auth.ts
db.ts
H
main.tsx
stripe.ts
styles.ts
Connections
Environment variables
3
Branches
1
Pull requests
Remixes
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 main branch: v29
View latest version
README.md

โšก Stripe Subscription Paywall โ€” Val Town Template

A complete, remixable template for gating content behind a Stripe subscription on Val Town.

What's included

LayerHow
AuthGoogle Sign-In via LastLogin โ€” zero API keys needed
PaymentsStripe Checkout (Apple Pay, Google Pay, all cards โ€” automatic)
Billing PortalStripe Customer Portal for self-serve manage / cancel
DatabaseVal Town SQLite โ€” email โ†” stripe_customer_id โ†” subscription_status
WebhooksHandles checkout.session.completed, subscription.updated, subscription.deleted

Flow

Visitor โ†’ Landing page โ†’ Sign In (Google) โ†’ Paywall โ†’ Stripe Checkout โ†’ Premium Dashboard
                                                                            โ†•
                                                                    Stripe Customer Portal
                                                                    (manage / cancel)

Setup (5 min)

1. Fork this project

2. In Stripe Dashboard:

  • Create a Product with a recurring Price (e.g. $9/month)
  • Create a Webhook โ†’ YOUR_VAL_URL/api/webhook
    • Events: checkout.session.completed, customer.subscription.updated, customer.subscription.deleted
  • Enable Apple Pay / Google Pay in Settings โ†’ Payment Methods
  • Configure Customer Portal in Settings โ†’ Billing โ†’ Customer Portal

3. Set env vars in your Val:

VariableValue
STRIPE_SECRET_KEYsk_test_...
STRIPE_PRICE_IDprice_...
STRIPE_WEBHOOK_SECRETwhsec_...

4. Test with card 4242 4242 4242 4242 (any future expiry, any CVC)

File structure

main.tsx          โ€” HTTP handler + routing (entry point)
db.ts             โ€” SQLite database layer
stripe.ts         โ€” Stripe API helpers (checkout, portal, webhooks)
styles.ts         โ€” All CSS (design tokens, page-specific styles)
pages/
  landing.tsx     โ€” Public landing page with pricing
  dashboard.tsx   โ€” Premium content (subscribers) / paywall (non-subscribers)
  setup.tsx       โ€” Setup instructions (shown when env vars are missing)

Routes

RouteMethodPurpose
/GETLanding / Dashboard / Setup (context-dependent)
/api/checkoutPOSTCreates Stripe Checkout Session
/api/portalPOSTCreates Stripe Customer Portal Session
/api/webhookPOSTReceives Stripe webhook events
/api/userGETReturns subscription status (JSON)
/auth/loginGETGoogle auth (LastLogin middleware)
/auth/logoutGETLogout (LastLogin middleware)

Customizing

Change pricing

Edit STRIPE_PRICE_ID env var. The $9/mo shown in the UI is just placeholder text in pages/dashboard.tsx and pages/landing.tsx.

Replace premium content

Edit PremiumContent component in pages/dashboard.tsx.

Change the look

Edit styles.ts โ€” all CSS variables and page styles are in one place.

Add multiple tiers

Store tier info in the plan_name column and gate content by tier instead of just active/inactive.

How Apple Pay / Google Pay work

Stripe Checkout automatically shows these buttons when:

  1. The customer's browser/device supports them
  2. You've enabled them in Stripe Dashboard โ†’ Settings โ†’ Payment Methods

No extra code needed.

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.