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

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

Consider FedEx? fee.

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