safe-agentic-workflow / rules
Cursor rule419 starsChanged 4 months agoMITView on GitHub
Stripe payment integration: webhooks, checkout sessions, subscriptions, idempotency, test mode safety.
- Reads credentials
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,531 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository60 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/00-core-principles.mdcCursor rule
- .cursor/rules/01-git-workflow.mdcCursor rule
- .cursor/rules/02-pattern-discovery.mdcCursor rule
- .cursor/rules/03-safe-ai-dlc.mdcCursor rule
- .cursor/rules/04-knowledge-vault.mdcCursor rule
- .cursor/rules/10-backend-python.mdcCursor rule
- .cursor/rules/11-frontend-react.mdcCursor rule
- .cursor/rules/12-database-sql.mdcCursor rule
- .cursor/rules/13-testing.mdcCursor rule
- .cursor/rules/14-spec-creation.mdcCursor rule
- .cursor/rules/15-deployment.mdcCursor rule
- .cursor/rules/20-agent-architect.mdcCursor rule
- .cursor/rules/21-agent-backend.mdcCursor rule
- .cursor/rules/22-agent-qas.mdcCursor rule
- .cursor/rules/23-agent-security.mdcCursor rule
- .cursor/rules/30-background-agents.mdcCursor rule
- .cursor/rules/31-mcp-integration.mdcCursor rule
- .cursor/rules/README.mdCursor rule
- agent-coordinationSkill
- api-patternsSkill
- confluence-docsSkill
- deployment-sopSkill
- frontend-patternsSkill
- git-advancedSkill
- linear-sopSkill
- migration-patternsSkill
- orchestration-patternsSkill
- pattern-discoverySkill
- release-patternsSkill
- rls-patternsSkill
- safe-ai-dlcSkill
- safe-workflowSkill
- security-auditSkill
- spec-creationSkill
- stripe-patternsSkill
- team-coordinationSkill
- testing-patternsSkill
- vault-syncSkill
- agent-coordinationSkill
- api-patternsSkill
- confluence-docsSkill
- deployment-sopSkill
- frontend-patternsSkill
- git-advancedSkill
- linear-sopSkill
- migration-patternsSkill
- orchestration-patternsSkill
- pattern-discoverySkill
- release-patternsSkill
- rls-patternsSkill
- safe-ai-dlcSkill
- safe-workflowSkill
- security-auditSkill
- spec-creationSkill
- stripe-patternsSkill
- team-coordinationSkill
- testing-patternsSkill
- vault-syncSkill
The file
We split this 16-stripe-payments.mdc into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 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.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
Before ANY payment work:
- Distinctive: line 22
ALWAYS: verify webhook signatures and handle idempotency:
- Distinctive: line 73
Use the Stripe CLI to forward events locally:
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule 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
---
description: "Stripe payment integration: webhooks, checkout sessions, subscriptions, idempotency, test mode safety."
globs: "core/**/billing/**,core/**/payments/**,core/**/stripe/**,**/webhook*stripe*"
alwaysApply: false
---
# Stripe Payment Rules
These rules apply when working on Stripe payment integration, webhooks, checkout flows, or subscription management.
## Test Mode Safety (CHECK FIRST)
Before ANY payment work:
- [ ] Verify `STRIPE_SECRET_KEY` starts with `sk_test_`
- [ ] Confirm test webhook secret (`whsec_...` from Stripe CLI)
- [ ] Use test card numbers only (4242 4242 4242 4242)
- [ ] Never use production keys in development
## Webhook Handler Pattern
**ALWAYS** verify webhook signatures and handle idempotency:
```python
import stripe
from fastapi import Request, HTTPException
async def handle_stripe_webhook(request: Request):
payload = await request.body()
signature = request.headers.get("stripe-signature")
try:
event = stripe.Webhook.construct_event(
payload, signature, settings.STRIPE_WEBHOOK_SECRET
)
except stripe.error.SignatureVerificationError:
raise HTTPException(status_code=400, detail="Invalid signature")
# Idempotency: check if event already processed
existing = await get_webhook_event(event.id)
if existing:
return {"status": "already_processed"}
# Process event and record
await process_event(event)
await record_webhook_event(event.id, event.type)
return {"status": "processed"}
```
## Idempotency Checklist
For ALL webhook handlers:
- [ ] Store event ID before processing
- [ ] Check for duplicate events before processing
- [ ] Use database transactions for atomicity
- [ ] Return 200 OK even on idempotency skip (Stripe retries on non-200)
## Common Webhook Events
```python
SUBSCRIPTION_EVENTS = [
"customer.subscription.created",
"customer.subscription.updated",
"customer.subscription.deleted",
"invoice.payment_succeeded",
"invoice.payment_failed",
]
```
## Local Webhook Testing
Use the Stripe CLI to forward events locally:
```bash
# Start webhook forwarding
stripe listen --forward-to localhost:8000/api/v1/webhooks/stripe
# Trigger test events
stripe trigger checkout.session.completed
stripe trigger invoice.payment_succeeded
stripe trigger customer.subscription.deleted
```
## FORBIDDEN
- Hardcoding API keys (use environment variables)
- Skipping webhook signature verification
- Processing webhooks without idempotency checks
- Using production Stripe keys in development or CI
- Ignoring failed payment events (always handle `invoice.payment_failed`)
## Evidence Template for Linear
Attach this after completing payment work:
```markdown
**Payment Testing Evidence**
- [ ] Test mode verified (`sk_test_` key)
- [ ] Webhook signature verification tested
- [ ] Idempotency tested (duplicate event handling)
- [ ] Success flow tested (card 4242...)
- [ ] Failure flow tested (card 4000 0000 0000 0002)
- [ ] Subscription lifecycle tested (create/update/cancel)
**Test Results:**
- Webhook events processed: {count}
- All flows: PASSED
```
## Key References
- **Stripe Docs**: https://stripe.com/docs
- **Webhook best practices**: https://stripe.com/docs/webhooks/best-practices
- **Payment patterns**: `patterns_library/` (search for payment/billing patterns)
- **Full skill docs**: `.claude/skills/stripe-patterns/SKILL.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.

