Reputation:
I am trying to implement a simple online payment system using PayPal, however I have tried everything I know and am still getting an INVALID response.
I know it's nothing too simple, because I get a VERIFIED response when using the IPN simulator. I have tried putting the items into a dict first, I have tried fixing the encoding, and still nothing. PayPal says the reasons for an INVALID response could be:
The following is the snippet concerned:
f = cgi.FieldStorage()
newparams = 'cmd=_notify-validate'
for key in f.keys():
val = f[key].value
newparams += '&' + urlencode({key: val.encode('utf-8')})
req = urllib2.Request(PP_URL, newparams)
req.add_header("Content-type", "application/x-www-form-urlencoded")
http = urllib2.urlopen(req)
ret = http.read()
fi.write(ret + '\n')
if ret == 'VERIFIED':
#*do stuff*
Upvotes: 1
Views: 2038
Reputation: 1
Make sure you are posting to the sandbox and not the live..
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
Upvotes: -1
Reputation: 419
in django
import httplib2
import urllib
h = httplib2.Http()
params = urllib.urlencode(request.POST, True)
response, content = h.request("http://www.paypal.com/cgi-bin/webscr?cmd=_notify-validate&%s" % params)
Upvotes: 1
Reputation: 147
The order is critical. You must verify in the same order that Paypal specify. The simplest way to achieve this is to use the exact order they were provided in:
def paypal_verify():
""" Returns false if the current request cannot be verified by paypal """
# Create verify param string from current query string
verify_string = "cmd=_notify_validate&" + cherrypy.request.query_string
req = urllib2.Request("http://www.paypal.com/cgi-bin/webscr", verify_string)
response = urllib2.urlopen(req)
result = response.read()
if response == "VERIFIED":
# All good
return True
# Fail
return False
If you're not using cherrypy, some other mechanism should be similarly available to get the query string as provided by Paypal.
Upvotes: 2
Reputation: 47082
It is hard to judge from what you've given me. Here are a couple of guesses/suggestions:
Upvotes: 0