Back
agentreel
Claude Code·agentreel-cloud·Tue, May 6 — 14:32
Add Stripe webhook for subscription downgrade
/r/4f9c1k
Duration
09:20
26 events · 3 notes
Total cost
$2.87
+12% over avg session
Tokens
184.3k
142k in · 42k out
Files changed
7
+234 · −17
Result
All tests passed
42 tests · 0 failed
EDIT01:24 → 01:54

Add subscription.deleted handler

apps/web/app/api/stripe/route.ts+424
apps/web/app/api/stripe/route.ts+42 · −4
38 const sig = req.headers.get('stripe-signature')
39 if (!sig) return new Response('no sig', { status: 400 })
40
41 const event = stripe.webhooks.constructEvent(
42 body, sig, env.STRIPE_WEBHOOK_SECRET
43 )
4444 if (event.type === 'invoice.paid') return
44+ switch (event.type) {
45+ case 'customer.subscription.deleted': {
46+ await downgradeWorkspace(event.data.object)
47+ break
48+ }
49+ case 'customer.subscription.updated': {
50+ await syncSubscriptionState(event.data.object)
51+ break
52+ }
53+ }
54
55 return new Response('ok', { status: 200 })
Pinned at 01:24
MMarco · pinned
This is where the architecture decision happens — picking a single handler over per-event routing.
00:04
PROMPT
User prompt
00:26
READ
Read existing stripe route
apps/web/app/api/stripe/route.ts
00:40
READ
Read workspace schema
packages/db/schema/workspaces.ts
00:58
TASK
Plan: webhook + retention gate
01:24
EDIT
Add subscription.deleted handler
apps/web/app/api/stripe/route.ts
01:54
EDIT
Add retention_until column
packages/db/schema/workspaces.ts
02:14
BASH
$ pnpm db:generate
02:26
BASH
$ pnpm db:migrate
02:38
WRITE
Create downgrade helper
apps/web/lib/billing/downgrade.ts
03:16
EDIT
Gate retention server-side
apps/web/middleware.ts
03:44
BASHFAIL
$ pnpm test billing
04:00
PROMPT
User prompt
04:30
READ
Read failing tests
apps/web/lib/billing/downgrade.test.ts
04:52
EDIT
Fix stripe mock setup
apps/web/lib/billing/downgrade.test.ts
05:20
BASH
$ pnpm test billing
05:34
WRITE
Add webhook integration test
apps/web/app/api/stripe/__tests__/webhook.test.ts
06:00
BASH
$ pnpm test stripe
06:16
PROMPT
User prompt
06:34
READ
Read share URL route
apps/web/app/r/[token]/page.tsx
07:06
EDIT
Add retention check on share route
apps/web/app/r/[token]/page.tsx
07:26
WRITE
Test retention expiry
apps/web/app/r/[token]/__tests__/expiry.test.ts
07:50
BASH
$ pnpm test
08:08
EDIT
Tighten signature verification
apps/web/app/api/stripe/route.ts
08:30
BASH
$ pnpm typecheck
08:42
BASH
$ pnpm lint
08:58
TASK
Summarize changes
COST · $2.87
00:00
01:00
02:00
03:00
04:00
05:00
06:00
07:00
08:00
09:00
TASK
EDIT
WRITE
EDIT
PROMPT
EDIT
WRITE
READ
WRITE
01:24
01:24 / 09:20
SPACE playJ/L stepN/P eventCOST $2.87