Skip to content

测试月度计划变更

1. 启动 Stripe CLI 转发 Webhook

bash
stripe listen --forward-to localhost:3000/api/auth/stripe/webhook

复制它打印的 whsec_... 密钥,并将其设置为 .env 中的 STRIPE_WEBHOOK_SECRET

2. 使用 Stripe 测试卡

场景卡号
支付成功4242 4242 4242 4242
卡被拒绝4000 0000 0000 0002
余额不足4000 0000 0000 9995

使用任意未来日期的有效期(如 12/34)和任意 3 位 CVC。

3. 测试流程

订阅(Free → Gold/Diamond)

  1. 转到 /membership
  2. 点击某个计划上的订阅 → 重定向到 Stripe Checkout
  3. 使用测试卡支付 → webhook checkout.session.completed 触发 → 等级更新、积分发放

升级(Gold → Diamond)

  • 使用 /membership 上的 Manage Billing 按钮 → 打开 Stripe Customer Portal
  • 将计划更改为 Diamond → webhook customer.subscription.updated 触发
  • 升级立即生效,按比例收费(立即收取差额)
  • 发放差额积分(如 24,000 − 4,000 = 20,000 额外积分)

降级(Diamond → Gold)

  • 相同的门户流程 → 降级在计费周期结束时生效(无立即退款)
  • 在计费周期结束前等级保持 Diamond

取消

  • 在门户中取消 → cancel_at_period_end 设为 true,在周期结束前仍可访问
  • 周期结束时 → customer.subscription.deleted 触发 → 等级降为 FREE

恢复已取消的订阅

  • /membership 上点击 "Resume" → 调用 authClient.subscription.restore()

4. 手动触发 Webhook(可选)

bash
stripe trigger customer.subscription.updated
stripe trigger customer.subscription.deleted
stripe trigger invoice.payment_succeeded

5. 验证结果

  • 查看 /membership 页面的更新后的等级和积分余额
  • 查看 /api/v1/membership(GET)的订阅状态和交易历史
  • 查看 Stripe Dashboard(测试模式)的订阅详情

Internal documentation for MysticX team