diff --git a/paypal/standard/helpers.py b/paypal/standard/helpers.py index 4cf0f34..60d8f8f 100644 --- a/paypal/standard/helpers.py +++ b/paypal/standard/helpers.py @@ -24,6 +24,7 @@ def duplicate_txn_id(ipn_obj): similars = (ipn_obj._default_manager .filter(txn_id=ipn_obj.txn_id) .exclude(id=ipn_obj.id) + .exclude(flag=True) .order_by('-created_at')[:1]) if len(similars) > 0: diff --git a/paypal/standard/ipn/tests/test_ipn.py b/paypal/standard/ipn/tests/test_ipn.py index 859bdae..8eb8d97 100644 --- a/paypal/standard/ipn/tests/test_ipn.py +++ b/paypal/standard/ipn/tests/test_ipn.py @@ -259,6 +259,16 @@ def test_duplicate_txn_id(self): self.assertEqual(ipn_obj.flag, True) self.assertEqual(ipn_obj.flag_info, "Duplicate txn_id. (51403485VH153354B)") + def test_duplicate_txn_id_with_first_flagged(self): + PayPalIPN._postback = lambda self: b"Internal Server Error" + self.paypal_post(IPN_POST_PARAMS) + PayPalIPN._postback = lambda self: b"VERIFIED" + self.paypal_post(IPN_POST_PARAMS) + self.assertEqual(len(PayPalIPN.objects.all()), 2) + ipn_objs = PayPalIPN.objects.order_by('created_at', 'pk') + self.assertEqual(ipn_objs[0].flag, True) + self.assertEqual(ipn_objs[1].flag, False) + def test_recurring_payment_skipped_ipn(self): update = { "recurring_payment_id": "BN5JZ2V7MLEV4",