Don't retrieve event from Stripe for a deauthorisation

This commit is contained in:
stveep
2017-01-21 10:57:13 +00:00
committed by Rob Harrington
parent 22e4a50807
commit 1450bfd726
2 changed files with 9 additions and 2 deletions

View File

@@ -51,8 +51,14 @@ module Admin
def fetch_event_from_stripe(request)
event_json = JSON.parse(request.body.read)
acct_param = event_json["user_id"] ? {"Stripe-Account" => event_json["user_id"]} : nil
Stripe::Event.retrieve(event_json["id"],acct_param)
# If the application has been deauthorised, we are no longer authorised to retrieve events for that account
# Left here in case it's useful for other webhooks
unless event_json["type"] == "account.application.deauthorized"
acct_param = event_json["user_id"] ? {"Stripe-Account" => event_json["user_id"]} : nil
Stripe::Event.retrieve(event_json["id"],acct_param)
else
Stripe::Event.construct_from(event_json)
end
end
def deauthorize_request_for_stripe_id(id)

View File

@@ -20,6 +20,7 @@ describe Admin::StripeAccountsController, type: :controller do
"type"=>"account.application.deauthorized",
"user_id"=>"webhook_id"}))
account = create(:stripe_account, stripe_user_id: "webhook_id")
expect(Stripe::Event).not_to receive(:retrieve) # should not retrieve direct for a deauth event
post 'destroy_from_webhook', {"id"=>"evt_wrfwg4323fw",
"object"=>"event",
"api_version"=>nil,