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

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

Fix xml record. Add ijmbe to first agreement.

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