本文へスキップ
Skillpedia
APIとサーバー(バックエンド)9.5k · #12236

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に貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/openclaw/clawhub/blob/main/.agents/skills/convex-billing/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“ConvexのアプリにStripeのサブスクリプションを加えて、有料ユーザーだけがプレミアム機能を使えるようにしてください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントは、Stripeのコンポーネントを入れ、StripeのキーをConvexの環境設定に保存し、チェックアウトのアクションとwebhookを設定し、ユーザーに有効なサブスクリプションがあるかをアプリに伝えるチェックを加えます。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

<!-- GENERATED from convex-agents content/capabilities/billing.json — do not edit by hand. -->

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

  1. Install the component: npm install @convex-dev/stripe.
  2. 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;
    
  3. Store Stripe keys in Convex env (use the env micro power): STRIPE_SECRET_KEY (sk_test_… / sk_live_…) and STRIPE_WEBHOOK_SECRET (whsec_…).
  4. Create convex/http.ts to 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;
    
  5. Create convex/billing.ts with 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");
      },
    });
    
  6. Run npx convex dev --once — it will install the component and push the functions. Verify output shows ✔ Installed component stripe.
  7. In Stripe Dashboard → Webhooks: add endpoint https://<deployment>.convex.site/stripe/webhook, subscribe to checkout.session.completed, customer.subscription.*, invoice.*, payment_intent.*. Copy the signing secret as STRIPE_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 env micro 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

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル