2
votes

Using the paypal IPN I am getting a problem when validating the payment.

Paypal returns to the Python/Django site that started the original transaction with payer_status as unverified. The site is then posting back to 'https://www.paypal.com/cgi-bin/webscr' with all the post parameters and 'cmd' parameter set to '_notify-validate' to verify the payment. PayPal IPN returns as INVALID.

Is this correct or is it something I have missed?

It uses the Requests Python HTTP library. I don't think its the code as most transactions are verified ok.

def paypalIPN(request):
   post_content = dict(request.POST.copy())
   return_data = {'cmd':'_notify-validate'} 

   if not post_content.keys():
      raise Http404("Post not found")

   for key in post_content.keys():
       return_data[key]=post_content[key][0]

   paypal_url = "https://www.paypal.com/cgi-bin/webscr"

   response = requests.post(paypal_url, data=return_data)
1
I think that is correct in theory. Can you post the code that does it?Brian Neal

1 Answers

2
votes

I think you are overwriting your cmd key / value in return_data by iterating over the post_content dict. I don't think you need to do that. Just make a copy of the POST parameters, then change the cmd value:

parameters = dict(request.POST.copy())
parameters['cmd'] = '_notify-validate'
paypal_url = "https://www.paypal.com/cgi-bin/webscr"
response = requests.post(paypal_url, data=parameters)

This is essentially what I do in my application, although I am not using the requests library.