You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Stripe CLI测试Webhooks集成时强制进入生产模式的问题求助

解决Stripe CLI触发Webhook时提示生产模式下使用测试ID的问题

问题场景

按照Stripe Webhooks快速入门步骤搭建本地测试环境,执行stripe trigger charge.dispute.created触发事件时,出现400错误:

Trigger failed: Request failed, status=400, body={
"error": {
"message": "You cannot use the test ID 'pm_card_createDisputeInquiry' in livemode. If you are testing your integration, please use your testmode API keys instead.",
"param": "payment_method",
"request_log_url": "https://dashboard.stripe.com/logs/req_IF0F0YgB7954el?t=1722687021",
"type": "invalid_request_error"
}
}

即使在stripe login和stripe listen中添加--api-key指定测试密钥,问题依旧,且Stripe控制台显示CLI处于生产模式。

解决方案

核心是让Stripe CLI彻底切换到测试模式账户,步骤如下:

  1. 注销当前CLI登录状态
stripe logout
  1. 重新登录并绑定测试模式账户
    两种方式二选一:
  • 直接通过测试密钥登录:
stripe login --api-key sk_test_你的测试API密钥
  • 或者运行stripe login,在弹出的浏览器页面中,切换到测试模式账户完成登录(控制台右上角可切换模式)
  1. 重启Webhook监听
stripe listen --forward-to localhost:4242/webhook

(可选:再次添加--api-key sk_test_你的测试密钥确保使用测试模式)

  1. 重新触发事件
stripe trigger charge.dispute.created

补充检查点

  • 登录Stripe控制台,切换到测试模式,在「Webhooks」->「本地监听器」中确认当前CLI监听器已注册在测试环境下
  • 检查CLI配置文件(路径:~/.config/stripe/config.toml),确保api_key字段值为sk_test_开头的测试密钥,若为sk_live_则手动修改

内容的提问来源于stack exchange,提问作者GGirotto

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 03:27:09