Skip to content

Commit

Permalink
Fix v2 event object name (#1459)
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
  • Loading branch information
jar-stripe authored Sep 28, 2024
1 parent 9ded62d commit fb9bc30
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion examples/stripe_webhook_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
event = client.v2.core.events.retrieve(thin_event.id)
if event.instance_of? Stripe::V1BillingMeterErrorReportTriggeredEvent
meter = event.fetch_related_object
meter_id = meter.id # rubocop:disable Lint/UselessAssignment
meter_id = meter.id
puts "Success!", meter_id
end

# Record the failures and alert your team
Expand Down
5 changes: 3 additions & 2 deletions lib/stripe/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ def self.convert_to_stripe_object_with_params(

# Try converting to a known object class. If none available, fall back
# to generic StripeObject
object_type = data[:type] || data["type"]
object_name = data[:object] || data["object"]
object_class = if api_mode == :v2
if object_name == "event"
thin_event_classes.fetch(data[:type] || data["type"])
if object_name == "v2.core.event" && thin_event_classes.key?(object_type)
thin_event_classes.fetch(object_type)
else
v2_object_classes.fetch(
object_name, StripeObject
Expand Down
6 changes: 3 additions & 3 deletions test/stripe/v2_event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ def retrieve_event(evt_id)

@v2_payload_no_related_object = {
"id" => "evt_234",
"object" => "event",
"object" => "v2.core.event",
"type" => "financial_account.balance.opened",
"created" => "2022-02-15T00:27:45.330Z",
}.to_json

@v2_push_payload = {
"id" => "evt_234",
"object" => "event",
"object" => "v2.core.event",
"type" => "v1.billing.meter.error_report_triggered",
"created" => "2022-02-15T00:27:45.330Z",
"related_object" => {
Expand All @@ -38,7 +38,7 @@ def retrieve_event(evt_id)

@v2_pull_payload = {
"id" => "evt_234",
"object" => "event",
"object" => "v2.core.event",
"type" => "v1.billing.meter.error_report_triggered",
"created" => "2022-02-15T00:27:45.330Z",
"related_object" => {
Expand Down

0 comments on commit fb9bc30

Please sign in to comment.