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

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

Change p_item_id.

  • Property svn:keywords set to Id
File size: 37.1 KB
Line 
1## $Id: browser.py 16691 2021-11-01 09:03:58Z 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            if self.applicant.__parent__.prefix == 'ijmbe':
116                xmldict['institution_bank_id'] = '123'
117                xmldict['institution_acct'] = '1012278272'
118        else:
119            self.product_id = PRODUCT_ID_REGULAR
120            self.pay_item_id = '109'
121            self.mac = MAC_REGULAR
122            if self.applicant.__parent__.prefix in ('utme', 'ude'):
123                provider_amt = 1000.0
124            elif self.applicant.__parent__.prefix in ('trans', 'cert'):
125                self.institution_acct = '1010827641'
126                self.institution_bank_id = '117'
127                self.provider_bank_id = '10'
128                self.provider_acct = '0427773399'
129                if self.applicant.applicant_id[:5] in ('cert7', 'cert8'):
130                    provider_amt = 0.0
131                if self.applicant.applicant_id[:6] in ('trans5', 'trans6'):
132                    self.institution_acct = '5210006575'
133                    self.institution_bank_id = '51'
134                #if self.applicant.applicant_id[:6] in ('trans1', 'trans6'):
135                #    fedex_amt = 10500.0
136                if self.context.p_category == 'app_balance':
137                    provider_amt = 0.0
138            elif self.applicant.applicant_id.startswith('bridge'): # easier to test
139                self.institution_acct = '1014847058'
140                self.institution_bank_id = '7'
141            elif self.applicant.applicant_id.startswith('dsh'): # easier to test
142                self.institution_acct = '1014847058'
143                self.institution_bank_id = '7'
144            elif self.applicant.__parent__.prefix in ('ver', 'send'):
145                provider_amt = 0.0
146            elif self.applicant.__parent__.prefix == 'fedex':
147                provider_amt = 0.0
148                self.institution_acct = '0001115694'
149                self.institution_bank_id = '10'
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                self.pay_item_id = '105'
320                if student.current_mode == 'found':
321                    self.pay_item_id = '103'
322                elif student.current_mode == 'ijmbe':
323                    self.pay_item_id = '103'
324                    xmldict['institution_bank_id'] = '123'
325                    xmldict['institution_acct'] = '1012278272'
326            else:
327                # Second agreement
328                joint_venture_amt = 1000.0
329                aaue_share_amt = 1500.0
330                provider_amt = 1500.0
331                student_union_due_amt = gateway_net_amt(
332                    academic_session.union_fee)
333                student_welfare_assurance_amt = gateway_net_amt(
334                    academic_session.welfare_fee)
335                sports_amt = gateway_net_amt(
336                    academic_session.sports_fee)
337                library_amt = gateway_net_amt(
338                    academic_session.library_fee)
339                library_amt_pg = gateway_net_amt(
340                    academic_session.library_pg_fee)
341                xmldict['student_union_bank_id'] = '7'
342                xmldict['student_union_acct'] = '1019763348'
343                xmldict['aaue_share_bank_id'] = '117'
344                xmldict['aaue_share_acct'] = '1010827641'
345                xmldict['joint_venture_bank_id'] = '117'
346                xmldict['joint_venture_acct'] = '1010827641'
347                self.pay_item_id = '107'
348                if student.is_postgrad:
349                    self.pay_item_id = '111'
350                    xmldict['institution_acct'] = '5210006575'
351                    xmldict['institution_bank_id'] = '51'
352
353            xmldict['provider_amt'] = 100 * provider_amt
354            xmldict['joint_venture_amt'] = 100 * joint_venture_amt
355            xmldict['aaue_share_amt'] = 100 * aaue_share_amt
356            if self.context.p_item == 'Balance':
357                xmldict['institution_amt'] = 100 * (
358                    gateway_net_amt(self.context.amount_auth))
359            elif self.context.p_category == 'schoolfee_2':
360                xmldict['institution_amt'] = 100 * gateway_net_amt(
361                    self.context.amount_auth)
362                xmltext = """<payment_item_detail>
363<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
364<item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
365</item_details>
366</payment_item_detail>""" % xmldict
367            elif self.context.p_category in ('schoolfee_incl', 'schoolfee_1') \
368                and student.current_mode != 'ijmbe':
369                # Schoolfee including additional fees
370                xmldict['student_union_due_amt'] = 100 * student_union_due_amt
371                xmldict['student_welfare_assurance_amt'] = 100 * student_welfare_assurance_amt
372
373                if student.entry_session >= 2018 and student.is_fresh:
374                    xmldict['sports_amt'] = 100 * sports_amt
375                    if student.is_postgrad:
376                        xmldict['library_amt'] = 100 * library_amt_pg
377                    else:
378                        xmldict['library_amt'] = 100 * library_amt
379                    xmldict['institution_amt'] = 100 * (
380                        gateway_net_amt(self.context.amount_auth)
381                        - provider_amt
382                        - joint_venture_amt
383                        - aaue_share_amt
384                        - student_union_due_amt
385                        - student_welfare_assurance_amt
386                        - sports_amt
387                        - library_amt)
388                    xmltext = """<payment_item_detail>
389<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
390<item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
391<item_detail item_id="2" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
392<item_detail item_id="3" item_name="Student Union" item_amt="%(student_union_due_amt)d" bank_id="%(student_union_bank_id)s" acct_num="%(student_union_acct)s" />
393<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />
394<item_detail item_id="5" item_name="Sports Development Fee" item_amt="%(sports_amt)d" bank_id="123" acct_num="1006407792" />
395<item_detail item_id="6" item_name="Library Development Fee" item_amt="%(library_amt)d" bank_id="8" acct_num="2000122995" />""" % xmldict
396                    if contr_agreement_student(student) == 'second':
397                        xmltext += """"
398<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" />
399<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" />
400</item_details>
401</payment_item_detail>""" % xmldict
402                    else:
403                        xmltext += """"
404</item_details>
405</payment_item_detail>"""
406                else:
407                    xmldict['institution_amt'] = 100 * (
408                        gateway_net_amt(self.context.amount_auth)
409                        - provider_amt
410                        - joint_venture_amt
411                        - aaue_share_amt
412                        - student_union_due_amt
413                        - student_welfare_assurance_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="Student Union" item_amt="%(student_union_due_amt)d" bank_id="%(student_union_bank_id)s" acct_num="%(student_union_acct)s" />
419<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />""" % xmldict
420                    if contr_agreement_student(student) == 'second':
421                        xmltext += """"
422<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" />
423<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" />
424</item_details>
425</payment_item_detail>""" % xmldict
426                    else:
427                        xmltext += """"
428</item_details>
429</payment_item_detail>"""
430            elif contr_agreement_student(student) == 'second':
431                # Schoolfee without Student Union Fee ands Student Welfare Assurance
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                xmltext = """<payment_item_detail>
438<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
439<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" />
440<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" />
441<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" />
442<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" />
443</item_details>
444</payment_item_detail>""" % xmldict
445            else:
446                xmldict['institution_amt'] = 100 * (
447                    gateway_net_amt(self.context.amount_auth)
448                    - provider_amt)
449                xmltext = """<payment_item_detail>
450<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
451<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" />
452<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" />
453</item_details>
454</payment_item_detail>""" % xmldict
455
456
457        # Clearance
458        elif self.context.p_category.startswith('clearance'):
459            xmldict['institution_acct'] = '1010835352'
460            provider_amt = 0.0
461            if contr_agreement_student(student) == 'first':
462                # First agreement
463                xmldict['institution_acct'] = '1014847058'
464                xmldict['institution_bank_id'] = '7'
465                self.pay_item_id = '104'
466                if student.current_mode == 'found':
467                    self.pay_item_id = '102'
468                elif student.current_mode == 'ijmbe':
469                    self.pay_item_id = '102'
470                    xmldict['institution_bank_id'] = '123'
471                    xmldict['institution_acct'] = '1012278272'
472            else:
473                # Second agreement
474                self.pay_item_id = '102'
475                if student.is_postgrad:
476                    self.pay_item_id = '110'
477                    xmldict['institution_acct'] = '5210006575'
478                    xmldict['institution_bank_id'] = '51'
479                # ivama: Acceptance fee split is unique to "ug_ft"
480                # The reason for split is perculiar to them only...
481                # That amount was deducted from UTME application fee because
482                # some regulatory body have pegged the application fee which
483                # didn't affect another programmes.
484                if student.current_mode == 'ug_ft':
485                    provider_amt = 1500.0
486            xmldict['provider_amt'] = 100 * provider_amt
487            if self.context.p_category.endswith('_incl'):
488                # Clearance including additional fees
489                gown_fee_amt = gateway_net_amt(academic_session.matric_gown_fee)
490                aaue_lf_fee_amt = gateway_net_amt(academic_session.lapel_fee)
491                xmldict['gown_fee_amt'] = 100 * gown_fee_amt
492                xmldict['aaue_lf_fee_amt'] = 100 * aaue_lf_fee_amt
493                xmldict['institution_amt'] = 100 * (
494                    gateway_net_amt(self.context.amount_auth)
495                    - gown_fee_amt
496                    - aaue_lf_fee_amt
497                    - provider_amt)
498                xmltext = """<payment_item_detail>
499<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
500<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" />
501<item_detail item_id="2" item_name="Matriculation Gown Fee" item_amt="%(gown_fee_amt)d" bank_id="117" acct_num=" 1010835352" />
502<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
503                if provider_amt:
504                    xmltext += """"
505<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" />
506</item_details>
507</payment_item_detail>""" % xmldict
508                else:
509                    xmltext += """"
510</item_details>
511</payment_item_detail>"""
512
513            elif student.current_mode == 'bridge':
514                # Clearance without any surcharge
515                xmldict['institution_amt'] = 100 * gateway_net_amt(
516                    self.context.amount_auth)
517                xmltext = """<payment_item_detail>
518<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
519<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" />
520</item_details>
521</payment_item_detail>""" % xmldict
522
523            else:
524                # Clearance without additional fees
525                xmldict['institution_amt'] = 100 * (
526                    gateway_net_amt(self.context.amount_auth)
527                    - provider_amt)
528                xmltext = """<payment_item_detail>
529<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
530<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
531                if provider_amt:
532                        xmltext += """"
533<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" />
534</item_details>
535</payment_item_detail>""" % xmldict
536                else:
537                        xmltext += """"
538</item_details>
539</payment_item_detail>"""
540
541        # Union Dues
542        elif self.context.p_category == 'union':
543            self.pay_item_id = '103'
544            xmldict['institution_amt'] = 100 * (
545                gateway_net_amt(self.context.amount_auth))
546            if contr_agreement_student(student) == 'first':
547                # First agreement
548                xmldict['institution_acct'] = '0051005007'
549                xmldict['institution_bank_id'] = '31'
550            else:
551                # Second agreement
552                xmldict['institution_bank_id'] = '7'
553                xmldict['institution_acct'] = '1019763348'
554
555        # Lapel/File
556        elif self.context.p_category == 'lapel':
557            self.pay_item_id = '104'
558            xmldict['institution_amt'] = 100 * (
559                gateway_net_amt(self.context.amount_auth))
560
561        # Welfare Assurance
562        elif self.context.p_category == 'welfare':
563            self.pay_item_id = '105'
564            xmldict['institution_acct'] = '1006407792'
565            xmldict['institution_bank_id'] = '123'
566            xmldict['institution_amt'] = 100 * (
567                gateway_net_amt(self.context.amount_auth))
568
569        # ID Card
570        elif self.context.p_category == 'id_card':
571            self.pay_item_id = '000'
572            xmldict['institution_amt'] = 100 * (
573                gateway_net_amt(self.context.amount_auth))
574
575        # Matric Gown
576        elif self.context.p_category == 'matric_gown':
577            self.pay_item_id = '106'
578            xmldict['institution_amt'] = 100 * (
579                gateway_net_amt(self.context.amount_auth))
580
581        # Concessional
582        elif self.context.p_category == 'concessional':
583            self.pay_item_id = '107'
584            xmldict['institution_amt'] = 100 * (
585                gateway_net_amt(self.context.amount_auth))
586
587        # Hostel Maintenance
588        elif self.context.p_category == 'hostel_maintenance':
589            provider_amt = 500.0
590            self.pay_item_id = '109'
591            xmldict['institution_acct'] = '1006406795'
592            xmldict['institution_bank_id'] = '123'
593            xmldict['provider_amt'] = 100 * provider_amt
594            xmldict['institution_amt'] = 100 * (
595                gateway_net_amt(self.context.amount_auth) - provider_amt)
596            xmltext = """<payment_item_detail>
597<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
598<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" />
599<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" />
600</item_details>
601</payment_item_detail>""" % xmldict
602
603        # GST Fees
604        elif self.context.p_category.startswith('gst_'):
605            if contr_agreement_student(student) == 'first':
606                self.pay_item_id = '115'
607            else:
608                self.pay_item_id = '116'
609            xmldict['institution_acct'] = '1010893123'
610            xmldict['institution_bank_id'] = '117'
611            xmldict['institution_amt'] = 100 * (
612                gateway_net_amt(self.context.amount_auth))
613
614        # ENT Fees
615        elif self.context.p_category.startswith('ent_'):
616            if contr_agreement_student(student) == 'first':
617                self.pay_item_id = '114'
618            else:
619                self.pay_item_id = '118'
620            xmldict['institution_acct'] = '6220029828'
621            xmldict['institution_bank_id'] = '51'
622            xmldict['institution_amt'] = 100 * (
623                gateway_net_amt(self.context.amount_auth))
624
625        # Faculty and Departmental Dues
626        elif self.context.p_category == 'fac_dep':
627            xmldict['institution_acct'] = '1016425386'
628            xmldict['institution_bank_id'] = '117'
629            self.pay_item_id = '117'
630            xmldict['institution_amt'] = 100 * (
631                gateway_net_amt(self.context.amount_auth))
632
633        # Restitution Fee
634        elif self.context.p_category == 'restitution':
635            self.pay_item_id = '117'
636            xmldict['institution_amt'] = 100 * (
637                gateway_net_amt(self.context.amount_auth))
638
639        # Faculty Laboratory Due
640        elif self.context.p_category in ('lab_1', 'lab_2'):
641            xmldict['institution_acct'] = '1016425386'
642            xmldict['institution_bank_id'] = '117'
643            self.pay_item_id = '117'
644            xmldict['institution_amt'] = 100 * (
645                gateway_net_amt(self.context.amount_auth))
646
647        # Sports Fee
648        #elif self.context.p_category == 'sports':
649        #    self.pay_item_id = '105'
650        #    xmldict['institution_amt'] = 100 * (
651        #        gateway_net_amt(self.context.amount_auth))
652
653        # Library Fee
654        #elif self.context.p_category == 'library':
655        #    self.pay_item_id = '105'
656        #    xmldict['institution_amt'] = 100 * (
657        #        gateway_net_amt(self.context.amount_auth))
658
659        # Library PG Fee
660        #elif self.context.p_category == 'library_pg':
661        #    self.pay_item_id = '105'
662        #    xmldict['institution_amt'] = 100 * (
663        #        gateway_net_amt(self.context.amount_auth))
664
665        # Sports & Library Fee    temporarily in 2020
666        elif self.context.p_category == 'sports_library':
667            self.pay_item_id = '105'
668            xmldict['sports_amt'] = 100 * 3000.0
669            xmldict['library_amt'] = 100 * 1000.0
670            xmltext = """<payment_item_detail>
671<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
672<item_detail item_id="1" item_name="Sports Development Fee" item_amt="%(sports_amt)d" bank_id="123" acct_num="1006407792" />
673<item_detail item_id="2" item_name="Library Development Fee" item_amt="%(library_amt)d" bank_id="8" acct_num="2000122995" />
674</item_details>
675</payment_item_detail>""" % xmldict
676
677        # Late Registration Fee
678        elif self.context.p_category == 'late_registration':
679            if contr_agreement_student(student) == 'first':
680                self.pay_item_id = '113'
681            else:
682                self.pay_item_id = '123'
683            xmldict['institution_amt'] = 100 * (
684                gateway_net_amt(self.context.amount_auth))
685            if student.is_postgrad:
686                xmldict['institution_acct'] = '5210006575'
687                xmldict['institution_bank_id'] = '51'
688        if not xmltext:
689            xmltext = """<payment_item_detail>
690<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
691<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" />
692</item_details>
693</payment_item_detail>""" % xmldict
694        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
695        self.context.provider_amt = provider_amt
696        self.context.gateway_amt = self.context.amount_auth - gateway_net_amt(
697            self.context.amount_auth)
698        xmlitems = ''
699        xmldoc = minidom.parseString(xmltext)
700        itemlist = xmldoc.getElementsByTagName('item_detail')
701        for s in itemlist:
702            xmlitems += "%s: %s, N%s, %s (%s)  " % (
703                s.attributes['item_id'].value,
704                s.attributes['item_name'].value,
705                int(s.attributes['item_amt'].value)/100,
706                s.attributes['acct_num'].value,
707                s.attributes['bank_id'].value,
708                )
709        self.context.p_split_data = xmlitems
710        self.amount_auth = int(100 * self.context.amount_auth)
711        hashargs = (
712            self.context.p_id +
713            self.product_id +
714            self.pay_item_id +
715            str(int(self.amount_auth)) +
716            self.site_redirect_url +
717            self.mac)
718        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
719        return
720
721
722class CustomInterswitchPaymentRequestWebservicePageApplicant(
723    InterswitchPaymentRequestWebservicePageApplicant):
724    """Request webservice view for the CollegePAY gateway
725    """
726    grok.context(ICustomApplicantOnlinePayment)
727    gateway_host = HOST
728    gateway_url = URL
729    https = HTTPS
730
731    @property
732    def mac(self):
733        if contr_agreement_applicant(self.context.__parent__) == 'first':
734            return MAC_PT
735        return MAC_REGULAR
736
737    @property
738    def product_id(self):
739        if contr_agreement_applicant(self.context.__parent__) == 'first':
740            return PRODUCT_ID_PT
741        return PRODUCT_ID_REGULAR
742
743class CustomInterswitchPaymentVerifyWebservicePageApplicant(
744    InterswitchPaymentVerifyWebservicePageApplicant):
745    """Payment verify view for the CollegePAY gateway
746    """
747    grok.context(ICustomApplicantOnlinePayment)
748    gateway_host = HOST
749    gateway_url = URL
750    https = HTTPS
751
752    @property
753    def mac(self):
754        if contr_agreement_applicant(self.context.__parent__) == 'first':
755            return MAC_PT
756        return MAC_REGULAR
757
758    @property
759    def product_id(self):
760        if contr_agreement_applicant(self.context.__parent__) == 'first':
761            return PRODUCT_ID_PT
762        return PRODUCT_ID_REGULAR
763
764class CustomInterswitchPaymentRequestWebservicePageStudent(
765    InterswitchPaymentRequestWebservicePageStudent):
766    """Request webservice view for the CollegePAY gateway
767    """
768    grok.context(ICustomStudentOnlinePayment)
769    gateway_host = HOST
770    gateway_url = URL
771    https = HTTPS
772
773    @property
774    def mac(self):
775        if contr_agreement_student(self.context.student) == 'first':
776            return MAC_PT
777        return MAC_REGULAR
778
779    @property
780    def product_id(self):
781        if contr_agreement_student(self.context.student) == 'first':
782            return PRODUCT_ID_PT
783        return PRODUCT_ID_REGULAR
784
785class CustomInterswitchPaymentVerifyWebservicePageStudent(
786    InterswitchPaymentVerifyWebservicePageStudent):
787    """Payment verify view for the CollegePAY gateway
788    """
789    grok.context(ICustomStudentOnlinePayment)
790    gateway_host = HOST
791    gateway_url = URL
792    https = HTTPS
793
794    @property
795    def mac(self):
796        if contr_agreement_student(self.context.student) == 'first':
797            return MAC_PT
798        return MAC_REGULAR
799
800    @property
801    def product_id(self):
802        if contr_agreement_student(self.context.student) == 'first':
803            return PRODUCT_ID_PT
804        return PRODUCT_ID_REGULAR
Note: See TracBrowser for help on using the repository browser.