Skip to content

Add EventNotificationHandler - #1724

Merged
xavdid-stripe merged 9 commits into
betafrom
DEVSDK-2822
Dec 16, 2025
Merged

Add EventNotificationHandler#1724
xavdid-stripe merged 9 commits into
betafrom
DEVSDK-2822

Conversation

@xavdid-stripe

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

Copy link
Copy Markdown
Contributor

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.

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.notification_handler(webhook_secret) do |notif, client, details|
  puts "Received unhandled notification:", notif.type
end

handler.on_v1_billing_meter_error_report_triggered 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
@xavdid-stripe
xavdid-stripe removed the request for review from a team November 21, 2025 00:36
Comment thread lib/stripe/stripe_event_router.rb Outdated
@xavdid-stripe

Copy link
Copy Markdown
Contributor Author

@prathmesh-stripe this is ready for final review!

@xavdid-stripe xavdid-stripe changed the title add event handler class Add EventNotificationHandler Dec 16, 2025
@xavdid-stripe
xavdid-stripe merged commit 0d940bb into beta Dec 16, 2025
15 checks passed
@xavdid-stripe
xavdid-stripe deleted the DEVSDK-2822 branch December 16, 2025 01:48
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.

3 participants