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

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

There is no technology charges in 2nd installment.

  • Property svn:keywords set to Id
File size: 32.1 KB
Line 
1## $Id: browser.py 15475 2019-06-24 15:10:52Z 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 = '1014261520'
40PROVIDER_BANK_ID = '117'
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                if self.context.p_category != 'schoolfee_2':
256                    provider_amt = 1900.0
257                joint_venture_amt = 0.0
258                aaue_share_amt = 0.0
259                student_union_due_amt = gateway_net_amt(
260                    academic_session.union_fee)
261                student_welfare_assurance_amt = gateway_net_amt(
262                    academic_session.welfare_fee)
263                sports_amt = gateway_net_amt(
264                    academic_session.sports_fee)
265                library_amt = gateway_net_amt(
266                    academic_session.library_fee)
267                library_amt_pg = gateway_net_amt(
268                    academic_session.library_fee_pg)
269                xmldict['student_union_bank_id'] = '31'
270                xmldict['student_union_acct'] = '0051005007'
271                xmldict['aaue_share_bank_id'] = '117'
272                xmldict['aaue_share_acct'] = '1010827641'
273                xmldict['joint_venture_bank_id'] = '117'
274                xmldict['joint_venture_acct'] = '1010827641'
275                xmldict['institution_acct'] = '1014847058'
276                xmldict['institution_bank_id'] = '7'
277                if student.current_mode == 'found':
278                    self.pay_item_id = '103'
279                else:
280                    self.pay_item_id = '105'
281            else:
282                # Second agreement
283                joint_venture_amt = 1000.0
284                aaue_share_amt = 1500.0
285                if  self.context.p_category != 'schoolfee_2':
286                    provider_amt = 1500.0
287                student_union_due_amt = gateway_net_amt(
288                    academic_session.union_fee)
289                student_welfare_assurance_amt = gateway_net_amt(
290                    academic_session.welfare_fee)
291                sports_amt = gateway_net_amt(
292                    academic_session.sports_fee)
293                library_amt = gateway_net_amt(
294                    academic_session.library_fee)
295                library_amt_pg = gateway_net_amt(
296                    academic_session.library_fee_pg)
297                xmldict['student_union_bank_id'] = '7'
298                xmldict['student_union_acct'] = '1019763348'
299                xmldict['aaue_share_bank_id'] = '117'
300                xmldict['aaue_share_acct'] = '1010827641'
301                xmldict['joint_venture_bank_id'] = '117'
302                xmldict['joint_venture_acct'] = '1010827641'
303                self.pay_item_id = '107'
304                if student.is_postgrad:
305                    self.pay_item_id = '111'
306                    xmldict['institution_acct'] = '5210006575'
307                    xmldict['institution_bank_id'] = '51'
308                if student.current_mode == 'ijmbe':
309                    self.pay_item_id = '119'
310                    xmldict['joint_venture_bank_id'] = '117'
311                    xmldict['joint_venture_acct'] = '1010827641'
312
313            xmldict['provider_amt'] = 100 * provider_amt
314            xmldict['joint_venture_amt'] = 100 * joint_venture_amt
315            xmldict['aaue_share_amt'] = 100 * aaue_share_amt
316            if self.context.p_item == 'Balance':
317                xmldict['institution_amt'] = 100 * (
318                    gateway_net_amt(self.context.amount_auth))
319            elif self.context.p_category in ('schoolfee_incl', 'schoolfee_1') \
320                and student.current_mode != 'ijmbe':
321                # Schoolfee including additional fees
322                xmldict['student_union_due_amt'] = 100 * student_union_due_amt
323                xmldict['student_welfare_assurance_amt'] = 100 * student_welfare_assurance_amt
324
325                if student.entry_session == 2018 and student.is_fresh:
326                    xmldict['sports_amt'] = 100 * sports_amt
327                    if student.is_postgrad:
328                        xmldict['library_amt'] = 100 * library_amt_pg
329                    else:
330                        xmldict['library_amt'] = 100 * library_amt
331                    xmldict['institution_amt'] = 100 * (
332                        gateway_net_amt(self.context.amount_auth)
333                        - provider_amt
334                        - joint_venture_amt
335                        - aaue_share_amt
336                        - student_union_due_amt
337                        - student_welfare_assurance_amt
338                        - sports_amt
339                        - library_amt)
340                    xmltext = """<payment_item_detail>
341<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
342<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" />
343<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" />
344<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" />
345<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />
346<item_detail item_id="5" item_name="Sports Development Fee" item_amt="%(sports_amt)d" bank_id="123" acct_num="1006407792" />
347<item_detail item_id="6" item_name="Library Development Fee" item_amt="%(library_amt)d" bank_id="8" acct_num="2000122995" />""" % xmldict
348                    if contr_agreement_student(student) == 'second':
349                        xmltext += """"
350<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" />
351<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" />
352</item_details>
353</payment_item_detail>""" % xmldict
354                    else:
355                        xmltext += """"
356</item_details>
357</payment_item_detail>"""
358                else:
359                    xmldict['institution_amt'] = 100 * (
360                        gateway_net_amt(self.context.amount_auth)
361                        - provider_amt
362                        - joint_venture_amt
363                        - aaue_share_amt
364                        - student_union_due_amt
365                        - student_welfare_assurance_amt)
366                    xmltext = """<payment_item_detail>
367<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
368<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" />
369<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" />
370<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" />
371<item_detail item_id="4" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="123" acct_num="1006407792" />""" % xmldict
372                    if contr_agreement_student(student) == 'second':
373                        xmltext += """"
374<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" />
375<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" />
376</item_details>
377</payment_item_detail>""" % xmldict
378                    else:
379                        xmltext += """"
380</item_details>
381</payment_item_detail>"""
382            elif contr_agreement_student(student) == 'second':
383                # Schoolfee without Student Union Fee ands Student Welfare Assurance
384                xmldict['institution_amt'] = 100 * (
385                    gateway_net_amt(self.context.amount_auth)
386                    - provider_amt
387                    - joint_venture_amt
388                    - aaue_share_amt)
389                xmltext = """<payment_item_detail>
390<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
391<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" />
392<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" />
393<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" />
394<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" />
395</item_details>
396</payment_item_detail>""" % xmldict
397            else:
398                xmldict['institution_amt'] = 100 * (
399                    gateway_net_amt(self.context.amount_auth)
400                    - provider_amt)
401                xmltext = """<payment_item_detail>
402<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
403<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" />
404<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" />
405</item_details>
406</payment_item_detail>""" % xmldict
407
408
409        # Clearance
410        elif self.context.p_category.startswith('clearance'):
411            provider_amt = 0.0
412            if contr_agreement_student(student) == 'first':
413                # First agreement
414                if student.current_mode == 'found':
415                    self.pay_item_id = '102'
416                else:
417                    self.pay_item_id = '104'
418                xmldict['institution_acct'] = '1014847058'
419                xmldict['institution_bank_id'] = '7'
420            else:
421                # Second agreement
422                self.pay_item_id = '102'
423                if student.is_postgrad:
424                    self.pay_item_id = '110'
425                    xmldict['institution_acct'] = '5210006575'
426                    xmldict['institution_bank_id'] = '51'
427                if student.current_mode == 'ijmbe':
428                    self.pay_item_id = '120'
429                # ivama: Acceptance fee split is unique to "ug_ft"
430                # The reason for split is perculiar to them only...
431                # That amount was deducted from UTME application fee because
432                # some regulatory body have pegged the application fee which
433                # didn't affect another programmes.
434                if student.current_mode == 'ug_ft':
435                    provider_amt = 1500.0
436            xmldict['provider_amt'] = 100 * provider_amt
437            if self.context.p_category.endswith('_incl'):
438                # Clearance including additional fees
439                gown_fee_amt = gateway_net_amt(academic_session.matric_gown_fee)
440                aaue_lf_fee_amt = gateway_net_amt(academic_session.lapel_fee)
441                xmldict['gown_fee_amt'] = 100 * gown_fee_amt
442                xmldict['aaue_lf_fee_amt'] = 100 * aaue_lf_fee_amt
443                xmldict['institution_amt'] = 100 * (
444                    gateway_net_amt(self.context.amount_auth)
445                    - gown_fee_amt
446                    - aaue_lf_fee_amt
447                    - provider_amt)
448                xmltext = """<payment_item_detail>
449<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
450<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" />
451<item_detail item_id="2" item_name="Matriculation Gown Fee" item_amt="%(gown_fee_amt)d" bank_id="117" acct_num="1010827641" />
452<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
453                if provider_amt:
454                    xmltext += """"
455<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" />
456</item_details>
457</payment_item_detail>""" % xmldict
458                else:
459                    xmltext += """"
460</item_details>
461</payment_item_detail>"""
462
463            elif student.current_mode == 'bridge':
464                # Clearance without any surcharge
465                xmldict['institution_amt'] = 100 * gateway_net_amt(
466                    self.context.amount_auth)
467                xmltext = """<payment_item_detail>
468<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
469<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" />
470</item_details>
471</payment_item_detail>""" % xmldict
472
473            else:
474                # Clearance without additional fees
475                xmldict['institution_amt'] = 100 * (
476                    gateway_net_amt(self.context.amount_auth)
477                    - provider_amt)
478                xmltext = """<payment_item_detail>
479<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
480<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
481                if provider_amt:
482                        xmltext += """"
483<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" />
484</item_details>
485</payment_item_detail>""" % xmldict
486                else:
487                        xmltext += """"
488</item_details>
489</payment_item_detail>"""
490
491        # Union Dues
492        elif self.context.p_category == 'union':
493            self.pay_item_id = '103'
494            xmldict['institution_amt'] = 100 * (
495                gateway_net_amt(self.context.amount_auth))
496            if contr_agreement_student(student) == 'first':
497                # First agreement
498                xmldict['institution_acct'] = '0051005007'
499                xmldict['institution_bank_id'] = '31'
500            else:
501                # Second agreement
502                xmldict['institution_bank_id'] = '7'
503                xmldict['institution_acct'] = '1019763348'
504
505        # Lapel/File
506        elif self.context.p_category == 'lapel':
507            self.pay_item_id = '104'
508            xmldict['institution_amt'] = 100 * (
509                gateway_net_amt(self.context.amount_auth))
510
511        # Welfare Assurance
512        elif self.context.p_category == 'welfare':
513            self.pay_item_id = '105'
514            xmldict['institution_acct'] = '1006407792'
515            xmldict['institution_bank_id'] = '123'
516            xmldict['institution_amt'] = 100 * (
517                gateway_net_amt(self.context.amount_auth))
518
519        # ID Card
520        elif self.context.p_category == 'id_card':
521            self.pay_item_id = '000'
522            xmldict['institution_amt'] = 100 * (
523                gateway_net_amt(self.context.amount_auth))
524
525        # Matric Gown
526        elif self.context.p_category == 'matric_gown':
527            self.pay_item_id = '106'
528            xmldict['institution_amt'] = 100 * (
529                gateway_net_amt(self.context.amount_auth))
530
531        # Concessional
532        elif self.context.p_category == 'concessional':
533            self.pay_item_id = '107'
534            xmldict['institution_amt'] = 100 * (
535                gateway_net_amt(self.context.amount_auth))
536
537        # Hostel Maintenance
538        elif self.context.p_category == 'hostel_maintenance':
539            provider_amt = 500.0
540            self.pay_item_id = '109'
541            xmldict['provider_amt'] = 100 * provider_amt
542            xmldict['institution_amt'] = 100 * (
543                gateway_net_amt(self.context.amount_auth) - provider_amt)
544            xmltext = """<payment_item_detail>
545<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
546<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" />
547<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" />
548</item_details>
549</payment_item_detail>""" % xmldict
550
551        # GST Fees
552        elif self.context.p_category.startswith('gst_'):
553            if contr_agreement_student(student) == 'first':
554                self.pay_item_id = '115'
555            else:
556                self.pay_item_id = '116'
557            xmldict['institution_acct'] = '1010893123'
558            xmldict['institution_bank_id'] = '117'
559            xmldict['institution_amt'] = 100 * (
560                gateway_net_amt(self.context.amount_auth))
561
562        # ENT Fees
563        elif self.context.p_category.startswith('ent_'):
564            if contr_agreement_student(student) == 'first':
565                self.pay_item_id = '114'
566            else:
567                self.pay_item_id = '118'
568            xmldict['institution_acct'] = '6220029828'
569            xmldict['institution_bank_id'] = '51'
570            xmldict['institution_amt'] = 100 * (
571                gateway_net_amt(self.context.amount_auth))
572
573        # Faculty and Departmental Dues
574        elif self.context.p_category == 'fac_dep':
575            self.pay_item_id = '117'
576            xmldict['institution_amt'] = 100 * (
577                gateway_net_amt(self.context.amount_auth))
578
579        # Restitution Fee
580        elif self.context.p_category == 'restitution':
581            self.pay_item_id = '117'
582            xmldict['institution_amt'] = 100 * (
583                gateway_net_amt(self.context.amount_auth))
584
585        # Late Registration Fee
586        elif self.context.p_category == 'late_registration':
587            if contr_agreement_student(student) == 'first':
588                self.pay_item_id = '113'
589            else:
590                self.pay_item_id = '123'
591            xmldict['institution_amt'] = 100 * (
592                gateway_net_amt(self.context.amount_auth))
593            if student.is_postgrad:
594                xmldict['institution_acct'] = '5210006575'
595                xmldict['institution_bank_id'] = '51'
596        if not xmltext:
597            xmltext = """<payment_item_detail>
598<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
599<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" />
600</item_details>
601</payment_item_detail>""" % xmldict
602        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
603        self.context.provider_amt = provider_amt
604        self.context.gateway_amt = self.amount_auth - gateway_net_amt(
605            self.amount_auth)
606        xmlitems = ''
607        xmldoc = minidom.parseString(xmltext)
608        itemlist = xmldoc.getElementsByTagName('item_detail')
609        for s in itemlist:
610            xmlitems += "%s: %s, N%s, %s (%s)  " % (
611                s.attributes['item_id'].value,
612                s.attributes['item_name'].value,
613                int(s.attributes['item_amt'].value)/100,
614                s.attributes['acct_num'].value,
615                s.attributes['bank_id'].value,
616                )
617        self.context.p_split_data = xmlitems
618        hashargs = (
619            self.context.p_id +
620            self.product_id +
621            self.pay_item_id +
622            str(int(self.amount_auth)) +
623            self.site_redirect_url +
624            self.mac)
625        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
626        return
627
628
629class CustomInterswitchPaymentRequestWebservicePageApplicant(
630    InterswitchPaymentRequestWebservicePageApplicant):
631    """Request webservice view for the CollegePAY gateway
632    """
633    grok.context(ICustomApplicantOnlinePayment)
634    gateway_host = HOST
635    gateway_url = URL
636    https = HTTPS
637
638    @property
639    def mac(self):
640        if contr_agreement_applicant(self.context.__parent__) == 'first':
641            return MAC_PT
642        return MAC_REGULAR
643
644    @property
645    def product_id(self):
646        if contr_agreement_applicant(self.context.__parent__) == 'first':
647            return PRODUCT_ID_PT
648        return PRODUCT_ID_REGULAR
649
650class CustomInterswitchPaymentVerifyWebservicePageApplicant(
651    InterswitchPaymentVerifyWebservicePageApplicant):
652    """Payment verify view for the CollegePAY gateway
653    """
654    grok.context(ICustomApplicantOnlinePayment)
655    gateway_host = HOST
656    gateway_url = URL
657    https = HTTPS
658
659    @property
660    def mac(self):
661        if contr_agreement_applicant(self.context.__parent__) == 'first':
662            return MAC_PT
663        return MAC_REGULAR
664
665    @property
666    def product_id(self):
667        if contr_agreement_applicant(self.context.__parent__) == 'first':
668            return PRODUCT_ID_PT
669        return PRODUCT_ID_REGULAR
670
671class CustomInterswitchPaymentRequestWebservicePageStudent(
672    InterswitchPaymentRequestWebservicePageStudent):
673    """Request webservice view for the CollegePAY gateway
674    """
675    grok.context(ICustomStudentOnlinePayment)
676    gateway_host = HOST
677    gateway_url = URL
678    https = HTTPS
679
680    @property
681    def mac(self):
682        if contr_agreement_student(self.context.student) == 'first':
683            return MAC_PT
684        return MAC_REGULAR
685
686    @property
687    def product_id(self):
688        if contr_agreement_student(self.context.student) == 'first':
689            return PRODUCT_ID_PT
690        return PRODUCT_ID_REGULAR
691
692class CustomInterswitchPaymentVerifyWebservicePageStudent(
693    InterswitchPaymentVerifyWebservicePageStudent):
694    """Payment verify view for the CollegePAY gateway
695    """
696    grok.context(ICustomStudentOnlinePayment)
697    gateway_host = HOST
698    gateway_url = URL
699    https = HTTPS
700
701    @property
702    def mac(self):
703        if contr_agreement_student(self.context.student) == 'first':
704            return MAC_PT
705        return MAC_REGULAR
706
707    @property
708    def product_id(self):
709        if contr_agreement_student(self.context.student) == 'first':
710            return PRODUCT_ID_PT
711        return PRODUCT_ID_REGULAR
Note: See TracBrowser for help on using the repository browser.