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

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

Fix typo.

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