Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
160 views
in Technique[技术] by (71.8m points)

python - django-paypal setup

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

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

myproject > paypal > (stdandard and pro folders)

to my settins.py file I added

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

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)

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

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

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

Traceback:

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

Edit

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 will send messages to these URL's.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...