Skip to content

barancw/stripe_event

 
 

Repository files navigation

stripe_event

Build Status

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.

Install

# Gemfile
gem 'stripe_event'
# config/routes.rb
mount StripeEvent::Engine => "/my-chosen-path" # provide a custom path

Usage

# 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
end

Register webhook url with Stripe

Setup webhook url

The "Test Webhooks" button doesn't work

Test Webhooks Fails

This 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.

About

Stripe webhook integration for Rails applications.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Ruby 97.1%
  • JavaScript 2.9%