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