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

Last change on this file since 16326 was 16283, checked in by Henrik Bettermann, 4 years ago

Change bank account.

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