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

Last change on this file since 15468 was 15467, checked in by Henrik Bettermann, 6 years ago

ivama: acceptance fee split is unique to "ug_ft"
The reason for split is perculiar to them only... That amount was deducted from UTME application fee because some regulatory body have pegged the application fee which didn't affect another programmes.

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