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

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

Change WAEAC bank account.

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