Files
openfoodnetwork/lib/stripe/webhook_handler.rb
Luis Ramos e52937c113 Use rubocop auto correct to add frozen string literal to all files
This is an unsafe auto corection, we will need to trust our build here
2021-06-17 23:07:26 +01:00

39 lines
755 B
Ruby

# frozen_string_literal: true
module Stripe
class WebhookHandler
def initialize(event)
@event = event
end
def handle
return :unknown unless known_event?
__send__(event_mappings[@event.type])
end
private
def event_mappings
{
"account.application.deauthorized" => :deauthorize
}
end
def known_event?
event_mappings.key?(@event.type)
end
def deauthorize
return :ignored unless @event.respond_to?(:account)
destroyed = destroy_stripe_accounts_linked_to(@event.account)
destroyed.any? ? :success : :ignored
end
def destroy_stripe_accounts_linked_to(account)
StripeAccount.where(stripe_user_id: account).destroy_all
end
end
end