Closed anark closed 9 years ago
I just check for livemode before processing.
# config/initializers/stripe.rb
StripeEvent.event_retriever = lambda do |params|
return Stripe::Event.construct_from(params.deep_symbolize_keys) unless params[:livemode]
api_key = Account.find_by!(stripe_user_id: params[:user_id]).api_key
Stripe::Event.retrieve(params[:id], api_key)
end
StripeEvent.configure do |events|
events.subscribe 'charge.failed' do |event|
next unless event.livemode
# Define subscriber behavior based on the event object
event.class #=> Stripe::Event
event.type #=> "charge.failed"
event.data.object #=> #<Stripe::Charge:0x3fcb34c115f8>
end
events.all do |event|
# Handle all event types - logging, etc.
end
end
Since we're already talking about a Stripe Connect application, this could be more easily done in the customized event_retriever
than having to build out a new config option and associated tests.
Of course this still requires that the backend skips the webhook callbacks if the event is nil
, but that's a much smaller code change to maintain.
See my comment on https://github.com/integrallis/stripe_event/pull/36#issuecomment-48727086 which suggests building a way to reject (or ignore) certain webhooks.
For example:
StripeEvent.event_retriever = lambda do |params|
return nil if Rails.env.production && !params[:livemode]
# your regular event retriever stuff...
end
See #38 for an implementation that would allow for the example snippet that I pasted in my comment above.
Closing. See #38.
From the stripe webhook documentation(https://stripe.com/docs/webhooks)
However I am having a lot of trouble filtering out testmode webhooks when using stripe_event. I am using the following event_retriever
Does anyone have any ideas on how to filter for only livemode webhooks using stripe_event for a stripe_connect application?
Thank You