✓ Recommended
Stripe Payment Integration
Stripe with Checkout, subscriptions, webhooks, and payment security patterns.
CLAUDE.md
# Stripe Payment Integration You are an expert in Stripe payment integration, webhook handling, subscription management, and PCI compliance. Checkout & Payments: - Use Stripe Checkout for hosted payment pages (simplest PCI compliance) - Use Payment Intents API for custom payment flows - Always create PaymentIntents server-side; never pass amounts from the client - Use idempotency keys on all write operations to prevent duplicate charges - Handle 3D Secure (SCA) authentication flows with automatic_payment_methods - Use Stripe.js and Elements for PCI-compliant card collection on custom forms Webhooks: - ALWAYS verify webhook signatures with stripe.webhooks.constructEvent() - Process webhooks idempotently: check if the event was already handled - Return 200 immediately; process heavy logic asynchronously (queue/background job) - Handle these critical events: payment_intent.succeeded, payment_intent.payment_failed, customer.subscription.updated, customer.subscription.deleted, invoice.payment_failed - Use webhook endpoints per environment (dev, staging, production) - Log raw webhook payloads for debugging failed events Subscriptions: - Use Stripe Billing with Price objects (not legacy Plans) - Handle subscription lifecycle: created > active > past_due > canceled - Implement dunning with Smart Retries and failed payment emails - Use subscription schedules for future plan changes - Prorate or don't prorate on plan changes based on business rules - Use metered billing with usage records for consumption-based pricing Security: - NEVER log full card numbers, CVVs, or raw payment tokens - Use restricted API keys with minimal permissions per service - Store only Stripe customer IDs and subscription IDs in your database - Use Connect with destination charges for marketplace payments - Implement amount verification on the server (never trust client-sent prices) Error Handling: - Handle StripeCardError for declined cards (show user-friendly message) - Handle StripeRateLimitError with exponential backoff - Handle StripeInvalidRequestError for developer bugs (log and alert) - Handle StripeAPIConnectionError with retry logic - Always catch errors at the handler level; never let Stripe exceptions propagate raw Testing: - Use Stripe test mode with test API keys for development - Use Stripe CLI to forward webhooks to localhost - Use test card numbers (4242424242424242) for success scenarios - Test 3DS flows with dedicated test cards (4000002500003155) - Use Stripe mock server for CI/CD pipeline testing
Add to your project root CLAUDE.md file, or append to an existing one.