Integrations

Stripe

配置 Stripe 进行计费、订阅和客户计费门户管理。

前提条件

  • 已安装 Stripe CLI:npm install -g stripe

第一步:设置环境变量

STRIPE_SECRET_KEY=sk_live_xxxxxxxxxxxxxxxxxxxx
STRIPE_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxxxxxx

开发时使用 sk_test_ 密钥。

第二步:在 Stripe 中创建产品

# 创建产品
stripe products create --name="Nebutra PRO"

# 创建价格
stripe prices create \
  --product=prod_xxx \
  --unit-amount=2900 \
  --currency=usd \
  --recurring[interval]=month

第三步:配置 Webhook 端点

在 Stripe 仪表板:开发者 → Webhooks → 添加端点

  • URL:https://api.nebutra.com/api/webhooks/stripe
  • 监听的事件:
    • checkout.session.completed
    • customer.subscription.updated
    • customer.subscription.deleted
    • invoice.paid
    • invoice.payment_failed

本地测试 Webhook

stripe listen --forward-to localhost:3000/api/webhooks/stripe

Stripe 测试卡

卡号场景
4242 4242 4242 4242支付成功
4000 0000 0000 9995余额不足
4000 0025 0000 31553D Secure 认证

使用任意未来到期日和任意 3 位 CVC。

相关文档

How is this guide?

目录