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

Last change on this file since 3091 was 3069, checked in by joachim, 17 years ago

avoid portal_catalog in payments-list

File size: 7.2 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"""
14
15mtool = context.portal_membership
16wftool = context.portal_workflow
17member = mtool.getAuthenticatedMember()
18if mtool.isAnonymousUser():
19    return None
20try:
21    from Products.zdb import set_trace
22except:
23    def set_trace():
24        pass
25
26
27#import logging
28#logger = logging.getLogger('Skins.getPaymentsFolderInfo')
29def cmp_id(a,b):
30    s1 = "%(id)s" % a
31    s2 = "%(id)s" % b
32    if s1 == s2:
33        return 0
34    if s1 > s2:
35        return 1
36    return -1
37
38import DateTime
39request = context.REQUEST
40students = context.portal_url.getPortalObject().campus.students
41student_id = context.getStudentId()
42if student_id is None:
43    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
44student = getattr(students,student_id)
45student_record = context.students_catalog.getRecordByKey(student_id)
46#context['updatePayments']()
47payments = []
48
49info = {}
50is_so = info['is_so'] = context.isSectionOfficer()
51is_student = info['is_student'] = context.isStudent()
52info['student_name'] = student_record.name
53info['query_url'] = "https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx"
54review_state = info['review_state'] = student_record.review_state
55parttime = student_record.mode and student_record.mode.endswith('_pt')
56fulltime = student_record.mode and student_record.mode.endswith('_ft')
57
58#if review_state == 'cleared_and_validated' or (parttime and review_state == 'returning'):
59#    online_payment = True
60#elif fulltime and review_state == 'returning':
61#    sc_payment = True
62
63session = student_record.session
64next_info = context.getNextInfo(student_record)
65info['next_session'] = next_info['next_session_id']
66info['next_session_str'] = next_info['next_session_str']
67info['payment_method'] = ""
68info['reasons'] = next_info['reasons']
69
70if review_state == 'cleared_and_validated':
71    info['payment_method'] = "online_payment"
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
77
78for payment_id,payment in context.objectItems():
79    row = {}
80    row['id'] = payment_id
81    row['title'] = payment.Title()
82    url = row['url'] = payment.absolute_url()
83    payment_doc = payment.getContent()
84    row['type'] = payment_doc.portal_type
85    review_state = row['review_state'] = wftool.getInfoFor(payment,'review_state',None)
86    if payment_doc.type_description.startswith('School Fee'):
87        row['is_approvable'] = is_so and (review_state == "opened") and info['review_state'] == 'cleared_and_validated'
88    else:
89        row['is_approvable'] = is_so and (review_state == "opened")
90    row['is_requeryable'] = False
91    #set_trace()
92    row['resp_desc'] = getattr(payment_doc,'resp_desc','no response')
93    row['trans_ref'] = getattr(payment_doc,'order_id','')
94    if payment_doc.type_description.startswith('School Fee'):
95        if (review_state == 'opened' and info['review_state'] in ('cleared_and_validated',) and \
96            hasattr(payment_doc, 'order_id') and not payment_doc.resp_code) or str(member) in ('admin',):
97            row['is_requeryable'] = True
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    elif payment_doc.type_description.startswith('Hostel'):
105        if (review_state == 'opened' and \
106            hasattr(payment_doc, 'order_id') and not payment_doc.resp_code) or str(member) in ('admin','delejason','isouaba'):
107            row['is_requeryable'] = True
108            row['callback_url'] = "%(url)s/interswitch_acco_cb" % row
109            href = '%(query_url)s' % info
110            href += '?transRef=%(trans_ref)s' % row
111            href += '&prodID=%(prod_id)s' % info
112            href += '&redirectURL=%(callback_url)s' % row
113            row['href'] = href
114    if (review_state == "closed") and payment_doc.resp_code in ('SC','00','AP','IP',):
115        row['confirmed'] = 'active'
116    else:
117        row['confirmed'] = 'unsuccessful'
118    row['is_editable'] = is_so and (row['confirmed'] == 'active')
119    payments.append(row)
120# payments_path = "%s/campus/students/%s/payments" % (context.portal_url.getPortalPath(),student_id)
121# sos = context.portal_catalog(container_path=payments_path)
122# info['is_so'] = is_so
123
124# for so in sos:
125#     row = {}
126#     row['id'] = so.getId
127#     row['title'] = so.Title
128#     url = row['url'] = "%s/%s" % (payments_path,so.getId)
129#     so_doc = context.restrictedTraverse(url,default=None).getContent()
130#     row['type'] = so.portal_type
131#     review_state = row['review_state'] = so.review_state
132#     if so_doc.type_description.startswith('School Fee'):
133#         row['is_approvable'] = is_so and (review_state == "opened") and info['review_state'] in ('cleared_and_validated','returning')
134#     else:
135#         row['is_approvable'] = False    # is_so and (review_state == "opened")
136#     row['is_requeryable'] = False
137#     #set_trace()
138#     row['resp_desc'] = getattr(so_doc,'resp_desc','no response')
139#     row['trans_ref'] = getattr(so_doc,'order_id','')
140#     if so_doc.type_description.startswith('School Fee'):
141#         if (review_state == 'opened' and info['review_state'] in ('cleared_and_validated','returning') and \
142#                                   hasattr(so_doc, 'order_id') and not so_doc.resp_code) or str(member) in ('admin','delejason','isouaba'):
143#             row['is_requeryable'] = True
144#             row['callback_url'] = "%s/payments/%s/interswitch_cb" % (student.absolute_url(),
145#                                                             so.getId)
146#             href = '%(query_url)s' % info
147#             href += '?transRef=%(trans_ref)s' % row
148#             href += '&prodID=%(prod_id)s' % info
149#             href += '&redirectURL=%(callback_url)s' % row
150#             row['href'] = href
151#     elif so_doc.type_description.startswith('Hostel'):
152#         if (review_state == 'opened' and \
153#                                   hasattr(so_doc, 'order_id') and not so_doc.resp_code) or str(member) in ('admin','delejason','isouaba'):
154#             row['is_requeryable'] = True
155#             row['callback_url'] = "%s/payments/%s/interswitch_acco_cb" % (student.absolute_url(),
156#                                                             so.getId)
157#             href = '%(query_url)s' % info
158#             href += '?transRef=%(trans_ref)s' % row
159#             href += '&prodID=%(prod_id)s' % info
160#             href += '&redirectURL=%(callback_url)s' % row
161#             row['href'] = href
162#     if (review_state == "closed") and so_doc.resp_code in ('SC','00','AP','IP',):
163#         row['confirmed'] = 'active'
164#     else:
165#         row['confirmed'] = 'unsuccessful'
166#     row['is_editable'] = is_so and (row['confirmed'] == 'active')
167#     payments.append(row)
168
169payments.sort(cmp_id)
170info['payments'] = payments
171return info
172
Note: See TracBrowser for help on using the repository browser.