diff options
author | Magnus Hagander | 2014-08-20 08:38:25 +0000 |
---|---|---|
committer | Magnus Hagander | 2014-08-20 08:38:25 +0000 |
commit | e21fb0f0cc8e34effa164a5395cba942b9bed529 (patch) | |
tree | dcd8d21a33287963439d94d25676d08e40dc6789 /postgresqleu/paypal/views.py | |
parent | d57d3de2c823cbb92e9a022aec421b54ee3b4b7f (diff) |
Double check for duplicate paypal transactions
Since our lookup to paypal can take a long time, sometimes a second
notification fires while we're still looking up the first one. To avoid
a key conflict in the db, repeat the check for existing transactions
before writing the new one, and if it's already in there, ignore the
new one. We assume that the result is going to be the same for both
of them.
Diffstat (limited to 'postgresqleu/paypal/views.py')
-rw-r--r-- | postgresqleu/paypal/views.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/postgresqleu/paypal/views.py b/postgresqleu/paypal/views.py index df92baf1..23b8eb6d 100644 --- a/postgresqleu/paypal/views.py +++ b/postgresqleu/paypal/views.py @@ -1,4 +1,4 @@ -from django.http import HttpResponseForbidden +from django.http import HttpResponseForbidden, HttpResponse from django.db import transaction from django.shortcuts import render_to_response from django.template import RequestContext @@ -106,6 +106,13 @@ def paypal_return_handler(request): # Payment is completed. Create a paypal transaction info # object for it, and then try to match it to an invoice. + # Double-check if it is already added. We did check this furter + # up, but it seems it can sometimes be called more than once + # asynchronously, due to the check with paypal taking too + # long. + if TransactionInfo.objects.filter(paypaltransid=tx).exists(): + return HttpResponse("Transaction already processed", content_type='text/plain') + # Paypal seems to randomly change which field actually contains # the transaction title. if d.has_key('transaction_subject') and d['transaction_subject'] != '': |