Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)9.5k · #12236

convex-billing

Skill này làm gì

Skill này kết nối thanh toán Stripe với app Convex. Nó bao gồm trang thanh toán, webhook ghi nhận giao dịch và kiểm tra để chỉ người trả phí mới dùng được một số tính năng nhất định.

Khi nào nên dùng

  • ✓Khi bạn muốn thu tiền từ khách hàng của app Convex.
  • ✓Khi bạn cần gói đăng ký để mở khóa một số tính năng trong app.
  • ✓Khi bạn muốn webhook của Stripe tự động cập nhật trạng thái thanh toán của app.

Liên kết skill

https://github.com/openclaw/clawhub/blob/main/.agents/skills/convex-billing/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/openclaw/clawhub/blob/main/.agents/skills/convex-billing/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Thêm gói đăng ký Stripe vào app Convex của tôi để chỉ người trả phí mới dùng được tính năng cao cấp.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent cài component Stripe, lưu khóa Stripe trong cài đặt Convex, thiết lập một action thanh toán và một webhook, rồi thêm kiểm tra để app biết người dùng có gói đăng ký đang hoạt động hay không.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

<!-- 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.
Câu hỏi thường gặp

Khóa Stripe được lưu ở đâu?

Trong cài đặt môi trường của Convex, không để trong code. Khóa thử nghiệm và khóa thật được tách riêng.

Skill có kiểm tra tin nhắn webhook không?

Có. Component Stripe tự động kiểm tra chữ ký của mỗi webhook.

Skill có xử lý thanh toán một lần không?

Skill tập trung vào thanh toán và gói đăng ký. Hãy xem lại code được tạo ra nếu bạn cần loại thanh toán khác.

Chi tiết

Mô tả gốc của tác giả

Add Stripe billing/payments to the Convex app via @convex-dev/stripe (checkout + webhook + gating).

repo: openclaw/clawhub

Độ phổ biến

Sao GitHub
9.5k
Vị trí xếp hạng
#12236
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự