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

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

not type but category!

Das hat bei dir auch nicht funktionieren können.

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