Skip to content

Commit

Permalink
Fix processing of account.application.deauthorized events
Browse files Browse the repository at this point in the history
don't try to fetch the event as we lost access to remote account
  • Loading branch information
ticosax committed Oct 26, 2017
1 parent c15668e commit 7858405
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
17 changes: 9 additions & 8 deletions pinax/stripe/tests/test_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,14 +602,15 @@ def test_process_webhook(self, SyncMock, RetrieveMock):
AccountUpdatedWebhook(event).process_webhook()
self.assertTrue(SyncMock.called)

@patch("pinax.stripe.actions.accounts.deauthorize")
def test_process_deauthorize(self, DeauthorizeMock):
def test_process_deauthorize(self):
data = {"data": {"object": {"id": self.account.stripe_id}},
"account": self.account.stripe_id}
event = Event.objects.create(
kind=AccountApplicationDeauthorizeWebhook.name,
webhook_message={},
valid=True,
processed=False
webhook_message=data,
)
event.validated_message = dict(data=dict(object=dict(id=self.account.stripe_id)))
AccountApplicationDeauthorizeWebhook(event).process_webhook()
self.assertTrue(DeauthorizeMock.called)
AccountApplicationDeauthorizeWebhook(event).process()
self.assertTrue(event.valid)
self.assertTrue(event.processed)
self.account.refresh_from_db()
self.assertFalse(self.account.authorized)
14 changes: 13 additions & 1 deletion pinax/stripe/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,20 @@ class AccountApplicationDeauthorizeWebhook(Webhook):
name = "account.application.deauthorized"
description = "Occurs whenever a user deauthorizes an application. Sent to the related application only."

def validate(self):
"""
Validate incoming events.
We don't fetch remote the event as we lost access to the account where the event belongs.
"""
self.stripe_account = models.Account.objects.filter(
stripe_id=self.event.webhook_message["account"]).first()
self.event.validated_message = self.event.webhook_message
self.event.stripe_account = self.stripe_account
self.event.valid = True

def process_webhook(self):
accounts.deauthorize(models.Account.objects.get(stripe_id=self.event.message["data"]["object"]["id"]))
accounts.deauthorize(self.stripe_account)


class AccountExternalAccountCreatedWebhook(Webhook):
Expand Down

0 comments on commit 7858405

Please sign in to comment.