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
Line 
1## $Id: browser.py 15520 2019-07-25 20:14:28Z henrik $
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
21from xml.dom import minidom
22from zope.interface import Interface
23from zope.component import queryAdapter
24from waeup.kofa.interfaces import CLEARED
25from kofacustom.nigeria.interswitch.browser import (
26    InterswitchPaymentRequestWebservicePageStudent,
27    InterswitchPaymentRequestWebservicePageApplicant,
28    InterswitchPaymentVerifyWebservicePageApplicant,
29    InterswitchPaymentVerifyWebservicePageStudent,
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
36PRODUCT_ID_PT = '5040'
37PRODUCT_ID_REGULAR = '5845'
38SITE_NAME = 'aaue.waeup.org'
39PROVIDER_ACCT = '0213065415'
40PROVIDER_BANK_ID = '47'
41PROVIDER_ITEM_NAME = 'WAeAC'
42INSTITUTION_NAME = 'AAU Ekpoma'
43CURRENCY = '566'
44GATEWAY_AMT = 250.0
45POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
46
47HOST = 'webpay.interswitchng.com'
48URL = '/paydirect/api/v1/gettransaction.json'
49HTTPS = True
50MAC_REGULAR = '9718FA00B0F5070B388A9896ADCED9B2FB02D30F71E12E68BDADC63F6852A3496FF97D8A0F9DA9F753B911A49BB09BB87B55FD02046BD325C74C46C0123CF023'
51MAC_PT = '74424F1DFECD6058F153148255CDD55E16724B4F380ADB2C63C5D1D7A5675759010C8153DCB930AAF2D38903CBF7CE32B8A6BA2C16BBC46721DF2E3F3E4548E3'
52
53httplib.HTTPSConnection.debuglevel = 0
54
55
56def gateway_net_amt(fee):
57    if fee > GATEWAY_AMT:
58        return fee - GATEWAY_AMT
59    return 0.0
60
61def contr_agreement_applicant(applicant):
62    if applicant.__parent__ in (
63        'fp',
64        'ptee',
65        'dsh',
66        'bridge',
67        'ijmbe',
68        ):
69        return 'first'
70    return 'second'
71
72def contr_agreement_student(student):
73    if student.current_mode in (
74        'found',
75        'bridge',
76        'ug_dsh',
77        'de_dsh',
78        'ug_pt',
79        'de_pt',
80        'dp_pt',
81        'ijmbe',
82        ):
83        return 'first'
84    return 'second'
85
86class CustomInterswitchPageApplicant(InterswitchPageApplicant):
87    """ View which sends a POST request to the Interswitch
88    CollegePAY payment gateway.
89
90    So far only PT application has been configured.
91    """
92    grok.context(ICustomApplicantOnlinePayment)
93    action = POST_ACTION
94    site_name = SITE_NAME
95    currency = CURRENCY
96    provider_bank_id = PROVIDER_BANK_ID
97    provider_acct = PROVIDER_ACCT
98    institution_acct = '1010835352'
99    institution_bank_id = '117'
100
101    def update(self):
102
103        error = self.init_update()
104        if error:
105            self.flash(error, type='danger')
106            self.redirect(self.url(self.context, '@@index'))
107            return
108        provider_amt = 2000.0
109        if contr_agreement_applicant(self.context.__parent__) == 'first':
110            self.product_id = PRODUCT_ID_PT
111            self.pay_item_id = '101'
112            self.mac = MAC_PT
113        else:
114            self.product_id = PRODUCT_ID_REGULAR
115            self.pay_item_id = '109'
116            self.mac = MAC_REGULAR
117            if self.applicant.__parent__.prefix in ('utme', 'ude'):
118                provider_amt = 1000.0
119            if self.applicant.__parent__.prefix in ('trans', 'cert'):
120                self.institution_acct = '1010827641'
121                self.institution_bank_id = '117'
122                self.provider_bank_id = '10'
123                self.provider_acct = '0427773399'
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'
128                    self.institution_bank_id = '51'
129            elif self.applicant.applicant_id.startswith('bridge',): # easier to test
130                self.institution_acct = '1014847058'
131                self.institution_bank_id = '7'
132        xmldict = {}
133        xmldict['detail_ref'] = self.context.p_id
134        xmldict['provider_amt'] = 100 * provider_amt
135        xmldict['provider_acct'] = self.provider_acct
136        xmldict['provider_bank_id'] = self.provider_bank_id
137        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
138        xmldict['institution_acct'] = self.institution_acct
139        xmldict['institution_bank_id'] = self.institution_bank_id
140        xmldict['institution_item_name'] = self.category
141        xmldict['institution_name'] = INSTITUTION_NAME
142        xmldict['institution_amt'] = 100 * (
143            self.context.amount_auth - provider_amt - GATEWAY_AMT)
144
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
151
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
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>
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" />
168<item_detail item_id="3" item_name="PG Handbook" item_amt="%(handbook_amount)d" bank_id="117" acct_num="1010827641" />
169</item_details>
170</payment_item_detail>""" % xmldict
171
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
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
187        hashargs = (
188            self.context.p_id +
189            self.product_id +
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
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
206    pay_item_id = '000'
207
208    def update(self):
209        error = self.init_update()
210
211        if error:
212            self.flash(error, type='danger')
213            self.redirect(self.url(self.context, '@@index'))
214            return
215
216        student = self.student
217        p_session = self.context.p_session
218        try:
219            academic_session = grok.getSite()['configuration'][str(p_session)]
220        except KeyError:
221            self.flash(_(u'Session configuration object is not available.'),
222                       type='danger')
223            self.redirect(self.url(self.context, '@@index'))
224            return
225        if contr_agreement_student(student) == 'first':
226            self.product_id = PRODUCT_ID_PT
227            self.mac = MAC_PT
228        else:
229            self.product_id = PRODUCT_ID_REGULAR
230            self.mac = MAC_REGULAR
231
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
237        # entry_session greater than 2012 only.
238        if self.context.p_category.startswith('schoolfee') and \
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 \
244                    ticket.p_category.startswith('clearance'):
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
253        xmldict = self.xmldict
254        xmltext = ""
255        xmldict['institution_acct'] = '1010827641'
256        xmldict['institution_bank_id'] = '117'
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
263        provider_amt = 0.0
264
265        # Schoolfee
266        if self.context.p_category.startswith('schoolfee'):
267            if contr_agreement_student(student) == 'first':
268                # First agreement
269                provider_amt = 1900.0
270                joint_venture_amt = 0.0
271                aaue_share_amt = 0.0
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)
276                sports_amt = gateway_net_amt(
277                    academic_session.sports_fee)
278                library_amt = gateway_net_amt(
279                    academic_session.library_fee)
280                library_amt_pg = gateway_net_amt(
281                    academic_session.library_fee_pg)
282                xmldict['student_union_bank_id'] = '31'
283                xmldict['student_union_acct'] = '0051005007'
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'
288                xmldict['institution_acct'] = '1014847058'
289                xmldict['institution_bank_id'] = '7'
290                if student.current_mode == 'found':
291                    self.pay_item_id = '103'
292                else:
293                    self.pay_item_id = '105'
294            else:
295                # Second agreement
296                joint_venture_amt = 1000.0
297                aaue_share_amt = 1500.0
298                provider_amt = 1500.0
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)
303                sports_amt = gateway_net_amt(
304                    academic_session.sports_fee)
305                library_amt = gateway_net_amt(
306                    academic_session.library_fee)
307                library_amt_pg = gateway_net_amt(
308                    academic_session.library_fee_pg)
309                xmldict['student_union_bank_id'] = '7'
310                xmldict['student_union_acct'] = '1019763348'
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'
315                self.pay_item_id = '107'
316                if student.is_postgrad:
317                    self.pay_item_id = '111'
318                    xmldict['institution_acct'] = '5210006575'
319                    xmldict['institution_bank_id'] = '51'
320                if student.current_mode == 'ijmbe':
321                    self.pay_item_id = '119'
322                    xmldict['joint_venture_bank_id'] = '117'
323                    xmldict['joint_venture_acct'] = '1010827641'
324
325            xmldict['provider_amt'] = 100 * provider_amt
326            xmldict['joint_venture_amt'] = 100 * joint_venture_amt
327            xmldict['aaue_share_amt'] = 100 * aaue_share_amt
328            if self.context.p_item == 'Balance':
329                xmldict['institution_amt'] = 100 * (
330                    gateway_net_amt(self.context.amount_auth))
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
341            elif self.context.p_category in ('schoolfee_incl', 'schoolfee_1') \
342                and student.current_mode != 'ijmbe':
343                # Schoolfee including additional fees
344                xmldict['student_union_due_amt'] = 100 * student_union_due_amt
345                xmldict['student_welfare_assurance_amt'] = 100 * student_welfare_assurance_amt
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
356                        - joint_venture_amt
357                        - aaue_share_amt
358                        - student_union_due_amt
359                        - student_welfare_assurance_amt
360                        - sports_amt
361                        - library_amt)
362                    xmltext = """<payment_item_detail>
363<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
364<item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
365<item_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" />
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" />
374</item_details>
375</payment_item_detail>""" % xmldict
376                    else:
377                        xmltext += """"
378</item_details>
379</payment_item_detail>"""
380                else:
381                    xmldict['institution_amt'] = 100 * (
382                        gateway_net_amt(self.context.amount_auth)
383                        - provider_amt
384                        - joint_venture_amt
385                        - aaue_share_amt
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" />
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" />
398</item_details>
399</payment_item_detail>""" % xmldict
400                    else:
401                        xmltext += """"
402</item_details>
403</payment_item_detail>"""
404            elif contr_agreement_student(student) == 'second':
405                # Schoolfee without Student Union Fee ands Student Welfare Assurance
406                xmldict['institution_amt'] = 100 * (
407                    gateway_net_amt(self.context.amount_auth)
408                    - provider_amt
409                    - joint_venture_amt
410                    - aaue_share_amt)
411                xmltext = """<payment_item_detail>
412<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
413<item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
414<item_detail item_id="2" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
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" />
417</item_details>
418</payment_item_detail>""" % xmldict
419            else:
420                xmldict['institution_amt'] = 100 * (
421                    gateway_net_amt(self.context.amount_auth)
422                    - provider_amt)
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'):
433            provider_amt = 0.0
434            if contr_agreement_student(student) == 'first':
435                # First agreement
436                if student.current_mode == 'found':
437                    self.pay_item_id = '102'
438                else:
439                    self.pay_item_id = '104'
440                xmldict['institution_acct'] = '1014847058'
441                xmldict['institution_bank_id'] = '7'
442            else:
443                # Second agreement
444                self.pay_item_id = '102'
445                if student.is_postgrad:
446                    self.pay_item_id = '110'
447                    xmldict['institution_acct'] = '5210006575'
448                    xmldict['institution_bank_id'] = '51'
449                if student.current_mode == 'ijmbe':
450                    self.pay_item_id = '120'
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
459            if self.context.p_category.endswith('_incl'):
460                # Clearance including additional fees
461                gown_fee_amt = gateway_net_amt(academic_session.matric_gown_fee)
462                aaue_lf_fee_amt = gateway_net_amt(academic_session.lapel_fee)
463                xmldict['gown_fee_amt'] = 100 * gown_fee_amt
464                xmldict['aaue_lf_fee_amt'] = 100 * aaue_lf_fee_amt
465                xmldict['institution_amt'] = 100 * (
466                    gateway_net_amt(self.context.amount_auth)
467                    - gown_fee_amt
468                    - aaue_lf_fee_amt
469                    - provider_amt)
470                xmltext = """<payment_item_detail>
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" />
473<item_detail item_id="2" item_name="Matriculation Gown Fee" item_amt="%(gown_fee_amt)d" bank_id="117" acct_num="1010827641" />
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
475                if provider_amt:
476                    xmltext += """"
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" />
478</item_details>
479</payment_item_detail>""" % xmldict
480                else:
481                    xmltext += """"
482</item_details>
483</payment_item_detail>"""
484
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
495            else:
496                # Clearance without additional fees
497                xmldict['institution_amt'] = 100 * (
498                    gateway_net_amt(self.context.amount_auth)
499                    - provider_amt)
500                xmltext = """<payment_item_detail>
501<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
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
503                if provider_amt:
504                        xmltext += """"
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
508                else:
509                        xmltext += """"
510</item_details>
511</payment_item_detail>"""
512
513        # Union Dues
514        elif self.context.p_category == 'union':
515            self.pay_item_id = '103'
516            xmldict['institution_amt'] = 100 * (
517                gateway_net_amt(self.context.amount_auth))
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'
526
527        # Lapel/File
528        elif self.context.p_category == 'lapel':
529            self.pay_item_id = '104'
530            xmldict['institution_amt'] = 100 * (
531                gateway_net_amt(self.context.amount_auth))
532
533        # Welfare Assurance
534        elif self.context.p_category == 'welfare':
535            self.pay_item_id = '105'
536            xmldict['institution_acct'] = '1006407792'
537            xmldict['institution_bank_id'] = '123'
538            xmldict['institution_amt'] = 100 * (
539                gateway_net_amt(self.context.amount_auth))
540
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
547        # Matric Gown
548        elif self.context.p_category == 'matric_gown':
549            self.pay_item_id = '106'
550            xmldict['institution_amt'] = 100 * (
551                gateway_net_amt(self.context.amount_auth))
552
553        # Concessional
554        elif self.context.p_category == 'concessional':
555            self.pay_item_id = '107'
556            xmldict['institution_amt'] = 100 * (
557                gateway_net_amt(self.context.amount_auth))
558
559        # Hostel Maintenance
560        elif self.context.p_category == 'hostel_maintenance':
561            provider_amt = 500.0
562            self.pay_item_id = '109'
563            xmldict['provider_amt'] = 100 * provider_amt
564            xmldict['institution_amt'] = 100 * (
565                gateway_net_amt(self.context.amount_auth) - provider_amt)
566            xmltext = """<payment_item_detail>
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" />
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" />
570</item_details>
571</payment_item_detail>""" % xmldict
572
573        # GST Fees
574        elif self.context.p_category.startswith('gst_'):
575            if contr_agreement_student(student) == 'first':
576                self.pay_item_id = '115'
577            else:
578                self.pay_item_id = '116'
579            xmldict['institution_acct'] = '1010893123'
580            xmldict['institution_bank_id'] = '117'
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_'):
586            if contr_agreement_student(student) == 'first':
587                self.pay_item_id = '114'
588            else:
589                self.pay_item_id = '118'
590            xmldict['institution_acct'] = '6220029828'
591            xmldict['institution_bank_id'] = '51'
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
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
607        # Late Registration Fee
608        elif self.context.p_category == 'late_registration':
609            if contr_agreement_student(student) == 'first':
610                self.pay_item_id = '113'
611            else:
612                self.pay_item_id = '123'
613            xmldict['institution_amt'] = 100 * (
614                gateway_net_amt(self.context.amount_auth))
615            if student.is_postgrad:
616                xmldict['institution_acct'] = '5210006575'
617                xmldict['institution_bank_id'] = '51'
618        if not xmltext:
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
624        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
625        self.context.provider_amt = provider_amt
626        self.context.gateway_amt = self.amount_auth - gateway_net_amt(
627            self.amount_auth)
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
640        hashargs = (
641            self.context.p_id +
642            self.product_id +
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
651class CustomInterswitchPaymentRequestWebservicePageApplicant(
652    InterswitchPaymentRequestWebservicePageApplicant):
653    """Request webservice view for the CollegePAY gateway
654    """
655    grok.context(ICustomApplicantOnlinePayment)
656    gateway_host = HOST
657    gateway_url = URL
658    https = HTTPS
659
660    @property
661    def mac(self):
662        if contr_agreement_applicant(self.context.__parent__) == 'first':
663            return MAC_PT
664        return MAC_REGULAR
665
666    @property
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
675    """
676    grok.context(ICustomApplicantOnlinePayment)
677    gateway_host = HOST
678    gateway_url = URL
679    https = HTTPS
680
681    @property
682    def mac(self):
683        if contr_agreement_applicant(self.context.__parent__) == 'first':
684            return MAC_PT
685        return MAC_REGULAR
686
687    @property
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
693class CustomInterswitchPaymentRequestWebservicePageStudent(
694    InterswitchPaymentRequestWebservicePageStudent):
695    """Request webservice view for the CollegePAY gateway
696    """
697    grok.context(ICustomStudentOnlinePayment)
698    gateway_host = HOST
699    gateway_url = URL
700    https = HTTPS
701
702    @property
703    def mac(self):
704        if contr_agreement_student(self.context.student) == 'first':
705            return MAC_PT
706        return MAC_REGULAR
707
708    @property
709    def product_id(self):
710        if contr_agreement_student(self.context.student) == 'first':
711            return PRODUCT_ID_PT
712        return PRODUCT_ID_REGULAR
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
724    def mac(self):
725        if contr_agreement_student(self.context.student) == 'first':
726            return MAC_PT
727        return MAC_REGULAR
728
729    @property
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.