source: WAeUP_SRP/trunk/skins/waeup_epayment/getPaymentsFolderInfo.py @ 3814

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

implement gown hiring

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