django-paypal ipn 工作正常但未收到信号

发布于 2024-11-16 11:22:20 字数 1366 浏览 4 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暖树树初阳… 2024-11-23 11:22:20

在 django-paypal 中,基本交易有两个信号:

payment_was_successful
payment_was_flagged

您必须处理这两个信号。

In django-paypal there are two signals for basic transactions:

payment_was_successful
payment_was_flagged

You must handle both signals.

好久不见√ 2024-11-23 11:22:20

我遇到了这个问题 - 并且在追寻了一些类似的问题后找到了适合我的具体案例的解决方案。我在这里提到它是为了防止其他人碰壁。

我还没有彻底研究过它,但看起来它很大程度上取决于您从哪个版本/存储库获取 django-paypal 副本。具体来说,我下载的版本没有更新以适应 {% csrf_token %} 习惯用法。为了让它工作,我必须将 @csrf_exempt 装饰器添加到两个视图中:

  1. paypal.standard.views 中的 ipn 视图
  2. 由我的 django paypal 字典中的返回 url 加载的视图(...这个标记了一个高度准确的错误如果你有调试)。

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:

  1. the ipn view in paypal.standard.views
  2. the view loaded by the return url in my django paypal dictionary (... this one flags a highly accurate error if you have debug on).
玻璃人 2024-11-23 11:22:20

settings.INSTALLED_APPS 中有 django-paypal 吗?

否则,我看不出有任何其他原因导致信号不会被发射。

Is django-paypal there in the settings.INSTALLED_APPS?

I don't see any other reason why the signal wouldn't be fired, otherwise.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文