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

Last change on this file since 16678 was 16678, checked in by Henrik Bettermann, 3 years ago

Change bank acount.

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