Gemeinsamer Stripe-Client und ein idempotenter, signaturgeprüfter Webhook, der Events an alle Module verteilt
Installieren
genpm add @core/stripeWas du bekommst
- Quellcode in src/lib/stripe/, 8 Dateien. (7,8 kB)
- KI-Regeln in src/lib/stripe/AGENTS.md, dazu Regeldateien für die IDE.
- Umgebungsvariablen in .env.example ergänzt: STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET.
- Löst @core/db für dich auf.
README
Dieses Paket hat keine README.
Genau das liest deine KI, wenn sie in src/lib/stripe arbeitet. Sonst wird ihrem Kontext nichts hinzugefügt.
@core/stripe — rules for AI agents
Purpose
The single Stripe integration point of the app: a lazily created client (getStripe) and ONE webhook endpoint that
verifies the signature, records each event in stripe_events (idempotency) and dispatches it, inside one database
transaction, to the handlers that modules register with onStripeEvent (@core/billing 2.x, @core/checkout…).
If a handler throws, everything rolls back and Stripe retries. No business logic here.
Map
index.ts— public API:getStripe,setStripe,onStripeEvent,handleStripeWebhook,stripeEvents.webhooks.ts— verification, idempotency and dispatch.client.ts— client.schema.ts—stripe_events.adapters/hono.ts—stripeWebhookRoutes().adapters/next.ts—stripeWebhookRoute.
Integration
- Env:
STRIPE_SECRET_KEYandSTRIPE_WEBHOOK_SECRET(whsec_…). Migrations as insrc/lib/db/AGENTS.md. - Mount the endpoint: Hono
app.route('/api/stripe/webhook', stripeWebhookRoutes()); Next.jsapp/api/stripe/webhook/route.ts→export { stripeWebhookRoute as POST } from '@/lib/stripe/adapters/next'. - In Stripe, create one webhook endpoint
<origin>/api/stripe/webhookwith the events the installed modules list in their AGENTS.md. Locally:stripe listen --forward-to localhost:3000/api/stripe/webhook. - Import the modules that register handlers at startup (their
index.tsregisters them on import). - Verify:
stripe trigger checkout.session.completedreturns 200 and a row appears instripe_events. - Optional MCP: with consent, the agent can use Stripe's MCP server to look up products and prices in test mode.
Conventions
- Handlers write only through the
txthey receive and must be idempotent. - Read the current object from the API when order matters (events can arrive out of order).
- @core/billing 1.x also defines
stripe_events; upgrade it to 2.x before installing this module.
Don't
- Don't create more webhook endpoints or call
constructEventelsewhere. - Don't parse the webhook body as JSON before verification; the signature covers the raw bytes.
- Don't log full event payloads, card data or keys.
# @core/stripe — rules for AI agents
## Purpose
The single Stripe integration point of the app: a lazily created client (`getStripe`) and ONE webhook endpoint that
verifies the signature, records each event in `stripe_events` (idempotency) and dispatches it, inside one database
transaction, to the handlers that modules register with `onStripeEvent` (@core/billing 2.x, @core/checkout…).
If a handler throws, everything rolls back and Stripe retries. No business logic here.
## Map
- `index.ts` — public API: `getStripe`, `setStripe`, `onStripeEvent`, `handleStripeWebhook`, `stripeEvents`.
- `webhooks.ts` — verification, idempotency and dispatch. `client.ts` — client. `schema.ts` — `stripe_events`.
- `adapters/hono.ts` — `stripeWebhookRoutes()`. `adapters/next.ts` — `stripeWebhookRoute`.
## Integration
1. Env: `STRIPE_SECRET_KEY` and `STRIPE_WEBHOOK_SECRET` (`whsec_…`). Migrations as in `src/lib/db/AGENTS.md`.
2. Mount the endpoint: Hono `app.route('/api/stripe/webhook', stripeWebhookRoutes())`; Next.js
`app/api/stripe/webhook/route.ts` → `export { stripeWebhookRoute as POST } from '@/lib/stripe/adapters/next'`.
3. In Stripe, create one webhook endpoint `<origin>/api/stripe/webhook` with the events the installed modules list in
their AGENTS.md. Locally: `stripe listen --forward-to localhost:3000/api/stripe/webhook`.
4. Import the modules that register handlers at startup (their `index.ts` registers them on import).
5. Verify: `stripe trigger checkout.session.completed` returns 200 and a row appears in `stripe_events`.
6. Optional MCP: with consent, the agent can use Stripe's MCP server to look up products and prices in test mode.
## Conventions
- Handlers write only through the `tx` they receive and must be idempotent.
- Read the current object from the API when order matters (events can arrive out of order).
- @core/billing 1.x also defines `stripe_events`; upgrade it to 2.x before installing this module.
## Don't
- Don't create more webhook endpoints or call `constructEvent` elsewhere.
- Don't parse the webhook body as JSON before verification; the signature covers the raw bytes.
- Don't log full event payloads, card data or keys.
Der genaue Baum, der nach .genpmignore eingebunden wird. Gepinnt an
MIT License
Copyright (c) 2026 GenPM
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
- Server
- stripe
- Befehl
- npx -y @stripe/mcp
- env
- STRIPE_SECRET_KEY
| Version | Commit | Veröffentlicht | Prüfung |
|---|---|---|---|
| 1.0.0 | 43dfe91 | vor 8 Stunden | Prüfung bestanden |
- genpm
- @core/db ^1.0.0
- vorgeschlagen
- GenPM schlägt den npm-Befehl vor und führt ihn nur aus, wenn du zustimmst.
- Verwendet von (2)
- @core/billing ^1.0.0@core/checkout ^1.0.0
- Prüfung
- Prüfung bestanden · 0 Befunde
- Commit
- v1.0.0 → 43dfe91b82752ce063e8399b4af8446da14236c1 · nach dem Abruf verifiziert
- Skripte
- Keine. GenPM führt niemals Paketcode aus.
- Lizenz
- MIT
- Qualität
- 100/100
- Anerkannte Lizenzerfüllt
- AGENTS.md erklärt den Zweckerfüllt
- AGENTS.md enthält Integrationsschritteerfüllt
- AGENTS.md nennt Konventionen oder Verboteerfüllt
- Enthält Testserfüllt
- Sicherheitsscan bestandenerfüllt
- In den letzten 6 Monaten veröffentlichterfüllt
- Verifizierter Herausgebererfüllt
- Zusammenfassung und Schlagwörtererfüllt
- Meldung
- Stimmt etwas nicht?