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

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

Configure bridge school fee split payment.

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