1
我已經使用django-paypal網站上的加密按鈕文檔設置了所有內容。我似乎沒有收到任何有關付款已經發生的通知。我知道我必須錯過某些東西或者做些微小的錯誤,但是除非付款,否則我不會收到任何POST請求,我點擊返回到網站。我需要先收到付款通知,然後才能繼續。謝謝。如何使用django-paypal獲得付款通知
這裏是我的觀點:
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')),
)