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

Last change on this file since 16822 was 16779, checked in by Henrik Bettermann, 3 years ago

Remove 2nd bug.

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