django paypal notify_url 未正确配置或工作

django paypal notify_url not configured correctly or working

我为 django paypal 安装了 pip。按钮呈现并且付款通过。 return url 也有效,但 notify_url 部分无效。所以我无法更新我的数据库,知道销售已经完成。

我也没有收到任何错误,所以我很困惑。如果有人可以提供帮助,我将不胜感激。谢谢

Edit: I added from paypal.standard.ipn.signals import payment_was_successful to the top of my views page. and changed the name of my notify_url to show_me_the_money (Not sure if that matters) I got it from a blog called http://djangodersleri.blogspot.ie/2013/11/paypal-ipn-with-django.html. But the good thing is now at least I seem to be getting my transactions recorded in the table paypal_ipn. But that's all! So still dont know if the show_me_the_money view is being executed.

这是我的..

设置...

    INSTALLED_APPS = (
    ...
        'paypal.standard.ipn',
)
PAYPAL_RECEIVER_EMAIL = "my_sandbox_test_email_is_here@gmail.com"
PAYPAL_TEST = True

网址...

(r'^show_me_the_money /', include('paypal.standard.ipn.urls')),

观看次数...

from paypal.standard.models import ST_PP_COMPLETED
from paypal.standard.ipn.signals import valid_ipn_received 
from paypal.standard.ipn.signals import payment_was_successful

def show_me_the_money (sender, **kwargs):
    ipn_obj = sender
    if ipn_obj.payment_status == ST_PP_COMPLETED:
        doc_id=ipn_obj.item_number1 # :document_id,
        us_id=ipn_obj.item_number2 #user.id,
        obj_doc=Document.objects.get(id=doc_id)
        my_user = User.objects.get(id=us_id)
        obj_doc.users.add(my_user)
        obj_doc.save()


    try:
        ipn_obj.verify(item_check_callable)
    except:
        import sys, traceback
        traceback.print_exc(file=sys.stdout)           

    valid_ipn_received.connect(paid)

@csrf_exempt
def myvideos(request):


    try:
        my_vids=Document.objects.filter(users=request.user.id)#request.user.id
    except: 
        return render_to_response(
        'myvideos.html',
        context_instance=RequestContext(request)
        )

       #my_vids= Document.objects.filter(users=request.user.id)       
    return render_to_response(
        'myvideos.html',
        {'my_vids': my_vids},
        context_instance=RequestContext(request)
        )


def video(request, document_id):

    document = Document.objects.get(id=document_id)

    if request.user.id:
        d1 =datetime.datetime.now()
        t=d1.strftime('%y%m%d%h%m%s')
        pp_price = str(document.price)
        # What you want the button to do.
        paypal_dict = {
            "business": settings.PAYPAL_RECEIVER_EMAIL,
            "amount": pp_price + ".00",
            "item_number1":document_id,
            "item_number2":request.user.id,
            "item_name": document.name,
            "invoice": document.name+t,
            "notify_url": "http://wackosmackosite.com/"+ reverse('paypal-ipn'),
            "return_url": "http://wackosmackosite.com/myvideos/",
            "cancel_return": "http://wackosmackosite.com/video/"+document_id+"/",
        }
        form = PayPalPaymentsForm(initial=paypal_dict)

        context = {"form": form, "document":document }
        return render(request, "video.html", context)
    else:
        return render_to_response('video.html',{'document': document},
                                  context_instance=RequestContext(request))

这是来自 paypal.standard.ipn

的 url
from django.conf.urls import url
from paypal.standard.ipn import views
urlpatterns = [
    url(r'^$', views.ipn, name="paypal-ipn"),
]

查看 signals 上的 Django 文档。 show_me_the_money 看来需要连接信号了。

首先@mcastle 非常感谢您的帮助。但我就是无法弄清楚 Django 信号。

好的,所以我最后要做的是转到 paypal.standard.ipn.views 文件并导入我的应用程序,然后在它之前的视图底部调用 show_me_the_money 视图returns http 响应。

所以 paypal 字典中的通知 url 是这样的...

"notify_url": "http://wackosmackosite.com/show_me_the_money/",

而我的 url 文件中的 url 是这样的..

 url(r'^show_me_the_money/', include('paypal.standard.ipn.urls')),

我能够从传递给 show_me_the_money 的参数中提取更新数据库所需的信息。像这样...

def show_me_the_money(sender, **kwargs):
    ipn_obj = sender

    payStatus=ipn_obj.POST.get('payment_status','')

    if payStatus=='Completed':
        ....

然后在paypal ipn查看 在顶部...

from myApp.views import show_me_the_money

在底部...

s_m_t_m=show_me_the_money(request, item_check_callable=None)
return HttpResponse("OKAY")

我发现整个设置非常混乱,并且认为对我来说文档只是遗漏了很多重要的东西。无论如何,这现在工作完美,我刚用 pay pal 下了 phone,他们很高兴它配置正确。