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

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

Change bank account for dsh application.

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