Skip to content

Conversation

@xavdid-stripe
Copy link
Member

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

Why?

We've been designing a streamlined approach to handling incoming events that is easy to get right and hard to get wrong. This PR has the initial implementation of this new system.

NOTE: final names for classes / methods are still being gaveled, so don't worry about those for now. Weigh in on this doc if you have strong feelings there!

The only other pending item is to add a method to allow handling a webhook without verifying the signature. This is good for testing and for Event Bridge, which doesn't use the signature-based verification. Otherwise, this is ready for review.

What?

  • add EventHandler class
  • add event handler constructor on StripeClient
  • add tests
  • tweak linting
  • added attr_reader :requestor on Client so we could modify the context live. Don't love it, but it's what it is

Example usage

client = Stripe::StripeClient.new(api_key)
handler = client.router(webhook_secret) do |notif, client, details|
  puts "Received unhandled notification:", notif.type
end

handler.on_V1BillingMeterErrorReportTriggeredEventNotification do |event_notification, client|
  meter = event_notification.fetch_related_object
  puts "Meter #{meter.display_name} (#{meter.id}) had a problem"
end

post "/webhook" do
  webhook_body = request.body.read
  sig_header = request.env["HTTP_STRIPE_SIGNATURE"]

  begin
    handler.handle(webhook_body, sig_header)
    status 200
  rescue Stripe::SignatureVerificationError => e
    puts "Signature verification failed:", e.message
    status 400
  end
end

See Also

@xavdid-stripe xavdid-stripe changed the base branch from master to beta November 15, 2025 18:11
@xavdid-stripe xavdid-stripe changed the title add "inverted" event handler add event handler class Nov 19, 2025
@xavdid-stripe xavdid-stripe marked this pull request as ready for review November 20, 2025 00:06
@xavdid-stripe xavdid-stripe requested a review from a team as a code owner November 20, 2025 00:06
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