Skip to content

Commit

Permalink
Fix v2 event object name (#1403)
Browse files Browse the repository at this point in the history
* changed the object_name for v2 events from "event" to "v2.core.event"

* improved debug output in stripe_webhook_handler example, and removed incorrect comment
  • Loading branch information
jar-stripe authored Sep 28, 2024
1 parent 52f5129 commit c0e5da3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/stripe_webhook_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def webhook():
# Fetch the event data to understand the failure
event = client.v2.core.events.retrieve(thin_event.id)
if isinstance(event, V1BillingMeterErrorReportTriggeredEvent):
# CHECK: fetch_object is present and callable, returning a strongly-typed object (without casting)
meter = event.fetch_related_object()
meter_id = meter.id
print("Success! " + str(meter_id))

# Record the failures and alert your team
# Add your logic here
Expand Down
2 changes: 1 addition & 1 deletion stripe/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def _convert_to_stripe_object(
resp = resp.copy()
klass_name = resp.get("object")
if isinstance(klass_name, str):
if api_mode == "V2" and klass_name == "event":
if api_mode == "V2" and klass_name == "v2.core.event":
event_name = resp.get("type", "")
klass = get_thin_event_classes().get(
event_name, stripe.StripeObject
Expand Down
2 changes: 1 addition & 1 deletion tests/test_stripe_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_v2_events_retrieve(self, http_client_mock):
http_client_mock.stub_request(
method,
path=path,
rbody='{"id": "evt_123","object": "event", "type": "v1.billing.meter.error_report_triggered"}',
rbody='{"id": "evt_123","object": "v2.core.event", "type": "v1.billing.meter.error_report_triggered"}',
rcode=200,
rheaders={},
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_v2_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def v2_payload_no_data(self):
return json.dumps(
{
"id": "evt_234",
"object": "event",
"object": "v2.core.event",
"type": "financial_account.balance.opened",
"created": "2022-02-15T00:27:45.330Z",
"related_object": {
Expand All @@ -37,7 +37,7 @@ def v2_payload_with_data(self):
return json.dumps(
{
"id": "evt_234",
"object": "event",
"object": "v2.core.event",
"type": "financial_account.balance.opened",
"created": "2022-02-15T00:27:45.330Z",
"related_object": {
Expand Down

0 comments on commit c0e5da3

Please sign in to comment.