1 | # -*- coding: utf-8 -*- |
---|
2 | ## $Id: browser.py 17429 2023-06-05 04:34:30Z henrik $ |
---|
3 | ## |
---|
4 | ## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann |
---|
5 | ## This program is free software; you can redistribute it and/or modify |
---|
6 | ## it under the terms of the GNU General Public License as published by |
---|
7 | ## the Free Software Foundation; either version 2 of the License, or |
---|
8 | ## (at your option) any later version. |
---|
9 | ## |
---|
10 | ## This program is distributed in the hope that it will be useful, |
---|
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty ofself.context.amount_auth |
---|
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | ## GNU General Public License for more details. |
---|
14 | ## |
---|
15 | ## You should have received a copy of the GNU General Public License |
---|
16 | ## along with this program; if not, write to the Free Software |
---|
17 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
18 | ## |
---|
19 | import httplib |
---|
20 | import hashlib |
---|
21 | import grok |
---|
22 | import os |
---|
23 | import csv |
---|
24 | from xml.dom import minidom |
---|
25 | from zope.interface import Interface |
---|
26 | from zope.component import queryAdapter |
---|
27 | from waeup.kofa.interfaces import CLEARED |
---|
28 | from kofacustom.nigeria.interswitch.browser import ( |
---|
29 | InterswitchPaymentRequestWebservicePageStudent, |
---|
30 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
31 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
32 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
33 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
34 | module_activated, |
---|
35 | ) |
---|
36 | from waeup.aaue.students.interfaces import ICustomStudentOnlinePayment |
---|
37 | from waeup.aaue.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
38 | from waeup.aaue.students.utils import SFEECHANGES |
---|
39 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
40 | |
---|
41 | PRODUCT_ID = '5845' |
---|
42 | SITE_NAME = 'aaue.waeup.org' |
---|
43 | PROVIDER_ACCT = '0200244434' |
---|
44 | PROVIDER_BANK_ID = '11' |
---|
45 | PROVIDER_ITEM_NAME = 'WAeAC Portal Fee' |
---|
46 | INSTITUTION_NAME = 'AAU Ekpoma' |
---|
47 | CURRENCY = '566' |
---|
48 | GATEWAY_AMT = 200.0 |
---|
49 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay' |
---|
50 | |
---|
51 | HOST = 'webpay.interswitchng.com' |
---|
52 | URL = '/paydirect/api/v1/gettransaction.json' |
---|
53 | HTTPS = True |
---|
54 | MAC = '9718FA00B0F5070B388A9896ADCED9B2FB02D30F71E12E68BDADC63F6852A3496FF97D8A0F9DA9F753B911A49BB09BB87B55FD02046BD325C74C46C0123CF023' |
---|
55 | |
---|
56 | httplib.HTTPSConnection.debuglevel = 0 |
---|
57 | |
---|
58 | BANK_ACCOUNTS = { |
---|
59 | 'edohis': ('2043582455', '8'), |
---|
60 | 'union': ('1019763348', '7'), |
---|
61 | 'union_pt': ('0051005007', '31'), |
---|
62 | 'sport': ('1021941220', '7'), |
---|
63 | 'access': ('1012688013', '123'), |
---|
64 | 'notebook': ('4011210501', '51'), |
---|
65 | 'accredit': ('5060023412', '51'), |
---|
66 | 'library': ('2000122995', '8'), |
---|
67 | 'fac1': ('1022438743', '7'), |
---|
68 | 'fac2': ('2000249757', '8'), |
---|
69 | 'fac3': ('1012678566', '123'), |
---|
70 | 'matricgown':('2000249757', '8'), |
---|
71 | 'lapel': ('2000249757', '8'), |
---|
72 | 'lmsplus': ('5060023429', '51'), |
---|
73 | |
---|
74 | 'acceptance': ('2043582644', '8'), |
---|
75 | 'parttime': ('1012678566', '123'), |
---|
76 | |
---|
77 | 'ijmb': ('1012278272', '123'), |
---|
78 | 'exam': ('1012278272', '123'), |
---|
79 | |
---|
80 | |
---|
81 | 'hostel_maintenance': ('1006406795', '123'), |
---|
82 | 'bed_allocation': ('1006406795', '123'), |
---|
83 | 'late_registration': ('5210006575', '51'), |
---|
84 | 'ent_combined': ('6220029828', '51'), |
---|
85 | 'ent_registration_0': ('6220029828', '51'), |
---|
86 | 'ent_registration_1': ('6220029828', '51'), |
---|
87 | 'ent_registration_2': ('6220029828', '51'), |
---|
88 | 'ent_text_book_0': ('6220029828', '51'), |
---|
89 | 'ent_text_book_1': ('6220029828', '51'), |
---|
90 | 'ent_text_book_2': ('6220029828', '51'), |
---|
91 | 'gst_registration_1': ('1010893123', '117'), |
---|
92 | 'gst_registration_2': ('1010893123', '117'), |
---|
93 | 'gst_text_book_0': ('1010893123', '117'), |
---|
94 | 'gst_text_book_1': ('1010893123', '117'), |
---|
95 | 'gst_text_book_2': ('1010893123', '117'), |
---|
96 | 'gst_text_book_3': ('1010893123', '117'), |
---|
97 | |
---|
98 | 'postgrad': ('1010827641', '117'), |
---|
99 | } |
---|
100 | |
---|
101 | FEE_NAMES = { |
---|
102 | 'edohis': 'Edo State Health Insurance Scheme', |
---|
103 | 'union': 'Student Union Dues', |
---|
104 | 'union_pt': 'Student Union Dues Part-Time', |
---|
105 | 'sport': 'Sport Development Fee', |
---|
106 | 'access': 'Access Card Fee', |
---|
107 | 'notebook': 'Branded Notebook', |
---|
108 | 'accredit': 'Accreditation Fee', |
---|
109 | 'library': 'Library Development Fee', |
---|
110 | 'tuition': 'Tuition', |
---|
111 | 'acceptance': 'Acceptance Fee', |
---|
112 | 'matricgown': 'Matriculation Gown Fee', |
---|
113 | 'lapel': 'File/Lapel Fee', |
---|
114 | 'lmsplus': 'LMS Plus Fee', |
---|
115 | 'nuga': 'NUGA Fee', |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | SCHOOLFEES = dict() |
---|
120 | |
---|
121 | for year in SFEECHANGES: |
---|
122 | schoolfees_path = os.path.join( |
---|
123 | os.path.dirname(__file__), '../students/schoolfees_%s.csv' %year) |
---|
124 | reader = csv.DictReader(open(schoolfees_path, 'rb')) |
---|
125 | SCHOOLFEES[year] = {item['code']:item for item in reader} |
---|
126 | |
---|
127 | acceptancefees_path = os.path.join( |
---|
128 | os.path.dirname(__file__), '../students/acceptancefees.csv') |
---|
129 | reader = csv.DictReader(open(acceptancefees_path, 'rb')) |
---|
130 | ACCEPTANCEFEES = {item['code']:item for item in reader} |
---|
131 | |
---|
132 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
133 | """ View which sends a POST request to the Interswitch |
---|
134 | CollegePAY payment gateway. |
---|
135 | |
---|
136 | So far only PT application has been configured. |
---|
137 | """ |
---|
138 | grok.context(ICustomApplicantOnlinePayment) |
---|
139 | action = POST_ACTION |
---|
140 | site_name = SITE_NAME |
---|
141 | currency = CURRENCY |
---|
142 | provider_bank_id = PROVIDER_BANK_ID |
---|
143 | provider_acct = PROVIDER_ACCT |
---|
144 | pay_item_id = '101' |
---|
145 | product_id = PRODUCT_ID |
---|
146 | |
---|
147 | def update(self): |
---|
148 | if not module_activated( |
---|
149 | self.context.__parent__.__parent__.year, self.context): |
---|
150 | self.flash(_('Forbidden'), type='danger') |
---|
151 | self.redirect(self.url(self.context, '@@index')) |
---|
152 | return |
---|
153 | error = self.init_update() |
---|
154 | if error: |
---|
155 | self.flash(error, type='danger') |
---|
156 | self.redirect(self.url(self.context, '@@index')) |
---|
157 | return |
---|
158 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
159 | # and add the gateway amount. |
---|
160 | if not self.context.r_company: |
---|
161 | self.context.net_amt = self.context.amount_auth |
---|
162 | self.context.amount_auth += GATEWAY_AMT |
---|
163 | self.context.gateway_amt = GATEWAY_AMT |
---|
164 | self.context.r_company = u'interswitch' |
---|
165 | xmldict = {} |
---|
166 | provider_amt = 2000.0 |
---|
167 | xmldict['institution_acct'] = '2043582644' |
---|
168 | xmldict['institution_bank_id'] = '8' |
---|
169 | if self.applicant.__parent__.code in ('ver2019', 'send2019', 'res2024'): |
---|
170 | provider_amt = 3000.0 |
---|
171 | xmldict['institution_acct'] = '2043583005' |
---|
172 | xmldict['institution_bank_id'] = '8' |
---|
173 | elif self.applicant.__parent__.code.startswith('cert'): |
---|
174 | provider_amt = 3000.0 |
---|
175 | elif self.applicant.__parent__.code.startswith('trans'): |
---|
176 | provider_amt = 3000.0 |
---|
177 | if self.applicant.applicant_id.startswith('dsh'): |
---|
178 | xmldict['institution_acct'] = '2043582644' |
---|
179 | xmldict['institution_bank_id'] = '8' |
---|
180 | elif self.applicant.applicant_id.startswith('ijmbe'): |
---|
181 | xmldict['institution_acct'] = '2043582644' |
---|
182 | xmldict['institution_bank_id'] = '8' |
---|
183 | elif 'alumni' in self.application_url(): |
---|
184 | xmldict['institution_acct'] = '2043583005' |
---|
185 | xmldict['detail_ref'] = self.context.p_id |
---|
186 | xmldict['provider_amt'] = 100 * provider_amt |
---|
187 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
188 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
189 | if 'alumni' in self.application_url(): |
---|
190 | xmldict['provider_acct'] = '0427773399' |
---|
191 | xmldict['provider_bank_id'] = '10' |
---|
192 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
193 | xmldict['institution_item_name'] = self.context.category |
---|
194 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
195 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
196 | if not self.context.provider_amt: |
---|
197 | self.context.provider_amt = provider_amt |
---|
198 | self.context.amount_auth += provider_amt |
---|
199 | if provider_amt: |
---|
200 | xmltext = """<payment_item_detail> |
---|
201 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
202 | <item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" /> |
---|
203 | <item_detail item_id="2" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" /> |
---|
204 | </item_details> |
---|
205 | </payment_item_detail>""" % xmldict |
---|
206 | else: |
---|
207 | xmltext = """<payment_item_detail> |
---|
208 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
209 | <item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" /> |
---|
210 | </item_details> |
---|
211 | </payment_item_detail>""" % xmldict |
---|
212 | |
---|
213 | # Overwrite above configuration |
---|
214 | if self.applicant.__parent__.code in ('cert1', 'cert2', 'cert6', 'cert9'): |
---|
215 | xmldict['institution_amt'] = 100 * self.context.net_amt - 100000 |
---|
216 | xmltext = """<payment_item_detail> |
---|
217 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
218 | <item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" /> |
---|
219 | <item_detail item_id="2" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" /> |
---|
220 | <item_detail item_id="3" item_name="Ambrose Alli Foundation" item_amt="100000" bank_id="117" acct_num="1015567975" /> |
---|
221 | </item_details> |
---|
222 | </payment_item_detail>""" % xmldict |
---|
223 | |
---|
224 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
225 | xmlitems = '' |
---|
226 | xmldoc = minidom.parseString(xmltext) |
---|
227 | itemlist = xmldoc.getElementsByTagName('item_detail') |
---|
228 | for s in itemlist: |
---|
229 | xmlitems += "%s (%s %s, %s (%s)), " % ( |
---|
230 | s.attributes['item_name'].value, |
---|
231 | u'\u20a6', |
---|
232 | int(s.attributes['item_amt'].value)/100, |
---|
233 | s.attributes['acct_num'].value, |
---|
234 | s.attributes['bank_id'].value, |
---|
235 | ) |
---|
236 | self.context.p_split_data = xmlitems |
---|
237 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
238 | hashargs = ( |
---|
239 | self.context.p_id + |
---|
240 | PRODUCT_ID + |
---|
241 | self.pay_item_id + |
---|
242 | str(int(self.amount_auth)) + |
---|
243 | self.site_redirect_url + |
---|
244 | MAC) |
---|
245 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
246 | return |
---|
247 | |
---|
248 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
249 | """ View which sends a POST request to the Interswitch |
---|
250 | CollegePAY payment gateway. |
---|
251 | """ |
---|
252 | grok.context(ICustomStudentOnlinePayment) |
---|
253 | action = POST_ACTION |
---|
254 | site_name = SITE_NAME |
---|
255 | currency = CURRENCY |
---|
256 | pay_item_id = '101' |
---|
257 | product_id = PRODUCT_ID |
---|
258 | |
---|
259 | def update(self): |
---|
260 | if not module_activated( |
---|
261 | self.context.student.current_session, self.context): |
---|
262 | self.flash(_('Forbidden'), type='danger') |
---|
263 | self.redirect(self.url(self.context, '@@index')) |
---|
264 | return |
---|
265 | error = self.init_update() |
---|
266 | if error: |
---|
267 | self.flash(error, type='danger') |
---|
268 | self.redirect(self.url(self.context, '@@index')) |
---|
269 | return |
---|
270 | student = self.student |
---|
271 | category = self.context.p_category |
---|
272 | # To guarantee that cleared students pay both acceptance fee |
---|
273 | # and school fees, the page can only be accessed |
---|
274 | # for school fee payments if acceptance/clearance fee has |
---|
275 | # been successfully queried/paid beforehand. This |
---|
276 | # requirement applies to students in state 'cleared' and |
---|
277 | # entry_session greater than 2012 only. |
---|
278 | if self.context.p_category.startswith('schoolfee') and \ |
---|
279 | student.state == CLEARED and \ |
---|
280 | student.entry_session > 2012: |
---|
281 | acceptance_fee_paid = False |
---|
282 | for ticket in student['payments'].values(): |
---|
283 | if ticket.p_state == 'paid' and \ |
---|
284 | ticket.p_category.startswith('clearance'): |
---|
285 | acceptance_fee_paid = True |
---|
286 | break |
---|
287 | if not acceptance_fee_paid: |
---|
288 | self.flash( |
---|
289 | _('Please pay acceptance fee first.'), type="danger") |
---|
290 | self.redirect(self.url(self.context, '@@index')) |
---|
291 | return |
---|
292 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
293 | # and add the gateway amount. |
---|
294 | if not self.context.r_company: |
---|
295 | self.context.net_amt = self.context.amount_auth |
---|
296 | self.context.amount_auth += GATEWAY_AMT |
---|
297 | self.context.gateway_amt = GATEWAY_AMT |
---|
298 | self.context.r_company = u'interswitch' |
---|
299 | xmldict = self.xmldict |
---|
300 | # Provider data |
---|
301 | xmldict['detail_ref'] = self.context.p_id |
---|
302 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
303 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
304 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
305 | # Institution data |
---|
306 | xmldict['institution_acct'] = '00000000' |
---|
307 | xmldict['institution_bank_id'] = '00' |
---|
308 | provider_amt = 0.0 |
---|
309 | if category.startswith('clearance'): |
---|
310 | provider_amt = 1500.0 |
---|
311 | elif category.startswith('hostel_maintenance'): |
---|
312 | provider_amt = 1000.0 |
---|
313 | elif category in ('schoolfee', 'schoolfee_1', 'schoolfee_incl'): |
---|
314 | provider_amt = 2500.0 |
---|
315 | xmldict['provider_amt'] = 100 * provider_amt |
---|
316 | xmldict['institution_item_name'] = self.context.category |
---|
317 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
318 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
319 | if not self.context.provider_amt: |
---|
320 | self.context.provider_amt = provider_amt |
---|
321 | self.context.amount_auth += provider_amt |
---|
322 | xmltext = '' |
---|
323 | |
---|
324 | # School fee |
---|
325 | if category.startswith('schoolfee'): |
---|
326 | # collect additional fees |
---|
327 | if self.context.p_category in ('schoolfee_1', 'schoolfee_incl'): |
---|
328 | xmltext = """<payment_item_detail> |
---|
329 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">""" % xmldict |
---|
330 | item_id = 1 |
---|
331 | |
---|
332 | if student.entry_session < 2013: |
---|
333 | sorted_items = SCHOOLFEES[12][student.certcode].items() |
---|
334 | elif student.entry_session < 2014: |
---|
335 | sorted_items = SCHOOLFEES[13][student.certcode].items() |
---|
336 | elif student.entry_session < 2015: |
---|
337 | sorted_items = SCHOOLFEES[14][student.certcode].items() |
---|
338 | elif student.entry_session < 2020: |
---|
339 | sorted_items = SCHOOLFEES[15][student.certcode].items() |
---|
340 | elif student.entry_session < 2021: |
---|
341 | sorted_items = SCHOOLFEES[20][student.certcode].items() |
---|
342 | elif student.entry_session < 2022: |
---|
343 | sorted_items = SCHOOLFEES[21][student.certcode].items() |
---|
344 | elif student.entry_session < 2023: |
---|
345 | sorted_items = SCHOOLFEES[22][student.certcode].items() |
---|
346 | else: |
---|
347 | sorted_items = SCHOOLFEES[23][student.certcode].items() |
---|
348 | # Move tuition. We expect that tuition is the fourth element |
---|
349 | sorted_items.insert(0, sorted_items.pop(3)) |
---|
350 | for item in sorted_items: |
---|
351 | try: |
---|
352 | if item[1].startswith('100_') and student.state == CLEARED: |
---|
353 | # first year payment only |
---|
354 | item_amt = int(item[1].split('_')[1]) |
---|
355 | else: |
---|
356 | item_amt = int(item[1]) |
---|
357 | if self.context.p_category == 'schoolfee_1' and item[0] == 'tuition': |
---|
358 | item_amt /= 2 |
---|
359 | # Add non-indigenous fee and session specific penalty fees |
---|
360 | try: |
---|
361 | academic_session = grok.getSite()['configuration'][str(self.context.p_session)] |
---|
362 | except KeyError: |
---|
363 | self.flash( |
---|
364 | _('Session configuration object is missing.'), type="danger") |
---|
365 | self.redirect(self.url(self.context, '@@index')) |
---|
366 | return |
---|
367 | if student.is_postgrad and item[0] == 'tuition': |
---|
368 | item_amt += academic_session.penalty_pg |
---|
369 | if student.lga and not student.lga.startswith('edo') \ |
---|
370 | and student.entry_session < 2022: |
---|
371 | item_amt += 20000.0 |
---|
372 | else: |
---|
373 | item_amt += academic_session.penalty_ug |
---|
374 | item_amt *= 100 |
---|
375 | acct_num = '' |
---|
376 | bank_id = '' |
---|
377 | item_name = '' |
---|
378 | # Find appropriate bank |
---|
379 | bank = None |
---|
380 | try: |
---|
381 | bank = BANK_ACCOUNTS[item[0]] |
---|
382 | except: # transfer to faculty account |
---|
383 | if student.is_postgrad: |
---|
384 | bank = BANK_ACCOUNTS['postgrad'] |
---|
385 | elif student.current_mode in ( |
---|
386 | 'ug_pt', 'de_pt','dp_pt', 'de_dsh', 'ug_dsh', 'dp_ft'): |
---|
387 | bank = BANK_ACCOUNTS['parttime'] |
---|
388 | elif student.faccode in ('FAG', 'FAT', 'FBM', 'FMLS', 'fac1'): |
---|
389 | bank = BANK_ACCOUNTS['fac1'] |
---|
390 | elif student.faccode in ('FCS', 'FED', 'FES', 'FET'): |
---|
391 | bank = BANK_ACCOUNTS['fac2'] |
---|
392 | elif student.faccode in ('FLS', 'FLW', 'FMS', 'FPS', 'FSS'): |
---|
393 | bank = BANK_ACCOUNTS['fac3'] |
---|
394 | elif student.faccode in ('FP',): |
---|
395 | bank = BANK_ACCOUNTS['ijmb'] |
---|
396 | if not bank: |
---|
397 | self.flash( |
---|
398 | 'Bank account not set (%s).' % item[0], type="danger") |
---|
399 | self.redirect(self.url(self.context, '@@index')) |
---|
400 | return |
---|
401 | acct_num = bank[0] |
---|
402 | bank_id = bank[1] |
---|
403 | item_name = FEE_NAMES[item[0]] |
---|
404 | xmltext += """ |
---|
405 | <item_detail item_id="%s" item_name="%s" item_amt="%d" bank_id="%s" acct_num="%s" />""" % (item_id, item_name, item_amt, bank_id, acct_num) |
---|
406 | item_id += 1 |
---|
407 | except: |
---|
408 | pass |
---|
409 | xmldict['item_id'] = item_id |
---|
410 | xmltext += """ |
---|
411 | <item_detail item_id="%(item_id)d" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" /> |
---|
412 | </item_details> |
---|
413 | </payment_item_detail>""" % xmldict |
---|
414 | # no additional charges, determine faculty bank only |
---|
415 | else: |
---|
416 | bank = None |
---|
417 | if student.is_postgrad: |
---|
418 | bank = BANK_ACCOUNTS['postgrad'] |
---|
419 | elif student.current_mode in ( |
---|
420 | 'ug_pt', 'de_pt','dp_pt', 'de_dsh', 'ug_dsh', 'dp_ft'): |
---|
421 | bank = BANK_ACCOUNTS['parttime'] |
---|
422 | elif student.faccode in ('FAG', 'FAT', 'FBM', 'FMLS', 'fac1'): |
---|
423 | bank = BANK_ACCOUNTS['fac1'] |
---|
424 | elif student.faccode in ('FCS', 'FED', 'FES', 'FET'): |
---|
425 | bank = BANK_ACCOUNTS['fac2'] |
---|
426 | elif student.faccode in ('FLS', 'FLW', 'FMS', 'FPS', 'FSS'): |
---|
427 | bank = BANK_ACCOUNTS['fac3'] |
---|
428 | elif student.faccode in ('FP',): |
---|
429 | bank = BANK_ACCOUNTS['ijmb'] |
---|
430 | if not bank: |
---|
431 | self.flash('Bank account not set.', type="danger") |
---|
432 | self.redirect(self.url(self.context, '@@index')) |
---|
433 | return |
---|
434 | xmldict['institution_acct'] = bank[0] |
---|
435 | xmldict['institution_bank_id'] = bank[1] |
---|
436 | |
---|
437 | # Clearance (acceptance) fee |
---|
438 | |
---|
439 | elif category.startswith('clearance'): |
---|
440 | # collect additional fees |
---|
441 | if self.context.p_category == 'clearance_incl': |
---|
442 | xmltext = """<payment_item_detail> |
---|
443 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">""" % xmldict |
---|
444 | item_id = 1 |
---|
445 | for item in ACCEPTANCEFEES[student.certcode].items(): |
---|
446 | try: |
---|
447 | item_amt = 100 * int(item[1]) |
---|
448 | bank = BANK_ACCOUNTS[item[0]] |
---|
449 | acct_num = bank[0] |
---|
450 | bank_id = bank[1] |
---|
451 | item_name = FEE_NAMES[item[0]] |
---|
452 | xmltext += """ |
---|
453 | <item_detail item_id="%s" item_name="%s" item_amt="%d" bank_id="%s" acct_num="%s" />""" % (item_id, item_name, item_amt, bank_id, acct_num) |
---|
454 | item_id += 1 |
---|
455 | except: |
---|
456 | pass |
---|
457 | xmldict['item_id'] = item_id |
---|
458 | xmltext += """ |
---|
459 | <item_detail item_id="%(item_id)d" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" /> |
---|
460 | </item_details> |
---|
461 | </payment_item_detail>""" % xmldict |
---|
462 | # no additional charges, determine faculty bank only |
---|
463 | else: |
---|
464 | if student.is_postgrad: |
---|
465 | bank = BANK_ACCOUNTS['postgrad'] |
---|
466 | else: |
---|
467 | bank = BANK_ACCOUNTS['acceptance'] |
---|
468 | xmldict['institution_acct'] = bank[0] |
---|
469 | xmldict['institution_bank_id'] = bank[1] |
---|
470 | |
---|
471 | # Hostel Maintenance |
---|
472 | |
---|
473 | elif category == 'hostel_maintenance': |
---|
474 | xmldict['institution_amt'] = 100 * self.context.net_amt - 1000000 |
---|
475 | bank = BANK_ACCOUNTS[category] |
---|
476 | xmldict['institution_acct'] = bank[0] |
---|
477 | xmldict['institution_bank_id'] = bank[1] |
---|
478 | xmltext = """<payment_item_detail> |
---|
479 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
480 | <item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" /> |
---|
481 | <item_detail item_id="2" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" /> |
---|
482 | <item_detail item_id="3" item_name="Hostel Consumable Fee" item_amt="1000000" bank_id="123" acct_num="1012332141" /> |
---|
483 | </item_details> |
---|
484 | </payment_item_detail>""" % xmldict |
---|
485 | |
---|
486 | # Other fees |
---|
487 | |
---|
488 | elif category in BANK_ACCOUNTS.keys(): |
---|
489 | bank = BANK_ACCOUNTS[category] |
---|
490 | xmldict['institution_acct'] = bank[0] |
---|
491 | xmldict['institution_bank_id'] = bank[1] |
---|
492 | |
---|
493 | if not xmltext and provider_amt == 0: |
---|
494 | xmltext = """<payment_item_detail> |
---|
495 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
496 | <item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" /> |
---|
497 | </item_details> |
---|
498 | </payment_item_detail>""" % xmldict |
---|
499 | elif not xmltext: |
---|
500 | xmltext = """<payment_item_detail> |
---|
501 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
502 | <item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" /> |
---|
503 | <item_detail item_id="2" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" /> |
---|
504 | </item_details> |
---|
505 | </payment_item_detail>""" % xmldict |
---|
506 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
507 | xmlitems = '' |
---|
508 | xmldoc = minidom.parseString(xmltext) |
---|
509 | itemlist = xmldoc.getElementsByTagName('item_detail') |
---|
510 | for s in itemlist: |
---|
511 | xmlitems += "%s (%s %s, %s (%s)), " % ( |
---|
512 | s.attributes['item_name'].value, |
---|
513 | u'\u20a6', |
---|
514 | int(s.attributes['item_amt'].value)/100, |
---|
515 | s.attributes['acct_num'].value, |
---|
516 | s.attributes['bank_id'].value, |
---|
517 | ) |
---|
518 | self.context.p_split_data = xmlitems |
---|
519 | self.context.provider_amt = provider_amt |
---|
520 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
521 | hashargs = ( |
---|
522 | self.context.p_id + |
---|
523 | PRODUCT_ID + |
---|
524 | self.pay_item_id + |
---|
525 | str(int(self.amount_auth)) + |
---|
526 | self.site_redirect_url + |
---|
527 | MAC) |
---|
528 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
529 | return |
---|
530 | |
---|
531 | |
---|
532 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
533 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
534 | """Request webservice view for the CollegePAY gateway |
---|
535 | """ |
---|
536 | grok.context(ICustomApplicantOnlinePayment) |
---|
537 | gateway_host = HOST |
---|
538 | gateway_url = URL |
---|
539 | https = HTTPS |
---|
540 | mac = MAC |
---|
541 | product_id = PRODUCT_ID |
---|
542 | |
---|
543 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
544 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
545 | """Payment verify view for the CollegePAY gateway |
---|
546 | """ |
---|
547 | grok.context(ICustomApplicantOnlinePayment) |
---|
548 | gateway_host = HOST |
---|
549 | gateway_url = URL |
---|
550 | https = HTTPS |
---|
551 | mac = MAC |
---|
552 | product_id = PRODUCT_ID |
---|
553 | |
---|
554 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
555 | InterswitchPaymentRequestWebservicePageStudent): |
---|
556 | """Request webservice view for the CollegePAY gateway |
---|
557 | """ |
---|
558 | grok.context(ICustomStudentOnlinePayment) |
---|
559 | gateway_host = HOST |
---|
560 | gateway_url = URL |
---|
561 | https = HTTPS |
---|
562 | mac = MAC |
---|
563 | product_id = PRODUCT_ID |
---|
564 | |
---|
565 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
566 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
567 | """Payment verify view for the CollegePAY gateway |
---|
568 | """ |
---|
569 | grok.context(ICustomStudentOnlinePayment) |
---|
570 | gateway_host = HOST |
---|
571 | gateway_url = URL |
---|
572 | https = HTTPS |
---|
573 | mac = MAC |
---|
574 | product_id = PRODUCT_ID |
---|