You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/event_notification_webhook_handler.py
+61-22Lines changed: 61 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,24 @@
1
1
"""
2
-
event_notification_webhook_handler.py - receive and process thin events like the
3
-
v1.billing.meter.error_report_triggered event.
2
+
event_notification_webhook_handler.py - receive and process event notifications (AKA thin events) like the v1.billing.meter.error_report_triggered and v1.billing.meter.no_meter_found events.
4
3
5
4
In this example, we:
6
5
- create a StripeClient called client
7
6
- use client.parse_event_notification() to parse the received notification webhook body
8
7
- if its type is "v1.billing.meter.error_report_triggered":
9
-
- call event_notification.fetch_event() to retrieve the full event object
10
8
- call event_notification.fetch_related_object() to retrieve the Meter that failed
9
+
- call event_notification.fetch_event() to retrieve the full event object
10
+
- log info about the failure
11
+
- if its type is "v1.billing.meter.no_meter_found":
12
+
- call event_notification.fetch_event() to retrieve the full event object
11
13
- log info about the failure
14
+
- if the SDK doesn't have types for it, it will be an UnknownEventNotification:
15
+
- optionally cast it to UnknownEventNotification to get more accurate typing
16
+
- match on the type property to handle specific unknown event types
0 commit comments