stripe-payment-webhooks
Skill10 starsChanged 6 months agoMITView on GitHub
Use when implementing or fixing Stripe payment webhooks: signature verification, event handlers, syncing subscriptions or Checkout to Supabase, webhook endpoint setup. Not for pricing page UI only, non-Stripe providers, or generic edge functions without payment events (see edge-functions-and-webhooks).
- Reads credentials
1 other project uses a version of this.
Adopted by
Most recently taken up by
- Blazkojj/skillhubtheir own version, first seen Aug 18, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- Blazkojj/skillhub★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository56 other files it gives its agents.
- accessibility-passSkill
- analytics-eventsSkill
- api-error-handlingSkill
- audit-logging-backendSkill
- background-jobs-and-cronSkill
- dark-mode-and-themingSkill
- dashboard-charts-rechartsSkill
- edge-functions-and-webhooksSkill
- email-and-notificationsSkill
- error-states-and-empty-uiSkill
- feature-flags-and-togglesSkill
- file-upload-storageSkill
- i18n-multi-languageSkill
- lovable-prompting-playbookSkill
- lovable-ship-checklistSkill
- migration-playbookSkill
- multi-tenant-backendSkill
- onboarding-copySkill
- optimistic-updatesSkill
- payment-failed-and-recoverySkill
- payment-webhook-idempotencySkill
- payment-webhook-testingSkill
- performance-budgetSkill
- pg-cron-recipesSkill
- pg-cron-scheduled-jobsSkill
- pg-cron-with-pg-net-edgeSkill
- postgres-full-text-searchSkill
- postgres-triggers-and-functionsSkill
- pricing-and-billingSkill
- programmatic-seo-content-qualitySkill
- programmatic-seo-pagesSkill
- rate-limiting-edgeSkill
- realtime-and-subscriptionsSkill
- refactor-safe-diffSkill
- release-notesSkill
- seo-core-web-vitalsSkill
- seo-landing-pageSkill
- seo-meta-tags-spaSkill
- seo-sitemap-generationSkill
- seo-ssr-and-prerenderingSkill
- seo-structured-dataSkill
- server-input-validationSkill
- shadcn-patternsSkill
- soft-delete-and-archivingSkill
- stripe-one-time-payment-webhooksSkill
- supabase-auth-flowsSkill
- supabase-database-designSkill
- supabase-rls-and-authSkill
- support-replySkill
- tanstack-infinite-queriesSkill
- tanstack-mutations-and-invalidationSkill
- tanstack-prefetch-and-hydrationSkill
- tanstack-query-alternativeSkill
- tanstack-router-data-loadersSkill
- tanstack-start-server-routesSkill
- typed-api-hooks-formsSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 20
Use raw body for signature verification (do not parse JSON first).
- Distinctive: line 116
Always set on Checkout Session creation (server or Stripe Dashboard template):
- Distinctive: line 121
Never trust webhook to grant access without resolving user from metadata you control at session creation.
- Very specific: line 125
After DB upsert, app reads subscriptions.status:
- Very specific: line 128
Not pro: canceled, unpaid, past_due, incomplete, missing row
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Stripe payment webhooks
Webhooks are the source of truth for paid state. Checkout success URLs and client callbacks are not sufficient alone.
Related: edge-functions-and-webhooks (hosting), payment-webhook-idempotency, payment-webhook-testing, payment-failed-and-recovery, pricing-and-billing.
Endpoint
- Supabase Edge Function:
supabase/functions/stripe-webhook/index.ts - Stripe Dashboard → Webhooks → endpoint URL → signing secret in
STRIPE_WEBHOOK_SECRET - Use raw body for signature verification (do not parse JSON first).
import Stripe from "npm:stripe@17";
const stripe = new Stripe(Deno.env.get("STRIPE_SECRET_KEY")!, {
apiVersion: "2024-11-20.acacia",
httpClient: Stripe.createFetchHttpClient(),
});
const cryptoProvider = Stripe.createSubtleCryptoProvider();
const signature = req.headers.get("stripe-signature");
const body = await req.text();
let event: Stripe.Event;
try {
event = await stripe.webhooks.constructEventAsync(
body,
signature!,
Deno.env.get("STRIPE_WEBHOOK_SECRET")!,
undefined,
cryptoProvider
);
} catch {
return new Response("Invalid signature", { status: 400 });
}Return 2xx quickly after enqueue or DB write; Stripe retries on non-2xx.
Database (service role inside function)
-- Processed events (idempotency) — see payment-webhook-idempotency skill
create table public.stripe_webhook_events (
id text primary key, -- Stripe event id evt_...
type text not null,
processed_at timestamptz default now()
);
create table public.subscriptions (
user_id uuid primary key references auth.users(id),
stripe_customer_id text unique,
stripe_subscription_id text unique,
status text not null,
price_id text,
current_period_end timestamptz,
cancel_at_period_end boolean default false,
updated_at timestamptz default now()
);Map user_id via client_reference_id on Checkout or metadata.user_id on Customer/Subscription.
Event handlers (subscriptions)
| Event | Action |
checkout.session.completed | Read subscription or mode; link customer to user_id; upsert subscription row |
customer.subscription.created | Upsert status, price_id, period end |
customer.subscription.updated | Same; handle plan change, cancel_at_period_end |
customer.subscription.deleted | Set status canceled; revoke entitlements |
invoice.paid | Confirm period; optional receipt email |
invoice.payment_failed | See payment-failed-and-recovery |
switch (event.type) {
case "checkout.session.completed": {
const session = event.data.object as Stripe.Checkout.Session;
const userId = session.client_reference_id ?? session.metadata?.user_id;
if (!userId) break;
// retrieve subscription if mode=subscription
break;
}
case "customer.subscription.updated":
case "customer.subscription.deleted": {
const sub = event.data.object as Stripe.Subscription;
await upsertSubscriptionFromStripe(sub);
break;
}
default:
// unhandled — still return 200 if intentionally ignored
}One-time payments
For mode: "payment" Checkout or Payment Links, handle:
checkout.session.completed(checkmode === "payment")payment_intent.succeeded
Store orders or purchases table; do not reuse subscription row without clear schema.
Metadata contract
Always set on Checkout Session creation (server or Stripe Dashboard template):
client_reference_id: Supabaseauth.users.idmetadata.user_id: same (backup)
Never trust webhook to grant access without resolving user from metadata you control at session creation.
Entitlements
After DB upsert, app reads subscriptions.status:
- Pro:
active,trialing - Not pro:
canceled,unpaid,past_due,incomplete, missing row
Avoid
- Skipping signature verification in production.
- Using Checkout
success_urlalone to setis_pro. - Logging full card or customer PII.
- 4xx on duplicate events (use idempotency — return 200 if already processed).
Checklist
- Raw body +
constructEvent/constructEventAsync stripe_webhook_eventsinsert before side effects- Service role client only inside function
- Test mode vs live mode secrets separated
Templates: examples.md.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

