stripe-dotnet: throwOnApiVersionMismatch flag is not working using EventUtility.ConstructEvent

I am using the following call:

EventUtility.ConstructEvent(JSON, Request.Headers["Stripe-Signature"], _secret, throwOnApiVersionMismatch: false);

I am still getting the following error. It appears the flag throwOnApiVersionMismatch doesn’t work?

Received event with API version 2019-03-14, but Stripe.net 24.6.0 expects API version 2019-02-19. 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.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

@matthewrwilliams If it’s not too much trouble, could you try to reproduce the issue with just:

var event = EventUtility.ParseEvent(JSON, throwOnApiVersionMismatch: false);

and let me know if that raises the same exception?

By default, the library will error out if the event you are trying to deserialize does not match the API version of the library. This is to prevent crashes and partial deserializations.

But in a lot of cases, events would deserialize just fine. This is due to the fact that one new API version changes some behaviour but rarely touches most objects. For example, with the 2019-03-14 API version, we only removed some minor properties on invoices and the rest of the changes are behavioural changes. So any events about a Charge or a Refund would not have changed and could still be deserialized. For that reason we added the option to try to deserialize anyway though it’s always risky.

Recently though, we added the option to have the webhook endpoint’s API version in sync with the library (it shipped around a month ago) and this is now the recommended approach.