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

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

WAeAC does not have share in 1st agreement acceptance.

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