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

如何使用Stripe CLI在invoice.paid事件中指定客户ID并测试

解决Stripe CLI测试invoice.paid时指定自定义客户ID的问题

核心原因

你之前的命令无效,是因为stripe trigger invoice.paid默认会自动创建新的订阅和关联客户,直接指定invoice:customer会被CLI自动生成的资源覆盖。发票的客户字段是从关联的订阅继承的,所以需要指定订阅关联的客户。

正确操作步骤

1. 确保测试环境存在目标客户

如果目标客户ID(cus_xxxxxxxxxxxxx)还没在测试环境中创建,先执行以下命令创建:

stripe customers create --email test@yourdomain.com --description "Test Target Customer"

执行后会返回包含客户ID的结果,确认是你需要的cus_xxx。

2. 使用正确的trigger命令指定客户

执行以下命令,通过指定订阅的客户,让生成的发票关联到目标客户:

stripe trigger invoice.paid --add subscription:customer=cus_xxxxxxxxxxxxx

3. 验证Webhook中的客户ID

触发事件后,你的本地Webhook接收端会收到invoice.paid事件,查看事件数据中的data.object.customer字段,应该就是你指定的cus_xxxxxxxxxxxxx。

备选方案:手动创建发票并触发支付

如果需要更精准的控制,可以手动创建发票并触发支付:

  1. 创建关联目标客户的发票:
stripe invoices create --customer cus_xxxxxxxxxxxxx --collection_method charge_automatically
  1. 支付该发票:
stripe invoices pay <INVOICE_ID>

此时Stripe会自动发送invoice.paid事件到你的Webhook,其中的客户ID就是指定的目标ID。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 03:27:39