如何调试Django PayPal IPN? [英] How to debug Django PayPal IPN?

查看:104
本文介绍了如何调试Django PayPal IPN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此django应用来实施PayPal IPN。我正在使用PayPal的 IPN模拟器进行测试,但是它告诉我

I'm using this django app to implement PayPal IPN. I'm testing it using PayPal's IPN simulator, but it's telling me


IPN传送失败。 HTTP错误代码500:内部服务器错误

IPN delivery failed. HTTP error code 500: Internal Server Error

那么如何调试这个,看看真的发生了什么?我已经挖了代码:

So how can I debug this and see what's really going on? I've dug into code:

@require_POST
def ipn(request, item_check_callable=None):
    """
    PayPal IPN endpoint (notify_url).
    Used by both PayPal Payments Pro and Payments Standard to confirm transactions.
    http://tinyurl.com/d9vu9d

    PayPal IPN Simulator:
    https://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session
    """
    flag = None
    ipn_obj = None
    form = PayPalIPNForm(request.POST)
    if form.is_valid():
        try:
            ipn_obj = form.save(commit=False)
        except Exception, e:
            flag = "Exception while processing. (%s)" % e
    else:
        flag = "Invalid form. (%s)" % form.errors

    if ipn_obj is None:
        ipn_obj = PayPalIPN()    

    ipn_obj.initialize(request)

    if flag is not None:
        ipn_obj.set_flag(flag)
    else:
        # Secrets should only be used over SSL.
        if request.is_secure() and 'secret' in request.GET:
            ipn_obj.verify_secret(form, request.GET['secret'])
        else:
            ipn_obj.verify(item_check_callable)

    ipn_obj.save()
    return HttpResponse("OKAY")

所有外观在这里很好看,但是由于没有发送回复我的浏览器,调试有点棘手。我该怎么办?我试图看看我的apache日志,但实际上并没有告诉我。

All looks fine and dandy there, but since it's not sending a response to my browser, it's kinda tricky to debug. What should I do? I'm trying to look at my apache logs, but it really isn't telling me much.


216.113.191.33 - - [06 / Mar / 2010:14:10:3​​0 -0600]POST / paypal / ipn HTTP / 1.0500 16282 - -

216.113.191.33 - - [06/Mar/2010:14:10:30 -0600] "POST /paypal/ipn HTTP/1.0" 500 16282 "-" "-"






当这个视图被调用时,我试图发送电子邮件和日志消息,但是不想工作。有可能我在IPN模拟器中输入了错误的网址:)我禁用了需要的帖子装饰器,直接进入页面,看看发生了什么。我的系统开始按预期记录无效交易(因为没有后期数据),然后我在黑暗中随机刺伤,认为Django的CSRF保护正在踢入并阻止PayPal向我发送数据。添加 @csrf_exempt 装饰器似乎已经修复了。 Yay for guessing errors。


I tried to send emails and log messages when this view was called, but neither wanted to work. It's possible that I entered the wrong URL into the IPN simulator :) I disabled the "post required" decorator and went to the page directly to see what was going on. My system started to logging "invalid transactions" as expected (since there was no post-data) and then I took a random stab in the dark and figured that Django's CSRF protection was kicking in and preventing PayPal from sending me the data. Adding the @csrf_exempt decorator seems to have fixed it. Yay for guessing errors.

推荐答案

我记得在使用django-paypal时也碰到过这样的东西。我不记得我的原因是什么,但是在将ipn应用程序包含在您的setttings.py中之后,您是否在数据库中创建/迁移了相应的IPN表?

I recall having hit (something like) this when using django-paypal too. I can't remember for sure what my cause was, but have you created/migrated the appropriate IPN tables in your database after including the ipn app in your setttings.py?

这篇关于如何调试Django PayPal IPN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆