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

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

Fix typo.

  • Property svn:keywords set to Id
File size: 42.9 KB
RevLine 
[16942]1# -*- coding: utf-8 -*-
[12730]2## $Id: browser.py 17118 2022-10-05 12:37:11Z henrik $
[11846]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
[15473]22from xml.dom import minidom
[11846]23from zope.interface import Interface
24from zope.component import queryAdapter
[12975]25from waeup.kofa.interfaces import CLEARED
[11846]26from kofacustom.nigeria.interswitch.browser import (
27    InterswitchPaymentRequestWebservicePageStudent,
28    InterswitchPaymentRequestWebservicePageApplicant,
[13586]29    InterswitchPaymentVerifyWebservicePageApplicant,
30    InterswitchPaymentVerifyWebservicePageStudent,
[11846]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
[13379]37PRODUCT_ID_PT = '5040'
38PRODUCT_ID_REGULAR = '5845'
[11846]39SITE_NAME = 'aaue.waeup.org'
[15927]40PROVIDER_ACCT = '5100189030'
41PROVIDER_BANK_ID = '307'
[14823]42PROVIDER_ITEM_NAME = 'WAeAC'
[11846]43INSTITUTION_NAME = 'AAU Ekpoma'
44CURRENCY = '566'
[15867]45GATEWAY_AMT = 200.0
[11933]46POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
[11846]47
[11933]48HOST = 'webpay.interswitchng.com'
[13586]49URL = '/paydirect/api/v1/gettransaction.json'
[11916]50HTTPS = True
[13606]51MAC_REGULAR = '9718FA00B0F5070B388A9896ADCED9B2FB02D30F71E12E68BDADC63F6852A3496FF97D8A0F9DA9F753B911A49BB09BB87B55FD02046BD325C74C46C0123CF023'
52MAC_PT = '74424F1DFECD6058F153148255CDD55E16724B4F380ADB2C63C5D1D7A5675759010C8153DCB930AAF2D38903CBF7CE32B8A6BA2C16BBC46721DF2E3F3E4548E3'
[11846]53
[11917]54httplib.HTTPSConnection.debuglevel = 0
[11846]55
[13379]56
[13414]57def gateway_net_amt(fee):
[13438]58    if fee > GATEWAY_AMT:
[13414]59        return fee - GATEWAY_AMT
[13438]60    return 0.0
[13406]61
[13532]62def contr_agreement_applicant(applicant):
[16779]63    if applicant.__parent__.prefix in (
[15396]64        'fp',
65        'ptee',
66        'dsh',
67        'bridge',
68        'ijmbe',
69        ):
[13532]70        return 'first'
71    return 'second'
72
73def contr_agreement_student(student):
[15382]74    if student.current_mode in (
[15387]75        'found',
76        'bridge',
77        'ug_dsh',
78        'de_dsh',
79        'ug_pt',
80        'de_pt',
[15396]81        'dp_pt',
82        'ijmbe',
83        ):
[13403]84        return 'first'
85    return 'second'
[13379]86
[11846]87class CustomInterswitchPageApplicant(InterswitchPageApplicant):
88    """ View which sends a POST request to the Interswitch
89    CollegePAY payment gateway.
[13379]90
91    So far only PT application has been configured.
[11846]92    """
93    grok.context(ICustomApplicantOnlinePayment)
94    action = POST_ACTION
95    site_name = SITE_NAME
96    currency = CURRENCY
[15135]97    provider_bank_id = PROVIDER_BANK_ID
98    provider_acct = PROVIDER_ACCT
[15224]99    institution_acct = '1010835352'
100    institution_bank_id = '117'
[11846]101
102    def update(self):
103
[12975]104        error = self.init_update()
105        if error:
106            self.flash(error, type='danger')
107            self.redirect(self.url(self.context, '@@index'))
108            return
[15761]109        self.context.r_company = u'interswitch'
[15260]110        provider_amt = 2000.0
[15746]111        fedex_amt = 0.0
[16779]112        if contr_agreement_applicant(self.applicant) == 'first':
[13532]113            self.product_id = PRODUCT_ID_PT
114            self.pay_item_id = '101'
[13606]115            self.mac = MAC_PT
[16681]116            if self.applicant.__parent__.prefix == 'ijmbe':
[16778]117                self.institution_bank_id = '123'
118                self.institution_acct = '1012278272'
[13532]119        else:
120            self.product_id = PRODUCT_ID_REGULAR
121            self.pay_item_id = '109'
[13606]122            self.mac = MAC_REGULAR
[15464]123            if self.applicant.__parent__.prefix in ('utme', 'ude'):
124                provider_amt = 1000.0
[15524]125            elif self.applicant.__parent__.prefix in ('trans', 'cert'):
[15512]126                self.institution_acct = '1010827641'
127                self.institution_bank_id = '117'
[15135]128                self.provider_bank_id = '10'
129                self.provider_acct = '0427773399'
[15512]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'
[15520]134                    self.institution_bank_id = '51'
[15837]135                #if self.applicant.applicant_id[:6] in ('trans1', 'trans6'):
136                #    fedex_amt = 10500.0
[15591]137                if self.context.p_category == 'app_balance':
138                    provider_amt = 0.0
[15524]139            elif self.applicant.applicant_id.startswith('bridge'): # easier to test
[15224]140                self.institution_acct = '1014847058'
141                self.institution_bank_id = '7'
[15524]142            elif self.applicant.applicant_id.startswith('dsh'): # easier to test
143                self.institution_acct = '1014847058'
144                self.institution_bank_id = '7'
[15735]145            elif self.applicant.__parent__.prefix in ('ver', 'send'):
146                provider_amt = 0.0
[15952]147            elif self.applicant.__parent__.prefix == 'fedex':
148                provider_amt = 0.0
[16003]149                self.institution_acct = '0001115694'
150                self.institution_bank_id = '10'
[16898]151            elif self.applicant.applicant_id.startswith('pg'):
152                self.institution_acct = '5210006575'
153                self.institution_bank_id = '51'
[16678]154
[11846]155        xmldict = {}
156        xmldict['detail_ref'] = self.context.p_id
157        xmldict['provider_amt'] = 100 * provider_amt
[15135]158        xmldict['provider_acct'] = self.provider_acct
159        xmldict['provider_bank_id'] = self.provider_bank_id
[11846]160        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
[15224]161        xmldict['institution_acct'] = self.institution_acct
162        xmldict['institution_bank_id'] = self.institution_bank_id
[13532]163        xmldict['institution_item_name'] = self.category
[11846]164        xmldict['institution_name'] = INSTITUTION_NAME
[15746]165        xmldict['fedex_amt'] = 100 * fedex_amt
[15224]166        xmldict['institution_amt'] = 100 * (
[15746]167            self.context.amount_auth - provider_amt - fedex_amt - GATEWAY_AMT)
[15512]168
[15224]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
[14121]175
[15512]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
[15746]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" />
[16003]188<item_detail item_id="3" item_name="FedEx" item_amt="%(fedex_amt)d" bank_id="10" acct_num="0001115694" />
[15746]189</item_details>
190</payment_item_detail>""" % xmldict
191
[14121]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>
[11846]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" />
[16895]201<item_detail item_id="3" item_name="PG Handbook" item_amt="%(handbook_amount)d" bank_id="51" acct_num="5210006575" />
[11846]202</item_details>
203</payment_item_detail>""" % xmldict
[14121]204
[11846]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
[15473]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
[15761]220        self.amount_auth = int(100 * self.context.amount_auth)
[11846]221        hashargs = (
222            self.context.p_id +
[13532]223            self.product_id +
[11846]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
[11868]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
[14248]240    pay_item_id = '000'
[11846]241
[11868]242    def update(self):
[12975]243        error = self.init_update()
244        if error:
245            self.flash(error, type='danger')
246            self.redirect(self.url(self.context, '@@index'))
247            return
[15761]248        self.context.r_company = u'interswitch'
[11868]249        student = self.student
[13408]250        p_session = self.context.p_session
[13400]251        try:
[13408]252            academic_session = grok.getSite()['configuration'][str(p_session)]
[13400]253        except KeyError:
[13407]254            self.flash(_(u'Session configuration object is not available.'),
255                       type='danger')
[13400]256            self.redirect(self.url(self.context, '@@index'))
257            return
[13532]258        if contr_agreement_student(student) == 'first':
[13382]259            self.product_id = PRODUCT_ID_PT
[13606]260            self.mac = MAC_PT
[13382]261        else:
262            self.product_id = PRODUCT_ID_REGULAR
[13606]263            self.mac = MAC_REGULAR
[13382]264
[12975]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
[14380]270        # entry_session greater than 2012 only.
[13400]271        if self.context.p_category.startswith('schoolfee') and \
[12975]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 \
[13400]277                    ticket.p_category.startswith('clearance'):
[12975]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
[11868]286        xmldict = self.xmldict
[12729]287        xmltext = ""
[14945]288        xmldict['institution_acct'] = '1010827641'
289        xmldict['institution_bank_id'] = '117'
[11868]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
[13381]296        provider_amt = 0.0
[16942]297        xmldict['institution_amt'] = 100 * (
298            gateway_net_amt(self.context.amount_auth))
[12729]299
[13400]300        # Schoolfee
301        if self.context.p_category.startswith('schoolfee'):
[13532]302            if contr_agreement_student(student) == 'first':
[13403]303                # First agreement
[15479]304                provider_amt = 1900.0
[15387]305                joint_venture_amt = 0.0
306                aaue_share_amt = 0.0
[13414]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)
[15180]311                sports_amt = gateway_net_amt(
312                    academic_session.sports_fee)
313                library_amt = gateway_net_amt(
314                    academic_session.library_fee)
[15181]315                library_amt_pg = gateway_net_amt(
[15971]316                    academic_session.library_pg_fee)
[16950]317                lms_sund_amt = gateway_net_amt(
318                    academic_session.lms_sund_fee)
[14980]319                xmldict['student_union_bank_id'] = '31'
320                xmldict['student_union_acct'] = '0051005007'
[15384]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'
[15359]325                xmldict['institution_acct'] = '1014847058'
326                xmldict['institution_bank_id'] = '7'
[16681]327                self.pay_item_id = '105'
[13379]328                if student.current_mode == 'found':
329                    self.pay_item_id = '103'
[16681]330                elif student.current_mode == 'ijmbe':
[16691]331                    self.pay_item_id = '103'
[16681]332                    xmldict['institution_bank_id'] = '123'
333                    xmldict['institution_acct'] = '1012278272'
[13400]334            else:
[13403]335                # Second agreement
[15384]336                joint_venture_amt = 1000.0
337                aaue_share_amt = 1500.0
[15479]338                provider_amt = 1500.0
[13414]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)
[15180]343                sports_amt = gateway_net_amt(
344                    academic_session.sports_fee)
345                library_amt = gateway_net_amt(
346                    academic_session.library_fee)
[15181]347                library_amt_pg = gateway_net_amt(
[15971]348                    academic_session.library_pg_fee)
[16942]349                lms_sund_amt = gateway_net_amt(
350                    academic_session.lms_sund_fee)
[14980]351                xmldict['student_union_bank_id'] = '7'
352                xmldict['student_union_acct'] = '1019763348'
[15384]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'
[13644]357                self.pay_item_id = '107'
[13527]358                if student.is_postgrad:
359                    self.pay_item_id = '111'
[15460]360                    xmldict['institution_acct'] = '5210006575'
361                    xmldict['institution_bank_id'] = '51'
[13400]362
363            xmldict['provider_amt'] = 100 * provider_amt
[15384]364            xmldict['joint_venture_amt'] = 100 * joint_venture_amt
365            xmldict['aaue_share_amt'] = 100 * aaue_share_amt
[16943]366            xmldict['lms_sund_amt'] = 100 * lms_sund_amt
[13732]367            if self.context.p_item == 'Balance':
368                xmldict['institution_amt'] = 100 * (
369                    gateway_net_amt(self.context.amount_auth))
[15479]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
[14987]378            elif self.context.p_category in ('schoolfee_incl', 'schoolfee_1') \
379                and student.current_mode != 'ijmbe':
[13400]380                # Schoolfee including additional fees
[13379]381                xmldict['student_union_due_amt'] = 100 * student_union_due_amt
382                xmldict['student_welfare_assurance_amt'] = 100 * student_welfare_assurance_amt
[15192]383
[15976]384                if student.entry_session >= 2018 and student.is_fresh:
[15192]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                        - student_union_due_amt
394                        - student_welfare_assurance_amt
395                        - sports_amt
[16942]396                        - library_amt
397                        - lms_sund_amt)
[15192]398                    xmltext = """<payment_item_detail>
[11868]399<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
400<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" />
[12729]401<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" />
[15387]402<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" />
403<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />
404<item_detail item_id="5" item_name="Sports Development Fee" item_amt="%(sports_amt)d" bank_id="123" acct_num="1006407792" />
[17083]405<item_detail item_id="6" item_name="Library Development Fee" item_amt="%(library_amt)d" bank_id="8" acct_num="2000122995" />
406</item_details>
407</payment_item_detail>""" % xmldict
[15387]408                    if contr_agreement_student(student) == 'second':
[17082]409                        xmldict['institution_amt'] = 100 * (
410                            gateway_net_amt(self.context.amount_auth)
411                            - provider_amt
412                            - joint_venture_amt
413                            - aaue_share_amt
414                            - student_union_due_amt
415                            - student_welfare_assurance_amt
416                            - sports_amt
[17083]417                            - library_amt)
418                        xmltext = """<payment_item_detail>
419<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
420<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" />
421<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" />
422<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" />
423<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />
424<item_detail item_id="5" item_name="Sports Development Fee" item_amt="%(sports_amt)d" bank_id="123" acct_num="1006407792" />
425<item_detail item_id="6" item_name="Library Development Fee" item_amt="%(library_amt)d" bank_id="8" acct_num="2000122995" />
426<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" />
427<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" />
428</item_details>
429</payment_item_detail>""" % xmldict
430
[16942]431                    if student.entry_session >= 2021 and student.current_mode == 'ug_ft':
[17082]432                        xmldict['institution_amt'] = 100 * (
433                            gateway_net_amt(self.context.amount_auth)
434                            - provider_amt
435                            - joint_venture_amt
436                            - aaue_share_amt
437                            - student_union_due_amt
438                            - student_welfare_assurance_amt
439                            - sports_amt
440                            - library_amt
[17083]441                            - lms_sund_amt) 
442                        xmltext = """<payment_item_detail>
443<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
444<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" />
445<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" />
446<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" />
447<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />
448<item_detail item_id="5" item_name="Sports Development Fee" item_amt="%(sports_amt)d" bank_id="123" acct_num="1006407792" />
449<item_detail item_id="6" item_name="Library Development Fee" item_amt="%(library_amt)d" bank_id="8" acct_num="2000122995" />
450<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" />
451<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" />
452<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" />
[15387]453</item_details>
[17083]454</payment_item_detail>""" % xmldict
455
[15192]456                else:
457                    xmldict['institution_amt'] = 100 * (
458                        gateway_net_amt(self.context.amount_auth)
459                        - provider_amt
460                        - student_union_due_amt
461                        - student_welfare_assurance_amt)
462                    xmltext = """<payment_item_detail>
463<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
464<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" />
465<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" />
[15387]466<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" />
[17083]467<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />
468</item_details>
469</payment_item_detail>""" % xmldict
[15387]470                    if contr_agreement_student(student) == 'second':
[17081]471                        xmldict['institution_amt'] = 100 * (
472                            gateway_net_amt(self.context.amount_auth)
473                            - provider_amt
474                            - joint_venture_amt
475                            - aaue_share_amt
476                            - student_union_due_amt
477                            - student_welfare_assurance_amt)                   
[17083]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="Student Union" item_amt="%(student_union_due_amt)d" bank_id="%(student_union_bank_id)s" acct_num="%(student_union_acct)s" />
483<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />
[15387]484<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" />
485<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" />
[15192]486</item_details>
487</payment_item_detail>""" % xmldict
[17083]488
[15387]489            elif contr_agreement_student(student) == 'second':
490                # Schoolfee without Student Union Fee ands Student Welfare Assurance
[15384]491                xmldict['institution_amt'] = 100 * (
492                    gateway_net_amt(self.context.amount_auth)
[15387]493                    - provider_amt
494                    - joint_venture_amt
495                    - aaue_share_amt)
[15384]496                xmltext = """<payment_item_detail>
497<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
498<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" />
499<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" />
[15387]500<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" />
501<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" />
[15384]502</item_details>
503</payment_item_detail>""" % xmldict
[13400]504            else:
505                xmldict['institution_amt'] = 100 * (
[13414]506                    gateway_net_amt(self.context.amount_auth)
[15387]507                    - provider_amt)
[13400]508                xmltext = """<payment_item_detail>
509<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
510<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" />
511<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" />
512</item_details>
513</payment_item_detail>""" % xmldict
514
515        # Clearance
516        elif self.context.p_category.startswith('clearance'):
[16283]517            xmldict['institution_acct'] = '1010835352'
[15467]518            provider_amt = 0.0
[13532]519            if contr_agreement_student(student) == 'first':
[13403]520                # First agreement
[16681]521                xmldict['institution_acct'] = '1014847058'
522                xmldict['institution_bank_id'] = '7'
523                self.pay_item_id = '104'
[13379]524                if student.current_mode == 'found':
525                    self.pay_item_id = '102'
[16681]526                elif student.current_mode == 'ijmbe':
[16689]527                    self.pay_item_id = '102'
[16681]528                    xmldict['institution_bank_id'] = '123'
529                    xmldict['institution_acct'] = '1012278272'
[13400]530            else:
[13403]531                # Second agreement
[13400]532                self.pay_item_id = '102'
[13527]533                if student.is_postgrad:
534                    self.pay_item_id = '110'
[15463]535                    xmldict['institution_acct'] = '5210006575'
536                    xmldict['institution_bank_id'] = '51'
[15467]537                # ivama: Acceptance fee split is unique to "ug_ft"
538                # The reason for split is perculiar to them only...
539                # That amount was deducted from UTME application fee because
540                # some regulatory body have pegged the application fee which
541                # didn't affect another programmes.
542                if student.current_mode == 'ug_ft':
543                    provider_amt = 1500.0
544            xmldict['provider_amt'] = 100 * provider_amt
[13410]545            if self.context.p_category.endswith('_incl'):
[13400]546                # Clearance including additional fees
[13414]547                gown_fee_amt = gateway_net_amt(academic_session.matric_gown_fee)
548                aaue_lf_fee_amt = gateway_net_amt(academic_session.lapel_fee)
[13379]549                xmldict['gown_fee_amt'] = 100 * gown_fee_amt
[13414]550                xmldict['aaue_lf_fee_amt'] = 100 * aaue_lf_fee_amt
[13379]551                xmldict['institution_amt'] = 100 * (
[13414]552                    gateway_net_amt(self.context.amount_auth)
[13409]553                    - gown_fee_amt
[15190]554                    - aaue_lf_fee_amt
555                    - provider_amt)
[13379]556                xmltext = """<payment_item_detail>
[11868]557<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
558<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" />
[16947]559<item_detail item_id="2" item_name="Matriculation Gown Fee" item_amt="%(gown_fee_amt)d" bank_id="117" acct_num="1010835352" />
560<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
[15467]561                if provider_amt:
[15391]562                    xmltext += """"
[15168]563<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" />
[11868]564</item_details>
565</payment_item_detail>""" % xmldict
[15391]566                else:
567                    xmltext += """"
568</item_details>
[15396]569</payment_item_detail>"""
[13400]570
[15375]571            elif student.current_mode == 'bridge':
572                # Clearance without any surcharge
573                xmldict['institution_amt'] = 100 * gateway_net_amt(
574                    self.context.amount_auth)
575                xmltext = """<payment_item_detail>
576<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
577<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" />
578</item_details>
579</payment_item_detail>""" % xmldict
580
[13381]581            else:
[13400]582                # Clearance without additional fees
[13381]583                xmldict['institution_amt'] = 100 * (
[15190]584                    gateway_net_amt(self.context.amount_auth)
585                    - provider_amt)
[15168]586                xmltext = """<payment_item_detail>
587<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
[15396]588<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
[15467]589                if provider_amt:
[15391]590                        xmltext += """"
[15168]591<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" />
592</item_details>
593</payment_item_detail>""" % xmldict
[15391]594                else:
595                        xmltext += """"
596</item_details>
[15396]597</payment_item_detail>"""
[13379]598
[13403]599        # Union Dues
[13400]600        elif self.context.p_category == 'union':
601            self.pay_item_id = '103'
602            xmldict['institution_amt'] = 100 * (
[13414]603                gateway_net_amt(self.context.amount_auth))
[14980]604            if contr_agreement_student(student) == 'first':
605                # First agreement
606                xmldict['institution_acct'] = '0051005007'
607                xmldict['institution_bank_id'] = '31'
608            else:
609                # Second agreement
610                xmldict['institution_bank_id'] = '7'
611                xmldict['institution_acct'] = '1019763348'
[13379]612
[13403]613        # Lapel/File
[13400]614        elif self.context.p_category == 'lapel':
615            self.pay_item_id = '104'
616            xmldict['institution_amt'] = 100 * (
[13414]617                gateway_net_amt(self.context.amount_auth))
[13381]618
[13403]619        # Welfare Assurance
[13400]620        elif self.context.p_category == 'welfare':
621            self.pay_item_id = '105'
[14979]622            xmldict['institution_acct'] = '1006407792'
623            xmldict['institution_bank_id'] = '123'
[13400]624            xmldict['institution_amt'] = 100 * (
[13414]625                gateway_net_amt(self.context.amount_auth))
[13381]626
[14234]627        # ID Card
628        elif self.context.p_category == 'id_card':
629            self.pay_item_id = '000'
630            xmldict['institution_amt'] = 100 * (
631                gateway_net_amt(self.context.amount_auth))
632
[13400]633        # Matric Gown
634        elif self.context.p_category == 'matric_gown':
635            self.pay_item_id = '106'
636            xmldict['institution_amt'] = 100 * (
[13414]637                gateway_net_amt(self.context.amount_auth))
[13381]638
[13400]639        # Concessional
640        elif self.context.p_category == 'concessional':
641            self.pay_item_id = '107'
642            xmldict['institution_amt'] = 100 * (
[13414]643                gateway_net_amt(self.context.amount_auth))
[13381]644
[13400]645        # Hostel Maintenance
646        elif self.context.p_category == 'hostel_maintenance':
[14223]647            provider_amt = 500.0
[13400]648            self.pay_item_id = '109'
[16661]649            xmldict['institution_acct'] = '1006406795'
650            xmldict['institution_bank_id'] = '123'
[14223]651            xmldict['provider_amt'] = 100 * provider_amt
[13400]652            xmldict['institution_amt'] = 100 * (
[14223]653                gateway_net_amt(self.context.amount_auth) - provider_amt)
[13400]654            xmltext = """<payment_item_detail>
[13383]655<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
656<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" />
[14223]657<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" />
[13383]658</item_details>
659</payment_item_detail>""" % xmldict
660
[14258]661        # GST Fees
662        elif self.context.p_category.startswith('gst_'):
[14687]663            if contr_agreement_student(student) == 'first':
664                self.pay_item_id = '115'
665            else:
666                self.pay_item_id = '116'
[14979]667            xmldict['institution_acct'] = '1010893123'
668            xmldict['institution_bank_id'] = '117'
[14258]669            xmldict['institution_amt'] = 100 * (
670                gateway_net_amt(self.context.amount_auth))
671
672        # ENT Fees
673        elif self.context.p_category.startswith('ent_'):
[14687]674            if contr_agreement_student(student) == 'first':
675                self.pay_item_id = '114'
676            else:
677                self.pay_item_id = '118'
[14979]678            xmldict['institution_acct'] = '6220029828'
679            xmldict['institution_bank_id'] = '51'
[14258]680            xmldict['institution_amt'] = 100 * (
681                gateway_net_amt(self.context.amount_auth))
682
683        # Faculty and Departmental Dues
684        elif self.context.p_category == 'fac_dep':
[15742]685            xmldict['institution_acct'] = '1016425386'
686            xmldict['institution_bank_id'] = '117'
[14258]687            self.pay_item_id = '117'
688            xmldict['institution_amt'] = 100 * (
689                gateway_net_amt(self.context.amount_auth))
690
[14376]691        # Restitution Fee
692        elif self.context.p_category == 'restitution':
693            self.pay_item_id = '117'
694            xmldict['institution_amt'] = 100 * (
695                gateway_net_amt(self.context.amount_auth))
696
[16021]697        # Faculty Laboratory Due
[16080]698        elif self.context.p_category in ('lab_1', 'lab_2'):
[16021]699            xmldict['institution_acct'] = '1016425386'
700            xmldict['institution_bank_id'] = '117'
701            self.pay_item_id = '117'
702            xmldict['institution_amt'] = 100 * (
703                gateway_net_amt(self.context.amount_auth))
704
[15971]705        # Sports Fee
[15978]706        #elif self.context.p_category == 'sports':
707        #    self.pay_item_id = '105'
708        #    xmldict['institution_amt'] = 100 * (
709        #        gateway_net_amt(self.context.amount_auth))
[15971]710
711        # Library Fee
[15978]712        #elif self.context.p_category == 'library':
713        #    self.pay_item_id = '105'
714        #    xmldict['institution_amt'] = 100 * (
715        #        gateway_net_amt(self.context.amount_auth))
[15971]716
717        # Library PG Fee
[15978]718        #elif self.context.p_category == 'library_pg':
719        #    self.pay_item_id = '105'
720        #    xmldict['institution_amt'] = 100 * (
721        #        gateway_net_amt(self.context.amount_auth))
722
[16940]723        # Exam Fee
724        elif self.context.p_category == 'exam':
[16941]725            self.pay_item_id = '103'
[16951]726            xmldict['institution_acct'] = '1012278272'
727            xmldict['institution_bank_id'] = '123'
[16940]728            xmldict['institution_amt'] = 100 * (
729                gateway_net_amt(self.context.amount_auth))
730
[17100]731        # Access Card Fee
732        elif self.context.p_category == 'access_card':
733            self.pay_item_id = '103'
[17118]734            xmldict['institution_acct'] = '1012688013'
[17100]735            xmldict['institution_bank_id'] = '123'
736            xmldict['institution_amt'] = 100 * (
737                gateway_net_amt(self.context.amount_auth))
738
[16942]739        # LMS + Sundry Fees
740        elif self.context.p_category == 'lms_sund':
741            self.pay_item_id = '103'
742            xmldict['institution_amt'] = 100 * (
743                gateway_net_amt(self.context.amount_auth))
744
[15992]745        # Sports & Library Fee    temporarily in 2020
[15978]746        elif self.context.p_category == 'sports_library':
[15976]747            self.pay_item_id = '105'
[15992]748            xmldict['sports_amt'] = 100 * 3000.0
749            xmldict['library_amt'] = 100 * 1000.0
750            xmltext = """<payment_item_detail>
751<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
752<item_detail item_id="1" item_name="Sports Development Fee" item_amt="%(sports_amt)d" bank_id="123" acct_num="1006407792" />
753<item_detail item_id="2" item_name="Library Development Fee" item_amt="%(library_amt)d" bank_id="8" acct_num="2000122995" />
754</item_details>
755</payment_item_detail>""" % xmldict
[15971]756
[14676]757        # Late Registration Fee
758        elif self.context.p_category == 'late_registration':
[14686]759            if contr_agreement_student(student) == 'first':
760                self.pay_item_id = '113'
761            else:
762                self.pay_item_id = '123'
[14676]763            xmldict['institution_amt'] = 100 * (
764                gateway_net_amt(self.context.amount_auth))
[15463]765            if student.is_postgrad:
766                xmldict['institution_acct'] = '5210006575'
767                xmldict['institution_bank_id'] = '51'
[14945]768        if not xmltext:
[14676]769            xmltext = """<payment_item_detail>
770<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
771<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" />
772</item_details>
773</payment_item_detail>""" % xmldict
[11868]774        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
775        self.context.provider_amt = provider_amt
[15761]776        self.context.gateway_amt = self.context.amount_auth - gateway_net_amt(
777            self.context.amount_auth)
[15471]778        xmlitems = ''
779        xmldoc = minidom.parseString(xmltext)
780        itemlist = xmldoc.getElementsByTagName('item_detail')
781        for s in itemlist:
[16944]782            xmlitems += "%s: %s, %s %s, %s (%s)  " % (
[15471]783                s.attributes['item_id'].value,
784                s.attributes['item_name'].value,
[16942]785                u'\u20a6',
[15471]786                int(s.attributes['item_amt'].value)/100,
787                s.attributes['acct_num'].value,
788                s.attributes['bank_id'].value,
789                )
790        self.context.p_split_data = xmlitems
[15761]791        self.amount_auth = int(100 * self.context.amount_auth)
[11868]792        hashargs = (
793            self.context.p_id +
[13382]794            self.product_id +
[11868]795            self.pay_item_id +
796            str(int(self.amount_auth)) +
797            self.site_redirect_url +
798            self.mac)
799        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
800        return
801
802
[11846]803class CustomInterswitchPaymentRequestWebservicePageApplicant(
804    InterswitchPaymentRequestWebservicePageApplicant):
[13586]805    """Request webservice view for the CollegePAY gateway
806    """
807    grok.context(ICustomApplicantOnlinePayment)
808    gateway_host = HOST
809    gateway_url = URL
810    https = HTTPS
[13379]811
[13586]812    @property
[13606]813    def mac(self):
814        if contr_agreement_applicant(self.context.__parent__) == 'first':
815            return MAC_PT
816        return MAC_REGULAR
817
818    @property
[13586]819    def product_id(self):
820        if contr_agreement_applicant(self.context.__parent__) == 'first':
821            return PRODUCT_ID_PT
822        return PRODUCT_ID_REGULAR
823
824class CustomInterswitchPaymentVerifyWebservicePageApplicant(
825    InterswitchPaymentVerifyWebservicePageApplicant):
826    """Payment verify view for the CollegePAY gateway
[11846]827    """
828    grok.context(ICustomApplicantOnlinePayment)
829    gateway_host = HOST
[13586]830    gateway_url = URL
[11916]831    https = HTTPS
[11868]832
[13532]833    @property
[13606]834    def mac(self):
835        if contr_agreement_applicant(self.context.__parent__) == 'first':
836            return MAC_PT
837        return MAC_REGULAR
838
839    @property
[13532]840    def product_id(self):
841        if contr_agreement_applicant(self.context.__parent__) == 'first':
842            return PRODUCT_ID_PT
843        return PRODUCT_ID_REGULAR
844
[11868]845class CustomInterswitchPaymentRequestWebservicePageStudent(
846    InterswitchPaymentRequestWebservicePageStudent):
[13586]847    """Request webservice view for the CollegePAY gateway
[11868]848    """
849    grok.context(ICustomStudentOnlinePayment)
850    gateway_host = HOST
[13586]851    gateway_url = URL
[11916]852    https = HTTPS
[13379]853
854    @property
[13606]855    def mac(self):
856        if contr_agreement_student(self.context.student) == 'first':
857            return MAC_PT
858        return MAC_REGULAR
859
860    @property
[13379]861    def product_id(self):
[13532]862        if contr_agreement_student(self.context.student) == 'first':
[13379]863            return PRODUCT_ID_PT
864        return PRODUCT_ID_REGULAR
[13586]865
866class CustomInterswitchPaymentVerifyWebservicePageStudent(
867    InterswitchPaymentVerifyWebservicePageStudent):
868    """Payment verify view for the CollegePAY gateway
869    """
870    grok.context(ICustomStudentOnlinePayment)
871    gateway_host = HOST
872    gateway_url = URL
873    https = HTTPS
874
875    @property
[13606]876    def mac(self):
877        if contr_agreement_student(self.context.student) == 'first':
878            return MAC_PT
879        return MAC_REGULAR
880
881    @property
[13586]882    def product_id(self):
883        if contr_agreement_student(self.context.student) == 'first':
884            return PRODUCT_ID_PT
885        return PRODUCT_ID_REGULAR
Note: See TracBrowser for help on using the repository browser.