PayPal IPN无效,使用_notify-validate和付款人状态为未验证。

3
使用Paypal IPN时,在验证付款时遇到了问题。
Paypal返回给Python/Django网站发起原始交易的付款人状态未经验证。然后该网站使用所有post参数和将“cmd”参数设置为“_notify-validate”来向'https://www.paypal.com/cgi-bin/webscr'发送回执信息以验证付款。 PayPal IPN返回结果为INVALID。
这是否正确或我漏掉了什么?
它使用Requests Python HTTP库。我认为不是代码的问题,因为大多数交易都验证通过了。
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)

我认为在理论上是正确的。你可以发一下实现它的代码吗? - Brian Neal
1个回答

2

我认为你在遍历 post_content 字典时,覆盖了 return_data 中的 cmd 键/值。我认为你不需要这样做。只需复制 POST 参数,然后更改 cmd 值:

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)

这基本上是我的应用程序所做的事情,尽管我没有使用requests库。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接