Why Paypal duplicates IPN when using django-paypal

I am trying to get a django-paypal app working in my Django project. I am using dcramer fork since Django 1.4. I also use a Paypal developer account with business and personal accounts, processing transactions through the Sandbox Paypal website.

If I don't have a receiver function connected to the signal payment_was_successful

, everything looks as expected. After the transaction has occurred, paypal_ipn

a new row is created in the database table that has the value "VERIFIED" in the column response

. IPN Paypal magazine reports that there were no attempts for this transaction.

When I have a receiver function connected to a signal payment_was_successful

, the table paypal_ipn

includes two new lines with created_at

10-15 seconds timestamps. They both have a "VERIFIED" value in the response column, but the last of the two is marked with a help flag_info

indicating something like:

'Duplicate txn_id. (5M907276M1007902B) '

The Paypal business account reports that the IPN has been repeated 1 time.

I found possible solutions that mention the use dispatch_uid

when connecting the receiver function to the signal, which I still have to try. My problem is that I have looked at the relevant django-paypal source code and I don't understand why Paypal would retry the IPN when the postback was checked on the first.

Has anyone else objected to this and found a solution that they understand?


Update:

I found that there was an error in my receiver function code that could have thrown an exception. Now that I have fixed this Paypal no longer repeats the IPN. I'm glad the problem went away, but I still can't figure out why this is happening.

Below is a snippet of the latest duplicate records in the database. Note that the first line was created and updated at least 10 seconds before the next one.

created_at                       updated_at                       response    flag
2013-02-03 07:53:56.628013+00    2013-02-03 07:53:56.628057+00    VERIFIED    FALSE
2013-02-03 07:54:07.393795+00    2013-02-03 07:54:07.403008+00    VERIFIED    TRUE

      

+3


source to share


1 answer


I understood that. The short answer is to make sure your receiver functions are working correctly.

When Paypal sends an IPN to the URL you specified, they expect a response with an HTTP 200 status code. If the response code is anything else, they will try again. Even if you process the callback and receive a VERIFIED message, the IPN from Paypal needs a 200 OK response.

I looked through the Apache access logs and found that when I had errors in my signal sink function payment_was_successful

, the original IPN from paypal got an HTTP 500 status code.



The django-paypal package HttpResponse("OKAY")

only responds after everything else has been processed, including postbacks to Paypal that return "VERIFIED", an object PayPalIPN

that is stored in the database, and sending signals. When something went wrong in my signal receiver function and an unhandled exception was thrown, Django responded with an HTTP 500 status code.

When Paypal repeated the IPN, the django-paypal packet found a duplicate txn_id and sent a signal payment_was_flagged

. My receiver function for this signal was error-free, so Paypal received an HTTP 200 status code that waited and stopped retrying.

Hope this helps someone else in the future.

+7


source







All Articles