如何使用django-paypal收到付款通知 [英] how to get a notification of payment with django-paypal

查看:182
本文介绍了如何使用django-paypal收到付款通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用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')),
)

解决方案

PayPal的IPN不会回叫到您的本地URL: 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模拟器进行测试了.

I have set everything up using the documentation for encrypted buttons on the django-paypal site. I just don't seem to be receiving any notification that the payment has happened. I know I must be missing something or doing something slightly wrong but I get no POST to any of there views unless after paying I click return to site. I need to get the notification of payment before I can move on. Thanks.

here are my views:

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)

Here are my Urls:

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

解决方案

PayPal's IPN won't call back to your local URL: http://127.0.0.1:8000/notify/

See their docs on IPN testing.

PayPal recommends coding your own test page with a form that submits directly to your notification endpoint. This could look like (from their docs):

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

Once you have your app on in a sandbox environment somewhere, you can start using the IPN Simulator to test.

这篇关于如何使用django-paypal收到付款通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆