stripe_event is built on the ActiveSupport::Notifications API. Incoming webhook requests are authenticated by retrieving the event object from Stripe. Define subscriber blocks to handle one, many, or all event types.
# Gemfile
gem 'stripe_event'# config/routes.rb
mount StripeEvent::Engine => "/my-chosen-path" # provide a custom path# config/initializers/stripe.rb
Stripe.api_key = ENV['STRIPE_API_KEY'] # Set your api key
StripeEvent.configure do
subscribe 'charge.failed' do |event|
MyClass.handle_failed_charge(event) # Define subscriber behavior
end
subscribe 'customer.created', 'customer.updated' do |event|
# Handle multiple event types
end
subscribe do |event|
# Handle all event types - logging, etc.
end
endThis implementation increases security by fetching the sent event again from stripe and eliminating any man in the middle or spoof attacks ( forum post ). Unfortunately this breaks the test button from this panel. If you need to test your setup make sure to trigger real events from your test site. These events will all load correctly.


