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

Last change on this file since 15796 was 15761, checked in by Henrik Bettermann, 5 years ago

Adjust to nigeria package.

Disable FecEx? fee.

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