source: WAeUP_SRP/trunk/skins/waeup_futminna/getPaymentsFolderInfo.py @ 5181

Last change on this file since 5181 was 4238, checked in by Henrik Bettermann, 16 years ago

resolve futminna #76

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