python django-paypal 设置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/757809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 20:48:25  来源:igfitidea点击:

django-paypal setup

pythondjangopaypal

提问by Joe

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

有没有人设置django-paypal?这里是链接到它在这里

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

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

myproject > paypal > (stdandard and pro folders)

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

to my settins.py file I added

到我添加的 settins.py 文件

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

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

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

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)

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

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

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

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

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

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

Traceback:

追溯:

File "...\accounts\views.py" in buy_my_item
  655.     return ppp(request)
File "...\paypal\pro\views.py" in __call__
  115.                 return self.validate_payment_form()
File "...\paypal\pro\views.py" in validate_payment_form
  133.             success = form.process(self.request, self.item)
File "...\paypal\pro\forms.py" in process
  1. params.update(item)
  1. params.update(项目)

采纳答案by S.Lott

In your code...

在你的代码...

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

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

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

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


Edit

编辑

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

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

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 发送消息。

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.

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

回答by Lakshman Prasad

PayPal django Integrationpost should help you.

PayPal django 集成帖子应该对您有所帮助。