PayPal ipn 无效,但检查 ipn 响应已验证



我得到的:

PayPal响应 200 - 表明我正在接收 IPN 信息。这也显示在我的 Django 管理员标志上,因为我可以看到收到的 IPN 和 IPN 详细信息。

我在 Django 管理员端收到的 IPN 显示响应 = 已验证。

尽管如此,我对 URL 接收器的响应返回无效。(这是我在下面的代码中得到的 r.text 响应(。

我检查过的事情:

据我所知,我正在从PayPal沙盒发布和接收。

我将PayPal设置更新为 UTF-8。

我正在使用我的PayPal沙盒买家电子邮件进行购买,并使用主持人电子邮件进行购买。

下面的代码非常简单。如果需要更多信息来评估我的问题发生的位置,请告诉我。

from django.core.urlresolvers import reverse
from django.shortcuts import render, get_object_or_404, render_to_response
from django.contrib.auth.models import User, Group
from django.contrib.contenttypes.models import ContentType
from django.views.decorators.csrf import csrf_exempt
import requests
import sqlite3
import time
import sys
import urllib.parse

from paypal.standard.forms import PayPalPaymentsForm
from paypal.standard.models import ST_PP_COMPLETED
from paypal.standard.ipn.signals import valid_ipn_received, invalid_ipn_received
from payment.models import Profile

def payment_view(request):
    host = request.get_host()
    # What you want the button to do.
    paypal_dict = {
        "business": "facilitator@gmail.com",
        "cmd": '_xclick-subscriptions',
        "item_name": "Monthly Subscription",
        "amount": "6.99",
        "a3": "6.99",
        "currency_code": "USD",
        "p3": "1",
        "t3": "M",
        "src": "1",
        "sra": "1",
        "no_note": "1",
        "modify": "1",
        "notify_url": "http://{}{}".format(host, reverse('paypal-ipn')),
        "return_url": "http://{}{}".format(host, reverse('payment:done')),
        "cancel_return": "http://{}{}".format(host, 
reverse('payment:canceled')),
     "custom": request.user.username
            }
# Create the instance.
form = PayPalPaymentsForm(initial=paypal_dict, button_type="subscribe")
context = {"form": form}
return render(request, "payment.html", context)

VERIFY_URL_PROD = 'https://www.paypal.com/cgi-bin/webscr'
VERIFY_URL_TEST = 'https://www.sandbox.paypal.com/cgi-bin/webscr'
VERIFY_URL = VERIFY_URL_TEST
param_str = sys.stdin.readline().strip()
params = urllib.parse.parse_qsl(param_str)
params.append(('cmd', '_notify-validate'))
headers = {'content-type': 'application/x-www-form-urlencoded', 'host': 'www.paypal.com'}
r = requests.post(VERIFY_URL, params=params, headers=headers, verify=True)
r.raise_for_status()
if r.text == 'VERIFIED':
    with open('/tmp/ipnout.txt','a') as f:
            f.write('valid')
elif r.text == 'INVALID':
    with open('/tmp/ipnout.txt','a') as f:
            f.write(r.text)
else:
    with open('/tmp/ipnout.txt','a') as f:
            f.write('neither')

当您尝试使用其他交易 ID(买家交易 ID(时,会出现此问题。

您是否使用任何东西将开发机器暴露给网络? 例如 ngrok?使用 ngrok 生成的网址作为 ipn 并在贝宝的设置 (https( 中返回网址。您还需要将"网站名称"设置设置为公开的 URL

检查 PayPal 中的 ipn 历史记录以获取错误消息

虽然老了,但我使用下面的几个片段构建了一个实现:http://greenash.net.au/thoughts/2014/03/using-paypal-wps-with-cartridge-mezzanine-django/

最新更新