convex-billing
它能做什么
这个技能把 Stripe 支付连接到 Convex 应用,涵盖结账、记录付款的 webhook,并检查某些功能是否只向付费用户开放。
适用场景
- ✓当你想向 Convex 应用的用户收费时。
- ✓当你需要通过订阅解锁应用中的某些功能时。
- ✓当你希望 Stripe webhook 自动更新应用的付款状态时。
技能链接
https://github.com/openclaw/clawhub/blob/main/.agents/skills/convex-billing/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为我的 Convex 应用添加 Stripe 订阅,让只有付费用户才能使用高级功能。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会安装 Stripe 组件,把你的 Stripe 密钥保存到 Convex 设置中,设置结账操作和 webhook,并添加一项检查,告诉应用某个用户是否有有效订阅。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Add billing / payments
Wire Stripe to Convex using @convex-dev/stripe: a checkout action, an httpAction webhook registered by the component (signature-verified automatically), subscription state stored in the component's tables, and server-side gating via a query.
Workflow
- Install the component:
npm install @convex-dev/stripe. - Create
convex/convex.config.ts:import stripe from "@convex-dev/stripe/convex.config.js"; import { defineApp } from "convex/server"; const app = defineApp(); app.use(stripe); export default app; - Store Stripe keys in Convex env (use the
envmicro power):STRIPE_SECRET_KEY(sk_test_… / sk_live_…) andSTRIPE_WEBHOOK_SECRET(whsec_…). - Create
convex/http.tsto register the webhook route (the component handles signature verification automatically):import { registerRoutes } from "@convex-dev/stripe"; import { httpRouter } from "convex/server"; import { components } from "./_generated/api"; const http = httpRouter(); registerRoutes(http, components.stripe, { webhookPath: "/stripe/webhook" }); export default http; - Create
convex/billing.tswith a checkout action and a subscription-gate query:import { StripeSubscriptions } from "@convex-dev/stripe"; import { v } from "convex/values"; import { components } from "./_generated/api"; import { action, query } from "./_generated/server"; const stripeClient = new StripeSubscriptions(components.stripe, {}); export const createSubscriptionCheckout = action({ args: { priceId: v.string() }, returns: v.object({ sessionId: v.string(), url: v.union(v.string(), v.null()) }), handler: async (ctx, args) => { const identity = await ctx.auth.getUserIdentity(); if (!identity) throw new Error("Not authenticated"); const customer = await stripeClient.getOrCreateCustomer(ctx, { userId: identity.subject, email: identity.email, name: identity.name, }); return await stripeClient.createCheckoutSession(ctx, { priceId: args.priceId, customerId: customer.customerId, mode: "subscription", successUrl: `${process.env.SITE_URL ?? "http://localhost:3000"}/?success=true`, cancelUrl: `${process.env.SITE_URL ?? "http://localhost:3000"}/?canceled=true`, subscriptionMetadata: { userId: identity.subject }, }); }, }); export const isSubscribed = query({ args: {}, returns: v.boolean(), handler: async (ctx) => { const identity = await ctx.auth.getUserIdentity(); if (!identity) return false; const subscriptions = await ctx.runQuery( components.stripe.public.listSubscriptionsByUserId, { userId: identity.subject }, ); return subscriptions.some((sub) => sub.status === "active" || sub.status === "trialing"); }, }); - Run
npx convex dev --once— it will install the component and push the functions. Verify output shows✔ Installed component stripe. - In Stripe Dashboard → Webhooks: add endpoint
https://<deployment>.convex.site/stripe/webhook, subscribe tocheckout.session.completed,customer.subscription.*,invoice.*,payment_intent.*. Copy the signing secret asSTRIPE_WEBHOOK_SECRET.
Rules
- Use @convex-dev/stripe (npm: @convex-dev/stripe@^0.1.4) — it handles webhook signature verification internally via registerRoutes; do NOT write a manual constructEvent webhook.
- Stripe keys live in Convex env (use the
envmicro power): STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET. - Gate on server-stored subscription state via isSubscribed query (reads component tables), not client claims.
- convex/convex.config.ts must import from '@convex-dev/stripe/convex.config.js' (not .ts) — the .js extension is required by the Convex bundler.
常见问题
Stripe 密钥应该放在哪里?
放在 Convex 环境设置中,而不是代码里。测试密钥和正式密钥分开保存。
技能会检查 webhook 消息吗?
会。Stripe 组件会自动检查每条 webhook 的签名。
它也处理一次性付款吗?
这个技能侧重结账和订阅。如果你需要其他付款类型,请检查生成的代码。
详情
作者的原始描述
Add Stripe billing/payments to the Convex app via @convex-dev/stripe (checkout + webhook + gating).
repo: openclaw/clawhub
热度
- GitHub 星标
- 9.5k
- 排名
- #12236
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
axiom-alerting
9.5k帮你的智能体通过 Axiom API 创建和管理监控器与通知路由,并检查告警是否按预期运行。
axiom-sre
9.5k帮你的智能体逐步调查生产事故和缺陷,在得出结论之前,用 Axiom 日志验证每一个猜测。
building-dashboards
9.5k帮你的智能体从仪表盘必须支持的决策出发,设计配有合适图表、查询和筛选器的 Axiom 仪表盘。
controlling-costs
9.5k帮你的智能体在 Axiom 中找出未被使用的数据,并构建用于追踪和削减日志成本的仪表盘与监控器。