【发布时间】:2016-11-05 01:31:26
【问题描述】:
我正在建立一个在线商店。
我的订单数据存储在请求中。我的观点具有以下一般结构:
payment.py
def payment(request):
order = request.order # Getting the order instance
# do some stuff
return render_to_response("payment.html")
我使用django-paypal。我关注this tutorial。 PayPal调用以下函数,它向我发出支付成功的信号。
payment_paypal_ipn_signal_handler.py
# Almost entirely copied from the django-paypal tutorial
from paypal.standard.models import ST_PP_COMPLETED
from paypal.standard.ipn.signals import valid_ipn_received
def payment_paypal_ipn_signal_handler(sender, **kwargs):
ipn_obj = sender
if ipn_obj.payment_status == ST_PP_COMPLETED:
# WARNING !
# Check that the receiver email is the same we previously
# set on the business field request. (The user could tamper
# with those fields on payment form before send it to PayPal)
if ipn_obj.receiver_email != "receiver_email@example.com":
# Not a valid payment
return
# ALSO: for the same reason, you need to check the amount
# received etc. are all what you expect.
# Undertake some action depending upon `ipn_obj`.
if ipn_obj.custom == "Upgrade all users!":
Users.objects.update(paid=True)
# Here I should add the code that handles a successful payment
request.order.paid = True # How do I get my 'request' here?
else:
#...
valid_ipn_received.connect(show_me_the_money)
但是,例如,我仍然需要我的 order 实例才能将其设置为付费。如何在 PayPal 调用的这个函数中获取我的数据?
【问题讨论】:
-
你不知道你是怎么想出来的吗?卡住了同样的问题。文档很糟糕:)
-
@JDavies ...我确实找到了解决方案。请看我的回答。
标签: python django paypal request django-1.9