KISO Docs

Stripe Event Dispatch System

#Overview

KISO Stripe Payments ships with an integral Event Dispatcher which is used to relay incoming Stripe events received via the webhook over Rails' ActiveSupport::Notifications subsystem, allowing you to listen and handle Stripe events anywhere in your app.
#Broadcasting an Event
If you need to, you can access the Event dispatcher on the KisoStripePayments class via the event_dispatcher property:
KisoStripePayments.event_dispatcher.broadcast_event('myevent.event', { ...payload... })
The above will broadcast the event myevent.event to all listeners. You can use any name you want as the event name.
#Listening for Events in your own App
You may want to listen for Stripe events in your own app, so that you can take additional App specific logic steps on certain events, like when a payment first succeeds. Simply create an initializer and register a listener for the event name you are interested in:
ActiveSupport::Notifications.subscribe 'invoice.payment_succeeded' do |*args|
  event = ActiveSupport::Notifications::Event.new(*args)

  invoice_id  = event.payload.data.object.id

  # Send a receipt email to the customer
  AccountMailer.receipt(invoice_id).deliver_later
end
#Integral Event Handlers
The event handlers shipped with KISO Stripe Payments are as follows:
Stripe Event
charge.dispute.closed
charge.dispute.created
charge.dispute.updated
charge.failed
charge.refunded
charge.succeeded
customer.subscription.created
customer.subscription.deleted
customer.subscription.updated
invoice.payment_succeeded
review.closed
review.opened