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

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

merge callback scripts and more

File size: 9.3 KB
RevLine 
[2644]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"""
[3226]14from Products.AdvancedQuery import Eq, Between, Le,In
[2644]15
16mtool = context.portal_membership
[3069]17wftool = context.portal_workflow
[2890]18member = mtool.getAuthenticatedMember()
[3226]19payments_catalog = context.payments_catalog
20aq_payments = payments_catalog.evalAdvancedQuery
[2644]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
[3226]43#students = context.portal_url.getPortalObject().campus.students
[2644]44student_id = context.getStudentId()
45if student_id is None:
46    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
[3226]47#student = getattr(students,student_id)
[2871]48student_record = context.students_catalog.getRecordByKey(student_id)
[2644]49
[3240]50
[2644]51info = {}
52is_so = info['is_so'] = context.isSectionOfficer()
53is_student = info['is_student'] = context.isStudent()
[2871]54info['student_name'] = student_record.name
[2644]55info['query_url'] = "https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx"
[2871]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')
[2644]59
60
[2871]61session = student_record.session
62next_info = context.getNextInfo(student_record)
[2644]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
[2657]68if review_state == 'cleared_and_validated':
[2644]69    info['payment_method'] = "online_payment"
[3237]70#elif review_state == 'cleared_and_validated' and session == '07':
71#    info['payment_method'] = "sc_payment"
[2657]72elif review_state == 'returning' and info['next_session'] != session:
73    info['payment_method'] = "online_payment"
[2834]74info['prod_id'] = '83'
[2644]75
[2871]76info['student_name'] = student_record.name
[3227]77payments_path = "%s/campus/students/%s/payments" % (context.portal_url(),student_id)
[3226]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":
[3230]84        paid_fees += "%s_%s" % (payment.category,payment.session_id),
85#info['pf'] = paid_fees
[3226]86for payment in payment_records:
[2644]87    row = {}
[3226]88    row['id'] = payment.key
89    row['title'] = "%s for Session %s, Naira %s, %s" % (vocabularies.payment_categories.get(payment.category),
90                                                        vocabularies.sessions.get(payment.session_id),
91                                                        payment.amount,
92                                                        payment.date.strftime("%d/%m/%y %H:%M:%S"))
93    url = row['url'] = "%s/p%s" % (payments_path,payment.order_id[6:])
[3230]94    row['is_requeryable'] = "%s_%s" % (payment.category,payment.session_id) not in paid_fees or str(member) in ('admin',)
[3240]95    row['is_approvable'] = is_so and row['is_requeryable'] and payment.category == 'schoolfee' # does not make sense for maitenance
[3229]96    row['resp_desc'] = payment.resp_desc or 'Payment Process Interrupted'
[3226]97    row['trans_ref'] = payment.order_id
98    if row['is_requeryable']:
[3240]99        row['callback_url'] = "%(url)s/interswitch_cb" % row
100#        if payment.category == 'schoolfee':
101#            row['callback_url'] = "%(url)s/interswitch_cb" % row
102#        elif payment.category == 'hostel_maintenance':
103#            row['callback_url'] = "%(url)s/interswitch_acco_cb" % row
104#        else:
[3226]105        href = '%(query_url)s' % info
106        href += '?transRef=%(trans_ref)s' % row
107        href += '&prodID=%(prod_id)s' % info
108        href += '&redirectURL=%(callback_url)s' % row
109        row['href'] = href
110    if payment.status == 'paid':
[2644]111        row['confirmed'] = 'active'
112    else:
113        row['confirmed'] = 'unsuccessful'
[2758]114    row['is_editable'] = is_so and (row['confirmed'] == 'active')
[2644]115    payments.append(row)
[3226]116# for payment_id,payment in context.objectItems():
117#     row = {}
118#     row['id'] = payment_id
119#     row['title'] = payment.Title()
120#     url = row['url'] = payment.absolute_url()
121#     payment_doc = payment.getContent()
122#     row['type'] = payment_doc.portal_type
123#     review_state = row['review_state'] = wftool.getInfoFor(payment,'review_state',None)
124#     if payment_doc.type_description.startswith('School Fee'):
125#         row['is_approvable'] = is_so and (review_state == "opened") and info['review_state'] == 'cleared_and_validated'
126#     else:
127#         row['is_approvable'] = is_so and (review_state == "opened")
128#     row['is_requeryable'] = False
129#     #set_trace()
130#     row['resp_desc'] = getattr(payment_doc,'resp_desc','no response')
131#     row['trans_ref'] = getattr(payment_doc,'order_id','')
132#     if payment_doc.type_description.startswith('School Fee'):
133#         if (review_state == 'opened' and info['review_state'] in ('cleared_and_validated',) and \
134#             hasattr(payment_doc, 'order_id') and not payment_doc.resp_code) or str(member) in ('admin',):
135#             row['is_requeryable'] = True
136#             row['callback_url'] = "%(url)s/interswitch_cb" % row
137#             href = '%(query_url)s' % info
138#             href += '?transRef=%(trans_ref)s' % row
139#             href += '&prodID=%(prod_id)s' % info
140#             href += '&redirectURL=%(callback_url)s' % row
141#             row['href'] = href
142#     elif payment_doc.type_description.startswith('Hostel'):
143#         if (review_state == 'opened' and \
144#             hasattr(payment_doc, 'order_id') and not payment_doc.resp_code) or str(member) in ('admin','delejason','isouaba'):
145#             row['is_requeryable'] = True
146#             row['callback_url'] = "%(url)s/interswitch_acco_cb" % row
147#             href = '%(query_url)s' % info
148#             href += '?transRef=%(trans_ref)s' % row
149#             href += '&prodID=%(prod_id)s' % info
150#             href += '&redirectURL=%(callback_url)s' % row
151#             row['href'] = href
152#     if (review_state == "closed") and payment_doc.resp_code in ('SC','00','AP','IP',):
153#         row['confirmed'] = 'active'
154#     else:
155#         row['confirmed'] = 'unsuccessful'
156#     row['is_editable'] = is_so and (row['confirmed'] == 'active')
157#     payments.append(row)
[3069]158# payments_path = "%s/campus/students/%s/payments" % (context.portal_url.getPortalPath(),student_id)
159# sos = context.portal_catalog(container_path=payments_path)
160# info['is_so'] = is_so
[2644]161
[3069]162# for so in sos:
163#     row = {}
164#     row['id'] = so.getId
165#     row['title'] = so.Title
166#     url = row['url'] = "%s/%s" % (payments_path,so.getId)
167#     so_doc = context.restrictedTraverse(url,default=None).getContent()
168#     row['type'] = so.portal_type
169#     review_state = row['review_state'] = so.review_state
170#     if so_doc.type_description.startswith('School Fee'):
171#         row['is_approvable'] = is_so and (review_state == "opened") and info['review_state'] in ('cleared_and_validated','returning')
172#     else:
173#         row['is_approvable'] = False    # is_so and (review_state == "opened")
174#     row['is_requeryable'] = False
175#     #set_trace()
176#     row['resp_desc'] = getattr(so_doc,'resp_desc','no response')
177#     row['trans_ref'] = getattr(so_doc,'order_id','')
178#     if so_doc.type_description.startswith('School Fee'):
179#         if (review_state == 'opened' and info['review_state'] in ('cleared_and_validated','returning') and \
180#                                   hasattr(so_doc, 'order_id') and not so_doc.resp_code) or str(member) in ('admin','delejason','isouaba'):
181#             row['is_requeryable'] = True
182#             row['callback_url'] = "%s/payments/%s/interswitch_cb" % (student.absolute_url(),
183#                                                             so.getId)
184#             href = '%(query_url)s' % info
185#             href += '?transRef=%(trans_ref)s' % row
186#             href += '&prodID=%(prod_id)s' % info
187#             href += '&redirectURL=%(callback_url)s' % row
188#             row['href'] = href
189#     elif so_doc.type_description.startswith('Hostel'):
190#         if (review_state == 'opened' and \
191#                                   hasattr(so_doc, 'order_id') and not so_doc.resp_code) or str(member) in ('admin','delejason','isouaba'):
192#             row['is_requeryable'] = True
193#             row['callback_url'] = "%s/payments/%s/interswitch_acco_cb" % (student.absolute_url(),
194#                                                             so.getId)
195#             href = '%(query_url)s' % info
196#             href += '?transRef=%(trans_ref)s' % row
197#             href += '&prodID=%(prod_id)s' % info
198#             href += '&redirectURL=%(callback_url)s' % row
199#             row['href'] = href
200#     if (review_state == "closed") and so_doc.resp_code in ('SC','00','AP','IP',):
201#         row['confirmed'] = 'active'
202#     else:
203#         row['confirmed'] = 'unsuccessful'
204#     row['is_editable'] = is_so and (row['confirmed'] == 'active')
205#     payments.append(row)
206
[2644]207payments.sort(cmp_id)
208info['payments'] = payments
209return info
210
Note: See TracBrowser for help on using the repository browser.