Skip to content

⚠️ Add strongly typed EventNotifications#3168

Merged
xavdid-stripe merged 13 commits intomasterfrom
DEVSDK-2662
Sep 25, 2025
Merged

⚠️ Add strongly typed EventNotifications#3168
xavdid-stripe merged 13 commits intomasterfrom
DEVSDK-2662

Conversation

@xavdid-stripe
Copy link
Copy Markdown
Contributor

@xavdid-stripe xavdid-stripe commented Sep 7, 2025

Why?

As part of the Next-Gen Event Handling project, we're adding fully typed classes to represent all the thin events Event Notifications a user could receive. There are also helper methods that help with the event handling experience.

What?

  • (see changelog below for user-facing changes)
  • add tests
  • add justfile recipe for test-one
  • generate event notification classes
  • added and internal GetConcreteType to the type registry (though we probably don't need it; see note)

See Also

DEVSDK-2662

Changelog

We've overhauled how V2 Events are handled in the SDK! This approach should provide a lot more information at authoring and compile time, leading to more robust integrations. As part of this process, there are a number of changes to be aware of.

  • Added matching EventNotification classes to every v2 Event. For example, there's now a V1BillingMeterErrorReportTriggeredEventNotification to match the existing V1BillingMeterErrorReportTriggeredEvent. Each notification class defines a fetchEvent() method to retrieve its corresponding event. For events with related objects, there's a fetchRelatedObject() method that performs the API call and casts the response to the correct type.
  • ⚠️ Rename function StripeClient.parseThinEvent to StripeClient.parseEventNotification and remove the Stripe.ThinEvent class.
    • This function now returns a Stripe.V2.Core.EventNotification (which is the shared base class that all of the more specific Stripe.Events.*EventNotification classes share) instead of Stripe.ThinEvent. When applicable, these event notifications will have the relatedObject property and a fetchRelatedObject() function. They also have a fetchEvent() method to retrieve their corresponding Stripe.Event.*Event instance.
    • If you parse an event the SDK doesn't have types for (e.g. it's newer than the SDK you're using), you'll get an instance of Stripe.Events.UnknownEventNotification instead of a more specific type. It has both the relatedObject property and the FetchRelatedObject() function (but they may be/return null)

@xavdid-stripe xavdid-stripe requested a review from a team as a code owner September 7, 2025 01:27
@xavdid-stripe xavdid-stripe marked this pull request as draft September 10, 2025 20:30
Comment thread src/Stripe.net/Entities/V2/Events/Event.partial.cs
Comment thread src/StripeTests/Events/V2/EventTest.cs Outdated
Comment thread src/StripeTests/Events/V2/EventTest.cs Outdated
Comment thread src/Stripe.net/Infrastructure/Public/UnknownEventNotification.cs Outdated
Comment thread src/Stripe.net/Entities/V2/Events/Event.partial.cs
Comment thread src/Stripe.net/Infrastructure/JsonConverters/V2EventConverter.cs Outdated
@xavdid-stripe xavdid-stripe marked this pull request as ready for review September 24, 2025 01:52
Comment thread src/Stripe.net/Infrastructure/JsonConverters/V2EventNotificationConverter.cs Outdated
Comment thread src/Stripe.net/Infrastructure/Public/EventNotification.cs Outdated
Comment thread src/Stripe.net/Infrastructure/JsonConverters/V2EventConverter.cs Outdated
Comment thread src/Stripe.net/Infrastructure/Public/UnknownEventNotification.cs Outdated
@xavdid-stripe
Copy link
Copy Markdown
Contributor Author

(ignore red CI; docker hub is having a problem so all tests are down. Everything besides compat was good before i merged master back into this and trigger the CI run.)

Copy link
Copy Markdown
Contributor

@jar-stripe jar-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more change; sorry I missed this earlier!

Comment thread src/Stripe.net/Infrastructure/Public/UnknownEventNotification.cs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants