source: WAeUP_SRP/trunk/skins/waeup_aaue/getPaymentsFolderInfo.py @ 5598

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

request payment goes live

File size: 7.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')
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 review_state in ('returning',) and info['next_session'] != session:
59    if session in ('06','07','08'):
60        info['payment_method'] = "online_payment"
61    else:
62        info['payment_method'] = "first_instalment"
63elif review_state in ('cleared_and_validated',):
64    if session in ('06','07','08','09'):
65        info['payment_method'] = "online_payment"
66    else:
67        info['payment_method'] = "first_instalment"
68elif session in ('09','10','11',) and review_state in ('school_fee_paid','courses_registered','courses_validated',):
69    second_instalment_records = aq_payments(Eq('student_id',student_id) & Eq('category','schoolfee2') & Eq('session_id',session) & Eq('status','paid'))
70    if not second_instalment_records:
71        info['payment_method'] = "second_instalment"
72    else:   
73        pass
74info['prod_id'] = '119'
75
76# end customization
77
78info['student_name'] = student_record.name
79payments_path = "%s/campus/students/%s/payments" % (context.portal_url(),student_id)
80payments = []
81payment_records = aq_payments(Eq('student_id',student_id)) # & Eq('session_id',student_record.session))
82vocabularies = context.portal_vocabularies
83paid_fees = []
84for payment in payment_records:
85    if payment.status == "paid":
86        paid_fees += "%s_%s" % (payment.category,payment.session_id),
87#info['pf'] = paid_fees
88for payment in payment_records:
89    row = {}
90    row['id'] = payment.key
91    if payment.status == 'invalid':
92        row['title'] = "Invalid Payment, Naira %s, %s" % (payment.amount,
93                                                          payment.date.strftime("%d/%m/%y %H:%M:%S"))
94    elif payment.type == 'request' and payment.resp_approved_amount:
95        row['title'] = "%s for Session %s, Naira %s, %s" % (vocabularies.payment_categories.get(payment.category),
96                                                            vocabularies.sessions.get(payment.session_id),
97                                                            payment.resp_approved_amount,
98                                                            payment.date.strftime("%d/%m/%y %H:%M:%S"))
99    elif payment.type == 'request':
100        row['title'] = "%s for Session %s, %s" % (vocabularies.payment_categories.get(payment.category),
101                                                            vocabularies.sessions.get(payment.session_id),
102                                                            payment.date.strftime("%d/%m/%y %H:%M:%S"))                                                           
103    else:
104        row['title'] = "%s for Session %s, Naira %s, %s" % (vocabularies.payment_categories.get(payment.category),
105                                                            vocabularies.sessions.get(payment.session_id),
106                                                            payment.amount,
107                                                            payment.date.strftime("%d/%m/%y %H:%M:%S"))
108    oid = payment.order_id
109    onr = oid.rfind('-')+1
110    if onr > 0:
111        start_pos = onr
112    else:
113        start_pos = 6
114    url = row['url'] = "%s/p%s" % (payments_path,oid[start_pos:])
115    row['is_requeryable'] = "%s_%s" % (payment.category,payment.session_id) not in paid_fees and (not payment.resp_desc or str(member) in ('admin','isouaba')) and payment.type == 'online'   # customized too
116    row['is_requestable'] = "%s_%s" % (payment.category,payment.session_id) not in paid_fees and (not payment.resp_desc or str(member) in ('admin','isouaba')) and payment.type == 'request'  # customized too
117    row['is_approvable'] = is_so and (row['is_requeryable'] or row['is_requestable']) and payment.category == 'schoolfee' # does not make sense for maintenance
118    row['resp_desc'] = payment.resp_desc or 'Payment Process Interrupted'
119    row['trans_ref'] = payment.order_id
120    if row['is_requeryable']:
121        if payment.category == 'schoolfee':
122            row['callback_url'] = "%(url)s/interswitch_cb" % row
123        elif payment.category == 'schoolfee2':
124            row['callback_url'] = "%(url)s/interswitch_cb2" % row             
125#        if payment.category == 'schoolfee':
126#            row['callback_url'] = "%(url)s/interswitch_cb" % row
127#        elif payment.category == 'hostel_maintenance':
128#            row['callback_url'] = "%(url)s/interswitch_acco_cb" % row
129#        else:
130        href = '%(query_url)s' % info
131        href += '?transRef=%(trans_ref)s' % row
132        href += '&prodID=%(prod_id)s' % info
133        href += '&redirectURL=%(callback_url)s' % row
134        row['href'] = href
135    elif row['is_requestable']:
136        if payment.category == 'schoolfee':
137            row['callback_url'] = "%(url)s/interswitch_request_cb" % row
138        elif payment.category == 'schoolfee2':
139            row['callback_url'] = "%(url)s/interswitch_request_cb2" % row     
140        #href = '%(query_url)s' % info
141        #href = "http://testwebpay.interswitchng.com/CollegepayService/TransactionQueryURL.aspx"
142        href = "http://webpay.interswitchng.com/CollegepayService/TransactionQueryURL.aspx "
143        href += '?redirectURL=%(callback_url)s' % row
144        #href += '&productid=%(prod_id)s' % info
145        href += '&productid=53'
146        href += '&merchantref=ignore'
147        href += '&custNumber=%s' % student_id
148        href += '&session=%s' % info['next_session_str']
149        href += '&semester=Semester 1'
150        if payment.category == 'schoolfee2':   
151            href += '&semester=Semester 2'         
152        row['href'] = href       
153    if payment.status == 'paid':
154        row['confirmed'] = 'active'
155    else:
156        row['confirmed'] = 'unsuccessful'
157    row['is_editable'] = is_so and (row['confirmed'] == 'active')
158    payments.append(row)
159
160payments.sort(cmp=lambda x,y: cmp(x['trans_ref'],y['trans_ref']))
161info['payments'] = payments
162return info
163
Note: See TracBrowser for help on using the repository browser.