Paypal fields integration in FORM

52 views
Skip to first unread message

Fabio Ceccarani

unread,
Mar 31, 2017, 5:22:14 AM3/31/17
to web...@googlegroups.com
Hi all,
I have this FORM with some fields + paypal fields and paypal action:

form = FORM(
        H1("SUBMISSION AND PAYMENT"),
        DIV(LABEL("Nome: ",_class="control-label col-sm-3")+DIV(auth.user.first_name,_class="col-sm9"),_class="form-group"),
        DIV(LABEL("Cognome: ",_class="control-label col-sm-3")+DIV(auth.user.last_name,_class="col-sm9"),_class="form-group"),
        # some others form elements...
        # start PAYPAL hidden fields
        INPUT(_type="hidden", _name="business", _value="exa...@email.com"),
        INPUT(_type="hidden", _name="cmd", _value="_xclick"),
        INPUT(_type="hidden", _name="paymentaction", _value="authorization"),
        INPUT(_type="hidden", _name="currency_code", _value="EUR"),
        INPUT(_type="hidden", _name="item_name", _value="Name of product"),
        INPUT(_type="hidden", _name="amount", _value="10.00")
        BUTTON('CONFIRM AND PAY',_value='conferma', _type='submit', _class='btn btn-success btn-lg center-block btn-prenota'),
# THIS IS THE PROBLEM: this action is required to pay, but so  form.accepts is not executed      
        _action="https://www.paypal.com/cgi-bin/webscr",
        _method="post"
)

# ON FORM ACCEPT
if form.accepts(request, session):
        date_subscription = datetime.datetime.today()

        #insert subscription
        db.subscriptions.insert(
            user_subscriber = auth.user.id,               #authenticated user
            course_id = session.current_course,  #current course
            course_title = course.title,
            course_subtitle = course.subtitle,
            subscription_date = date_subscription,
            course_date = prenotation_date,
            number_of_persons = number_of_persons,
            paid = False,
            archived = False
            )
# OTHER ACTION ON FORM ACCEPT (send emails, ecc...)


There's a way to execute before form.accepts and after redirect to _action url (with _method="post")?
I want before register the subscription, then goto to paypal page.

Thanks!
Fabio

黄祥

unread,
Mar 31, 2017, 7:57:13 AM3/31/17
to web2py-users
perhaps you can use onvalidation
ref:

best regards,
stifan

Anthony

unread,
Mar 31, 2017, 10:25:11 AM3/31/17
to web...@googlegroups.com
You are submitting the form directly to PayPal, so your server will not get the data. You have two options:
  1. Instead, submit the form to your web2py app, and then use urllib2 or the requests library to post the data from your server to PayPal (in that case, the user will not be redirected to the PayPal page -- not sure if that matters).
  2. Use Javascript to capture the form submission and (a) first send an Ajax request with the form data to your web2py app, and then (b) submit the form as usual to the PayPal URL.

Anthony

Anthony

unread,
Mar 31, 2017, 10:25:48 AM3/31/17
to web2py-users
On Friday, March 31, 2017 at 7:57:13 AM UTC-4, 黄祥 wrote:

That will not help -- the problem is that the form is not being submitted to the web2py application at all.

Anthony

Fabio Ceccarani

unread,
Apr 3, 2017, 9:54:59 AM4/3/17
to web2py-users
Thanks Antony and Stifan,
I choose (for now) a simplest way: two page, one for confirm subscription and one (a simple redirect after subscription) only with Paypal form.
In future, when I became more expert I will try Antony solutions!
Thanks!
Fabio
Reply all
Reply to author
Forward
0 new messages