django-paypal ipn 工作正常但未收到信号
我的 models.py 文件末尾有此代码
from paypal.standard.ipn.signals import payment_was_successful
def confirm_payment(sender, **kwargs):
# it's important to check that the product exists
logging.debug('** CONFIRMED PAYMENT ***') #never reached this point
try:
bfeat = BuyingFeature.objects.get(slug=sender.item_number)
except BuyingFeature.DoesNotExist:
return
# And that someone didn't tamper with the price
if int(bfeat.price) != int(sender.mc_gross):
return
# Check to see if it's an existing customer
try:
customer = User.objects.get(email=sender.payer_email)
except User.DoesNotExist:
customer = User.objects.create(
email=sender.payer_email,
first_name=sender.first_name,
last_name=sender.last_name
)
# Add a new order
CustomerOrder.objects.create(customer=customer, feature=bfeat, quantity=1, paypal_email=sender.payer_email, invoice=sender.invoice, remarks='')
payment_was_successful.connect(confirm_payment)
整个过程运行正常。付款完成。 return_url 和 cancel_url 工作正常。 notify_url 已通过 paypal 沙箱的测试工具进行了测试,并且工作正常。然而,信号从未被接收到。
信号代码放置在 models.py 的末尾,django-paypal 代码放置在我的项目目录中。
(代码是从此处“窃取”的)
我一定做错了什么。任何帮助将不胜感激!
I have this code at the end of my models.py file
from paypal.standard.ipn.signals import payment_was_successful
def confirm_payment(sender, **kwargs):
# it's important to check that the product exists
logging.debug('** CONFIRMED PAYMENT ***') #never reached this point
try:
bfeat = BuyingFeature.objects.get(slug=sender.item_number)
except BuyingFeature.DoesNotExist:
return
# And that someone didn't tamper with the price
if int(bfeat.price) != int(sender.mc_gross):
return
# Check to see if it's an existing customer
try:
customer = User.objects.get(email=sender.payer_email)
except User.DoesNotExist:
customer = User.objects.create(
email=sender.payer_email,
first_name=sender.first_name,
last_name=sender.last_name
)
# Add a new order
CustomerOrder.objects.create(customer=customer, feature=bfeat, quantity=1, paypal_email=sender.payer_email, invoice=sender.invoice, remarks='')
payment_was_successful.connect(confirm_payment)
The whole process runs ok. Payment is complete. return_url and cancel_url work fine. notify_url was tested from the paypal sandbox's test tools and works ok. However, signal is never received.
Signal code is placed at the end of the models.py and django-paypal code is placed inside my project's directory.
(code was 'stolen' from here)
I must be doing something completely wrong. Any help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 django-paypal 中,基本交易有两个信号:
您必须处理这两个信号。
In django-paypal there are two signals for basic transactions:
You must handle both signals.
我遇到了这个问题 - 并且在追寻了一些类似的问题后找到了适合我的具体案例的解决方案。我在这里提到它是为了防止其他人碰壁。
我还没有彻底研究过它,但看起来它很大程度上取决于您从哪个版本/存储库获取 django-paypal 副本。具体来说,我下载的版本没有更新以适应 {% csrf_token %} 习惯用法。为了让它工作,我必须将 @csrf_exempt 装饰器添加到两个视图中:
I had this problem - and having chased around a few similar questions have found a resolution for my specific case. I mention it here in case anyone else is hitting this wall.
I've not researched it thoroughly, but it looks as though it's highly dependent on which version/repository you source your copy of django-paypal from. Specifically, the version I downloaded wasn't updated to accommodate the {% csrf_token %} idiom. To get this to work, I had to add the @csrf_exempt decorator to two views:
settings.INSTALLED_APPS
中有django-paypal
吗?否则,我看不出有任何其他原因导致信号不会被发射。
Is
django-paypal
there in thesettings.INSTALLED_APPS
?I don't see any other reason why the signal wouldn't be fired, otherwise.