AI summary by TwinMind
I Fixed Stripe
Theo - t3․gg
28m 29s
Introduction & Stripe's Decline
- Stripe was early pioneer in developer-first payment solutions
- Prioritized APIs, SDKs, documentation
- Made payments easy for developers initially
- By 2025, genuinely difficult to use and setup
- World caught up to Stripe's level, then surpassed while Stripe got worse
- Weird edge cases, multiple webhook types, complex setup required
- Created open source repo "my stripe recommendations" documenting learnings
Split Brain Problem
- Core issue: data exists in two places requiring sync
- User wants to send message → API checks if user paid → database responds
- Cannot simply replace database with Stripe API calls because:
- User IDs don't match Stripe customer IDs
- Stripe API has aggressive rate limits: 100 reads/writes per second
- API calls take 3-10 seconds to resolve
- Would make entire service run at Stripe's slow speed
- Must store customer ID in database to make API calls
- Stripe recommends webhooks but they're unreliable
Webhook Problems
- Webhooks don't have guaranteed order
- Can receive subscription confirmation before subscription creation
- Can get payment event before customer creation
- Partial events and inconsistent data
- Cannot rely purely on webhook data
- Creates messy sync between Stripe API → webhooks → database → API checks
Recommended Solution Architecture
- Use webhooks as indication, not source of truth
- Webhook triggers function to fetch fresh data from Stripe API
- Store data in fast key-value store (KV)
- Two KV stores needed:
- User ID → Customer ID mapping
- Customer ID → Stripe subscription data
- Process: webhook received → get customer ID → call Stripe API for latest data → update KV
- API checks read from KV (fast) instead of Stripe API (slow)
- Only out of sync for ~4 seconds maximum
Code Implementation Details
- Webhook processing function with signature verification
- Allowed events list: subscription created/updated/deleted/paused/resumed, invoice events, payment intents
- Never trust webhook event data directly
- Extract customer ID from webhook, then fetch fresh data via API
updateKVWithLatestStripeDatafunction takes 3-4 seconds but only runs on eventsgetSubTierfunction checks KV for user's payment status- Returns "pro" if subscription status is active, otherwise "free"
Customer Creation Requirements
- Critical: Never let users checkout without pre-existing customer ID
- Create customer before checkout session
- Include metadata: user ID and email for dashboard visibility
- Store customer ID in KV immediately
- Without proper customer handling, users can have multiple unlinked customer IDs
- Stripe API doesn't allow lookup by user ID metadata
Checkout Session Implementation
- 75 lines of code that "should not be necessary but are 100% necessary"
- Check authentication first
- Prevent duplicate subscriptions by checking existing sub status
- Get or create customer ID before proceeding
- Include subscription metadata with user identifier
- Always pass existing customer ID to prevent random customer generation
- Stripe checkout page creates temporary customers that get randomly discarded
Success Page & Sync Handling
- Redirect to
/successURL after checkout - Problem: user returns before webhooks processed
- Solution: trigger sync on success page
- Call
updateKVWithLatestStripeDatato ensure KV is current - Prevents showing free tier when user just paid
- Prevents double checkout attempts
Double Subscription Prevention
- Stripe allows users to subscribe multiple times by default
- Had 5 customers successfully checkout twice with two active subscriptions
- Hidden setting: Settings → Checkout and Payment Links → Subscriptions → "Limit customers to one subscription"
- This should be checked - not default but essential
- Even with proper code, still Stripe's responsibility to prevent
- Still had one user somehow checkout twice even with setting enabled
Cash App Pay Scam Problem
- Cash App Pay enabled by default
- Provides payment info then redirects to success URL immediately
- Users scan code later in Cash App to actually pay
- 17 Cash App attempts on T3 chat: 1 real customer, 16 scam attempts
- Scammers exploit services that assume success URL = payment complete
- Recommendation: Turn off Cash App Pay - majority of requests likely never fulfilled
- Should be off by default like other "sketchy options"
Price ID Management Hell
- Need separate price IDs for dev and prod environments
- Cannot hardcode subscription information
- Must use environment variables
- Updating price IDs requires redeployment
- Manual sync required between dev/prod environments, UI, payment options, existing subscriptions
- "What the f***" - extremely poor developer experience
Alternative Solutions
Lemon Squeezy (Acquired by Stripe)
- Merchant of record service
- Handles incorporation, taxes across countries
- Users see "Lemon Squeezy" on credit card statements
- Much better developer experience
- Acquired by Stripe - founder JR now leading Stripe improvements
- Hope: Lemon Squeezy becomes "sane path" to Stripe
Polar
- Modern DX for Stripe integration
- Simple API:
polar.checkouts.custom.create(product_id, success_url) - Built on Stripe but abstracts complexity
- Pricing: 4% + 40¢ vs Stripe's 3% + 30¢
- Open source (Python + TypeScript)
- Can self-host or use their service
Framework Solutions
- Laravel, Rails have built-in payment handling
- Often limited and not fully integrated
- May have same edge cases as direct Stripe integration
Clerk Integration (Vaporware)
- Clerk (auth company) announced Stripe integration April 2023
- Would integrate billing with user profiles
- Hired full-time developer but hasn't shipped
- CEO post from April 2023, still no Early Access
- "I think it's vaporware" - would make Clerk essential if it existed
- Approaching one year since announcement
Sponsor: Code Rabbit
- AI-powered code review tool
- Leaves useful comments before human review
- Provides PR summaries and file-by-file breakdowns
- Can generate diagrams of PR functionality
- One-click apply for suggested changes
- Recently added docstring support
- Free for open source, relatively cheap Pro plan
- Promo code: THEO1M for free month of Pro
