Skip to content

Conversation

xavdid-stripe
Copy link
Member

@xavdid-stripe xavdid-stripe commented Jul 11, 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 below for user-facing changes)
  • add just test-one recipe
  • added tests
  • renamed THIN_EVENT_CLASSES
  • added from_json static constructor to EventNotification

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 fetch_event() method to retrieve its corresponding event. For events with related objects, there's a fetch_related_object() method that performs the API call and casts the response to the correct type.
  • ⚠️ Rename function StripeClient.parse_thin_event to StripeClient.parse_event_notification 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 related_object property and a fetch_related_object() function. They also have a fetch_() method to retrieve their corresponding stripe.events.*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 changed the base branch from master to sdk-release/next-major July 29, 2025 17:05
@xavdid-stripe xavdid-stripe changed the base branch from sdk-release/next-major to master July 29, 2025 17:06
@xavdid-stripe xavdid-stripe changed the base branch from master to sdk-release/next-major July 29, 2025 17:22
@xavdid-stripe xavdid-stripe deleted the branch master August 6, 2025 23:23
@xavdid-stripe xavdid-stripe reopened this Aug 8, 2025
@xavdid-stripe xavdid-stripe changed the title Add strongly typed Thin Event push payloads ⚠️ Add strongly typed EventNotifications Aug 29, 2025
@xavdid-stripe xavdid-stripe changed the base branch from sdk-release/next-major to master August 29, 2025 22:45
@xavdid-stripe xavdid-stripe marked this pull request as ready for review September 24, 2025 01:51
@xavdid-stripe xavdid-stripe requested a review from a team as a code owner September 24, 2025 01:51
@xavdid-stripe xavdid-stripe removed the request for review from a team September 24, 2025 01:52
@xavdid-stripe
Copy link
Member 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
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.

Couple comments/questions but otherwise good to go!

@xavdid-stripe xavdid-stripe merged commit ce7cac8 into master Sep 25, 2025
14 checks passed
@xavdid-stripe xavdid-stripe deleted the DEVSDK-2662 branch September 25, 2025 01:53
ramya-stripe added a commit that referenced this pull request Sep 25, 2025
* wip generating push payload events

[skip ci]

* improve generation

[skip ci]

* generate related object method

* Return a union from parse thin event & add UnknownThinEvent

* fix unused import

* fix related_object generation and add big test

* Some name cleanup

* rename thin_event

* small fixes

* export UnknownEventNotification

* fix reason parsing

* rename thin_event

* fix example & re-export event notifications

* move some imports

* swap event fetch_related_object to stripe-context

* update docstring

* update comment

Co-authored-by: David Brownman <[email protected]>
Co-authored-by: Ramya Rao <[email protected]>
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.

2 participants