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

如何在Stripe中模拟订阅续费支付失败?为何未触发预期事件?

Stripe订阅续费支付失败事件问题解析

为何仅触发invoice.payment_failed而非payment_intent.payment_failed?

Stripe的自动订阅续费流程中,系统默认通过发票自动支付逻辑处理扣款,不会单独生成独立的Payment Intent。这类场景下,支付失败的状态会直接通过invoice.payment_failed事件推送,该事件的payload已包含支付失败原因、关联客户/订阅、重试计划等所有必要信息,足以支撑后端处理续费失败的业务逻辑。

只有当你主动创建Payment Intent来支付发票(比如手动触发支付),或者订阅配置为使用基于Payment Intent的支付流程(如启用payment_behavior: 'default_incomplete'的新订阅模式)时,才会触发payment_intent.payment_failed事件。

正确模拟订阅续费支付失败的步骤

常规场景(仅需invoice.payment_failed)

你当前的操作流程是正确的,只需确认以下几点:

  • 测试卡4000 0000 0000 0341已设为客户默认支付方式
  • 订阅为月度周期,时间推进操作正确触发了续费发票生成
  • Webhook已订阅invoice.payment_failed事件

需要触发payment_intent.payment_failed的场景

若需验证该事件的处理逻辑,可按以下步骤调整:

  1. 切换到基于Payment Intent的订阅流程
    创建订阅时指定payment_behavior: 'default_incomplete',确保后续续费生成Payment Intent:

    // 示例代码(Node.js)
    const subscription = await stripe.subscriptions.create({
      customer: 'cus_xxx',
      items: [{ price: 'price_xxx' }],
      payment_behavior: 'default_incomplete',
      payment_settings: { save_default_payment_method: 'on_subscription' },
    });
    
  2. 手动触发发票支付
    在Stripe Dashboard找到生成的续费发票,点击“尝试支付”,此时系统会创建Payment Intent并尝试扣款,失败后将触发payment_intent.payment_failed。

  3. 使用Stripe CLI模拟
    用CLI推进订阅周期并强制生成Payment Intent:

    stripe subscriptions advance --id sub_xxx --periods 1
    stripe invoices pay --id in_xxx
    
  4. 验证Webhook配置
    确认测试环境的Webhook已订阅payment_intent.payment_failed事件,且端点能正常接收事件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 09:20:14