共享 Stripe 客户端和单一的幂等、验签 Webhook 端点,将事件分发给各模块
代码8 个文件上下文约 545 个 tokenMCP stripe扫描通过
安装
$
genpm add @core/stripe你将获得
- 源代码位于 src/lib/stripe/,共 8 个文件。 (7.8 kB)
- AI 规则位于 src/lib/stripe/AGENTS.md,另附 IDE 规则文件。
- 添加到 .env.example 的环境变量:STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET。
- 自动为你解析 @core/db。
README
此包没有 README。
约 545 个 token→ src/lib/stripe/AGENTS.md→ .cursor/rules/genpm-core-stripe.mdc
这正是你的 AI 在 src/lib/stripe 中工作时读取的内容。不会向其上下文添加其他任何内容。
@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.
应用 .genpmignore 后将被注入的确切目录树。固定于
// Tablas de @core/stripe. Las recoge drizzle-kit vía src/lib/db/drizzle.config.ts.
// Misma tabla que tenía @core/billing 1.x: al pasar a billing 2.0 no hay migración de datos.
import { pgTable, text, timestamp } from 'drizzle-orm/pg-core';
/** Idempotencia: cada evento de Stripe se procesa una sola vez aunque llegue repetido. */
export const stripeEvents = pgTable('stripe_events', {
id: text('id').primaryKey(),
type: text('type').notNull(),
processedAt: timestamp('processed_at', { withTimezone: true, mode: 'date' }).notNull().defaultNow(),
});
- 服务器
- stripe
- 命令
- npx -y @stripe/mcp
- env
- STRIPE_SECRET_KEY
| 版本 | 提交 | 发布时间 | 扫描 |
|---|---|---|---|
| 1.0.0 | 43dfe91 | 8小时前 | 扫描通过 |
- genpm
- @core/db ^1.0.0
- 建议
- GenPM 会给出 npm 命令建议,只有你同意时才会运行。
- 扫描
- 扫描通过 · 0 个问题
- 提交
- v1.0.0 → 43dfe91b82752ce063e8399b4af8446da14236c1 · 获取后已校验
- 脚本
- 无。GenPM 从不运行包中的代码。
- 许可证
- MIT
- 质量
- 100/100
- 可识别的许可证已满足
- AGENTS.md 说明了用途已满足
- AGENTS.md 包含集成步骤已满足
- AGENTS.md 列出约定或禁止事项已满足
- 包含测试已满足
- 通过安全扫描已满足
- 最近 6 个月内发布已满足
- 已验证的发布者已满足
- 摘要和关键词已满足
- 举报
- 发现问题了吗?