source: WAeUP_SRP/trunk/skins/waeup_fceokene/getPaymentsFolderInfo.py @ 16422

Last change on this file since 16422 was 7711, checked in by Henrik Bettermann, 13 years ago

Enable payment switch in fceokene portal.

File size: 4.8 KB
Line 
1## Script (Python) "getPaymentsFolderInfo"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=
8##title=
9##
10# $Id: getPaymentsFolderInfo.py 2480 2007-10-30 15:23:25Z joachim $
11"""
12Info for the PaymentsFolder
13"""
14from Products.AdvancedQuery import Eq, Between, Le,In
15
16pprops = context.portal_properties
17payment_disabled = not pprops.enable_payment
18
19mtool = context.portal_membership
20wftool = context.portal_workflow
21member = mtool.getAuthenticatedMember()
22payments_catalog = context.payments_catalog
23aq_payments = payments_catalog.evalAdvancedQuery
24if mtool.isAnonymousUser():
25    return None
26try:
27    from Products.zdb import set_trace
28except:
29    def set_trace():
30        pass
31
32import DateTime
33request = context.REQUEST
34#students = context.portal_url.getPortalObject().campus.students
35student_id = context.getStudentId()
36if student_id is None:
37    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
38#student = getattr(students,student_id)
39student_record = context.students_catalog.getRecordByKey(student_id)
40
41
42info = {}
43is_so = info['is_so'] = context.isSectionOfficer()
44is_student = info['is_student'] = context.isStudent()
45info['student_name'] = student_record.name
46info['query_url'] = "https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx"
47review_state = info['review_state'] = student_record.review_state
48parttime = student_record.mode and student_record.mode.endswith('_pt')
49fulltime = student_record.mode and student_record.mode.endswith('_ft')
50
51
52session = student_record.session
53next_info = context.getNextInfo(student_record)
54info['next_session'] = next_info['next_session_id']
55info['next_session_str'] = next_info['next_session_str']
56info['payment_method'] = ""
57info['reasons'] = next_info['reasons']
58
59# begin customization
60
61if review_state == 'cleared_and_validated':
62    info['payment_method'] = "online_payment"
63#elif review_state == 'cleared_and_validated' and session == '07':
64#    info['payment_method'] = "sc_payment"
65elif review_state == 'returning' and info['next_session'] != session:
66    info['payment_method'] = "online_payment"
67info['prod_id'] = '83'
68
69if payment_disabled:
70    info['payment_method'] = ""
71
72# end customization
73
74info['student_name'] = student_record.name
75payments_path = "%s/campus/students/%s/payments" % (context.portal_url(),student_id)
76payments = []
77payment_records = aq_payments(Eq('student_id',student_id)) # & Eq('session_id',student_record.session))
78vocabularies = context.portal_vocabularies
79paid_fees = []
80for payment in payment_records:
81    if payment.status == "paid":
82        paid_fees += "%s_%s" % (payment.category,payment.session_id),
83#info['pf'] = paid_fees
84for payment in payment_records:
85    row = {}
86    row['id'] = payment.key
87    if payment.status == 'invalid':
88        row['title'] = "Invalid Payment, Naira %s, %s" % (payment.amount,
89                                                          payment.date.strftime("%d/%m/%y %H:%M:%S"))
90    else:
91        row['title'] = "%s for Session %s, Naira %s, %s" % (vocabularies.payment_categories.get(payment.category),
92                                                            vocabularies.sessions.get(payment.session_id),
93                                                            payment.amount,
94                                                            payment.date.strftime("%d/%m/%y %H:%M:%S"))
95    oid = payment.order_id
96    onr = oid.rfind('-')+1
97    if onr > 0:
98        start_pos = onr
99    else:
100        start_pos = 6
101    url = row['url'] = "%s/p%s" % (payments_path,oid[start_pos:])
102    row['is_requeryable'] = "%s_%s" % (payment.category,payment.session_id) not in paid_fees and payment.type == 'online' or str(member) in ('admin',)
103    row['is_approvable'] = is_so and row['is_requeryable'] and payment.category == 'schoolfee' # does not make sense for maitenance
104    row['resp_desc'] = payment.resp_desc or 'Payment Process Interrupted'
105    row['trans_ref'] = payment.order_id
106    if row['is_requeryable']:
107        row['callback_url'] = "%(url)s/interswitch_cb" % row
108#        if payment.category == 'schoolfee':
109#            row['callback_url'] = "%(url)s/interswitch_cb" % row
110#        elif payment.category == 'hostel_maintenance':
111#            row['callback_url'] = "%(url)s/interswitch_acco_cb" % row
112#        else:
113        href = '%(query_url)s' % info
114        href += '?transRef=%(trans_ref)s' % row
115        href += '&prodID=%(prod_id)s' % info
116        href += '&redirectURL=%(callback_url)s' % row
117        row['href'] = href
118    if payment.status == 'paid':
119        row['confirmed'] = 'active'
120    else:
121        row['confirmed'] = 'unsuccessful'
122    row['is_editable'] = is_so and (row['confirmed'] == 'active')
123    payments.append(row)
124
125payments.sort(cmp=lambda x,y: cmp(x['trans_ref'],y['trans_ref']))
126
127
128info['payments'] = payments
129return info
130
Note: See TracBrowser for help on using the repository browser.