Module: Stripe::EventDispatch

Included in:
EventsController
Defined in:
app/models/stripe/event_dispatch.rb

Instance Method Summary collapse

Instance Method Details

#dispatch_stripe_event(request) ⇒ Object



3
4
5
6
7
8
# File 'app/models/stripe/event_dispatch.rb', line 3

def dispatch_stripe_event(request)
  retrieve_stripe_event(request) do |evt|
    target = evt.data.object
    ::Stripe::Callbacks.run_callbacks(evt, target)
  end
end

#retrieve_stripe_event(request) {|event| ... } ⇒ Object

Yields:

  • (event)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/stripe/event_dispatch.rb', line 10

def retrieve_stripe_event(request)
  id = request['id']
  body = request.body.read
  sig_header = request.headers['HTTP_STRIPE_SIGNATURE']
  endpoint_secrets = ::Rails.application.config.stripe.signing_secrets

  if Object.const_defined?('Stripe::Webhook') && sig_header && endpoint_secrets
    event = webhook_event(body, sig_header, endpoint_secrets)
  else
    event = Stripe::Event.retrieve(id)
  end

  yield event
end