1---2name: skill-stripe-integration-23description: Integrate Stripe Checkout, Billing, subscriptions, Customer Portal, invoices, trials, coupons, webhook handling, entitlement sync, and SaaS payment state management.4---56# skill-stripe-integration78## Workflow9101. Inspect existing backend boundaries, env naming, Stripe SDK usage, price/product mapping, subscription tables, and entitlement tables.112. Keep Stripe secret keys and webhook secrets in server-only code. Browser code may only receive publishable keys and backend-created session/portal URLs.123. Create Checkout or Portal sessions on the backend with authenticated actor context and stable metadata.134. Verify webhook signatures with the raw request body before parsing business data.145. Deduplicate events by Stripe event ID and store relevant Stripe IDs for support: customer, checkout session, subscription, invoice, payment intent, price, and product.156. Sync product access from backend subscription/payment state and local entitlement policy, not from the success redirect alone.167. Validate with Stripe test mode, CLI/webhook events, and the project build/typecheck.1718## Guardrails19201. Use official Stripe libraries for webhook signature verification.212. Configure the framework route so the webhook endpoint receives the raw body.223. Listen only to required event types.234. Return a 2xx quickly; move heavy processing to a queue/job when possible.245. Re-fetch critical Stripe objects when event ordering or stale local state matters.256. Keep plan and entitlement rules in local product tables; Stripe prices/products are billing evidence, not the whole access model.267. Never log secret keys, webhook secrets, complete card/payment details, or unnecessary PII.2728## Typical SaaS Events2930- `checkout.session.completed`: first checkout completion and customer/subscription linking.31- `invoice.paid`: renewal succeeded; extend access.32- `invoice.payment_failed`: mark past due or start grace policy.33- `customer.subscription.updated`: sync status, period, cancellation flags, price changes.34- `customer.subscription.deleted`: revoke or expire access according to policy.3536## Data Contract3738- Map internal plans to Stripe price IDs per environment.39- Store Stripe IDs on server records, not as frontend-only state.40- Track subscription status, current period, cancellation flags, trial dates, grace policy, and last sync timestamp.41- Add audit logs for plan changes, portal cancellations, payment failures, refunds, and admin overrides.4243## Verification4445- Use Stripe test mode and CLI/webhook test events.46- Confirm webhook route is HTTPS in production.47- Confirm live mode uses live price IDs, live keys, and live webhook endpoint secret.48- Check dashboard event deliveries before assuming frontend checkout failed.49- Verify duplicate events do not duplicate payments, extend access twice, or create duplicate audit rows.50