source: main/waeup.aaue/trunk/src/waeup/aaue/interswitch/browser.py @ 16951

Last change on this file since 16951 was 16951, checked in by Henrik Bettermann, 2 years ago

Change bank acount.

  • Property svn:keywords set to Id
File size: 38.4 KB
Line 
1# -*- coding: utf-8 -*-
2## $Id: browser.py 16951 2022-05-10 09:41:17Z 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 of
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##
19import httplib
20import hashlib
21import grok
22from xml.dom import minidom
23from zope.interface import Interface
24from zope.component import queryAdapter
25from waeup.kofa.interfaces import CLEARED
26from kofacustom.nigeria.interswitch.browser import (
27    InterswitchPaymentRequestWebservicePageStudent,
28    InterswitchPaymentRequestWebservicePageApplicant,
29    InterswitchPaymentVerifyWebservicePageApplicant,
30    InterswitchPaymentVerifyWebservicePageStudent,
31    InterswitchPageStudent, InterswitchPageApplicant,
32    )
33from waeup.aaue.students.interfaces import ICustomStudentOnlinePayment
34from waeup.aaue.applicants.interfaces import ICustomApplicantOnlinePayment
35from waeup.aaue.interfaces import MessageFactory as _
36
37PRODUCT_ID_PT = '5040'
38PRODUCT_ID_REGULAR = '5845'
39SITE_NAME = 'aaue.waeup.org'
40PROVIDER_ACCT = '5100189030'
41PROVIDER_BANK_ID = '307'
42PROVIDER_ITEM_NAME = 'WAeAC'
43INSTITUTION_NAME = 'AAU Ekpoma'
44CURRENCY = '566'
45GATEWAY_AMT = 200.0
46POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
47
48HOST = 'webpay.interswitchng.com'
49URL = '/paydirect/api/v1/gettransaction.json'
50HTTPS = True
51MAC_REGULAR = '9718FA00B0F5070B388A9896ADCED9B2FB02D30F71E12E68BDADC63F6852A3496FF97D8A0F9DA9F753B911A49BB09BB87B55FD02046BD325C74C46C0123CF023'
52MAC_PT = '74424F1DFECD6058F153148255CDD55E16724B4F380ADB2C63C5D1D7A5675759010C8153DCB930AAF2D38903CBF7CE32B8A6BA2C16BBC46721DF2E3F3E4548E3'
53
54httplib.HTTPSConnection.debuglevel = 0
55
56
57def gateway_net_amt(fee):
58    if fee > GATEWAY_AMT:
59        return fee - GATEWAY_AMT
60    return 0.0
61
62def contr_agreement_applicant(applicant):
63    if applicant.__parent__.prefix in (
64        'fp',
65        'ptee',
66        'dsh',
67        'bridge',
68        'ijmbe',
69        ):
70        return 'first'
71    return 'second'
72
73def contr_agreement_student(student):
74    if student.current_mode in (
75        'found',
76        'bridge',
77        'ug_dsh',
78        'de_dsh',
79        'ug_pt',
80        'de_pt',
81        'dp_pt',
82        'ijmbe',
83        ):
84        return 'first'
85    return 'second'
86
87class CustomInterswitchPageApplicant(InterswitchPageApplicant):
88    """ View which sends a POST request to the Interswitch
89    CollegePAY payment gateway.
90
91    So far only PT application has been configured.
92    """
93    grok.context(ICustomApplicantOnlinePayment)
94    action = POST_ACTION
95    site_name = SITE_NAME
96    currency = CURRENCY
97    provider_bank_id = PROVIDER_BANK_ID
98    provider_acct = PROVIDER_ACCT
99    institution_acct = '1010835352'
100    institution_bank_id = '117'
101
102    def update(self):
103
104        error = self.init_update()
105        if error:
106            self.flash(error, type='danger')
107            self.redirect(self.url(self.context, '@@index'))
108            return
109        self.context.r_company = u'interswitch'
110        provider_amt = 2000.0
111        fedex_amt = 0.0
112        if contr_agreement_applicant(self.applicant) == 'first':
113            self.product_id = PRODUCT_ID_PT
114            self.pay_item_id = '101'
115            self.mac = MAC_PT
116            if self.applicant.__parent__.prefix == 'ijmbe':
117                self.institution_bank_id = '123'
118                self.institution_acct = '1012278272'
119        else:
120            self.product_id = PRODUCT_ID_REGULAR
121            self.pay_item_id = '109'
122            self.mac = MAC_REGULAR
123            if self.applicant.__parent__.prefix in ('utme', 'ude'):
124                provider_amt = 1000.0
125            elif self.applicant.__parent__.prefix in ('trans', 'cert'):
126                self.institution_acct = '1010827641'
127                self.institution_bank_id = '117'
128                self.provider_bank_id = '10'
129                self.provider_acct = '0427773399'
130                if self.applicant.applicant_id[:5] in ('cert7', 'cert8'):
131                    provider_amt = 0.0
132                if self.applicant.applicant_id[:6] in ('trans5', 'trans6'):
133                    self.institution_acct = '5210006575'
134                    self.institution_bank_id = '51'
135                #if self.applicant.applicant_id[:6] in ('trans1', 'trans6'):
136                #    fedex_amt = 10500.0
137                if self.context.p_category == 'app_balance':
138                    provider_amt = 0.0
139            elif self.applicant.applicant_id.startswith('bridge'): # easier to test
140                self.institution_acct = '1014847058'
141                self.institution_bank_id = '7'
142            elif self.applicant.applicant_id.startswith('dsh'): # easier to test
143                self.institution_acct = '1014847058'
144                self.institution_bank_id = '7'
145            elif self.applicant.__parent__.prefix in ('ver', 'send'):
146                provider_amt = 0.0
147            elif self.applicant.__parent__.prefix == 'fedex':
148                provider_amt = 0.0
149                self.institution_acct = '0001115694'
150                self.institution_bank_id = '10'
151            elif self.applicant.applicant_id.startswith('pg'):
152                self.institution_acct = '5210006575'
153                self.institution_bank_id = '51'
154
155        xmldict = {}
156        xmldict['detail_ref'] = self.context.p_id
157        xmldict['provider_amt'] = 100 * provider_amt
158        xmldict['provider_acct'] = self.provider_acct
159        xmldict['provider_bank_id'] = self.provider_bank_id
160        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
161        xmldict['institution_acct'] = self.institution_acct
162        xmldict['institution_bank_id'] = self.institution_bank_id
163        xmldict['institution_item_name'] = self.category
164        xmldict['institution_name'] = INSTITUTION_NAME
165        xmldict['fedex_amt'] = 100 * fedex_amt
166        xmldict['institution_amt'] = 100 * (
167            self.context.amount_auth - provider_amt - fedex_amt - GATEWAY_AMT)
168
169        xmltext = """<payment_item_detail>
170<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
171<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" />
172<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" />
173</item_details>
174</payment_item_detail>""" % xmldict
175
176        if provider_amt == 0.0:
177            xmltext = """<payment_item_detail>
178<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
179<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" />
180</item_details>
181</payment_item_detail>""" % xmldict
182
183        if fedex_amt:
184            xmltext = """<payment_item_detail>
185<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
186<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" />
187<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" />
188<item_detail item_id="3" item_name="FedEx" item_amt="%(fedex_amt)d" bank_id="10" acct_num="0001115694" />
189</item_details>
190</payment_item_detail>""" % xmldict
191
192        if self.applicant.applicant_id.startswith('pg'):
193            handbook_amount = 2000.0
194            xmldict['handbook_amount'] = 100 * handbook_amount
195            xmldict['institution_amt'] = 100 * (
196                self.context.amount_auth - provider_amt - handbook_amount -GATEWAY_AMT)
197            xmltext = """<payment_item_detail>
198<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
199<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" />
200<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" />
201<item_detail item_id="3" item_name="PG Handbook" item_amt="%(handbook_amount)d" bank_id="51" acct_num="5210006575" />
202</item_details>
203</payment_item_detail>""" % xmldict
204
205        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
206        self.context.provider_amt = provider_amt
207        self.context.gateway_amt = GATEWAY_AMT
208        xmlitems = ''
209        xmldoc = minidom.parseString(xmltext)
210        itemlist = xmldoc.getElementsByTagName('item_detail')
211        for s in itemlist:
212            xmlitems += "%s: %s, N%s, %s (%s)  " % (
213                s.attributes['item_id'].value,
214                s.attributes['item_name'].value,
215                int(s.attributes['item_amt'].value)/100,
216                s.attributes['acct_num'].value,
217                s.attributes['bank_id'].value,
218                )
219        self.context.p_split_data = xmlitems
220        self.amount_auth = int(100 * self.context.amount_auth)
221        hashargs = (
222            self.context.p_id +
223            self.product_id +
224            self.pay_item_id +
225            str(int(self.amount_auth)) +
226            self.site_redirect_url +
227            self.mac)
228        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
229
230        return
231
232class CustomInterswitchPageStudent(InterswitchPageStudent):
233    """ View which sends a POST request to the Interswitch
234    CollegePAY payment gateway.
235    """
236    grok.context(ICustomStudentOnlinePayment)
237    action = POST_ACTION
238    site_name = SITE_NAME
239    currency = CURRENCY
240    pay_item_id = '000'
241
242    def update(self):
243        error = self.init_update()
244        if error:
245            self.flash(error, type='danger')
246            self.redirect(self.url(self.context, '@@index'))
247            return
248        self.context.r_company = u'interswitch'
249        student = self.student
250        p_session = self.context.p_session
251        try:
252            academic_session = grok.getSite()['configuration'][str(p_session)]
253        except KeyError:
254            self.flash(_(u'Session configuration object is not available.'),
255                       type='danger')
256            self.redirect(self.url(self.context, '@@index'))
257            return
258        if contr_agreement_student(student) == 'first':
259            self.product_id = PRODUCT_ID_PT
260            self.mac = MAC_PT
261        else:
262            self.product_id = PRODUCT_ID_REGULAR
263            self.mac = MAC_REGULAR
264
265        # To guarantee that cleared students pay both acceptance fee
266        # and school fees, the page can only be accessed
267        # for school fee payments if acceptance/clearance fee has
268        # been successfully queried/paid beforehand. This
269        # requirement applies to students in state 'cleared' and
270        # entry_session greater than 2012 only.
271        if self.context.p_category.startswith('schoolfee') and \
272            student.state == CLEARED and \
273            student.entry_session > 2012:
274            acceptance_fee_paid = False
275            for ticket in student['payments'].values():
276                if ticket.p_state == 'paid' and \
277                    ticket.p_category.startswith('clearance'):
278                    acceptance_fee_paid = True
279                    break
280            if not acceptance_fee_paid:
281                self.flash(
282                    _('Please pay acceptance fee first.'), type="danger")
283                self.redirect(self.url(self.context, '@@index'))
284                return
285
286        xmldict = self.xmldict
287        xmltext = ""
288        xmldict['institution_acct'] = '1010827641'
289        xmldict['institution_bank_id'] = '117'
290        xmldict['detail_ref'] = self.context.p_id
291        xmldict['provider_acct'] = PROVIDER_ACCT
292        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
293        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
294        xmldict['institution_item_name'] = self.category
295        xmldict['institution_name'] = INSTITUTION_NAME
296        provider_amt = 0.0
297        xmldict['institution_amt'] = 100 * (
298            gateway_net_amt(self.context.amount_auth))
299
300        # Schoolfee
301        if self.context.p_category.startswith('schoolfee'):
302            if contr_agreement_student(student) == 'first':
303                # First agreement
304                provider_amt = 1900.0
305                joint_venture_amt = 0.0
306                aaue_share_amt = 0.0
307                student_union_due_amt = gateway_net_amt(
308                    academic_session.union_fee)
309                student_welfare_assurance_amt = gateway_net_amt(
310                    academic_session.welfare_fee)
311                sports_amt = gateway_net_amt(
312                    academic_session.sports_fee)
313                library_amt = gateway_net_amt(
314                    academic_session.library_fee)
315                library_amt_pg = gateway_net_amt(
316                    academic_session.library_pg_fee)
317                lms_sund_amt = gateway_net_amt(
318                    academic_session.lms_sund_fee)
319                xmldict['student_union_bank_id'] = '31'
320                xmldict['student_union_acct'] = '0051005007'
321                xmldict['aaue_share_bank_id'] = '117'
322                xmldict['aaue_share_acct'] = '1010827641'
323                xmldict['joint_venture_bank_id'] = '117'
324                xmldict['joint_venture_acct'] = '1010827641'
325                xmldict['institution_acct'] = '1014847058'
326                xmldict['institution_bank_id'] = '7'
327                self.pay_item_id = '105'
328                if student.current_mode == 'found':
329                    self.pay_item_id = '103'
330                elif student.current_mode == 'ijmbe':
331                    self.pay_item_id = '103'
332                    xmldict['institution_bank_id'] = '123'
333                    xmldict['institution_acct'] = '1012278272'
334            else:
335                # Second agreement
336                joint_venture_amt = 1000.0
337                aaue_share_amt = 1500.0
338                provider_amt = 1500.0
339                student_union_due_amt = gateway_net_amt(
340                    academic_session.union_fee)
341                student_welfare_assurance_amt = gateway_net_amt(
342                    academic_session.welfare_fee)
343                sports_amt = gateway_net_amt(
344                    academic_session.sports_fee)
345                library_amt = gateway_net_amt(
346                    academic_session.library_fee)
347                library_amt_pg = gateway_net_amt(
348                    academic_session.library_pg_fee)
349                lms_sund_amt = gateway_net_amt(
350                    academic_session.lms_sund_fee)
351                xmldict['student_union_bank_id'] = '7'
352                xmldict['student_union_acct'] = '1019763348'
353                xmldict['aaue_share_bank_id'] = '117'
354                xmldict['aaue_share_acct'] = '1010827641'
355                xmldict['joint_venture_bank_id'] = '117'
356                xmldict['joint_venture_acct'] = '1010827641'
357                self.pay_item_id = '107'
358                if student.is_postgrad:
359                    self.pay_item_id = '111'
360                    xmldict['institution_acct'] = '5210006575'
361                    xmldict['institution_bank_id'] = '51'
362
363            xmldict['provider_amt'] = 100 * provider_amt
364            xmldict['joint_venture_amt'] = 100 * joint_venture_amt
365            xmldict['aaue_share_amt'] = 100 * aaue_share_amt
366            xmldict['lms_sund_amt'] = 100 * lms_sund_amt
367            if self.context.p_item == 'Balance':
368                xmldict['institution_amt'] = 100 * (
369                    gateway_net_amt(self.context.amount_auth))
370            elif self.context.p_category == 'schoolfee_2':
371                xmldict['institution_amt'] = 100 * gateway_net_amt(
372                    self.context.amount_auth)
373                xmltext = """<payment_item_detail>
374<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
375<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" />
376</item_details>
377</payment_item_detail>""" % xmldict
378            elif self.context.p_category in ('schoolfee_incl', 'schoolfee_1') \
379                and student.current_mode != 'ijmbe':
380                # Schoolfee including additional fees
381                xmldict['student_union_due_amt'] = 100 * student_union_due_amt
382                xmldict['student_welfare_assurance_amt'] = 100 * student_welfare_assurance_amt
383
384                if student.entry_session >= 2018 and student.is_fresh:
385                    xmldict['sports_amt'] = 100 * sports_amt
386                    if student.is_postgrad:
387                        xmldict['library_amt'] = 100 * library_amt_pg
388                    else:
389                        xmldict['library_amt'] = 100 * library_amt
390                    xmldict['institution_amt'] = 100 * (
391                        gateway_net_amt(self.context.amount_auth)
392                        - provider_amt
393                        - joint_venture_amt
394                        - aaue_share_amt
395                        - student_union_due_amt
396                        - student_welfare_assurance_amt
397                        - sports_amt
398                        - library_amt
399                        - lms_sund_amt)
400                    xmltext = """<payment_item_detail>
401<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
402<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" />
403<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" />
404<item_detail item_id="3" item_name="Student Union" item_amt="%(student_union_due_amt)d" bank_id="%(student_union_bank_id)s" acct_num="%(student_union_acct)s" />
405<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />
406<item_detail item_id="5" item_name="Sports Development Fee" item_amt="%(sports_amt)d" bank_id="123" acct_num="1006407792" />
407<item_detail item_id="6" item_name="Library Development Fee" item_amt="%(library_amt)d" bank_id="8" acct_num="2000122995" />""" % xmldict
408                    if contr_agreement_student(student) == 'second':
409                        xmltext += """"
410<item_detail item_id="7" item_name="Joint Venture" item_amt="%(joint_venture_amt)d" bank_id="%(joint_venture_bank_id)s" acct_num="%(joint_venture_acct)s" />
411<item_detail item_id="8" item_name="AAUE Share" item_amt="%(aaue_share_amt)d" bank_id="%(aaue_share_bank_id)s" acct_num="%(aaue_share_acct)s" />""" % xmldict
412                    if student.entry_session >= 2021 and student.current_mode == 'ug_ft':
413                        xmltext += """"
414<item_detail item_id="9" item_name="LMS plus Sundry Fees" item_amt="%(lms_sund_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />""" % xmldict
415                    xmltext += """"
416</item_details>
417</payment_item_detail>"""
418                else:
419                    xmldict['institution_amt'] = 100 * (
420                        gateway_net_amt(self.context.amount_auth)
421                        - provider_amt
422                        - joint_venture_amt
423                        - aaue_share_amt
424                        - student_union_due_amt
425                        - student_welfare_assurance_amt)
426                    xmltext = """<payment_item_detail>
427<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
428<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" />
429<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" />
430<item_detail item_id="3" item_name="Student Union" item_amt="%(student_union_due_amt)d" bank_id="%(student_union_bank_id)s" acct_num="%(student_union_acct)s" />
431<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />""" % xmldict
432                    if contr_agreement_student(student) == 'second':
433                        xmltext += """"
434<item_detail item_id="5" item_name="Joint Venture" item_amt="%(joint_venture_amt)d" bank_id="%(joint_venture_bank_id)s" acct_num="%(joint_venture_acct)s" />
435<item_detail item_id="6" item_name="AAUE Share" item_amt="%(aaue_share_amt)d" bank_id="%(aaue_share_bank_id)s" acct_num="%(aaue_share_acct)s" />
436</item_details>
437</payment_item_detail>""" % xmldict
438                    else:
439                        xmltext += """"
440</item_details>
441</payment_item_detail>"""
442            elif contr_agreement_student(student) == 'second':
443                # Schoolfee without Student Union Fee ands Student Welfare Assurance
444                xmldict['institution_amt'] = 100 * (
445                    gateway_net_amt(self.context.amount_auth)
446                    - provider_amt
447                    - joint_venture_amt
448                    - aaue_share_amt)
449                xmltext = """<payment_item_detail>
450<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
451<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" />
452<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" />
453<item_detail item_id="3" item_name="Joint Venture" item_amt="%(joint_venture_amt)d" bank_id="%(joint_venture_bank_id)s" acct_num="%(joint_venture_acct)s" />
454<item_detail item_id="4" item_name="AAUE Share" item_amt="%(aaue_share_amt)d" bank_id="%(aaue_share_bank_id)s" acct_num="%(aaue_share_acct)s" />
455</item_details>
456</payment_item_detail>""" % xmldict
457            else:
458                xmldict['institution_amt'] = 100 * (
459                    gateway_net_amt(self.context.amount_auth)
460                    - provider_amt)
461                xmltext = """<payment_item_detail>
462<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
463<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" />
464<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" />
465</item_details>
466</payment_item_detail>""" % xmldict
467
468
469        # Clearance
470        elif self.context.p_category.startswith('clearance'):
471            xmldict['institution_acct'] = '1010835352'
472            provider_amt = 0.0
473            if contr_agreement_student(student) == 'first':
474                # First agreement
475                xmldict['institution_acct'] = '1014847058'
476                xmldict['institution_bank_id'] = '7'
477                self.pay_item_id = '104'
478                if student.current_mode == 'found':
479                    self.pay_item_id = '102'
480                elif student.current_mode == 'ijmbe':
481                    self.pay_item_id = '102'
482                    xmldict['institution_bank_id'] = '123'
483                    xmldict['institution_acct'] = '1012278272'
484            else:
485                # Second agreement
486                self.pay_item_id = '102'
487                if student.is_postgrad:
488                    self.pay_item_id = '110'
489                    xmldict['institution_acct'] = '5210006575'
490                    xmldict['institution_bank_id'] = '51'
491                # ivama: Acceptance fee split is unique to "ug_ft"
492                # The reason for split is perculiar to them only...
493                # That amount was deducted from UTME application fee because
494                # some regulatory body have pegged the application fee which
495                # didn't affect another programmes.
496                if student.current_mode == 'ug_ft':
497                    provider_amt = 1500.0
498            xmldict['provider_amt'] = 100 * provider_amt
499            if self.context.p_category.endswith('_incl'):
500                # Clearance including additional fees
501                gown_fee_amt = gateway_net_amt(academic_session.matric_gown_fee)
502                aaue_lf_fee_amt = gateway_net_amt(academic_session.lapel_fee)
503                xmldict['gown_fee_amt'] = 100 * gown_fee_amt
504                xmldict['aaue_lf_fee_amt'] = 100 * aaue_lf_fee_amt
505                xmldict['institution_amt'] = 100 * (
506                    gateway_net_amt(self.context.amount_auth)
507                    - gown_fee_amt
508                    - aaue_lf_fee_amt
509                    - provider_amt)
510                xmltext = """<payment_item_detail>
511<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
512<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" />
513<item_detail item_id="2" item_name="Matriculation Gown Fee" item_amt="%(gown_fee_amt)d" bank_id="117" acct_num="1010835352" />
514<item_detail item_id="3" item_name="AAU File-Lapel Fee" item_amt="%(aaue_lf_fee_amt)d" bank_id="117" acct_num="1010835352" />""" % xmldict
515                if provider_amt:
516                    xmltext += """"
517<item_detail item_id="4" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
518</item_details>
519</payment_item_detail>""" % xmldict
520                else:
521                    xmltext += """"
522</item_details>
523</payment_item_detail>"""
524
525            elif student.current_mode == 'bridge':
526                # Clearance without any surcharge
527                xmldict['institution_amt'] = 100 * gateway_net_amt(
528                    self.context.amount_auth)
529                xmltext = """<payment_item_detail>
530<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
531<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" />
532</item_details>
533</payment_item_detail>""" % xmldict
534
535            else:
536                # Clearance without additional fees
537                xmldict['institution_amt'] = 100 * (
538                    gateway_net_amt(self.context.amount_auth)
539                    - provider_amt)
540                xmltext = """<payment_item_detail>
541<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
542<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" />""" % xmldict
543                if provider_amt:
544                        xmltext += """"
545<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" />
546</item_details>
547</payment_item_detail>""" % xmldict
548                else:
549                        xmltext += """"
550</item_details>
551</payment_item_detail>"""
552
553        # Union Dues
554        elif self.context.p_category == 'union':
555            self.pay_item_id = '103'
556            xmldict['institution_amt'] = 100 * (
557                gateway_net_amt(self.context.amount_auth))
558            if contr_agreement_student(student) == 'first':
559                # First agreement
560                xmldict['institution_acct'] = '0051005007'
561                xmldict['institution_bank_id'] = '31'
562            else:
563                # Second agreement
564                xmldict['institution_bank_id'] = '7'
565                xmldict['institution_acct'] = '1019763348'
566
567        # Lapel/File
568        elif self.context.p_category == 'lapel':
569            self.pay_item_id = '104'
570            xmldict['institution_amt'] = 100 * (
571                gateway_net_amt(self.context.amount_auth))
572
573        # Welfare Assurance
574        elif self.context.p_category == 'welfare':
575            self.pay_item_id = '105'
576            xmldict['institution_acct'] = '1006407792'
577            xmldict['institution_bank_id'] = '123'
578            xmldict['institution_amt'] = 100 * (
579                gateway_net_amt(self.context.amount_auth))
580
581        # ID Card
582        elif self.context.p_category == 'id_card':
583            self.pay_item_id = '000'
584            xmldict['institution_amt'] = 100 * (
585                gateway_net_amt(self.context.amount_auth))
586
587        # Matric Gown
588        elif self.context.p_category == 'matric_gown':
589            self.pay_item_id = '106'
590            xmldict['institution_amt'] = 100 * (
591                gateway_net_amt(self.context.amount_auth))
592
593        # Concessional
594        elif self.context.p_category == 'concessional':
595            self.pay_item_id = '107'
596            xmldict['institution_amt'] = 100 * (
597                gateway_net_amt(self.context.amount_auth))
598
599        # Hostel Maintenance
600        elif self.context.p_category == 'hostel_maintenance':
601            provider_amt = 500.0
602            self.pay_item_id = '109'
603            xmldict['institution_acct'] = '1006406795'
604            xmldict['institution_bank_id'] = '123'
605            xmldict['provider_amt'] = 100 * provider_amt
606            xmldict['institution_amt'] = 100 * (
607                gateway_net_amt(self.context.amount_auth) - provider_amt)
608            xmltext = """<payment_item_detail>
609<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
610<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" />
611<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" />
612</item_details>
613</payment_item_detail>""" % xmldict
614
615        # GST Fees
616        elif self.context.p_category.startswith('gst_'):
617            if contr_agreement_student(student) == 'first':
618                self.pay_item_id = '115'
619            else:
620                self.pay_item_id = '116'
621            xmldict['institution_acct'] = '1010893123'
622            xmldict['institution_bank_id'] = '117'
623            xmldict['institution_amt'] = 100 * (
624                gateway_net_amt(self.context.amount_auth))
625
626        # ENT Fees
627        elif self.context.p_category.startswith('ent_'):
628            if contr_agreement_student(student) == 'first':
629                self.pay_item_id = '114'
630            else:
631                self.pay_item_id = '118'
632            xmldict['institution_acct'] = '6220029828'
633            xmldict['institution_bank_id'] = '51'
634            xmldict['institution_amt'] = 100 * (
635                gateway_net_amt(self.context.amount_auth))
636
637        # Faculty and Departmental Dues
638        elif self.context.p_category == 'fac_dep':
639            xmldict['institution_acct'] = '1016425386'
640            xmldict['institution_bank_id'] = '117'
641            self.pay_item_id = '117'
642            xmldict['institution_amt'] = 100 * (
643                gateway_net_amt(self.context.amount_auth))
644
645        # Restitution Fee
646        elif self.context.p_category == 'restitution':
647            self.pay_item_id = '117'
648            xmldict['institution_amt'] = 100 * (
649                gateway_net_amt(self.context.amount_auth))
650
651        # Faculty Laboratory Due
652        elif self.context.p_category in ('lab_1', 'lab_2'):
653            xmldict['institution_acct'] = '1016425386'
654            xmldict['institution_bank_id'] = '117'
655            self.pay_item_id = '117'
656            xmldict['institution_amt'] = 100 * (
657                gateway_net_amt(self.context.amount_auth))
658
659        # Sports Fee
660        #elif self.context.p_category == 'sports':
661        #    self.pay_item_id = '105'
662        #    xmldict['institution_amt'] = 100 * (
663        #        gateway_net_amt(self.context.amount_auth))
664
665        # Library Fee
666        #elif self.context.p_category == 'library':
667        #    self.pay_item_id = '105'
668        #    xmldict['institution_amt'] = 100 * (
669        #        gateway_net_amt(self.context.amount_auth))
670
671        # Library PG Fee
672        #elif self.context.p_category == 'library_pg':
673        #    self.pay_item_id = '105'
674        #    xmldict['institution_amt'] = 100 * (
675        #        gateway_net_amt(self.context.amount_auth))
676
677        # Exam Fee
678        elif self.context.p_category == 'exam':
679            self.pay_item_id = '103'
680            xmldict['institution_acct'] = '1012278272'
681            xmldict['institution_bank_id'] = '123'
682            xmldict['institution_amt'] = 100 * (
683                gateway_net_amt(self.context.amount_auth))
684
685        # LMS + Sundry Fees
686        elif self.context.p_category == 'lms_sund':
687            self.pay_item_id = '103'
688            xmldict['institution_amt'] = 100 * (
689                gateway_net_amt(self.context.amount_auth))
690
691        # Sports & Library Fee    temporarily in 2020
692        elif self.context.p_category == 'sports_library':
693            self.pay_item_id = '105'
694            xmldict['sports_amt'] = 100 * 3000.0
695            xmldict['library_amt'] = 100 * 1000.0
696            xmltext = """<payment_item_detail>
697<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
698<item_detail item_id="1" item_name="Sports Development Fee" item_amt="%(sports_amt)d" bank_id="123" acct_num="1006407792" />
699<item_detail item_id="2" item_name="Library Development Fee" item_amt="%(library_amt)d" bank_id="8" acct_num="2000122995" />
700</item_details>
701</payment_item_detail>""" % xmldict
702
703        # Late Registration Fee
704        elif self.context.p_category == 'late_registration':
705            if contr_agreement_student(student) == 'first':
706                self.pay_item_id = '113'
707            else:
708                self.pay_item_id = '123'
709            xmldict['institution_amt'] = 100 * (
710                gateway_net_amt(self.context.amount_auth))
711            if student.is_postgrad:
712                xmldict['institution_acct'] = '5210006575'
713                xmldict['institution_bank_id'] = '51'
714        if not xmltext:
715            xmltext = """<payment_item_detail>
716<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
717<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" />
718</item_details>
719</payment_item_detail>""" % xmldict
720        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
721        self.context.provider_amt = provider_amt
722        self.context.gateway_amt = self.context.amount_auth - gateway_net_amt(
723            self.context.amount_auth)
724        xmlitems = ''
725        xmldoc = minidom.parseString(xmltext)
726        itemlist = xmldoc.getElementsByTagName('item_detail')
727        for s in itemlist:
728            xmlitems += "%s: %s, %s %s, %s (%s)  " % (
729                s.attributes['item_id'].value,
730                s.attributes['item_name'].value,
731                u'\u20a6',
732                int(s.attributes['item_amt'].value)/100,
733                s.attributes['acct_num'].value,
734                s.attributes['bank_id'].value,
735                )
736        self.context.p_split_data = xmlitems
737        self.amount_auth = int(100 * self.context.amount_auth)
738        hashargs = (
739            self.context.p_id +
740            self.product_id +
741            self.pay_item_id +
742            str(int(self.amount_auth)) +
743            self.site_redirect_url +
744            self.mac)
745        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
746        return
747
748
749class CustomInterswitchPaymentRequestWebservicePageApplicant(
750    InterswitchPaymentRequestWebservicePageApplicant):
751    """Request webservice view for the CollegePAY gateway
752    """
753    grok.context(ICustomApplicantOnlinePayment)
754    gateway_host = HOST
755    gateway_url = URL
756    https = HTTPS
757
758    @property
759    def mac(self):
760        if contr_agreement_applicant(self.context.__parent__) == 'first':
761            return MAC_PT
762        return MAC_REGULAR
763
764    @property
765    def product_id(self):
766        if contr_agreement_applicant(self.context.__parent__) == 'first':
767            return PRODUCT_ID_PT
768        return PRODUCT_ID_REGULAR
769
770class CustomInterswitchPaymentVerifyWebservicePageApplicant(
771    InterswitchPaymentVerifyWebservicePageApplicant):
772    """Payment verify view for the CollegePAY gateway
773    """
774    grok.context(ICustomApplicantOnlinePayment)
775    gateway_host = HOST
776    gateway_url = URL
777    https = HTTPS
778
779    @property
780    def mac(self):
781        if contr_agreement_applicant(self.context.__parent__) == 'first':
782            return MAC_PT
783        return MAC_REGULAR
784
785    @property
786    def product_id(self):
787        if contr_agreement_applicant(self.context.__parent__) == 'first':
788            return PRODUCT_ID_PT
789        return PRODUCT_ID_REGULAR
790
791class CustomInterswitchPaymentRequestWebservicePageStudent(
792    InterswitchPaymentRequestWebservicePageStudent):
793    """Request webservice view for the CollegePAY gateway
794    """
795    grok.context(ICustomStudentOnlinePayment)
796    gateway_host = HOST
797    gateway_url = URL
798    https = HTTPS
799
800    @property
801    def mac(self):
802        if contr_agreement_student(self.context.student) == 'first':
803            return MAC_PT
804        return MAC_REGULAR
805
806    @property
807    def product_id(self):
808        if contr_agreement_student(self.context.student) == 'first':
809            return PRODUCT_ID_PT
810        return PRODUCT_ID_REGULAR
811
812class CustomInterswitchPaymentVerifyWebservicePageStudent(
813    InterswitchPaymentVerifyWebservicePageStudent):
814    """Payment verify view for the CollegePAY gateway
815    """
816    grok.context(ICustomStudentOnlinePayment)
817    gateway_host = HOST
818    gateway_url = URL
819    https = HTTPS
820
821    @property
822    def mac(self):
823        if contr_agreement_student(self.context.student) == 'first':
824            return MAC_PT
825        return MAC_REGULAR
826
827    @property
828    def product_id(self):
829        if contr_agreement_student(self.context.student) == 'first':
830            return PRODUCT_ID_PT
831        return PRODUCT_ID_REGULAR
Note: See TracBrowser for help on using the repository browser.