Skip to content

Commit

Permalink
Ignore duplicate notifications
Browse files Browse the repository at this point in the history
Adyen duplicates many notifications. Luckily, our audit trail gives us
an easy way to check for duplicates. We ignore duplicated notifications,
but acknowledge them nonetheless.
  • Loading branch information
maiksprenger committed Jul 14, 2015
1 parent 59681e1 commit 956eaaf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions adyen/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ def assess_notification_relevance(self, request):
if request.POST.get(Constants.EVENT_CODE) != Constants.EVENT_CODE_AUTHORISATION:
return False, True

# Adyen duplicates many notifications. This bit makes sure we ignore them.
# "Duplicate notifications have the same corresponding values for their eventCode and
# pspReference fields." https://docs.adyen.com/display/TD/Accept+notifications
reference = request.POST[Constants.PSP_REFERENCE]
# The event code gets checked above, so we only need to check for the reference now.
if AdyenTransaction.objects.filter(reference=reference).exists():
# We already stored a transaction with this reference, so we can ignore the
# notification. As above, we still acknowledge it to Adyen, in case it missed
# our previous acknowledgment.
return False, True

# Seems legit, just do it :)
return True, True

Expand Down
19 changes: 19 additions & 0 deletions tests/test_adyen.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,22 @@ def test_assess_notification_relevance(self):
self.request.POST['eventCode'] = 'REPORT_AVAILABLE'
must_process, must_ack = self.scaffold.assess_notification_relevance(self.request)
self.assertTupleEqual((must_process, must_ack), (False, True))

def test_assert_duplicate_notifications(self):
"""
This test tests that duplicate notifications are ignored.
"""
self.request.method = 'POST'
self.request.POST = deepcopy(AUTHORISED_PAYMENT_PARAMS_POST)

# We have a valid request. So let's confirm that we think we should process
# and acknowledge it.
assert (True, True) == self.scaffold.assess_notification_relevance(self.request)

# Let's process it then.
__, __, __ = self.scaffold.handle_payment_feedback(self.request)

# As we have already processed that request, we now shouldn't process the request
# any more. But we still acknowledge it.
assert (False, True) == self.scaffold.assess_notification_relevance(self.request)

0 comments on commit 956eaaf

Please sign in to comment.