【发布时间】:2011-08-15 14:10:30
【问题描述】:
我正在尝试使用 django-paypal。我正在关注中提到的内容 Jay on Django
这就是我所做的......
##in my view.py file
def ask_payment(request):
# What you want the button to do.
paypal_dict = {
"business": settings.PAYPAL_RECEIVER_EMAIL,
"amount": "0.10",
"item_name": "book",
"invoice": "yong138peng",
"notify_url": "http://127.0.0.1:8000/accounts/my-ipn-location/",
"return_url": "http://127.0.0.1:8000/accounts/my-return-location/",
"cancel_return": "http://127.0.0.1:8000/accounts/my-cancel-location/",
}
# Create the instance.
form = PayPalPaymentsForm(initial=paypal_dict)
context = {"PP_form": form}
return render_to_response("paypal/payment.html",{'PP_form':form},context_instance=RequestContext(request))
@csrf_exempt
def payment_status(request,status):
return render_to_response("paypal/payment_status.html",
{'status':status},context_instance=RequestContext(request))
##then in my urls.py file
(r'^askforpayment/$','coltrane.views.ask_payment'),
(r'^my-ipn-location/', include('paypal.standard.ipn.urls')),
(r'^my-return-location/$','coltrane.views.payment_status',{'status':'success'}),
(r'^my-cancel-location/$','coltrane.views.payment_status',{'status':'cancel'}),
##in my models.py
def show_me_the_money(sender, **kwargs):
ipn_obj = sender
print "payment was successful!"
# Undertake some action depending upon `ipn_obj`.
if ipn_obj.custom == "Upgrade all users!": ## what is this for, this is sent by paypal??
Users.objects.update(paid=True)
payment_was_successful.connect(show_me_the_money)
我的问题是:
根据jay on django,我必须在 paypay.standard.ipn.views.ipn 函数之前放置一个@csrf_exempt 以避免django 抱怨@csrf_token 问题。我做到了,但我仍然面临同样的问题。然后我把@csrf_exempt放在我的return url view函数之前,在这种情况下是payment_status(request,status),csrf_token问题就消失了。所以我不知道为什么会这样。
信号处理程序中的这条语句是干什么用的? "if ipn_obj.custom == "升级所有用户!": .... " 这是来自paypay吗?除了“升级所有用户”之外,还有什么可能的价值?
我设法在沙盒中完成了购买并完成了整个支付过程。但现在的问题是,paypal 没有将 IPN 发布回我的 notify_url,它是一个本地主机。我从Paypal Sandbox IPN Problem 读到我不能使用 localhost (http://127.0.0.1:8000) 来测试 IPN。那么测试需要哪些步骤呢?我不明白post 中提供的解决方案。谁能教我如何在不部署真正的生产服务器的情况下测试 IPN?
【问题讨论】:
标签: django paypal paypal-ipn