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 8593 2012-06-01 21:20:25Z henrik $ |
---|
11 | """ |
---|
12 | Info for the PaymentsFolder |
---|
13 | """ |
---|
14 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
15 | |
---|
16 | mtool = context.portal_membership |
---|
17 | wftool = context.portal_workflow |
---|
18 | member = mtool.getAuthenticatedMember() |
---|
19 | payments_catalog = context.payments_catalog |
---|
20 | aq_payments = payments_catalog.evalAdvancedQuery |
---|
21 | if mtool.isAnonymousUser(): |
---|
22 | return None |
---|
23 | try: |
---|
24 | from Products.zdb import set_trace |
---|
25 | except: |
---|
26 | def set_trace(): |
---|
27 | pass |
---|
28 | |
---|
29 | import DateTime |
---|
30 | request = context.REQUEST |
---|
31 | #students = context.portal_url.getPortalObject().campus.students |
---|
32 | student_id = context.getStudentId() |
---|
33 | if student_id is None: |
---|
34 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
35 | #student = getattr(students,student_id) |
---|
36 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
37 | |
---|
38 | |
---|
39 | info = {} |
---|
40 | is_so = info['is_so'] = context.isSectionOfficer() |
---|
41 | is_student = info['is_student'] = context.isStudent() |
---|
42 | info['student_name'] = student_record.name |
---|
43 | info['query_url'] = "https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx" |
---|
44 | info['query_url_tranzact'] = "https://www.etranzact.net/Query/queryPayoutletTransaction.jsp" |
---|
45 | review_state = info['review_state'] = student_record.review_state |
---|
46 | parttime = student_record.mode and student_record.mode.endswith('_pt') |
---|
47 | fulltime = student_record.mode and student_record.mode.endswith('_ft') |
---|
48 | |
---|
49 | |
---|
50 | session = student_record.session |
---|
51 | next_info = context.getNextInfo(student_record) |
---|
52 | info['next_session'] = next_info['next_session_id'] |
---|
53 | info['next_session_str'] = next_info['next_session_str'] |
---|
54 | info['payment_method'] = "" |
---|
55 | info['reasons'] = next_info['reasons'] |
---|
56 | |
---|
57 | # begin customization |
---|
58 | |
---|
59 | info['payment_method'] = "" |
---|
60 | |
---|
61 | if not next_info['payment_allowed']: |
---|
62 | pass |
---|
63 | elif review_state == 'cleared_and_validated' and session in ('11','12','13'): |
---|
64 | info['payment_method'] = "online_payment" |
---|
65 | elif review_state == 'returning' and session in ('10','11','12','13'): |
---|
66 | info['payment_method'] = "online_payment" |
---|
67 | elif review_state == 'returning' or review_state == 'cleared_and_validated': |
---|
68 | info['payment_method'] = "both_payments" |
---|
69 | else: |
---|
70 | info['payment_method'] = "" |
---|
71 | |
---|
72 | info['prod_id'] = '57' |
---|
73 | |
---|
74 | gown_records = aq_payments(Eq('student_id',student_id) & Eq('category','gown')) |
---|
75 | try: |
---|
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 |
---|
80 | except: |
---|
81 | pass |
---|
82 | |
---|
83 | if review_state == 'admitted': |
---|
84 | info['acceptance'] = True |
---|
85 | else: |
---|
86 | info['acceptance'] = False |
---|
87 | |
---|
88 | # end customization |
---|
89 | |
---|
90 | info['student_name'] = student_record.name |
---|
91 | payments_path = "%s/campus/students/%s/payments" % (context.portal_url(),student_id) |
---|
92 | payments = [] |
---|
93 | payment_records = aq_payments(Eq('student_id',student_id)) # & Eq('session_id',student_record.session)) |
---|
94 | vocabularies = context.portal_vocabularies |
---|
95 | paid_fees = [] |
---|
96 | for payment in payment_records: |
---|
97 | if payment.status == "paid": |
---|
98 | paid_fees += "%s_%s" % (payment.category,payment.session_id), |
---|
99 | #info['pf'] = paid_fees |
---|
100 | for payment in payment_records: |
---|
101 | row = {} |
---|
102 | row['id'] = payment.key |
---|
103 | try: |
---|
104 | p_date = payment.date.strftime("%d/%m/%y %H:%M:%S") |
---|
105 | except: |
---|
106 | p_date = '(no payment date provided)' |
---|
107 | if payment.status == 'invalid': |
---|
108 | row['title'] = "Invalid Payment, Naira %s, %s" % (payment.amount, |
---|
109 | p_date) |
---|
110 | else: |
---|
111 | row['title'] = "%s for Session %s, Naira %s, %s" % (vocabularies.payment_categories.get(payment.category), |
---|
112 | vocabularies.sessions.get(payment.session_id), |
---|
113 | payment.amount, |
---|
114 | p_date) |
---|
115 | oid = payment.order_id |
---|
116 | onr = oid.rfind('-')+1 |
---|
117 | if onr > 0: |
---|
118 | start_pos = onr |
---|
119 | else: |
---|
120 | start_pos = 6 |
---|
121 | row['sort_param'] = payment.date |
---|
122 | url = row['url'] = "%s/p%s" % (payments_path,oid[start_pos:]) |
---|
123 | row['is_requeryable_interswitch'] = "%s_%s" % (payment.category,payment.session_id) not in paid_fees and payment.type == 'online' #or str(member) in ('admin',) |
---|
124 | row['is_requeryable_etranzact'] = "%s_%s" % (payment.category,payment.session_id) not in paid_fees and payment.type == 'etranzact' #or str(member) in ('admin',) |
---|
125 | row['is_approvable'] = is_so and (row['is_requeryable_interswitch'] or row['is_requeryable_etranzact']) |
---|
126 | row['resp_desc'] = payment.resp_desc or 'Payment Process Interrupted' |
---|
127 | row['trans_ref'] = payment.order_id |
---|
128 | if row['is_requeryable_interswitch']: |
---|
129 | row['callback_url_inter'] = "%(url)s/interswitch_cb" % row |
---|
130 | # if payment.category == 'schoolfee': |
---|
131 | # row['callback_url'] = "%(url)s/interswitch_cb" % row |
---|
132 | # elif payment.category == 'hostel_maintenance': |
---|
133 | # row['callback_url'] = "%(url)s/interswitch_acco_cb" % row |
---|
134 | # else: |
---|
135 | href = '%(query_url)s' % info |
---|
136 | href += '?transRef=%(trans_ref)s' % row |
---|
137 | href += '&prodID=%(prod_id)s' % info |
---|
138 | href += '&redirectURL=%(callback_url_inter)s' % row |
---|
139 | row['href_inter'] = href |
---|
140 | |
---|
141 | if row['is_requeryable_etranzact']: |
---|
142 | row['callback_url_tranzact'] = "%(url)s/etranzact_cb" % row |
---|
143 | # if payment.category == 'schoolfee': |
---|
144 | # row['callback_url'] = "%(url)s/interswitch_cb" % row |
---|
145 | # elif payment.category == 'hostel_maintenance': |
---|
146 | # row['callback_url'] = "%(url)s/interswitch_acco_cb" % row |
---|
147 | # else: |
---|
148 | |
---|
149 | href = 'enter_tranzact_pin' |
---|
150 | href += '?query_url=%(query_url_tranzact)s' % info |
---|
151 | href += '&redirectURL=%(callback_url_tranzact)s' % row |
---|
152 | row['href_tranzact'] = href |
---|
153 | |
---|
154 | if payment.status == 'paid': |
---|
155 | row['confirmed'] = 'active' |
---|
156 | else: |
---|
157 | row['confirmed'] = 'unsuccessful' |
---|
158 | row['is_editable'] = is_so and (row['confirmed'] == 'active') |
---|
159 | payments.append(row) |
---|
160 | |
---|
161 | payments.sort(cmp=lambda x,y: cmp(x['sort_param'],y['sort_param'])) |
---|
162 | info['payments'] = payments |
---|
163 | return info |
---|