mcpField
S
stripe-subscription

stripe-subscription

github.com/rebyteai-template开发1768 次安装19 周前更新
代码仓库

关于 stripe-subscription

面向需要订阅付费功能的开发者的 Stripe 集成模板,基于 Express.js 提供 Stripe Checkout 和 Customer Portal。无需配置 webhook,并包含本地启动及 Vercel、Netlify 部署说明。

主要功能

  1. 01通过 Stripe Checkout 创建订阅
  2. 02集成 Customer Portal
  3. 03无需配置 webhook
  4. 04基于 Express.js 构建
  5. 05提供 Vercel 与 Netlify 部署说明

适用场景

  1. 01为应用添加循环订阅付款
  2. 02让客户管理付款方式或取消订阅
  3. 03部署订阅服务到 Vercel 或 Netlify

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/rebyteai-template/rebyte-skills --skill stripe-subscription

安装后在 Claude Code 中输入/stripe-subscription确认已加载。

详细介绍

Stripe Subscription

用于周期性订阅的 Stripe Checkout 集成,带客户门户。无需配置 Webhook。

技术栈

  • 后端:Express.js
  • 支付:Stripe Checkout + Customer Portal
  • 语言:JavaScript
  • 包管理器:npm
  • 端口:4242

设置

1. 克隆模板
git clone --depth 1 https://github.com/Eng0AI/stripe-subscription.git .

如果目录非空:

git clone --depth 1 https://github.com/Eng0AI/stripe-subscription.git _temp_template
mv _temp_template/* _temp_template/.* . 2>/dev/null || true
rm -rf _temp_template
2. 移除 Git 历史记录(可选)
rm -rf .git
git init
3. 安装依赖项
npm install
4. 设置环境变量
cp .env.example .env

必需:

  • STRIPE_SECRET_KEY - 你的 Stripe 密钥(sk_test_xxx)
  • STRIPE_PUBLISHABLE_KEY - 你的 Stripe 可发布密钥(pk_test_xxx)

可选(未设置时会自动创建):

  • BASIC_PRICE - Starter 方案的价格 ID(默认 $12/月)
  • PRO_PRICE - Professional 方案的价格 ID(默认 $18/月)
5. 启动服务
npm start

服务运行于 http://localhost:4242。如果未设置价格 ID,系统会自动创建订阅方案。

部署到 Vercel

第 1 步:创建无服务器 API 包装器

创建 api/index.js,加入 Stripe 订阅逻辑(参见完整部署指南)。

第 2 步:创建 Vercel 配置

创建 vercel.json:

{
  "version": 2,
  "buildCommand": "",
  "outputDirectory": "client/html",
  "rewrites": [
    { "source": "/config", "destination": "/api" },
    { "source": "/checkout-session", "destination": "/api" },
    { "source": "/create-checkout-session", "destination": "/api" },
    { "source": "/customer-portal", "destination": "/api" }
  ]
}
第 3 步:设置环境变量
printf "YOUR_SECRET_KEY" | vercel env add STRIPE_SECRET_KEY production -t $VERCEL_TOKEN
printf "YOUR_PUBLISHABLE_KEY" | vercel env add STRIPE_PUBLISHABLE_KEY production -t $VERCEL_TOKEN
第 4 步:部署
vercel --prod -t $VERCEL_TOKEN --yes

部署到 Netlify

创建 netlify/functions/api.js 和 netlify.toml,并采用类似配置,然后:

netlify deploy --prod

测试

使用以下测试卡号:

  • 成功:4242 4242 4242 4242
  • 拒绝:4000 0000 0000 0002

客户门户配置

上线前,请在 Stripe Dashboard > Settings > Billing > Customer Portal 中进行配置:

  • 启用:更新支付方式、取消订阅、切换方案

正式上线

  1. 将测试密钥替换为正式密钥(sk_live_/pk_live_)
  2. 在 Stripe Dashboard 的正式模式下创建订阅产品
  3. 完成 Stripe 账户验证(KYC)
  4. 为正式模式配置 Customer Portal
  5. 使用真实订阅进行测试

评论

支持 Markdown