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

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

Adjust to nigeria package.

Disable FecEx? fee.

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