stripe-subscription
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStripe Subscription
Stripe 订阅服务
Stripe Checkout integration for recurring subscriptions with Customer Portal. No webhook configuration required.
集成Stripe Checkout实现定期订阅功能,并搭配客户门户。无需配置webhook。
Tech Stack
技术栈
- Backend: Express.js
- Payments: Stripe Checkout + Customer Portal
- Language: JavaScript
- Package Manager: npm
- Port: 4242
- 后端:Express.js
- 支付:Stripe Checkout + 客户门户
- 语言:JavaScript
- 包管理器:npm
- 端口:4242
Setup
安装步骤
1. Clone the Template
1. 克隆模板
bash
git clone --depth 1 https://github.com/Eng0AI/stripe-subscription.git .If the directory is not empty:
bash
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_templatebash
git clone --depth 1 https://github.com/Eng0AI/stripe-subscription.git .如果目录非空:
bash
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_template2. Remove Git History (Optional)
2. 移除Git历史记录(可选)
bash
rm -rf .git
git initbash
rm -rf .git
git init3. Install Dependencies
3. 安装依赖
bash
npm installbash
npm install4. Setup Environment Variables
4. 设置环境变量
bash
cp .env.example .envRequired:
- - Your Stripe secret key (sk_test_xxx)
STRIPE_SECRET_KEY - - Your Stripe publishable key (pk_test_xxx)
STRIPE_PUBLISHABLE_KEY
Optional (auto-created if not set):
- - Price ID for Starter plan ($12/month default)
BASIC_PRICE - - Price ID for Professional plan ($18/month default)
PRO_PRICE
bash
cp .env.example .env必填项:
- - 你的Stripe密钥(sk_test_xxx)
STRIPE_SECRET_KEY - - 你的Stripe可发布密钥(pk_test_xxx)
STRIPE_PUBLISHABLE_KEY
可选项(若未设置则自动创建):
- - 基础套餐的价格ID(默认$12/月)
BASIC_PRICE - - 专业套餐的价格ID(默认$18/月)
PRO_PRICE
5. Start the Server
5. 启动服务器
bash
npm startServer runs at http://localhost:4242. If price IDs are not set, it auto-creates subscription plans.
bash
npm startDeploy to Vercel
部署到Vercel
Step 1: Create Serverless API Wrapper
步骤1:创建Serverless API包装器
Create with the Stripe subscription logic (see full deploy guide).
api/index.js创建并写入Stripe订阅逻辑(详见完整部署指南)。
api/index.jsStep 2: Create Vercel Config
步骤2:创建Vercel配置文件
Create :
vercel.jsonjson
{
"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" }
]
}创建:
vercel.jsonjson
{
"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" }
]
}Step 3: Set Environment Variables
步骤3:设置环境变量
bash
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_TOKENbash
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_TOKENStep 4: Deploy
步骤4:部署
bash
vercel --prod -t $VERCEL_TOKEN --yesbash
vercel --prod -t $VERCEL_TOKEN --yesDeploy to Netlify
部署到Netlify
Create and with similar configuration, then:
netlify/functions/api.jsnetlify.tomlbash
netlify deploy --prod创建和并配置类似内容,然后执行:
netlify/functions/api.jsnetlify.tomlbash
netlify deploy --prodTesting
测试
Use test card numbers:
- Success: 4242 4242 4242 4242
- Decline: 4000 0000 0000 0002
使用测试卡号:
- 支付成功:4242 4242 4242 4242
- 支付失败:4000 0000 0000 0002
Customer Portal Configuration
客户门户配置
Before going live, configure at Stripe Dashboard > Settings > Billing > Customer Portal:
- Enable: Update payment method, Cancel subscription, Switch plans
上线前,请在Stripe控制台 > 设置 > 账单 > 客户门户进行配置:
- 启用:更新支付方式、取消订阅、切换套餐
Going Live
正式上线
- Replace test keys with live keys (sk_live_/pk_live_)
- Create subscription products in Stripe Dashboard Live mode
- Complete Stripe account verification (KYC)
- Configure Customer Portal for live mode
- Test with a real subscription
- 将测试密钥替换为正式密钥(sk_live_/pk_live_)
- 在Stripe控制台正式环境中创建订阅产品
- 完成Stripe账户验证(KYC)
- 配置正式环境的客户门户
- 使用真实订阅进行测试