如何获得付款的通知Django的贝宝(how to get a notification of pa

2019-10-21 19:44发布

我一直在使用的文档的Django的PayPal网站加密按钮设置好一切。 我似乎就是不被接受的支付已经发生的任何通知。 我知道我必须失去了一些东西或做一些轻微错误的,但我没有得到任何POST到任何有意见,除非支付后,我点击返回站点。 我需要支付的通知之前,我可以继续前进。 谢谢。

这里是我的看法:

from django.http import HttpResponse
from django.template import RequestContext, loader
from django.shortcuts import render, HttpResponseRedirect, render_to_response
from paypal.standard.forms import PayPalEncryptedPaymentsForm
from django.core.urlresolvers import reverse
import eccomerce.settings as settings
from datetime import datetime
from paypal.standard.models import ST_PP_COMPLETED
from django.views.decorators.csrf import csrf_exempt
from paypal.standard.ipn.signals import valid_ipn_received

def show_me_the_money(sender, **kwargs):
    ipn_obj = sender
    if ipn_obj.payment_status == ST_PP_COMPLETED:
        # Undertake some action depending upon `ipn_obj`.
        payment = True
    else:
        payment = False

valid_ipn_received.connect(show_me_the_money)

def index(request):

    # What you want the button to do.
    paypal_dict = {
    "business": settings.PAYPAL_RECEIVER_EMAIL,
    "amount": "0.01",
    "currency_code": "GBP",
    "item_name": "picture01",
    "invoice": "unique-%s" % (str(datetime.now())),
    "notify_url": "http://127.0.0.1:8000/notify/",
    "return_url": "http://127.0.0.1:8000/return/",
    "cancel_return": "http://127.0.0.1:8000/cancel/",

    }
    valid_ipn_received.connect(show_me_the_money)

    # Create the instance.
    form = PayPalEncryptedPaymentsForm(initial=paypal_dict)
    context = {"form": form}
    return render_to_response("eccomerce_webapp/index.html", context)


@csrf_exempt
def notify(request):
    valid_ipn_received.connect(show_me_the_money)

    context = {}
    return render_to_response("eccomerce_webapp/notify.html", context)


@csrf_exempt
def cancel(request):
    valid_ipn_received.connect(show_me_the_money)

    context = {}
    return render_to_response("eccomerce_webapp/cancel.html", context)

@csrf_exempt
def return_view(request):
    valid_ipn_received.connect(show_me_the_money)

    context = {}
    return render_to_response("eccomerce_webapp/return.html", context)

这里是我的网址:

from django.conf.urls import patterns, include, url
from eccomerce_webapp import views

urlpatterns = patterns('',
    url(r'^notify/$', views.notify, name='notify'),
    url(r'^return/$', views.return_view, name='return'),
    url(r'^cancel/$', views.cancel, name='cancel'),
    url(r'^$', views.index, name='index'),
    (r'^something/paypal/', include('paypal.standard.ipn.urls')),
)

Answer 1:

PayPal的IPN不会再打到你的本地网址: http://127.0.0.1:8000/notify/

看到自己的文档IPN测试 。

PayPal建议与直接提交到您的通知端点的形式编码自己的测试页面。 这可能看起来像(从自己的文件):

<form target="_new" method="post" action="{% url 'notify' %}">
    <input type="hidden" name="SomePayPalVar" value="SomeValue1"/>
    <input type="hidden" name="SomeOtherPPVar" value="SomeValue2"/>

    <!-- code for other variables to be tested ... -->

    <input type="submit"/>
</form>

一旦你在沙箱环境中有你的应用程序上的某个地方,你就可以开始使用IPN模拟器进行测试。



文章来源: how to get a notification of payment with django-paypal