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

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

fix URL

File size: 9.1 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#if review_state == 'cleared_and_validated' or (parttime and review_state == 'returning'):
61#    online_payment = True
62#elif fulltime and review_state == 'returning':
63#    sc_payment = True
64
65session = student_record.session
66next_info = context.getNextInfo(student_record)
67info['next_session'] = next_info['next_session_id']
68info['next_session_str'] = next_info['next_session_str']
69info['payment_method'] = ""
70info['reasons'] = next_info['reasons']
71
72if review_state == 'cleared_and_validated':
73    info['payment_method'] = "online_payment"
74elif review_state == 'returning' and info['next_session'] != session:
75    info['payment_method'] = "online_payment"
76info['prod_id'] = '83'
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.type,payment.session_id),
87for payment in payment_records:
88    row = {}
89    row['id'] = payment.key
90    row['title'] = "%s for Session %s, Naira %s, %s" % (vocabularies.payment_categories.get(payment.category),
91                                                        vocabularies.sessions.get(payment.session_id),
92                                                        payment.amount,
93                                                        payment.date.strftime("%d/%m/%y %H:%M:%S"))
94    url = row['url'] = "%s/p%s" % (payments_path,payment.order_id[6:])
95    row['is_requeryable'] = "%s_%s" % (payment.type,payment.session_id) not in paid_fees or str(member) in ('admin',)
96    row['is_approvable'] = is_so and row['is_requeryable']
97    row['resp_desc'] = payment.resp_desc or (row['is_requeryable'] and 'Payment Process Interrupted')
98    row['trans_ref'] = payment.order_id
99    if row['is_requeryable']:
100        row['callback_url'] = "%(url)s/interswitch_cb" % row
101        href = '%(query_url)s' % info
102        href += '?transRef=%(trans_ref)s' % row
103        href += '&prodID=%(prod_id)s' % info
104        href += '&redirectURL=%(callback_url)s' % row
105        row['href'] = href
106    if payment.status == 'paid':
107        row['confirmed'] = 'active'
108    else:
109        row['confirmed'] = 'unsuccessful'
110    row['is_editable'] = is_so and (row['confirmed'] == 'active')
111    payments.append(row)
112# for payment_id,payment in context.objectItems():
113#     row = {}
114#     row['id'] = payment_id
115#     row['title'] = payment.Title()
116#     url = row['url'] = payment.absolute_url()
117#     payment_doc = payment.getContent()
118#     row['type'] = payment_doc.portal_type
119#     review_state = row['review_state'] = wftool.getInfoFor(payment,'review_state',None)
120#     if payment_doc.type_description.startswith('School Fee'):
121#         row['is_approvable'] = is_so and (review_state == "opened") and info['review_state'] == 'cleared_and_validated'
122#     else:
123#         row['is_approvable'] = is_so and (review_state == "opened")
124#     row['is_requeryable'] = False
125#     #set_trace()
126#     row['resp_desc'] = getattr(payment_doc,'resp_desc','no response')
127#     row['trans_ref'] = getattr(payment_doc,'order_id','')
128#     if payment_doc.type_description.startswith('School Fee'):
129#         if (review_state == 'opened' and info['review_state'] in ('cleared_and_validated',) and \
130#             hasattr(payment_doc, 'order_id') and not payment_doc.resp_code) or str(member) in ('admin',):
131#             row['is_requeryable'] = True
132#             row['callback_url'] = "%(url)s/interswitch_cb" % row
133#             href = '%(query_url)s' % info
134#             href += '?transRef=%(trans_ref)s' % row
135#             href += '&prodID=%(prod_id)s' % info
136#             href += '&redirectURL=%(callback_url)s' % row
137#             row['href'] = href
138#     elif payment_doc.type_description.startswith('Hostel'):
139#         if (review_state == 'opened' and \
140#             hasattr(payment_doc, 'order_id') and not payment_doc.resp_code) or str(member) in ('admin','delejason','isouaba'):
141#             row['is_requeryable'] = True
142#             row['callback_url'] = "%(url)s/interswitch_acco_cb" % row
143#             href = '%(query_url)s' % info
144#             href += '?transRef=%(trans_ref)s' % row
145#             href += '&prodID=%(prod_id)s' % info
146#             href += '&redirectURL=%(callback_url)s' % row
147#             row['href'] = href
148#     if (review_state == "closed") and payment_doc.resp_code in ('SC','00','AP','IP',):
149#         row['confirmed'] = 'active'
150#     else:
151#         row['confirmed'] = 'unsuccessful'
152#     row['is_editable'] = is_so and (row['confirmed'] == 'active')
153#     payments.append(row)
154# payments_path = "%s/campus/students/%s/payments" % (context.portal_url.getPortalPath(),student_id)
155# sos = context.portal_catalog(container_path=payments_path)
156# info['is_so'] = is_so
157
158# for so in sos:
159#     row = {}
160#     row['id'] = so.getId
161#     row['title'] = so.Title
162#     url = row['url'] = "%s/%s" % (payments_path,so.getId)
163#     so_doc = context.restrictedTraverse(url,default=None).getContent()
164#     row['type'] = so.portal_type
165#     review_state = row['review_state'] = so.review_state
166#     if so_doc.type_description.startswith('School Fee'):
167#         row['is_approvable'] = is_so and (review_state == "opened") and info['review_state'] in ('cleared_and_validated','returning')
168#     else:
169#         row['is_approvable'] = False    # is_so and (review_state == "opened")
170#     row['is_requeryable'] = False
171#     #set_trace()
172#     row['resp_desc'] = getattr(so_doc,'resp_desc','no response')
173#     row['trans_ref'] = getattr(so_doc,'order_id','')
174#     if so_doc.type_description.startswith('School Fee'):
175#         if (review_state == 'opened' and info['review_state'] in ('cleared_and_validated','returning') and \
176#                                   hasattr(so_doc, 'order_id') and not so_doc.resp_code) or str(member) in ('admin','delejason','isouaba'):
177#             row['is_requeryable'] = True
178#             row['callback_url'] = "%s/payments/%s/interswitch_cb" % (student.absolute_url(),
179#                                                             so.getId)
180#             href = '%(query_url)s' % info
181#             href += '?transRef=%(trans_ref)s' % row
182#             href += '&prodID=%(prod_id)s' % info
183#             href += '&redirectURL=%(callback_url)s' % row
184#             row['href'] = href
185#     elif so_doc.type_description.startswith('Hostel'):
186#         if (review_state == 'opened' and \
187#                                   hasattr(so_doc, 'order_id') and not so_doc.resp_code) or str(member) in ('admin','delejason','isouaba'):
188#             row['is_requeryable'] = True
189#             row['callback_url'] = "%s/payments/%s/interswitch_acco_cb" % (student.absolute_url(),
190#                                                             so.getId)
191#             href = '%(query_url)s' % info
192#             href += '?transRef=%(trans_ref)s' % row
193#             href += '&prodID=%(prod_id)s' % info
194#             href += '&redirectURL=%(callback_url)s' % row
195#             row['href'] = href
196#     if (review_state == "closed") and so_doc.resp_code in ('SC','00','AP','IP',):
197#         row['confirmed'] = 'active'
198#     else:
199#         row['confirmed'] = 'unsuccessful'
200#     row['is_editable'] = is_so and (row['confirmed'] == 'active')
201#     payments.append(row)
202
203payments.sort(cmp_id)
204info['payments'] = payments
205return info
206
Note: See TracBrowser for help on using the repository browser.