stripe-integration
Skill1 starsChanged 7 months agoMITView on GitHub
Integrate Stripe end-to-end — Checkout, Customer Portal, subscriptions with proration, webhooks with idempotency, refunds, invoicing, tax. Use when adding Stripe to a Node/Python/Go backend or debugging webhook signature/idempotency issues. Pairs with razorpay-integration for India/SE Asia.
- Reads credentials
11 other projects use a version of this.
Adopted by
Most recently taken up by
- SkillMedev/full-stack-web-devtheir own version, first seen Oct 5, 2026
- Cure-Consulting-Group/ProductEngineeringSkillstheir own version, first seen Sep 28, 2026
- xeroc/skillstheir own version, first seen Jul 17, 2026
- Fandry96/k3-agentic-skillstheir own version, first seen May 12, 2026
- FelipeAngeli/skillstheir own version, first seen Apr 10, 2026
- goodnessibeh/ai-dev-boilerplatetheir own version, first seen Apr 9, 2026
Other versions11 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 11
- kivo360/OmoiOS★ 79same name
- inbharatai/claude-skills★ 37same name
- Fandry96/k3-agentic-skills★ 27same name
- xfstudio/skills★ 9same name
- Cure-Consulting-Group/ProductEngineeringSkills★ 3same name
- ai4brands-design/claude-skills★ 2same name
- CodeWithBehnam/cc-docs★ 2same name
- FelipeAngeli/skills★ 2same name
- goodnessibeh/ai-dev-boilerplate★ 1same name
- SkillMedev/full-stack-web-dev★ 1same name
1 more not listed
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 repository50 other files it gives its agents.
- algolia-searchSkill
- audit-tautological-testsSkill
- blame-archaeologySkill
- brevo-emailSkill
- bun-runtimeSkill
- clerk-authSkill
- cloudflare-workersSkill
- dbt-data-modelingSkill
- explain-this-diffSkill
- extract-skill-from-sessionSkill
- fastapi-productionSkill
- find-dead-codeSkill
- find-real-bugSkill
- gdpr-dpiaSkill
- github-actions-ciSkill
- graphql-relaySkill
- grpc-servicesSkill
- hipaa-auditSkill
- india-dpdp-actSkill
- java-8-to-21Skill
- jest-to-vitestSkill
- kubernetes-helmSkill
- mongo-to-postgresSkill
- nextjs-pages-to-appSkill
- node-version-upgradeSkill
- opentelemetry-instrumentSkill
- pci-dss-checklistSkill
- plan-the-rollbackSkill
- python-2-to-3Skill
- razorpay-integrationSkill
- react-native-expoSkill
- scaffold-cli-toolSkill
- scaffold-fullstack-appSkill
- scaffold-go-microserviceSkill
- scaffold-new-appSkill
- scaffold-saas-starterSkill
- sentry-monitoringSkill
- shrink-this-prSkill
- soc2-evidenceSkill
- spec-from-conversationSkill
- supabase-backendSkill
- terraform-patternsSkill
- threat-modeling-strideSkill
- triage-stack-traceSkill
- wcag-accessibility-auditSkill
- webpack-to-viteSkill
- write-adrSkill
- write-commit-messageSkill
- write-pr-descriptionSkill
- write-runbookSkill
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.
0
Common
Most of the 11 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 34
Critical: never store card details. Use Checkout or Elements.
- Very specific: line 180
Test mode vs live mode keys are visually distinct (sk_test_...
“Common” is measured: kept by at least 6 in 10 of the 11 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Stripe Integration
Stripe's docs are excellent for individual endpoints. This skill is the flow — which endpoints to compose, where the foot-guns are, and how to keep the webhook handler idempotent.
When to use
- Adding Stripe to a global SaaS (US/EU customers).
- Subscription billing with plans, trials, proration.
- Debugging webhook signature failures or duplicate fulfillment.
- Migrating off Razorpay/Paddle to Stripe.
When NOT to use
- India-only —
razorpay-integrationhandles RBI mandates better. - Marketplace with split payouts — use Stripe Connect (different scaffolding).
Core objects
| Object | Purpose |
Customer | Long-lived person/org record |
Product + Price | Catalog. A product has many prices (monthly/annual/currency) |
Subscription | A customer's active recurring purchase of a price |
Invoice | Generated per billing cycle; can be paid, void, or open |
Checkout Session | Hosted payment page; produces a subscription or one-time payment |
Customer Portal | Hosted UI for cancel, update card, view invoices |
Event | Webhook payload for state changes |
Critical: never store card details. Use Checkout or Elements; Stripe holds the PAN.
The 80% flow: Checkout + Customer Portal + webhook
1. Create a Checkout Session
// apps/api/src/routes/checkout.ts
import Stripe from "stripe";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, { apiVersion: "2024-12-18.acacia" });
export async function startCheckout(req, res) {
const { userId, priceId } = req.body;
const user = await db.user.findUnique({ where: { id: userId } });
if (!user) return res.status(404).end();
// Reuse existing Stripe customer if we have one
let customerId = user.stripeCustomerId;
if (!customerId) {
const c = await stripe.customers.create({ email: user.email, metadata: { userId } });
customerId = c.id;
await db.user.update({ where: { id: userId }, data: { stripeCustomerId: customerId } });
}
const session = await stripe.checkout.sessions.create({
mode: "subscription",
customer: customerId,
line_items: [{ price: priceId, quantity: 1 }],
success_url: `${process.env.APP_URL}/billing/success?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${process.env.APP_URL}/billing`,
allow_promotion_codes: true,
automatic_tax: { enabled: true }, // requires Stripe Tax
subscription_data: { metadata: { userId } }, // surfaces in webhook
});
res.json({ url: session.url });
}2. Customer Portal for self-service
export async function openPortal(req, res) {
const user = await db.user.findUnique({ where: { id: req.userId } });
const portal = await stripe.billingPortal.sessions.create({
customer: user.stripeCustomerId,
return_url: `${process.env.APP_URL}/billing`,
});
res.json({ url: portal.url });
}Configure Portal in Dashboard → Settings → Customer Portal: enable cancel, update card, change plan, view invoices. You don't need to build any of this UI.
3. Webhook handler (the source of truth)
import express from "express";
const router = express.Router();
router.post(
"/stripe/webhook",
express.raw({ type: "application/json" }), // raw body!
async (req, res) => {
const sig = req.header("stripe-signature");
let event: Stripe.Event;
try {
event = stripe.webhooks.constructEvent(req.body, sig!, process.env.STRIPE_WEBHOOK_SECRET!);
} catch {
return res.status(400).end();
}
const seen = await db.webhookEvent.findUnique({ where: { id: event.id } });
if (seen) return res.status(200).json({ deduped: true });
await db.$transaction(async (tx) => {
await tx.webhookEvent.create({ data: { id: event.id, type: event.type } });
await handle(event, tx);
});
res.status(200).json({ ok: true });
}
);
async function handle(event: Stripe.Event, tx) {
switch (event.type) {
case "customer.subscription.created":
case "customer.subscription.updated":
await upsertSubscription(tx, event.data.object as Stripe.Subscription);
break;
case "customer.subscription.deleted":
await markSubscriptionCanceled(tx, event.data.object as Stripe.Subscription);
break;
case "invoice.payment_failed":
await flagPaymentFailed(tx, event.data.object as Stripe.Invoice);
break;
case "invoice.payment_succeeded":
await markInvoicePaid(tx, event.data.object as Stripe.Invoice);
break;
}
}The events you actually need (everything else can be ignored at first):
customer.subscription.created/updated/deletedinvoice.payment_succeeded/payment_failedcheckout.session.completed(for one-time payments)
State machine to mirror in your DB
incomplete → trialing → active → past_due → canceled
↓
unpaid (after dunning fails)Drive UI from subscriptions.status in your DB, updated only by webhooks. Don't query Stripe per page load.
Subscription changes (proration)
// Upgrade plan with prorated charge mid-cycle
await stripe.subscriptions.update(subId, {
items: [{ id: subItemId, price: newPriceId }],
proration_behavior: "create_prorations", // default; bills the diff now
});
// Or end-of-period change without proration
await stripe.subscriptions.update(subId, {
items: [{ id: subItemId, price: newPriceId }],
proration_behavior: "none",
billing_cycle_anchor: "unchanged",
});Pick once and document. Mixing creates confusion when customers see weird invoice line items.
Test cards
| Number | Behavior |
4242 4242 4242 4242 | Always succeeds |
4000 0027 6000 3184 | Requires 3DS authentication |
4000 0000 0000 9995 | Insufficient funds (decline) |
4000 0000 0000 0341 | Charge succeeds, attached card later fails |
Test mode vs live mode keys are visually distinct (sk_test_... vs sk_live_...). Wrap creation in a check at boot:
if (process.env.NODE_ENV === "production" && !process.env.STRIPE_SECRET_KEY?.startsWith("sk_live_")) {
throw new Error("Production env using test Stripe key — refusing to start");
}Anti-patterns
- Trusting client-side
priceId— server must verify the price the user selected is one of the offered plans (e.g. enum or DB lookup), not free-form. - JSON-parsing webhook before signature verification —
express.json()middleware will run first if not carved out. Useexpress.raw()on this route only. - Fulfilling on
checkout.session.completedredirect callback — browser can die. Webhook is canonical. - No idempotency on webhook handler — Stripe retries on 5xx; without
event.iddedup, you'll double-fulfill. - Storing subscription state by querying Stripe per request — slow, hits API limits, and Stripe is eventually consistent. Mirror in your DB.
- One Stripe account for prod + staging — staging emails and charges leak. Use separate accounts.
- Per-user
priceIdin DB — Stripe's price IDs are environment-scoped. Sync prod and staging price IDs by name/lookup_key, not by ID. - Custom retry/dunning logic in your code — Stripe Smart Retries handles this; configure in dashboard, don't reinvent.
- Hardcoding tax rates — Stripe Tax handles 70+ jurisdictions. Enable
automatic_tax: { enabled: true }. - Fetching
event.data.objectand assuming it's still current — Stripe events can be delayed. Re-fetch the object via API if you need latest state.
Verify it worked
- Test card
4242...produces a successful subscription; row in your DB hasstatus: 'active'. - Tampered webhook body is rejected (signature check works).
- Replaying same
event.idtwice → only one fulfillment. - Customer Portal link opens with cancel + update card + change plan; no custom UI built.
customer.subscription.deletedwebhook updates DB tocanceled.- Failed payment (
4000 0000 0000 9995) triggersinvoice.payment_failed→ DBpast_due. - Production env refuses to boot with
sk_test_key. stripeCustomerIdis on the user row before any subscription is created.- Stripe Tax shows tax on test invoice for an EU customer.
- Prod + staging are separate Stripe accounts (different
STRIPE_SECRET_KEY).
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.

