django-paypal 设置 [英] django-paypal setup

查看:32
本文介绍了django-paypal 设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人安装过django-paypal吗?这是它的链接这里?

Has anyone setup django-paypal? Here is the link to it here?

我有myproject"设置,我的文件夹结构如下所示:

I have "myproject" setup, and my folder sturecture looks like this:

myproject > paypal >(标准和专业文件夹)

myproject > paypal > (stdandard and pro folders)

到我添加的 settins.py 文件

to my settins.py file I added

INSTALLED_APPS = (
    'myproject.paypal.standard',
    'myproject.paypal.pro',
)

在我的帐户应用程序的 url 文件中,我添加了:

in my url's file for my account app I added:

urlpatterns += patterns('myproject.account.views',
    (r'^payment-url/$', 'buy_my_item'),                   
)

并在我的帐户视图中添加:

and in my account view I added:

from myproject.paypal.pro.views import PayPalPro
from myproject.paypal.pro.forms import PaymentForm, ConfirmForm

def buy_my_item(request):
    item = {'amt':"10.00",              # amount to charge for item
            'inv':"1111",         # unique tracking variable paypal
            'custom':"2222",       # custom tracking variable for you
            'cancelurl':"http://127.0.0.1:8000/",   # Express checkout cancel url
            'returnurl':"http://127.0.0.1:8000/"}   # Express checkout return url

    kw = {'item':'item',                            # what you're selling
           'payment_template': 'pro/payment.html',          # template to use for payment form
           'confirm_template': ConfirmForm,  # form class to use for Express checkout confirmation
           'payment_form_cls': PaymentForm,  # form class to use for payment
           'success_url': '/success',               # where to redirect after successful payment
           }

    ppp = PayPalPro(**kw)
    return ppp(request)

--- 编辑 ---------然后,我将 pro 和标准模板文件夹添加到我的项目模板文件夹中.

--- EDIT --------- Then, I added the pro and standard template folders to my projects template folder.

当我去http://127.0.0.1:8000/account/payment-url/ 并提交表单...

When I go to http://127.0.0.1:8000/account/payment-url/ and submit the form...

我收到一个 ValueError :字典更新序列元素 #0 的长度为 1;需要 2"

I get a ValueError : "dictionary update sequence element #0 has length 1; 2 is required"

追溯:

File "...accountsviews.py" in buy_my_item
  655.     return ppp(request)
File "...paypalproviews.py" in __call__
  115.                 return self.validate_payment_form()
File "...paypalproviews.py" in validate_payment_form
  133.             success = form.process(self.request, self.item)
File "...paypalproforms.py" in process

  1. params.update(item)

推荐答案

在你的代码中...

  'payment_form_cls': 'payment_form_cls',  # form class to use for payment

这必须是用于验证的 Form 对象.

This must be a Form object that's used for validation.

   'payment_form_cls': MyValidationForm,  # form class to use for payment

<小时>

编辑

http://github.com/johnboxall/django-paypal/tree/master

您的请求应该包括通知网址、返回网址和取消返回.您提供给 Paypal 的所有三个网址.

Your request is supposed to include a notify-url, return-url and cancel-return. All three url's YOU provide to Paypal.

Paypal 将向这些 URL 发送消息.

Paypal will send messages to these URL's.

由于 Paypal 会向这些 URL 发送消息,因此您必须将它们放在 urls.py 中.您必须为这三个 url 编写视图函数.这些网址会将您的贝宝回复发送给他们.

Since Paypal will send messages to these URL's, YOU must put them in your urls.py. You must write view functions for these three urls'. These urls will have your paypal responses sent to them.

这篇关于django-paypal 设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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