Code & Dev Compatible: claude

Idempotent Stripe Webhook Handler

Complexity Level: Beginner
Prompt Code Block

Specify a production Stripe webhook handler that stays correct when Stripe retries, events arrive out of order, and the handler crashes halfway. STACK Runtime: [NODE | PYTHON | GO] Framework: [NEXT.JS ROUTE | EXPRESS | FASTAPI | HONO] Database: [POSTGRES] Events we care about: [checkout.session.completed, customer.subscription.updated, customer.subscription.deleted, invoice.paid, invoice.payment_failed — edit this list] What each event must change in our DB: [MAP EVENT → TABLES] Signature secret env var: [NAME] DELIVER 1) Route contract: raw body required for signature verification, which parsers will break it, and the exact rejection codes (400 vs 401 vs 500) and why 500 is the one Stripe should retry. 2) Verification steps with the Stripe library call, tolerance window, and what we log on failure (never the payload secrets). 3) Idempotency design: a processed_events table (event id primary key, type, created_at, status) and the insert-first pattern that makes a retry a no-op. Show the SQL, including the unique conflict path. 4) Ordering: how we handle an updated event that arrives before created, using Stripe object status as the source of truth rather than event arrival order. 5) The DB transaction boundary: what is inside the transaction with the event row, and which side effects (email, analytics) happen after commit and how they retry without double-granting entitlements. 6) A table of 6 failure cases and the expected outcome: duplicate delivery, signature mismatch, unknown event type, partial failure after commit, clock skew, subscription canceled then a late invoice.paid. 7) Local test recipe: Stripe CLI command shape and 3 fixtures to assert. Do not tell me to trust the client for plan state. Entitlements change only from verified events or a server-side Stripe API read.

🌟 Example Output / Preview

### Generated Component Preview: ```typescript // Fully validated modern structure import { z } from 'zod'; export const RequestSchema = z.object({ id: z.string().uuid(), createdAt: z.date().default(() => new Date()), data: z.record(z.string(), z.any()) }); export type ValidatedRequest = z.infer<typeof RequestSchema>; ```

Prompt Metadata

DifficultyBeginner
Compatibilityclaude

Primary Use Cases:

  • •Legacy code modernization & technical refactoring
  • •Full-stack layout generation & component structuring
  • •CI/CD workflow automation & unit/E2E testing suites

Associated Tags:

#stripe #webhook #api #payments

💡 Pro Tips & Advice

1. Use bracketed items: Be sure to fill out all [PLACEHOLDER] elements with specific details before sending the prompt to the AI model.

2. Adjust temperature: For creative tasks, set AI temperature higher (e.g., 0.8), or lower (e.g., 0.2) for strict coding/technical tasks.

🔗 Related AI Prompts

Code & Dev
★ Featured

Full SaaS Landing Page Build Spec (SEO + Conversion)

You are a Staff Product Designer + Frontend Engineer + SEO strategist. Build a complete, production-ready marketing landing page f...

Compatible:claudeDiff:Advanced
#landing-page #saas #seo #nextjs #tailwind
Code & Dev
★ Featured 🔥 Trending

SaaS Analytics Dashboard Full Build Spec

You are a Principal Product Designer + Frontend Lead. Design and specify a complete [LIGHT | DARK] analytics dashboard for [PRODUC...

Compatible:claudeDiff:Intermediate
#dashboard #saas #ui #tailwind #seo
Code & Dev

SaaS Admin Panel Dashboard Build Spec

Design a full internal Admin Dashboard for [PRODUCT_NAME] used by [ADMIN_ROLE: support | ops | super-admin]. --- 🎯 CONTEXT Adm...

Compatible:claudeDiff:Intermediate
#admin #dashboard #saas #crud #tailwind