Skip to content

Commit

Permalink
CustomerUpdatedWebhook: use provided customer object from the event
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Sep 28, 2017
1 parent 335530d commit 33878a9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pinax/stripe/actions/customers.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def set_default_source(customer, source):

def sync_customer(customer, cu=None):
"""
Syncronizes a local Customer object with details from the Stripe API
Synchronizes a local Customer object with details from the Stripe API
Args:
customer: a Customer object
Expand Down
13 changes: 12 additions & 1 deletion pinax/stripe/tests/test_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,18 @@ class CustomerUpdatedWebhookTest(TestCase):
def test_process_webhook(self, SyncMock):
event = Event.objects.create(kind=CustomerUpdatedWebhook.name, webhook_message={}, valid=True, processed=False)
CustomerUpdatedWebhook(event).process_webhook()
self.assertTrue(SyncMock.called)
self.assertEquals(SyncMock.call_count, 1)
self.assertEquals(SyncMock.call_args[0], (None, None))

@patch("pinax.stripe.actions.customers.sync_customer")
def test_process_webhook_with_data(self, SyncMock):
event = Event.objects.create(kind=CustomerUpdatedWebhook.name, webhook_message={}, valid=True, processed=False)
obj = object()
event.validated_message = dict(data=dict(object=obj))
CustomerUpdatedWebhook(event).process_webhook()
self.assertEquals(SyncMock.call_count, 1)
self.assertIsNone(SyncMock.call_args[0][0])
self.assertIs(SyncMock.call_args[0][1], obj)


class CustomerSourceCreatedWebhookTest(TestCase):
Expand Down
7 changes: 6 additions & 1 deletion pinax/stripe/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ class CustomerUpdatedWebhook(Webhook):
description = "Occurs whenever any property of a customer changes."

def process_webhook(self):
customers.sync_customer(self.event.customer)
cu = None
try:
cu = self.event.message["data"]["object"]
except (KeyError, TypeError):
pass
customers.sync_customer(self.event.customer, cu)


class CustomerDiscountCreatedWebhook(Webhook):
Expand Down

0 comments on commit 33878a9

Please sign in to comment.