用途:Stripe CLI 是 Stripe 官方命令行工具,用于在终端管理 Stripe 账户资源、在本地测试 Webhook、触发测试事件,替代部分仪表盘操作。
主要能力:支持登录认证、Webhook 转发与事件过滤、触发测试事件、管理客户/支付意图/产品/价格/订阅等资源、实时查看 API 日志、列出与重发事件,以及通过 fixture 文件生成测试数据。
使用方式:认证可用 stripe login 打开浏览器,或用 stripe login --api-key sk_test_xxx 直接指定密钥。Webhook 测试常用 stripe listen --forward-to localhost:3000/webhook,可用 --events 过滤事件;用 stripe trigger payment_intent.succeeded 触发测试事件。资源操作如 stripe customers list --limit 5、stripe payment_intents create --amount 2000 --currency usd。日志与事件可用 stripe logs tail、stripe events list --limit 10、stripe events resend evt_xxx。fixture 用 stripe fixtures path/to/fixture.json。
适用场景:本地开发调试支付、订阅与 Webhook 处理逻辑,排查 API 问题,自动化测试数据准备。
限制与建议:代理操作应始终使用测试模式密钥(sk_test_*);可用 --json 或 jq 获取结构化输出;stripe listen 为长驻进程,需后台运行。官方仓库 https://github.com/stripe/stripe-cli,文档 https://docs.stripe.com/stripe-cli。