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

Stripe测试环境下Node.js SDK无法发送发票邮件的问题咨询

测试模式下Node.js SDK/API触发Stripe发票邮件的解决方案

测试模式下完全可以通过Node.js SDK/API触发发票邮件发送,你的问题大概率是代码参数配置或流程遗漏导致的,以下是具体排查和解决方法:

  • 检查send_invoice参数配置
    通过API创建发票时,必须显式设置send_invoice: true才会触发邮件发送——而Stripe仪表盘操作默认会勾选该选项,这就是你仪表盘能发、SDK调用不行的核心原因之一。
    示例代码:

    const stripe = require('stripe')('你的测试API密钥');
    
    const invoice = await stripe.invoices.create({
      customer: 'cus_xxxxxx',
      collection_method: 'send_invoice',
      days_until_due: 30,
      send_invoice: true, // 关键参数,必须设置为true
      // 发票项等其他配置
    });
    
  • 验证草稿发票的发送流程
    如果你是先创建草稿发票再发送,必须调用stripe.invoices.sendInvoice()方法,仅更新发票状态不会触发邮件逻辑,这个方法对应仪表盘里「发送发票」的操作:

    // 创建草稿发票
    const draftInvoice = await stripe.invoices.create({
      customer: 'cus_xxxxxx',
      collection_method: 'send_invoice',
      days_until_due: 30,
      auto_advance: false, // 保持草稿状态
      // 其他配置
    });
    
    // 触发邮件发送
    const sentInvoice = await stripe.invoices.sendInvoice(draftInvoice.id);
    
  • 确认测试邮箱格式
    Stripe测试模式下,仅特定格式的测试邮箱会实际收到邮件(比如test+customer@example.com这类带加号的邮箱)。如果用了非测试格式邮箱,Stripe会模拟发送但不会投递,你可以在测试模式仪表盘的「日志」里查看邮件触发记录。

  • 核对测试模式邮件设置
    登录测试模式仪表盘,进入「设置」→「账单设置」→「发票邮件」,确认发送发票邮件的选项处于开启状态(仪表盘能发说明大概率是开启的,可排除异常配置)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 04:25:19