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

Last change on this file since 15477 was 15475, checked in by Henrik Bettermann, 6 years ago

There is no technology charges in 2nd installment.

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