source: WAeUP_SRP/trunk/skins/waeup_uniben/getPaymentsFolderInfo.py @ 8134

Last change on this file since 8134 was 8134, checked in by Henrik Bettermann, 12 years ago

Replace eTranzact URL.

  • Property svn:keywords set to Id
File size: 6.0 KB
RevLine 
[7900]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 8134 2012-04-12 18:33:06Z henrik $
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
29import DateTime
30request = context.REQUEST
31#students = context.portal_url.getPortalObject().campus.students
32student_id = context.getStudentId()
33if student_id is None:
34    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
35#student = getattr(students,student_id)
36student_record = context.students_catalog.getRecordByKey(student_id)
37
38
39info = {}
40is_so = info['is_so'] = context.isSectionOfficer()
41is_student = info['is_student'] = context.isStudent()
42info['student_name'] = student_record.name
43info['query_url'] = "https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx"
[8134]44info['query_url_tranzact'] = "https://www.etranzact.net/Query/queryPayoutletTransaction.jsp"
[7900]45review_state = info['review_state'] = student_record.review_state
46parttime = student_record.mode and student_record.mode.endswith('_pt')
47fulltime = student_record.mode and student_record.mode.endswith('_ft')
48
49
50session = student_record.session
51next_info = context.getNextInfo(student_record)
52info['next_session'] = next_info['next_session_id']
53info['next_session_str'] = next_info['next_session_str']
54info['payment_method'] = ""
55info['reasons'] = next_info['reasons']
56
57# begin customization
58
[7902]59info['payment_method'] = ""
60
[8110]61if not next_info['payment_allowed']:
62    pass
63elif review_state == 'cleared_and_validated' and session in ('11','12','13'):
[7900]64    info['payment_method'] = "online_payment"
[8000]65elif review_state == 'returning' and session in ('11','12','13'):
66    info['payment_method'] = "online_payment"
[8011]67elif review_state == 'returning' or review_state == 'cleared_and_validated':
[8004]68    info['payment_method'] = "both_payments"
[7901]69else:
[7902]70    info['payment_method'] = ""
[7900]71
72info['prod_id'] = '61'
73
74gown_records = aq_payments(Eq('student_id',student_id)  & Eq('category','gown'))
75try:
76    level = int(student_record.level)
77    end_level = int(student_record.end_level)
78    if level >= end_level and not gown_records:
79        info['gown'] = True
80except:
81    pass
82
[8028]83if review_state == 'admitted':
84    info['acceptance'] = True
85else:
86    info['acceptance'] = False
87
[7900]88# end customization
89
90info['student_name'] = student_record.name
91payments_path = "%s/campus/students/%s/payments" % (context.portal_url(),student_id)
92payments = []
93payment_records = aq_payments(Eq('student_id',student_id)) # & Eq('session_id',student_record.session))
94vocabularies = context.portal_vocabularies
95paid_fees = []
96for payment in payment_records:
97    if payment.status == "paid":
98        paid_fees += "%s_%s" % (payment.category,payment.session_id),
99#info['pf'] = paid_fees
100for payment in payment_records:
101    row = {}
102    row['id'] = payment.key
103    if payment.status == 'invalid':
104        row['title'] = "Invalid Payment, Naira %s, %s" % (payment.amount,
105                                                          payment.date.strftime("%d/%m/%y %H:%M:%S"))
106    else:
107        row['title'] = "%s for Session %s, Naira %s, %s" % (vocabularies.payment_categories.get(payment.category),
108                                                            vocabularies.sessions.get(payment.session_id),
109                                                            payment.amount,
110                                                            payment.date.strftime("%d/%m/%y %H:%M:%S"))
111    oid = payment.order_id
112    onr = oid.rfind('-')+1
113    if onr > 0:
114        start_pos = onr
115    else:
116        start_pos = 6
117    row['sort_param'] = payment.date
118    url = row['url'] = "%s/p%s" % (payments_path,oid[start_pos:])
[7901]119    row['is_requeryable_interswitch'] = "%s_%s" % (payment.category,payment.session_id) not in paid_fees and payment.type == 'online' #or str(member) in ('admin',)
120    row['is_requeryable_etranzact'] = "%s_%s" % (payment.category,payment.session_id) not in paid_fees and payment.type == 'etranzact' #or str(member) in ('admin',)
121    row['is_approvable'] = is_so and (row['is_requeryable_interswitch'] or row['is_requeryable_etranzact'])and payment.category == 'schoolfee' # does not make sense for maitenance
[7900]122    row['resp_desc'] = payment.resp_desc or 'Payment Process Interrupted'
123    row['trans_ref'] = payment.order_id
[7901]124    if row['is_requeryable_interswitch']:
125        row['callback_url_inter'] = "%(url)s/interswitch_cb" % row
[7900]126#        if payment.category == 'schoolfee':
127#            row['callback_url'] = "%(url)s/interswitch_cb" % row
128#        elif payment.category == 'hostel_maintenance':
129#            row['callback_url'] = "%(url)s/interswitch_acco_cb" % row
130#        else:
131        href = '%(query_url)s' % info
132        href += '?transRef=%(trans_ref)s' % row
133        href += '&prodID=%(prod_id)s' % info
[7901]134        href += '&redirectURL=%(callback_url_inter)s' % row
135        row['href_inter'] = href
136
137    if row['is_requeryable_etranzact']:
[8028]138        row['callback_url_tranzact'] = "%(url)s/etranzact_cb" % row
[7901]139#        if payment.category == 'schoolfee':
140#            row['callback_url'] = "%(url)s/interswitch_cb" % row
141#        elif payment.category == 'hostel_maintenance':
142#            row['callback_url'] = "%(url)s/interswitch_acco_cb" % row
143#        else:
144
145        href = 'enter_tranzact_pin'
146        href += '?query_url=%(query_url_tranzact)s' % info
147        href += '&redirectURL=%(callback_url_tranzact)s' % row
148        row['href_tranzact'] = href
149
[7900]150    if payment.status == 'paid':
151        row['confirmed'] = 'active'
152    else:
153        row['confirmed'] = 'unsuccessful'
154    row['is_editable'] = is_so and (row['confirmed'] == 'active')
155    payments.append(row)
156
157payments.sort(cmp=lambda x,y: cmp(x['sort_param'],y['sort_param']))
158info['payments'] = payments
159return info
Note: See TracBrowser for help on using the repository browser.