【问题标题】:Not getting notified on return/return_cancel using Django paypal使用 Django paypal 没有收到关于 return/return_cancel 的通知
【发布时间】:2015-01-16 17:45:10
【问题描述】:

我在我的电子商务网站上使用 django paypal 并且付款一切正常,但是一旦付款完成,它就不会重定向回我的网站。我在我的本地主机中使用 paypal IPN。是因为我在本地运行machine,下面是发送数据到paypal的代码。

def checkout(request,name):
    product=Products.objects.get(name=name)
    print "producttttttttttttttttttttt",product
    # What you want the button to do.
    paypal_dict = {
        "business": settings.PAYPAL_RECEIVER_EMAIL,
        "amount": product.price,
        "item_name": product.name,
        "invoice": "unique-invoice-id",
        "notify_url": "192.168.5.108:8000" + reverse('paypalipn'),
        "return_url": "192.168.5.108:8000/payment-complete/",
        "cancel_return": "192.168.5.108:8000",

    }
    form = PayPalPaymentsForm(initial=paypal_dict)
    context = {"form": form}
    return render_to_response("payment.html", context)

以下视图用于从 paypal ipn 获取数据:

def paypalipn(request,item_check_callable=None): ''' django paypal 查看存储IPN。通知 url 执行此视图。 ''' 打印“哈啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊” """ 贝宝 IPN 端点 (notify_url)。 PayPal Payments Pro 和 Payments Standard 都使用它来确认交易。 https://www.paypal.com/it/home

PayPal IPN Simulator:
https://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session
"""
#TODO: Clean up code so that we don't need to set None here and have a lot
#      of if checks just to determine if flag is set.
flag = None
ipn_obj = None

# Clean up the data as PayPal sends some weird values such as "N/A"
# Also, need to cope with custom encoding, which is stored in the body (!).
# Assuming the tolerate parsing of QueryDict and an ASCII-like encoding,
# such as windows-1252, latin1 or UTF8, the following will work:

encoding = request.POST.get('charset', None)

if encoding is None:
    flag = "Invalid form - no charset passed, can't decode"
    data = None
else:
    try:
        data = QueryDict(request.body, encoding=encoding)
    except LookupError:
        data = None
        flag = "Invalid form - invalid charset"

if data is not None:
    date_fields = ('time_created', 'payment_date', 'next_payment_date',
                   'subscr_date', 'subscr_effective')
    for date_field in date_fields:
        if data.get(date_field) == 'N/A':
            del data[date_field]

    form = PayPalIPNForm(data)
    if form.is_valid():
        try:
            #When commit = False, object is returned without saving to DB.
            ipn_obj = form.save(commit=False)
        except Exception, e:
            flag = "Exception while processing. (%s)" % e
    else:
        flag = "Invalid form. (%s)" % form.errors

if ipn_obj is None:
    ipn_obj = PayPalIPN()

#Set query params and sender's IP address
ipn_obj.initialize(request)

if flag is not None:
    #We save errors in the flag field
    ipn_obj.set_flag(flag)
else:
    # Secrets should only be used over SSL.
    if request.is_secure() and 'secret' in request.GET:
        ipn_obj.verify_secret(form, request.GET['secret'])
    else:
        ipn_obj.verify(item_check_callable)
ipn_obj.save()
return HttpResponse("OKAY")

请帮忙???

【问题讨论】:

    标签: django paypal-sandbox django-paypal


    【解决方案1】:

    问题发生是因为我在本地主机上工作,当我移动到开发服务器时它对我有用。页面被重定向回我的网站。

    【讨论】:

      【解决方案2】:

      我会直接从django-paypal documentation引用这个:

      如果您尝试在开发环境中使用 PayPal 沙箱对此进行测试,并且您的计算机位于防火墙/路由器后面,因此无法在 Internet 上公开访问(大多数开发人员计算机都会出现这种情况) , PayPal 将无法发回您的视图。您将需要使用https://ngrok.com/ 之类的工具使您的计算机可公开访问,并确保在 notify_url、return 和 cancel_return 字段中向 PayPal 发送您的公共 URL,而不是 localhost。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-13
        • 1970-01-01
        • 2018-11-12
        • 2015-02-05
        • 1970-01-01
        • 1970-01-01
        • 2013-02-24
        • 1970-01-01
        相关资源
        最近更新 更多