source: WAeUP_SRP/fceokene/waeup_custom/getPaymentsFolderInfo.py @ 3229

Last change on this file since 3229 was 3229, checked in by Henrik Bettermann, 17 years ago

adjust getPaymentsFolderInfo.py to Okene version

File size: 8.9 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
29
30#import logging
31#logger = logging.getLogger('Skins.getPaymentsFolderInfo')
32def cmp_id(a,b):
33    s1 = "%(id)s" % a
34    s2 = "%(id)s" % b
35    if s1 == s2:
36        return 0
37    if s1 > s2:
38        return 1
39    return -1
40
41import DateTime
42request = context.REQUEST
43#students = context.portal_url.getPortalObject().campus.students
44student_id = context.getStudentId()
45if student_id is None:
46    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
47#student = getattr(students,student_id)
48student_record = context.students_catalog.getRecordByKey(student_id)
49#context['updatePayments']()
50
51info = {}
52is_so = info['is_so'] = context.isSectionOfficer()
53is_student = info['is_student'] = context.isStudent()
54info['student_name'] = student_record.name
55info['query_url'] = "https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx"
56review_state = info['review_state'] = student_record.review_state
57parttime = student_record.mode and student_record.mode.endswith('_pt')
58fulltime = student_record.mode and student_record.mode.endswith('_ft')
59
60
61session = student_record.session
62next_info = context.getNextInfo(student_record)
63info['next_session'] = next_info['next_session_id']
64info['next_session_str'] = next_info['next_session_str']
65info['payment_method'] = ""
66info['reasons'] = next_info['reasons']
67
68if review_state == 'cleared_and_validated':
69    info['payment_method'] = "online_payment"
70
71
72elif review_state == 'returning' and info['next_session'] != session:
73    info['payment_method'] = "online_payment"
74info['prod_id'] = '83'
75
76info['student_name'] = student_record.name
77payments_path = "%s/campus/students/%s/payments" % (context.portal_url(),student_id)
78payments = []
79payment_records = aq_payments(Eq('student_id',student_id) & Eq('session_id',student_record.session))
80vocabularies = context.portal_vocabularies
81paid_fees = []
82for payment in payment_records:
83    if payment.status == "paid":
84        paid_fees += "%s_%s" % (payment.type,payment.session_id),
85for payment in payment_records:
86    row = {}
87    row['id'] = payment.key
88    row['title'] = "%s for Session %s, Naira %s, %s" % (vocabularies.payment_categories.get(payment.category),
89                                                        vocabularies.sessions.get(payment.session_id),
90                                                        payment.amount,
91                                                        payment.date.strftime("%d/%m/%y %H:%M:%S"))
92    url = row['url'] = "%s/p%s" % (payments_path,payment.order_id[6:])
93    row['is_requeryable'] = "%s_%s" % (payment.type,payment.session_id) not in paid_fees or str(member) in ('admin',)
94    row['is_approvable'] = is_so and row['is_requeryable']
95    row['resp_desc'] = payment.resp_desc or 'Payment Process Interrupted'
96    row['trans_ref'] = payment.order_id
97    if row['is_requeryable']:
98        row['callback_url'] = "%(url)s/interswitch_cb" % row
99        href = '%(query_url)s' % info
100        href += '?transRef=%(trans_ref)s' % row
101        href += '&prodID=%(prod_id)s' % info
102        href += '&redirectURL=%(callback_url)s' % row
103        row['href'] = href
104    if payment.status == 'paid':
105        row['confirmed'] = 'active'
106    else:
107        row['confirmed'] = 'unsuccessful'
108    row['is_editable'] = is_so and (row['confirmed'] == 'active')
109    payments.append(row)
110# for payment_id,payment in context.objectItems():
111#     row = {}
112#     row['id'] = payment_id
113#     row['title'] = payment.Title()
114#     url = row['url'] = payment.absolute_url()
115#     payment_doc = payment.getContent()
116#     row['type'] = payment_doc.portal_type
117#     review_state = row['review_state'] = wftool.getInfoFor(payment,'review_state',None)
118#     if payment_doc.type_description.startswith('School Fee'):
119#         row['is_approvable'] = is_so and (review_state == "opened") and info['review_state'] == 'cleared_and_validated'
120#     else:
121#         row['is_approvable'] = is_so and (review_state == "opened")
122#     row['is_requeryable'] = False
123#     #set_trace()
124#     row['resp_desc'] = getattr(payment_doc,'resp_desc','no response')
125#     row['trans_ref'] = getattr(payment_doc,'order_id','')
126#     if payment_doc.type_description.startswith('School Fee'):
127#         if (review_state == 'opened' and info['review_state'] in ('cleared_and_validated',) and \
128#             hasattr(payment_doc, 'order_id') and not payment_doc.resp_code) or str(member) in ('admin',):
129#             row['is_requeryable'] = True
130#             row['callback_url'] = "%(url)s/interswitch_cb" % row
131#             href = '%(query_url)s' % info
132#             href += '?transRef=%(trans_ref)s' % row
133#             href += '&prodID=%(prod_id)s' % info
134#             href += '&redirectURL=%(callback_url)s' % row
135#             row['href'] = href
136#     elif payment_doc.type_description.startswith('Hostel'):
137#         if (review_state == 'opened' and \
138#             hasattr(payment_doc, 'order_id') and not payment_doc.resp_code) or str(member) in ('admin','delejason','isouaba'):
139#             row['is_requeryable'] = True
140#             row['callback_url'] = "%(url)s/interswitch_acco_cb" % row
141#             href = '%(query_url)s' % info
142#             href += '?transRef=%(trans_ref)s' % row
143#             href += '&prodID=%(prod_id)s' % info
144#             href += '&redirectURL=%(callback_url)s' % row
145#             row['href'] = href
146#     if (review_state == "closed") and payment_doc.resp_code in ('SC','00','AP','IP',):
147#         row['confirmed'] = 'active'
148#     else:
149#         row['confirmed'] = 'unsuccessful'
150#     row['is_editable'] = is_so and (row['confirmed'] == 'active')
151#     payments.append(row)
152# payments_path = "%s/campus/students/%s/payments" % (context.portal_url.getPortalPath(),student_id)
153# sos = context.portal_catalog(container_path=payments_path)
154# info['is_so'] = is_so
155
156# for so in sos:
157#     row = {}
158#     row['id'] = so.getId
159#     row['title'] = so.Title
160#     url = row['url'] = "%s/%s" % (payments_path,so.getId)
161#     so_doc = context.restrictedTraverse(url,default=None).getContent()
162#     row['type'] = so.portal_type
163#     review_state = row['review_state'] = so.review_state
164#     if so_doc.type_description.startswith('School Fee'):
165#         row['is_approvable'] = is_so and (review_state == "opened") and info['review_state'] in ('cleared_and_validated','returning')
166#     else:
167#         row['is_approvable'] = False    # is_so and (review_state == "opened")
168#     row['is_requeryable'] = False
169#     #set_trace()
170#     row['resp_desc'] = getattr(so_doc,'resp_desc','no response')
171#     row['trans_ref'] = getattr(so_doc,'order_id','')
172#     if so_doc.type_description.startswith('School Fee'):
173#         if (review_state == 'opened' and info['review_state'] in ('cleared_and_validated','returning') and \
174#                                   hasattr(so_doc, 'order_id') and not so_doc.resp_code) or str(member) in ('admin','delejason','isouaba'):
175#             row['is_requeryable'] = True
176#             row['callback_url'] = "%s/payments/%s/interswitch_cb" % (student.absolute_url(),
177#                                                             so.getId)
178#             href = '%(query_url)s' % info
179#             href += '?transRef=%(trans_ref)s' % row
180#             href += '&prodID=%(prod_id)s' % info
181#             href += '&redirectURL=%(callback_url)s' % row
182#             row['href'] = href
183#     elif so_doc.type_description.startswith('Hostel'):
184#         if (review_state == 'opened' and \
185#                                   hasattr(so_doc, 'order_id') and not so_doc.resp_code) or str(member) in ('admin','delejason','isouaba'):
186#             row['is_requeryable'] = True
187#             row['callback_url'] = "%s/payments/%s/interswitch_acco_cb" % (student.absolute_url(),
188#                                                             so.getId)
189#             href = '%(query_url)s' % info
190#             href += '?transRef=%(trans_ref)s' % row
191#             href += '&prodID=%(prod_id)s' % info
192#             href += '&redirectURL=%(callback_url)s' % row
193#             row['href'] = href
194#     if (review_state == "closed") and so_doc.resp_code in ('SC','00','AP','IP',):
195#         row['confirmed'] = 'active'
196#     else:
197#         row['confirmed'] = 'unsuccessful'
198#     row['is_editable'] = is_so and (row['confirmed'] == 'active')
199#     payments.append(row)
200
201payments.sort(cmp_id)
202info['payments'] = payments
203return info
204
Note: See TracBrowser for help on using the repository browser.