Selecting payment method

39 views
Skip to first unread message

Maurice Waka

unread,
Dec 22, 2020, 11:25:57 AM12/22/20
to web2py-users
I worked on a way to pay through various methods. It involves a user selecting the appropriate method he/she likes or wants to use.

This is the code:
#Controller

form = SQLFORM(Pending, formstyle="divs", submit_button='Subscribe'),
    if form.process().accepted:
        session.pending = form.vars
        redirect(URL('e_pay', form.vars.pay_with, ))

form_one = SQLFORM(Subscription_one, formstyle="divs", submit_button='Subscribe')
if form_one.process().accepted:
    session.pending_one = form_one.vars
    redirect(URL('e_pay', form_one.vars.pay_with, ))

#db.py
one_month = timedelta(days=365/12)
Subscription_one = db.define_table('subscription_one',
                               Field('user_id', 'reference auth_user'),
                               Field('Subscription_type','text', default = 'One Month', represent = lambda value, row: DIV(str(value),_style="color:#38D9D6; text-align: center;")),#Only modified by Admin
                               Field('Amount','double', default= 3.49, represent = lambda value, row: DIV('$' + str(value) + '/month', _style='text-align: center; color: red; font-size: 30px;')),#Only modified by Admin
                               Field('pay_with',requires=IS_IN_SET((['paypal','stripe',])),default='None'),
                               Field('confirmed', 'boolean', default=False),
                               Field('start_date', 'date', default=request.now),
                               Field('renew_date', 'date', default=request.now+one_month),)
three_month = timedelta(days=365/4)
Subscription_three = db.define_table('subscription_three',
                               Field('user_id', 'reference auth_user'),
                               Field('Subscription_type','text', default = 'Three Months', represent = lambda value, row: DIV(str(value),_style="color:#38D9D6; text-align: center;")),#Only modified by Admin
                               Field('Amount','double', default= 3.29, represent = lambda value, row: DIV('$' + str(value) + '/month', _style='text-align: center; color: red; font-size: 30px;')),#Only modified by Adminn
                               Field('pay_with',requires=IS_IN_SET((['paypal','stripe',])),default='None'),
                               Field('confirmed', 'boolean', default=False),
                               Field('start_date', 'date', default=request.now),
                               Field('renew_date', 'date', default=request.now+three_month),)

The problem is that the user when selecting an option, 'paypal' and decides against it and selects 'stripe', the options are still 'active' and not deselected.So on clicking submit, both might be posted.
How can I prevent both selections at the same time?
I also need to align the buttons to the center or left but _select='align-items:center' is not working.
Kind regards

Annet

unread,
Dec 23, 2020, 6:57:03 AM12/23/20
to web2py-users
I am not sure I fully understand your question, but doesn't SQLFORM.widgets.radio.widget
on the pay_with solve your issue?

Best,

Annet

Op dinsdag 22 december 2020 om 17:25:57 UTC+1 schreef mauri...@gmail.com:

Maurice Waka

unread,
Dec 23, 2020, 8:37:57 AM12/23/20
to web2py-users
I had to separate the payment methods to different pages than all in one. So a user selects a button and gets redirected to the subsequent subscription type. 
Previously i handled all payments in one function 
def pay():
    subscr_one
    ...process subscr_one
    subscr_three
    ...process subscr_three
    subscr_six
    ...process subscr_six
but each subscription has its own function now:
def subscr_one():
    ...process subscr_one
def subscr_three():
    ...process subscr_three
def subscr_six():
    ...process subscr_six

Reply all
Reply to author
Forward
0 new messages