source: WAeUP_SRP/trunk/skins/waeup_aaua/getPaymentsFolderInfo.py @ 7279

Last change on this file since 7279 was 5878, checked in by Henrik Bettermann, 14 years ago

Add session 2010/2011.

File size: 5.4 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')
47sandwich = student_record.mode and student_record.mode.endswith('_sw')
48
49
50session = student_record.session
51next_info = context.getNextInfo(student_record)
52info['next_session'] = next_info['next_session_id']
53info['next_session_str'] = next_info['next_session_str']
54info['payment_method'] = ""
55info['reasons'] = next_info['reasons']
56
57# begin customization
58
59if review_state in ('returning',) and info['next_session'] != session:
60    if session in ('06',) or sandwich:
61        info['payment_method'] = "online_payment"
62    else:
63        info['payment_method'] = "first_instalment"
64elif review_state in ('cleared_and_validated',):
65    if session in ('06','07',) or sandwich:
66        info['payment_method'] = "online_payment"
67    else:
68        info['payment_method'] = "first_instalment"
69elif session in ('08','09','10') and review_state in ('school_fee_paid','courses_registered','courses_validated',) and not sandwich:
70    second_instalment_records = aq_payments(Eq('student_id',student_id) & Eq('category','schoolfee2') & Eq('session_id',session) & Eq('status','paid'))
71    if not second_instalment_records:
72        info['payment_method'] = "second_instalment"
73    else:   
74        pass
75info['prod_id'] = '105'
76
77# end customization
78
79info['student_name'] = student_record.name
80payments_path = "%s/campus/students/%s/payments" % (context.portal_url(),student_id)
81payments = []
82payment_records = aq_payments(Eq('student_id',student_id)) # & Eq('session_id',student_record.session))
83vocabularies = context.portal_vocabularies
84paid_fees = []
85for payment in payment_records:
86    if payment.status == "paid":
87        paid_fees += "%s_%s" % (payment.category,payment.session_id),
88#info['pf'] = paid_fees
89for payment in payment_records:
90    row = {}
91    row['id'] = payment.key
92    if payment.status == 'invalid':
93        row['title'] = "Invalid Payment, Naira %s, %s" % (payment.amount,
94                                                          payment.date.strftime("%d/%m/%y %H:%M:%S"))
95    else:
96        row['title'] = "%s for Session %s, Naira %s, %s" % (vocabularies.payment_categories.get(payment.category),
97                                                            vocabularies.sessions.get(payment.session_id),
98                                                            payment.amount,
99                                                            payment.date.strftime("%d/%m/%y %H:%M:%S"))
100    oid = payment.order_id
101    onr = oid.rfind('-')+1
102    if onr > 0:
103        start_pos = onr
104    else:
105        start_pos = 6
106    url = row['url'] = "%s/p%s" % (payments_path,oid[start_pos:])
107    row['is_requeryable'] = "%s_%s" % (payment.category,payment.session_id) not in paid_fees and not payment.resp_desc and payment.type == 'online' or str(member) in ('admin',)  # customized too
108    #row['is_approvable'] = is_so and row['is_requeryable'] and payment.category == 'schoolfee' # does not make sense for maintenance
109    row['is_approvable'] = is_so and row['is_requeryable']
110    row['resp_desc'] = payment.resp_desc or 'Payment Process Interrupted'
111    row['trans_ref'] = payment.order_id
112    if row['is_requeryable']:
113        if payment.category == 'schoolfee':
114            row['callback_url'] = "%(url)s/interswitch_cb" % row
115        elif payment.category == 'schoolfee2':
116            row['callback_url'] = "%(url)s/interswitch_cb2" % row           
117#        elif payment.category == 'hostel_maintenance':
118#            row['callback_url'] = "%(url)s/interswitch_acco_cb" % row
119#        else:
120        href = '%(query_url)s' % info
121        href += '?transRef=%(trans_ref)s' % row
122        href += '&prodID=%(prod_id)s' % info
123        href += '&redirectURL=%(callback_url)s' % row
124        row['href'] = href
125    if payment.status == 'paid':
126        row['confirmed'] = 'active'
127    else:
128        row['confirmed'] = 'unsuccessful'
129    row['is_editable'] = is_so and (row['confirmed'] == 'active')
130    payments.append(row)
131
132payments.sort(cmp=lambda x,y: cmp(x['trans_ref'],y['trans_ref']))
133info['payments'] = payments
134return info
135
Note: See TracBrowser for help on using the repository browser.