【问题标题】:paypal ipn coming up invalid but checking the ipn response its verified贝宝 ipn 出现无效但检查 ipn 响应其已验证
【发布时间】:2017-04-13 11:49:14
【问题描述】:

我得到了什么:

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

我在 Django 管理员端收到的 IPN 显示 RESPONSE = VERIFIED。

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

我检查的内容:

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

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

我正在使用我的贝宝沙盒买家电子邮件进行购买,并使用促进者电子邮件进行购买。

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

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')

【问题讨论】:

  • This question 可能与您遇到的问题相同。
  • 使用该线程中的解决方案并没有导致改变。我将 enctype="multipart/form-data" 添加到按钮中。

标签: django python-3.x paypal


【解决方案1】:

当您尝试使用不同的交易 ID(买家交易 ID)时会出现此问题。

【讨论】:

    【解决方案2】:

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

    检查paypal中的ipn历史错误信息

    虽然变老了,但我从这里使用了一些 sn-ps 构建了一个实现:http://greenash.net.au/thoughts/2014/03/using-paypal-wps-with-cartridge-mezzanine-django/

    【讨论】:

      猜你喜欢
      • 2011-02-17
      • 2023-01-13
      • 2018-08-12
      • 2017-02-17
      • 2015-06-16
      • 2016-05-09
      • 2013-01-27
      • 2016-08-10
      • 2013-04-24
      相关资源
      最近更新 更多