Sha256: f654204e216193159cf9e6165b6a844cb0b81fa2da0400c1f2aebf4b3a042a77

Contents?: true

Size: 1.04 KB

Versions: 18

Compression:

Stored size: 1.04 KB

Contents

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

    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

    private

    def webhook_event(body, sig_header, endpoint_secrets)
      endpoint_secrets.each_with_index do |secret, i|
        begin
          return ::Stripe::Webhook.construct_event(body, sig_header, secret.to_s)
        rescue ::Stripe::SignatureVerificationError
          raise if i == endpoint_secrets.length - 1
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
stripe-rails-2.5.0 app/models/stripe/event_dispatch.rb
stripe-rails-2.4.0 app/models/stripe/event_dispatch.rb
stripe-rails-2.3.5 app/models/stripe/event_dispatch.rb
stripe-rails-2.3.4 app/models/stripe/event_dispatch.rb
stripe-rails-2.3.3 app/models/stripe/event_dispatch.rb
stripe-rails-2.3.2 app/models/stripe/event_dispatch.rb
stripe-rails-2.3.1 app/models/stripe/event_dispatch.rb
stripe-rails-2.3.0 app/models/stripe/event_dispatch.rb
stripe-rails-2.2.1 app/models/stripe/event_dispatch.rb
stripe-rails-2.2.0 app/models/stripe/event_dispatch.rb
stripe-rails-2.1.0 app/models/stripe/event_dispatch.rb
stripe-rails-2.0.0 app/models/stripe/event_dispatch.rb
stripe-rails-1.10.2 app/models/stripe/event_dispatch.rb
stripe-rails-2.0.0.pre app/models/stripe/event_dispatch.rb
stripe-rails-1.10.1 app/models/stripe/event_dispatch.rb
stripe-rails-1.10.0 app/models/stripe/event_dispatch.rb
stripe-rails-1.9.1 app/models/stripe/event_dispatch.rb
stripe-rails-1.9.0 app/models/stripe/event_dispatch.rb