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

Last change on this file since 17421 was 17118, checked in by Henrik Bettermann, 2 years ago

Fix typo.

  • Property svn:keywords set to Id
File size: 42.9 KB
Line 
1# -*- coding: utf-8 -*-
2## $Id: browser.py 17118 2022-10-05 12:37:11Z henrik $
3##
4## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann
5## This program is free software; you can redistribute it and/or modify
6## it under the terms of the GNU General Public License as published by
7## the Free Software Foundation; either version 2 of the License, or
8## (at your option) any later version.
9##
10## This program is distributed in the hope that it will be useful,
11## but WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13## GNU General Public License for more details.
14##
15## You should have received a copy of the GNU General Public License
16## along with this program; if not, write to the Free Software
17## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18##
19import httplib
20import hashlib
21import grok
22from xml.dom import minidom
23from zope.interface import Interface
24from zope.component import queryAdapter
25from waeup.kofa.interfaces import CLEARED
26from kofacustom.nigeria.interswitch.browser import (
27    InterswitchPaymentRequestWebservicePageStudent,
28    InterswitchPaymentRequestWebservicePageApplicant,
29    InterswitchPaymentVerifyWebservicePageApplicant,
30    InterswitchPaymentVerifyWebservicePageStudent,
31    InterswitchPageStudent, InterswitchPageApplicant,
32    )
33from waeup.aaue.students.interfaces import ICustomStudentOnlinePayment
34from waeup.aaue.applicants.interfaces import ICustomApplicantOnlinePayment
35from waeup.aaue.interfaces import MessageFactory as _
36
37PRODUCT_ID_PT = '5040'
38PRODUCT_ID_REGULAR = '5845'
39SITE_NAME = 'aaue.waeup.org'
40PROVIDER_ACCT = '5100189030'
41PROVIDER_BANK_ID = '307'
42PROVIDER_ITEM_NAME = 'WAeAC'
43INSTITUTION_NAME = 'AAU Ekpoma'
44CURRENCY = '566'
45GATEWAY_AMT = 200.0
46POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
47
48HOST = 'webpay.interswitchng.com'
49URL = '/paydirect/api/v1/gettransaction.json'
50HTTPS = True
51MAC_REGULAR = '9718FA00B0F5070B388A9896ADCED9B2FB02D30F71E12E68BDADC63F6852A3496FF97D8A0F9DA9F753B911A49BB09BB87B55FD02046BD325C74C46C0123CF023'
52MAC_PT = '74424F1DFECD6058F153148255CDD55E16724B4F380ADB2C63C5D1D7A5675759010C8153DCB930AAF2D38903CBF7CE32B8A6BA2C16BBC46721DF2E3F3E4548E3'
53
54httplib.HTTPSConnection.debuglevel = 0
55
56
57def gateway_net_amt(fee):
58    if fee > GATEWAY_AMT:
59        return fee - GATEWAY_AMT
60    return 0.0
61
62def contr_agreement_applicant(applicant):
63    if applicant.__parent__.prefix in (
64        'fp',
65        'ptee',
66        'dsh',
67        'bridge',
68        'ijmbe',
69        ):
70        return 'first'
71    return 'second'
72
73def contr_agreement_student(student):
74    if student.current_mode in (
75        'found',
76        'bridge',
77        'ug_dsh',
78        'de_dsh',
79        'ug_pt',
80        'de_pt',
81        'dp_pt',
82        'ijmbe',
83        ):
84        return 'first'
85    return 'second'
86
87class CustomInterswitchPageApplicant(InterswitchPageApplicant):
88    """ View which sends a POST request to the Interswitch
89    CollegePAY payment gateway.
90
91    So far only PT application has been configured.
92    """
93    grok.context(ICustomApplicantOnlinePayment)
94    action = POST_ACTION
95    site_name = SITE_NAME
96    currency = CURRENCY
97    provider_bank_id = PROVIDER_BANK_ID
98    provider_acct = PROVIDER_ACCT
99    institution_acct = '1010835352'
100    institution_bank_id = '117'
101
102    def update(self):
103
104        error = self.init_update()
105        if error:
106            self.flash(error, type='danger')
107            self.redirect(self.url(self.context, '@@index'))
108            return
109        self.context.r_company = u'interswitch'
110        provider_amt = 2000.0
111        fedex_amt = 0.0
112        if contr_agreement_applicant(self.applicant) == 'first':
113            self.product_id = PRODUCT_ID_PT
114            self.pay_item_id = '101'
115            self.mac = MAC_PT
116            if self.applicant.__parent__.prefix == 'ijmbe':
117                self.institution_bank_id = '123'
118                self.institution_acct = '1012278272'
119        else:
120            self.product_id = PRODUCT_ID_REGULAR
121            self.pay_item_id = '109'
122            self.mac = MAC_REGULAR
123            if self.applicant.__parent__.prefix in ('utme', 'ude'):
124                provider_amt = 1000.0
125            elif self.applicant.__parent__.prefix in ('trans', 'cert'):
126                self.institution_acct = '1010827641'
127                self.institution_bank_id = '117'
128                self.provider_bank_id = '10'
129                self.provider_acct = '0427773399'
130                if self.applicant.applicant_id[:5] in ('cert7', 'cert8'):
131                    provider_amt = 0.0
132                if self.applicant.applicant_id[:6] in ('trans5', 'trans6'):
133                    self.institution_acct = '5210006575'
134                    self.institution_bank_id = '51'
135                #if self.applicant.applicant_id[:6] in ('trans1', 'trans6'):
136                #    fedex_amt = 10500.0
137                if self.context.p_category == 'app_balance':
138                    provider_amt = 0.0
139            elif self.applicant.applicant_id.startswith('bridge'): # easier to test
140                self.institution_acct = '1014847058'
141                self.institution_bank_id = '7'
142            elif self.applicant.applicant_id.startswith('dsh'): # easier to test
143                self.institution_acct = '1014847058'
144                self.institution_bank_id = '7'
145            elif self.applicant.__parent__.prefix in ('ver', 'send'):
146                provider_amt = 0.0
147            elif self.applicant.__parent__.prefix == 'fedex':
148                provider_amt = 0.0
149                self.institution_acct = '0001115694'
150                self.institution_bank_id = '10'
151            elif self.applicant.applicant_id.startswith('pg'):
152                self.institution_acct = '5210006575'
153                self.institution_bank_id = '51'
154
155        xmldict = {}
156        xmldict['detail_ref'] = self.context.p_id
157        xmldict['provider_amt'] = 100 * provider_amt
158        xmldict['provider_acct'] = self.provider_acct
159        xmldict['provider_bank_id'] = self.provider_bank_id
160        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
161        xmldict['institution_acct'] = self.institution_acct
162        xmldict['institution_bank_id'] = self.institution_bank_id
163        xmldict['institution_item_name'] = self.category
164        xmldict['institution_name'] = INSTITUTION_NAME
165        xmldict['fedex_amt'] = 100 * fedex_amt
166        xmldict['institution_amt'] = 100 * (
167            self.context.amount_auth - provider_amt - fedex_amt - GATEWAY_AMT)
168
169        xmltext = """<payment_item_detail>
170<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
171<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" />
172<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" />
173</item_details>
174</payment_item_detail>""" % xmldict
175
176        if provider_amt == 0.0:
177            xmltext = """<payment_item_detail>
178<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
179<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" />
180</item_details>
181</payment_item_detail>""" % xmldict
182
183        if fedex_amt:
184            xmltext = """<payment_item_detail>
185<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
186<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" />
187<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" />
188<item_detail item_id="3" item_name="FedEx" item_amt="%(fedex_amt)d" bank_id="10" acct_num="0001115694" />
189</item_details>
190</payment_item_detail>""" % xmldict
191
192        if self.applicant.applicant_id.startswith('pg'):
193            handbook_amount = 2000.0
194            xmldict['handbook_amount'] = 100 * handbook_amount
195            xmldict['institution_amt'] = 100 * (
196                self.context.amount_auth - provider_amt - handbook_amount -GATEWAY_AMT)
197            xmltext = """<payment_item_detail>
198<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
199<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" />
200<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" />
201<item_detail item_id="3" item_name="PG Handbook" item_amt="%(handbook_amount)d" bank_id="51" acct_num="5210006575" />
202</item_details>
203</payment_item_detail>""" % xmldict
204
205        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
206        self.context.provider_amt = provider_amt
207        self.context.gateway_amt = GATEWAY_AMT
208        xmlitems = ''
209        xmldoc = minidom.parseString(xmltext)
210        itemlist = xmldoc.getElementsByTagName('item_detail')
211        for s in itemlist:
212            xmlitems += "%s: %s, N%s, %s (%s)  " % (
213                s.attributes['item_id'].value,
214                s.attributes['item_name'].value,
215                int(s.attributes['item_amt'].value)/100,
216                s.attributes['acct_num'].value,
217                s.attributes['bank_id'].value,
218                )
219        self.context.p_split_data = xmlitems
220        self.amount_auth = int(100 * self.context.amount_auth)
221        hashargs = (
222            self.context.p_id +
223            self.product_id +
224            self.pay_item_id +
225            str(int(self.amount_auth)) +
226            self.site_redirect_url +
227            self.mac)
228        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
229
230        return
231
232class CustomInterswitchPageStudent(InterswitchPageStudent):
233    """ View which sends a POST request to the Interswitch
234    CollegePAY payment gateway.
235    """
236    grok.context(ICustomStudentOnlinePayment)
237    action = POST_ACTION
238    site_name = SITE_NAME
239    currency = CURRENCY
240    pay_item_id = '000'
241
242    def update(self):
243        error = self.init_update()
244        if error:
245            self.flash(error, type='danger')
246            self.redirect(self.url(self.context, '@@index'))
247            return
248        self.context.r_company = u'interswitch'
249        student = self.student
250        p_session = self.context.p_session
251        try:
252            academic_session = grok.getSite()['configuration'][str(p_session)]
253        except KeyError:
254            self.flash(_(u'Session configuration object is not available.'),
255                       type='danger')
256            self.redirect(self.url(self.context, '@@index'))
257            return
258        if contr_agreement_student(student) == 'first':
259            self.product_id = PRODUCT_ID_PT
260            self.mac = MAC_PT
261        else:
262            self.product_id = PRODUCT_ID_REGULAR
263            self.mac = MAC_REGULAR
264
265        # To guarantee that cleared students pay both acceptance fee
266        # and school fees, the page can only be accessed
267        # for school fee payments if acceptance/clearance fee has
268        # been successfully queried/paid beforehand. This
269        # requirement applies to students in state 'cleared' and
270        # entry_session greater than 2012 only.
271        if self.context.p_category.startswith('schoolfee') and \
272            student.state == CLEARED and \
273            student.entry_session > 2012:
274            acceptance_fee_paid = False
275            for ticket in student['payments'].values():
276                if ticket.p_state == 'paid' and \
277                    ticket.p_category.startswith('clearance'):
278                    acceptance_fee_paid = True
279                    break
280            if not acceptance_fee_paid:
281                self.flash(
282                    _('Please pay acceptance fee first.'), type="danger")
283                self.redirect(self.url(self.context, '@@index'))
284                return
285
286        xmldict = self.xmldict
287        xmltext = ""
288        xmldict['institution_acct'] = '1010827641'
289        xmldict['institution_bank_id'] = '117'
290        xmldict['detail_ref'] = self.context.p_id
291        xmldict['provider_acct'] = PROVIDER_ACCT
292        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
293        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
294        xmldict['institution_item_name'] = self.category
295        xmldict['institution_name'] = INSTITUTION_NAME
296        provider_amt = 0.0
297        xmldict['institution_amt'] = 100 * (
298            gateway_net_amt(self.context.amount_auth))
299
300        # Schoolfee
301        if self.context.p_category.startswith('schoolfee'):
302            if contr_agreement_student(student) == 'first':
303                # First agreement
304                provider_amt = 1900.0
305                joint_venture_amt = 0.0
306                aaue_share_amt = 0.0
307                student_union_due_amt = gateway_net_amt(
308                    academic_session.union_fee)
309                student_welfare_assurance_amt = gateway_net_amt(
310                    academic_session.welfare_fee)
311                sports_amt = gateway_net_amt(
312                    academic_session.sports_fee)
313                library_amt = gateway_net_amt(
314                    academic_session.library_fee)
315                library_amt_pg = gateway_net_amt(
316                    academic_session.library_pg_fee)
317                lms_sund_amt = gateway_net_amt(
318                    academic_session.lms_sund_fee)
319                xmldict['student_union_bank_id'] = '31'
320                xmldict['student_union_acct'] = '0051005007'
321                xmldict['aaue_share_bank_id'] = '117'
322                xmldict['aaue_share_acct'] = '1010827641'
323                xmldict['joint_venture_bank_id'] = '117'
324                xmldict['joint_venture_acct'] = '1010827641'
325                xmldict['institution_acct'] = '1014847058'
326                xmldict['institution_bank_id'] = '7'
327                self.pay_item_id = '105'
328                if student.current_mode == 'found':
329                    self.pay_item_id = '103'
330                elif student.current_mode == 'ijmbe':
331                    self.pay_item_id = '103'
332                    xmldict['institution_bank_id'] = '123'
333                    xmldict['institution_acct'] = '1012278272'
334            else:
335                # Second agreement
336                joint_venture_amt = 1000.0
337                aaue_share_amt = 1500.0
338                provider_amt = 1500.0
339                student_union_due_amt = gateway_net_amt(
340                    academic_session.union_fee)
341                student_welfare_assurance_amt = gateway_net_amt(
342                    academic_session.welfare_fee)
343                sports_amt = gateway_net_amt(
344                    academic_session.sports_fee)
345                library_amt = gateway_net_amt(
346                    academic_session.library_fee)
347                library_amt_pg = gateway_net_amt(
348                    academic_session.library_pg_fee)
349                lms_sund_amt = gateway_net_amt(
350                    academic_session.lms_sund_fee)
351                xmldict['student_union_bank_id'] = '7'
352                xmldict['student_union_acct'] = '1019763348'
353                xmldict['aaue_share_bank_id'] = '117'
354                xmldict['aaue_share_acct'] = '1010827641'
355                xmldict['joint_venture_bank_id'] = '117'
356                xmldict['joint_venture_acct'] = '1010827641'
357                self.pay_item_id = '107'
358                if student.is_postgrad:
359                    self.pay_item_id = '111'
360                    xmldict['institution_acct'] = '5210006575'
361                    xmldict['institution_bank_id'] = '51'
362
363            xmldict['provider_amt'] = 100 * provider_amt
364            xmldict['joint_venture_amt'] = 100 * joint_venture_amt
365            xmldict['aaue_share_amt'] = 100 * aaue_share_amt
366            xmldict['lms_sund_amt'] = 100 * lms_sund_amt
367            if self.context.p_item == 'Balance':
368                xmldict['institution_amt'] = 100 * (
369                    gateway_net_amt(self.context.amount_auth))
370            elif self.context.p_category == 'schoolfee_2':
371                xmldict['institution_amt'] = 100 * gateway_net_amt(
372                    self.context.amount_auth)
373                xmltext = """<payment_item_detail>
374<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
375<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" />
376</item_details>
377</payment_item_detail>""" % xmldict
378            elif self.context.p_category in ('schoolfee_incl', 'schoolfee_1') \
379                and student.current_mode != 'ijmbe':
380                # Schoolfee including additional fees
381                xmldict['student_union_due_amt'] = 100 * student_union_due_amt
382                xmldict['student_welfare_assurance_amt'] = 100 * student_welfare_assurance_amt
383
384                if student.entry_session >= 2018 and student.is_fresh:
385                    xmldict['sports_amt'] = 100 * sports_amt
386                    if student.is_postgrad:
387                        xmldict['library_amt'] = 100 * library_amt_pg
388                    else:
389                        xmldict['library_amt'] = 100 * library_amt
390                    xmldict['institution_amt'] = 100 * (
391                        gateway_net_amt(self.context.amount_auth)
392                        - provider_amt
393                        - student_union_due_amt
394                        - student_welfare_assurance_amt
395                        - sports_amt
396                        - library_amt
397                        - lms_sund_amt)
398                    xmltext = """<payment_item_detail>
399<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
400<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" />
401<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" />
402<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" />
403<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />
404<item_detail item_id="5" item_name="Sports Development Fee" item_amt="%(sports_amt)d" bank_id="123" acct_num="1006407792" />
405<item_detail item_id="6" item_name="Library Development Fee" item_amt="%(library_amt)d" bank_id="8" acct_num="2000122995" />
406</item_details>
407</payment_item_detail>""" % xmldict
408                    if contr_agreement_student(student) == 'second':
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                            - student_union_due_amt
415                            - student_welfare_assurance_amt
416                            - sports_amt
417                            - library_amt)
418                        xmltext = """<payment_item_detail>
419<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
420<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" />
421<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" />
422<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" />
423<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />
424<item_detail item_id="5" item_name="Sports Development Fee" item_amt="%(sports_amt)d" bank_id="123" acct_num="1006407792" />
425<item_detail item_id="6" item_name="Library Development Fee" item_amt="%(library_amt)d" bank_id="8" acct_num="2000122995" />
426<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" />
427<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" />
428</item_details>
429</payment_item_detail>""" % xmldict
430
431                    if student.entry_session >= 2021 and student.current_mode == 'ug_ft':
432                        xmldict['institution_amt'] = 100 * (
433                            gateway_net_amt(self.context.amount_auth)
434                            - provider_amt
435                            - joint_venture_amt
436                            - aaue_share_amt
437                            - student_union_due_amt
438                            - student_welfare_assurance_amt
439                            - sports_amt
440                            - library_amt
441                            - lms_sund_amt) 
442                        xmltext = """<payment_item_detail>
443<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
444<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" />
445<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" />
446<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" />
447<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />
448<item_detail item_id="5" item_name="Sports Development Fee" item_amt="%(sports_amt)d" bank_id="123" acct_num="1006407792" />
449<item_detail item_id="6" item_name="Library Development Fee" item_amt="%(library_amt)d" bank_id="8" acct_num="2000122995" />
450<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" />
451<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" />
452<item_detail item_id="9" item_name="LMS plus Sundry Fees" item_amt="%(lms_sund_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
453</item_details>
454</payment_item_detail>""" % xmldict
455
456                else:
457                    xmldict['institution_amt'] = 100 * (
458                        gateway_net_amt(self.context.amount_auth)
459                        - provider_amt
460                        - student_union_due_amt
461                        - student_welfare_assurance_amt)
462                    xmltext = """<payment_item_detail>
463<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
464<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" />
465<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" />
466<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" />
467<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />
468</item_details>
469</payment_item_detail>""" % xmldict
470                    if contr_agreement_student(student) == 'second':
471                        xmldict['institution_amt'] = 100 * (
472                            gateway_net_amt(self.context.amount_auth)
473                            - provider_amt
474                            - joint_venture_amt
475                            - aaue_share_amt
476                            - student_union_due_amt
477                            - student_welfare_assurance_amt)                   
478                        xmltext = """<payment_item_detail>
479<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
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" />
481<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" />
482<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" />
483<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />
484<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" />
485<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" />
486</item_details>
487</payment_item_detail>""" % xmldict
488
489            elif contr_agreement_student(student) == 'second':
490                # Schoolfee without Student Union Fee ands Student Welfare Assurance
491                xmldict['institution_amt'] = 100 * (
492                    gateway_net_amt(self.context.amount_auth)
493                    - provider_amt
494                    - joint_venture_amt
495                    - aaue_share_amt)
496                xmltext = """<payment_item_detail>
497<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
498<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" />
499<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" />
500<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" />
501<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" />
502</item_details>
503</payment_item_detail>""" % xmldict
504            else:
505                xmldict['institution_amt'] = 100 * (
506                    gateway_net_amt(self.context.amount_auth)
507                    - provider_amt)
508                xmltext = """<payment_item_detail>
509<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
510<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" />
511<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" />
512</item_details>
513</payment_item_detail>""" % xmldict
514
515        # Clearance
516        elif self.context.p_category.startswith('clearance'):
517            xmldict['institution_acct'] = '1010835352'
518            provider_amt = 0.0
519            if contr_agreement_student(student) == 'first':
520                # First agreement
521                xmldict['institution_acct'] = '1014847058'
522                xmldict['institution_bank_id'] = '7'
523                self.pay_item_id = '104'
524                if student.current_mode == 'found':
525                    self.pay_item_id = '102'
526                elif student.current_mode == 'ijmbe':
527                    self.pay_item_id = '102'
528                    xmldict['institution_bank_id'] = '123'
529                    xmldict['institution_acct'] = '1012278272'
530            else:
531                # Second agreement
532                self.pay_item_id = '102'
533                if student.is_postgrad:
534                    self.pay_item_id = '110'
535                    xmldict['institution_acct'] = '5210006575'
536                    xmldict['institution_bank_id'] = '51'
537                # ivama: Acceptance fee split is unique to "ug_ft"
538                # The reason for split is perculiar to them only...
539                # That amount was deducted from UTME application fee because
540                # some regulatory body have pegged the application fee which
541                # didn't affect another programmes.
542                if student.current_mode == 'ug_ft':
543                    provider_amt = 1500.0
544            xmldict['provider_amt'] = 100 * provider_amt
545            if self.context.p_category.endswith('_incl'):
546                # Clearance including additional fees
547                gown_fee_amt = gateway_net_amt(academic_session.matric_gown_fee)
548                aaue_lf_fee_amt = gateway_net_amt(academic_session.lapel_fee)
549                xmldict['gown_fee_amt'] = 100 * gown_fee_amt
550                xmldict['aaue_lf_fee_amt'] = 100 * aaue_lf_fee_amt
551                xmldict['institution_amt'] = 100 * (
552                    gateway_net_amt(self.context.amount_auth)
553                    - gown_fee_amt
554                    - aaue_lf_fee_amt
555                    - provider_amt)
556                xmltext = """<payment_item_detail>
557<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
558<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" />
559<item_detail item_id="2" item_name="Matriculation Gown Fee" item_amt="%(gown_fee_amt)d" bank_id="117" acct_num="1010835352" />
560<item_detail item_id="3" item_name="AAU File-Lapel Fee" item_amt="%(aaue_lf_fee_amt)d" bank_id="117" acct_num="1010835352" />""" % xmldict
561                if provider_amt:
562                    xmltext += """"
563<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" />
564</item_details>
565</payment_item_detail>""" % xmldict
566                else:
567                    xmltext += """"
568</item_details>
569</payment_item_detail>"""
570
571            elif student.current_mode == 'bridge':
572                # Clearance without any surcharge
573                xmldict['institution_amt'] = 100 * gateway_net_amt(
574                    self.context.amount_auth)
575                xmltext = """<payment_item_detail>
576<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
577<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" />
578</item_details>
579</payment_item_detail>""" % xmldict
580
581            else:
582                # Clearance without additional fees
583                xmldict['institution_amt'] = 100 * (
584                    gateway_net_amt(self.context.amount_auth)
585                    - provider_amt)
586                xmltext = """<payment_item_detail>
587<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
588<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
589                if provider_amt:
590                        xmltext += """"
591<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" />
592</item_details>
593</payment_item_detail>""" % xmldict
594                else:
595                        xmltext += """"
596</item_details>
597</payment_item_detail>"""
598
599        # Union Dues
600        elif self.context.p_category == 'union':
601            self.pay_item_id = '103'
602            xmldict['institution_amt'] = 100 * (
603                gateway_net_amt(self.context.amount_auth))
604            if contr_agreement_student(student) == 'first':
605                # First agreement
606                xmldict['institution_acct'] = '0051005007'
607                xmldict['institution_bank_id'] = '31'
608            else:
609                # Second agreement
610                xmldict['institution_bank_id'] = '7'
611                xmldict['institution_acct'] = '1019763348'
612
613        # Lapel/File
614        elif self.context.p_category == 'lapel':
615            self.pay_item_id = '104'
616            xmldict['institution_amt'] = 100 * (
617                gateway_net_amt(self.context.amount_auth))
618
619        # Welfare Assurance
620        elif self.context.p_category == 'welfare':
621            self.pay_item_id = '105'
622            xmldict['institution_acct'] = '1006407792'
623            xmldict['institution_bank_id'] = '123'
624            xmldict['institution_amt'] = 100 * (
625                gateway_net_amt(self.context.amount_auth))
626
627        # ID Card
628        elif self.context.p_category == 'id_card':
629            self.pay_item_id = '000'
630            xmldict['institution_amt'] = 100 * (
631                gateway_net_amt(self.context.amount_auth))
632
633        # Matric Gown
634        elif self.context.p_category == 'matric_gown':
635            self.pay_item_id = '106'
636            xmldict['institution_amt'] = 100 * (
637                gateway_net_amt(self.context.amount_auth))
638
639        # Concessional
640        elif self.context.p_category == 'concessional':
641            self.pay_item_id = '107'
642            xmldict['institution_amt'] = 100 * (
643                gateway_net_amt(self.context.amount_auth))
644
645        # Hostel Maintenance
646        elif self.context.p_category == 'hostel_maintenance':
647            provider_amt = 500.0
648            self.pay_item_id = '109'
649            xmldict['institution_acct'] = '1006406795'
650            xmldict['institution_bank_id'] = '123'
651            xmldict['provider_amt'] = 100 * provider_amt
652            xmldict['institution_amt'] = 100 * (
653                gateway_net_amt(self.context.amount_auth) - provider_amt)
654            xmltext = """<payment_item_detail>
655<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
656<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" />
657<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" />
658</item_details>
659</payment_item_detail>""" % xmldict
660
661        # GST Fees
662        elif self.context.p_category.startswith('gst_'):
663            if contr_agreement_student(student) == 'first':
664                self.pay_item_id = '115'
665            else:
666                self.pay_item_id = '116'
667            xmldict['institution_acct'] = '1010893123'
668            xmldict['institution_bank_id'] = '117'
669            xmldict['institution_amt'] = 100 * (
670                gateway_net_amt(self.context.amount_auth))
671
672        # ENT Fees
673        elif self.context.p_category.startswith('ent_'):
674            if contr_agreement_student(student) == 'first':
675                self.pay_item_id = '114'
676            else:
677                self.pay_item_id = '118'
678            xmldict['institution_acct'] = '6220029828'
679            xmldict['institution_bank_id'] = '51'
680            xmldict['institution_amt'] = 100 * (
681                gateway_net_amt(self.context.amount_auth))
682
683        # Faculty and Departmental Dues
684        elif self.context.p_category == 'fac_dep':
685            xmldict['institution_acct'] = '1016425386'
686            xmldict['institution_bank_id'] = '117'
687            self.pay_item_id = '117'
688            xmldict['institution_amt'] = 100 * (
689                gateway_net_amt(self.context.amount_auth))
690
691        # Restitution Fee
692        elif self.context.p_category == 'restitution':
693            self.pay_item_id = '117'
694            xmldict['institution_amt'] = 100 * (
695                gateway_net_amt(self.context.amount_auth))
696
697        # Faculty Laboratory Due
698        elif self.context.p_category in ('lab_1', 'lab_2'):
699            xmldict['institution_acct'] = '1016425386'
700            xmldict['institution_bank_id'] = '117'
701            self.pay_item_id = '117'
702            xmldict['institution_amt'] = 100 * (
703                gateway_net_amt(self.context.amount_auth))
704
705        # Sports Fee
706        #elif self.context.p_category == 'sports':
707        #    self.pay_item_id = '105'
708        #    xmldict['institution_amt'] = 100 * (
709        #        gateway_net_amt(self.context.amount_auth))
710
711        # Library Fee
712        #elif self.context.p_category == 'library':
713        #    self.pay_item_id = '105'
714        #    xmldict['institution_amt'] = 100 * (
715        #        gateway_net_amt(self.context.amount_auth))
716
717        # Library PG Fee
718        #elif self.context.p_category == 'library_pg':
719        #    self.pay_item_id = '105'
720        #    xmldict['institution_amt'] = 100 * (
721        #        gateway_net_amt(self.context.amount_auth))
722
723        # Exam Fee
724        elif self.context.p_category == 'exam':
725            self.pay_item_id = '103'
726            xmldict['institution_acct'] = '1012278272'
727            xmldict['institution_bank_id'] = '123'
728            xmldict['institution_amt'] = 100 * (
729                gateway_net_amt(self.context.amount_auth))
730
731        # Access Card Fee
732        elif self.context.p_category == 'access_card':
733            self.pay_item_id = '103'
734            xmldict['institution_acct'] = '1012688013'
735            xmldict['institution_bank_id'] = '123'
736            xmldict['institution_amt'] = 100 * (
737                gateway_net_amt(self.context.amount_auth))
738
739        # LMS + Sundry Fees
740        elif self.context.p_category == 'lms_sund':
741            self.pay_item_id = '103'
742            xmldict['institution_amt'] = 100 * (
743                gateway_net_amt(self.context.amount_auth))
744
745        # Sports & Library Fee    temporarily in 2020
746        elif self.context.p_category == 'sports_library':
747            self.pay_item_id = '105'
748            xmldict['sports_amt'] = 100 * 3000.0
749            xmldict['library_amt'] = 100 * 1000.0
750            xmltext = """<payment_item_detail>
751<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
752<item_detail item_id="1" item_name="Sports Development Fee" item_amt="%(sports_amt)d" bank_id="123" acct_num="1006407792" />
753<item_detail item_id="2" item_name="Library Development Fee" item_amt="%(library_amt)d" bank_id="8" acct_num="2000122995" />
754</item_details>
755</payment_item_detail>""" % xmldict
756
757        # Late Registration Fee
758        elif self.context.p_category == 'late_registration':
759            if contr_agreement_student(student) == 'first':
760                self.pay_item_id = '113'
761            else:
762                self.pay_item_id = '123'
763            xmldict['institution_amt'] = 100 * (
764                gateway_net_amt(self.context.amount_auth))
765            if student.is_postgrad:
766                xmldict['institution_acct'] = '5210006575'
767                xmldict['institution_bank_id'] = '51'
768        if not xmltext:
769            xmltext = """<payment_item_detail>
770<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
771<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" />
772</item_details>
773</payment_item_detail>""" % xmldict
774        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
775        self.context.provider_amt = provider_amt
776        self.context.gateway_amt = self.context.amount_auth - gateway_net_amt(
777            self.context.amount_auth)
778        xmlitems = ''
779        xmldoc = minidom.parseString(xmltext)
780        itemlist = xmldoc.getElementsByTagName('item_detail')
781        for s in itemlist:
782            xmlitems += "%s: %s, %s %s, %s (%s)  " % (
783                s.attributes['item_id'].value,
784                s.attributes['item_name'].value,
785                u'\u20a6',
786                int(s.attributes['item_amt'].value)/100,
787                s.attributes['acct_num'].value,
788                s.attributes['bank_id'].value,
789                )
790        self.context.p_split_data = xmlitems
791        self.amount_auth = int(100 * self.context.amount_auth)
792        hashargs = (
793            self.context.p_id +
794            self.product_id +
795            self.pay_item_id +
796            str(int(self.amount_auth)) +
797            self.site_redirect_url +
798            self.mac)
799        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
800        return
801
802
803class CustomInterswitchPaymentRequestWebservicePageApplicant(
804    InterswitchPaymentRequestWebservicePageApplicant):
805    """Request webservice view for the CollegePAY gateway
806    """
807    grok.context(ICustomApplicantOnlinePayment)
808    gateway_host = HOST
809    gateway_url = URL
810    https = HTTPS
811
812    @property
813    def mac(self):
814        if contr_agreement_applicant(self.context.__parent__) == 'first':
815            return MAC_PT
816        return MAC_REGULAR
817
818    @property
819    def product_id(self):
820        if contr_agreement_applicant(self.context.__parent__) == 'first':
821            return PRODUCT_ID_PT
822        return PRODUCT_ID_REGULAR
823
824class CustomInterswitchPaymentVerifyWebservicePageApplicant(
825    InterswitchPaymentVerifyWebservicePageApplicant):
826    """Payment verify view for the CollegePAY gateway
827    """
828    grok.context(ICustomApplicantOnlinePayment)
829    gateway_host = HOST
830    gateway_url = URL
831    https = HTTPS
832
833    @property
834    def mac(self):
835        if contr_agreement_applicant(self.context.__parent__) == 'first':
836            return MAC_PT
837        return MAC_REGULAR
838
839    @property
840    def product_id(self):
841        if contr_agreement_applicant(self.context.__parent__) == 'first':
842            return PRODUCT_ID_PT
843        return PRODUCT_ID_REGULAR
844
845class CustomInterswitchPaymentRequestWebservicePageStudent(
846    InterswitchPaymentRequestWebservicePageStudent):
847    """Request webservice view for the CollegePAY gateway
848    """
849    grok.context(ICustomStudentOnlinePayment)
850    gateway_host = HOST
851    gateway_url = URL
852    https = HTTPS
853
854    @property
855    def mac(self):
856        if contr_agreement_student(self.context.student) == 'first':
857            return MAC_PT
858        return MAC_REGULAR
859
860    @property
861    def product_id(self):
862        if contr_agreement_student(self.context.student) == 'first':
863            return PRODUCT_ID_PT
864        return PRODUCT_ID_REGULAR
865
866class CustomInterswitchPaymentVerifyWebservicePageStudent(
867    InterswitchPaymentVerifyWebservicePageStudent):
868    """Payment verify view for the CollegePAY gateway
869    """
870    grok.context(ICustomStudentOnlinePayment)
871    gateway_host = HOST
872    gateway_url = URL
873    https = HTTPS
874
875    @property
876    def mac(self):
877        if contr_agreement_student(self.context.student) == 'first':
878            return MAC_PT
879        return MAC_REGULAR
880
881    @property
882    def product_id(self):
883        if contr_agreement_student(self.context.student) == 'first':
884            return PRODUCT_ID_PT
885        return PRODUCT_ID_REGULAR
Note: See TracBrowser for help on using the repository browser.