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

stripe-integration-expert

Skill này làm gì

Skill này khiến agent xây dựng và gỡ lỗi thanh toán Stripe trong ứng dụng web. Skill dành cho lập trình viên thêm đăng ký, thanh toán một lần hoặc tính phí theo mức sử dụng vào các dự án Next.js, Express hoặc Django.

Khi nào nên dùng

  • ✓Khi bạn muốn thêm thanh toán đăng ký có thời gian dùng thử miễn phí vào ứng dụng.
  • ✓Khi bạn cần xử lý các webhook Stripe bị lỗi hoặc đến nhiều hơn một lần.
  • ✓Khi bạn muốn người dùng nâng cấp, hạ cấp hoặc hủy gói của họ.

Liên kết skill

https://github.com/alirezarezvani/claude-skills/blob/main/engineering-team/skills/stripe-integration-expert/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/alirezarezvani/claude-skills/blob/main/engineering-team/skills/stripe-integration-expert/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ý hằng tháng với dùng thử miễn phí 14 ngày vào ứng dụng Next.js của tôi, dùng Stripe checkout.”

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

Cách hoạt động

Agent thiết kế vòng đời đăng ký, thiết lập checkout và cổng khách hàng, rồi viết các trình xử lý webhook an toàn khi được chạy lại. Nó cũng giúp gỡ lỗi các vấn đề phân phát webhook.

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.

Stripe Integration Expert

Tier: POWERFUL
Category: Engineering Team
Domain: Payments / Billing Infrastructure


Overview

Implement production-grade Stripe integrations: subscriptions with trials and proration, one-time payments, usage-based billing, checkout sessions, idempotent webhook handlers, customer portal, and invoicing. Covers Next.js, Express, and Django patterns.


Core Capabilities

  • Subscription lifecycle management (create, upgrade, downgrade, cancel, pause)
  • Trial handling and conversion tracking
  • Proration calculation and credit application
  • Usage-based billing with metered pricing
  • Idempotent webhook handlers with signature verification
  • Customer portal integration
  • Invoice generation and PDF access
  • Full Stripe CLI local testing setup

When to Use

  • Adding subscription billing to any web app
  • Implementing plan upgrades/downgrades with proration
  • Building usage-based or seat-based billing
  • Debugging webhook delivery failures
  • Migrating from one billing model to another

Subscription Lifecycle State Machine

FREE_TRIAL ──paid──► ACTIVE ──cancel──► CANCEL_PENDING ──period_end──► CANCELED
     │                  │                                                    │
     │               downgrade                                            reactivate
     │                  ▼                                                    │
     │             DOWNGRADING ──period_end──► ACTIVE (lower plan)           │
     │                                                                        │
     └──trial_end without payment──► PAST_DUE ──payment_failed 3x──► CANCELED
                                          │
                                     payment_success
                                          │
                                          ▼
                                        ACTIVE

DB subscription status values:

trialing | active | past_due | canceled | cancel_pending | paused | unpaid


Stripe Client Setup

// lib/stripe.ts
import Stripe from "stripe"

export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
  apiVersion: "2024-04-10",
  typescript: true,
  appInfo: {
    name: "myapp",
    version: "1.0.0",
  },
})

// Price IDs by plan (set in env)
export const PLANS = {
  starter: {
    monthly: process.env.STRIPE_STARTER_MONTHLY_PRICE_ID!,
    yearly: process.env.STRIPE_STARTER_YEARLY_PRICE_ID!,
    features: ["5 projects", "10k events"],
  },
  pro: {
    monthly: process.env.STRIPE_PRO_MONTHLY_PRICE_ID!,
    yearly: process.env.STRIPE_PRO_YEARLY_PRICE_ID!,
    features: ["Unlimited projects", "1M events"],
  },
} as const

Checkout Session (Next.js App Router)

// app/api/billing/checkout/route.ts
import { NextResponse } from "next/server"
import { stripe } from "@/lib/stripe"
import { getAuthUser } from "@/lib/auth"
import { db } from "@/lib/db"

export async function POST(req: Request) {
  const user = await getAuthUser()
  if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 })

  const { priceId, interval = "monthly" } = await req.json()

  // Get or create Stripe customer
  let stripeCustomerId = user.stripeCustomerId
  if (!stripeCustomerId) {
    const customer = await stripe.customers.create({
      email: user.email,
      name: "username-undefined"
      metadata: { userId: user.id },
    })
    stripeCustomerId = customer.id
    await db.user.update({ where: { id: user.id }, data: { stripeCustomerId } })
  }

  const session = await stripe.checkout.sessions.create({
    customer: stripeCustomerId,
    mode: "subscription",
    payment_method_types: ["card"],
    line_items: [{ price: priceId, quantity: 1 }],
    allow_promotion_codes: true,
    subscription_data: {
      trial_period_days: user.hasHadTrial ? undefined : 14,
      metadata: { userId: user.id },
    },
    success_url: `${process.env.NEXT_PUBLIC_APP_URL}/dashboard?session_id={CHECKOUT_SESSION_ID}`,
    cancel_url: `${process.env.NEXT_PUBLIC_APP_URL}/pricing`,
    metadata: { userId: user.id },
  })

  return NextResponse.json({ url: session.url })
}

Subscription Upgrade/Downgrade

// lib/billing.ts
export async function changeSubscriptionPlan(
  subscriptionId: string,
  newPriceId: string,
  immediate = false
) {
  const subscription = await stripe.subscriptions.retrieve(subscriptionId)
  const currentItem = subscription.items.data[0
Câu hỏi thường gặp

Trình xử lý webhook idempotent là gì?

Đó là trình xử lý cho ra cùng một kết quả ngay cả khi Stripe gửi cùng một sự kiện nhiều lần.

Skill có xử lý phân bổ theo thời gian (proration) khi gói thay đổi không?

Có. Skill bao gồm các phép tính phân bổ và tín dụng khi người dùng nâng cấp hoặc hạ cấp.

Tôi có thể thử thanh toán ở máy cục bộ không?

Có. Skill có thiết lập Stripe CLI để kiểm thử cục bộ.

Chi tiết

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

Use for any Stripe integration: subscriptions, trials, proration, checkout, usage billing, webhooks, customer portal or invoicing in Next.js, Express or Django. Writes idempotent webhook handlers and debugs delivery failures.

repo: alirezarezvani/claude-skills

Độ phổ biến

Sao GitHub
29k
Vị trí xếp hạng
#9519
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ự