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

配置应用使用指定.NET版本后,为何仍收到Stripe版本不匹配报错?

中文提问

我在运行应用调用Stripe接口时持续收到报错,我的.NET包版本是:

<PackageReference Include="Stripe.net" Version="44.0.0" />

并且已经在Stripe控制面板中更新了平台设置(见截图)。为什么会出现以下报错?

Stripe.StripeException: Received event with API version 2022-11-15, but Stripe.net 44.0.0 expects API version 2024-04-10. We recommend that you create a WebhookEndpoint with this API version. Otherwise, you can disable this exception by passing throwOnApiVersionMismatch: false to Stripe.EventUtility.ParseEvent or Stripe.EventUtility.ConstructEvent, but be wary that objects may be incorrectly deserialized.at Stripe.EventUtility.ParseEvent(String json, Boolean throwOnApiVersionMismatch) in //src/Stripe.net/Services/Events/EventUtility.cs:line 47at Stripe.EventUtility.ConstructEvent(String json, String stripeSignatureHeader, String secret, Int64 tolerance, Int64 utcNow, Boolean throwOnApiVersionMismatch) in //src/Stripe.net/Services/Events/EventUtility.cs:line 128at Stripe.EventUtility.ConstructEvent(String json, String stripeSignatureHeader, String secret, Int64 tolerance, Boolean throwOnApiVersionMismatch) in /_/src/Stripe.net/Services/Events/EventUtility.cs:line 88at Functions.StripePlatformWebhook.Run(HttpRequestData req) in /Users/charles/yogabandy2020/Functions/StripePlatformWebhook.cs:line 61


问题原因

Stripe的Webhook事件版本由创建Webhook端点时指定的API版本决定,而非平台全局设置的默认API版本。你虽然更新了平台默认版本,但已存在的Webhook端点仍保留旧版本(2022-11-15)来发送事件,而Stripe.net 44.0.0 SDK默认适配2024-04-10版本,版本不匹配触发了该异常。

解决方法

方法1:更新Webhook端点的API版本(推荐)

  1. 登录Stripe控制面板,找到对应的Webhook端点
  2. 编辑端点,将API版本修改为2024-04-10(与SDK版本一致)
  3. 保存后,后续事件将使用新版本发送,异常会自动消失

方法2:临时关闭版本匹配检查(仅过渡用)

若暂时无法更新Webhook端点,可在解析事件时添加参数关闭异常抛出:

var stripeEvent = EventUtility.ConstructEvent(
    json,
    stripeSignatureHeader,
    secret,
    throwOnApiVersionMismatch: false
);

⚠️ 注意:此方法可能导致事件对象反序列化错误(旧版本事件结构与SDK期望的新版本结构可能不一致),仅作为临时过渡方案,最终仍建议更新Webhook端点版本。

补充说明

平台设置的默认API版本仅影响新创建的资源和新Webhook端点,已存在的端点不会自动同步版本,必须手动修改。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 19:22:49