source: main/kofacustom.dspg/trunk/src/kofacustom/dspg/interswitch/browser.py @ 16752

Last change on this file since 16752 was 16750, checked in by Henrik Bettermann, 3 years ago

Configure split payment for hostel maintenance fee.

  • Property svn:keywords set to Id
File size: 41.4 KB
Line 
1## $Id: browser.py 16750 2022-01-17 19:55:44Z 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 waeup.kofa.interfaces import CLEARED, RETURNING
22from kofacustom.nigeria.interswitch.browser import (
23    InterswitchPaymentRequestWebservicePageApplicant,
24    InterswitchPaymentRequestWebservicePageStudent,
25    InterswitchPaymentVerifyWebservicePageApplicant,
26    InterswitchPaymentVerifyWebservicePageStudent,
27    InterswitchPageStudent, InterswitchPageApplicant,
28    )
29from kofacustom.dspg.students.interfaces import ICustomStudentOnlinePayment
30from kofacustom.dspg.applicants.interfaces import ICustomApplicantOnlinePayment
31from kofacustom.dspg.interfaces import MessageFactory as _
32from kofacustom.dspg.students.utils import MICROSOFT_FEE
33
34PRODUCT_ID = '7269' # must be provided by Interswitch
35SITE_NAME = 'dspg.waeup.org'
36PROVIDER_ACCT = '2028964403'
37PROVIDER_BANK_ID = '8'
38PROVIDER_ITEM_NAME = 'WAEAC'
39INSTITUTION_NAME = 'Delta State Polytechnic Ogwashi-Uku'
40CURRENCY = '566'
41GATEWAY_AMT = 250.0
42MAC = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627'
43
44POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
45#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
46HOST = 'webpay.interswitchng.com'
47#HOST = 'sandbox.interswitchng.com'
48URL = '/paydirect/api/v1/gettransaction.json'
49#URL = '/webpay/api/v1/gettransaction.json'
50
51httplib.HTTPSConnection.debuglevel = 0
52HTTPS = True
53
54SPECIAL_PAYMENT_PARAMS = {
55
56    'carryover1': ('101', 500.0, '1015220292', '117'),
57    'carryover4': ('101', 500.0, '1015220292', '117'),
58    'carryover5': ('101', 500.0, '1015220292', '117'),
59    'carryover6': ('101', 500.0, '1015220292', '117'),
60    'carryover7': ('101', 500.0, '1015220292', '117'),
61    'carryover8': ('101', 500.0, '1015220292', '117'),
62    'carryover9': ('101', 500.0, '1015220292', '117'),
63    'carryover10': ('101', 500.0, '1015220292', '117'),
64    'carryover11': ('101', 500.0, '1015220292', '117'),
65    'carryover12': ('101', 500.0, '1015220292', '117'),
66    'balance': ('101', 500.0, '1015220292', '117'),
67
68    'certificate': ('111', 500.0, '1012808851', '117'),
69    'state_result': ('112', 500.0, '1012808851', '117'),
70    'transcript_local': ('113', 500.0, '1012808851', '117'),
71    'transcript_foreign': ('114', 500.0, '1012808851', '117'),
72    'ver_result': ('115', 500.0, '1012808851', '117'),
73    'change_course': ('116', 500.0, '1012808851', '117'),
74    'change_inst': ('117', 500.0, '1012808851', '117'),
75    'jamb_reject': ('118', 500.0, '1012808851', '117'),
76    'cert_of_cert': ('119', 500.0, '1012808851', '117'),
77    'ref_let': ('120', 500.0, '1012808851', '117'),
78    'proc_cert': ('121', 500.0, '1012808851', '117'),
79    'loss_idcard': ('122', 9.0, '1012808851', '117'),
80    'loss_examcard': ('123', 4.5, '1012808851', '117'),
81    'loss_result': ('124', 500.0, '1012808851', '117'),
82    'loss_receipt': ('125', 500.0, '1012808851', '117'),
83    'loss_clearance': ('126', 500.0, '1012808851', '117'),
84    'conv_brochure': ('127', 500.0, '1012808851', '117'),
85    'hnd_certificate': ('128', 500.0, '1012808851', '117'),
86    'hnd_state_result': ('129', 500.0, '1012808851', '117'),
87    'hnd_transcript_local': ('130', 500.0, '1012808851', '117'),
88    'hnd_transcript_foreign': ('131', 500.0, '1012808851', '117'),
89    'staff_loss_idcard': ('132', 9.0, '1012808851', '117'),
90    'hnd_conv_brochure': ('133', 500.0, '1012808851', '117'),
91    'pgd_state_result': ('134', 500.0, '1012808851', '117'),
92    'pgd_conv_brochure': ('135', 500.0, '1012808851', '117'),
93    'pgd_certificate': ('136', 500.0, '1012808851', '117'),
94    'log_book': ('137', 4.5, '1012808851', '117'),
95    'pgd_transcript_foreign': ('138', 500.0, '1012808851', '117'),
96    'pgd_transcript_local': ('139', 500.0, '1012808851', '117'),
97    'jamb_regularization': ('140', 500.0, '1012808851', '117'),
98    'utme_registration': ('142', 9.0, '1012808851', '117'),
99    'utme_cbt': ('143', 9.0, '1012808851', '117'),
100    'nysc_id_card': ('144', 9.0, '1012808851', '117'),
101    'ijmb_result': ('147', 500.0, '1012808851', '117'),
102    'conv': ('151', 500.0, '1012808851', '117'),
103    }
104
105
106# Not yet readily configured. Bank account numbers are
107# contradictory. pay_item_ids are not yet assigned.
108
109class CustomInterswitchPageStudent(InterswitchPageStudent):
110    """ View which sends a POST request to the Interswitch
111    CollegePAY payment gateway.
112    """
113    grok.context(ICustomStudentOnlinePayment)
114    action = POST_ACTION
115    site_name = SITE_NAME
116    currency = CURRENCY
117    product_id = PRODUCT_ID
118    mac = MAC
119    pay_item_id = '000'
120
121    def update(self):
122        error = self.init_update()
123        if error:
124            self.flash(error, type='danger')
125            self.redirect(self.url(self.context, '@@index'))
126            return
127        self.context.r_company = u'interswitch'
128        student = self.student
129        xmldict = self.xmldict
130        # Provider data
131        xmldict['detail_ref'] = self.context.p_id
132        xmldict['provider_acct'] = PROVIDER_ACCT
133        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
134        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
135        # Institution data
136        xmldict['institution_acct'] = '00000000'
137        xmldict['institution_bank_id'] = '00'
138        xmldict['institution_amt'] = '0.0'
139        provider_amt = 0.0
140        tech_fee = 0.0
141        microsoft_fee = 0.0
142        if self.context.p_category.startswith('schoolfee'):
143            self.pay_item_id = '102'
144            if self.context.p_item != 'Balance':
145                provider_amt = 2800.0
146                tech_fee = 1200.0
147                if student.state == RETURNING:
148                    microsoft_fee = MICROSOFT_FEE
149            if student.faccode == 'SPAT':
150                xmldict['institution_acct'] = '1556004203'
151                xmldict['institution_bank_id'] = '388'
152            elif student.current_mode in ('nd_ft', 'hnd_ft'):
153                xmldict['institution_acct'] = '2004145840'
154                xmldict['institution_bank_id'] = '8'
155        elif self.context.p_category == 'clearance':
156            self.pay_item_id = '103'
157            if self.context.p_item != 'Balance':
158                provider_amt = 500.0
159            if student.faccode == 'SPAT':
160                xmldict['institution_acct'] = '1015220292'
161                xmldict['institution_bank_id'] = '117'
162            elif student.current_mode in ('nd_ft', 'hnd_ft'):
163                xmldict['institution_acct'] = '0072223654'
164                xmldict['institution_bank_id'] = '121'
165        elif self.context.p_category == 'gown':
166            self.pay_item_id = '102' # We use school fee item id.
167            xmldict['institution_acct'] = '2006612782'
168            xmldict['institution_bank_id'] = '8'
169        elif self.context.p_category == 'sports':
170            self.pay_item_id = '110'
171            xmldict['institution_acct'] = '6060300688'
172            xmldict['institution_bank_id'] = '51'
173        elif self.context.p_category == 'siwes':
174            self.pay_item_id = '111'
175            xmldict['institution_acct'] = '0080527351'
176            xmldict['institution_bank_id'] = '11'
177        elif self.context.p_category == 'eed_1':
178            self.pay_item_id = '112'
179            xmldict['institution_acct'] = '0039782431'
180            xmldict['institution_bank_id'] = '11'
181        elif self.context.p_category == 'eed_2':
182            self.pay_item_id = '116'
183            xmldict['institution_acct'] = '0039782431'
184            xmldict['institution_bank_id'] = '11'
185        elif self.context.p_category == 'eed_extra':
186            self.pay_item_id = '157'
187            xmldict['institution_acct'] = '0039782431'
188            xmldict['institution_bank_id'] = '11'
189        elif self.context.p_category == 'olevel_results_1':
190            self.pay_item_id = '113'
191            xmldict['institution_acct'] = '2015327204'
192            xmldict['institution_bank_id'] = '8'
193        elif self.context.p_category == 'olevel_results_2':
194            self.pay_item_id = '115'
195            xmldict['institution_acct'] = '2015327204'
196            xmldict['institution_bank_id'] = '8'
197        elif self.context.p_category == 'gns_1':
198            self.pay_item_id = '154'
199            xmldict['institution_acct'] = '2017447652'
200            xmldict['institution_bank_id'] = '8'
201        elif self.context.p_category == 'gns_2':
202            self.pay_item_id = '155'
203            xmldict['institution_acct'] = '2017447652'
204            xmldict['institution_bank_id'] = '8'
205        #elif self.context.p_category == 'hostel_maintenance':
206        #    if self.context.p_item != 'Balance':
207        #        provider_amt = 500.0
208        #    self.pay_item_id = '117'
209        #    xmldict['institution_acct'] = '1012808851'
210        #    xmldict['institution_bank_id'] = '117'
211        elif self.context.p_category == 'lsfp_penalty':
212            self.pay_item_id = '102'
213            xmldict['institution_acct'] = '1012808851'
214            xmldict['institution_bank_id'] = '117'
215        elif self.context.p_category == 'eng_1':
216            self.pay_item_id = '118'
217            xmldict['institution_acct'] = '2024473077'
218            xmldict['institution_bank_id'] = '8'
219        elif self.context.p_category == 'eng_2':
220            self.pay_item_id = '119'
221            xmldict['institution_acct'] = '2024473077'
222            xmldict['institution_bank_id'] = '8'
223        elif self.context.p_category == 'bfn':
224            self.pay_item_id = '125'
225            xmldict['institution_acct'] = '0048039049'
226            xmldict['institution_bank_id'] = '11'
227        elif self.context.p_category == 'facilities':
228            self.pay_item_id = '156'
229            xmldict['institution_acct'] = '1012808851'
230            xmldict['institution_bank_id'] = '117'
231        elif self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
232            self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
233            provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
234            xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
235            xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
236        xmldict['provider_amt'] = 100 * provider_amt
237        xmldict['tech_fee'] = 100 * tech_fee
238        xmldict['microsoft_fee'] = 100 * microsoft_fee
239        xmldict['institution_item_name'] = self.context.category
240        xmldict['institution_name'] = INSTITUTION_NAME
241        xmldict['institution_amt'] = institution_amt = 100 * (
242            self.context.amount_auth - provider_amt - tech_fee - microsoft_fee - GATEWAY_AMT)
243
244        if provider_amt == 0:
245            xmltext = """<payment_item_detail>
246<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
247<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" />
248</item_details>
249</payment_item_detail>""" % xmldict
250        elif tech_fee == 0:
251            xmltext = """<payment_item_detail>
252<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
253<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" />
254<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" />
255</item_details>
256</payment_item_detail>""" % xmldict
257        elif microsoft_fee == 0:
258            xmltext = """<payment_item_detail>
259<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
260<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" />
261<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" />
262<item_detail item_id="3" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="10" acct_num="0032256360" />
263</item_details>
264</payment_item_detail>""" % xmldict
265        else:
266            xmltext = """<payment_item_detail>
267<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
268<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" />
269<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" />
270<item_detail item_id="3" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="10" acct_num="0032256360" />
271<item_detail item_id="4" item_name="Microsoft Academy Fee" item_amt="%(microsoft_fee)d" bank_id="8" acct_num="2011810360" />
272</item_details>
273</payment_item_detail>""" % xmldict
274
275        # isouaba: All certificates in SPAT are part time thus any payments
276        # coming from those certificates (Application, Acceptance, school fees
277        # etc) 40% should be split to keystone account.
278        # abraham: Please, kindly exclude the 40% going to Keystone bank for school of part-
279        # time (SPAT) O'level Results Verification payment.
280        if student.faccode == 'SPAT' and not self.context.p_category.startswith('olevel_results'):
281            xmldict['institution_amt_2'] = 0.4 * institution_amt
282            xmldict['institution_amt_1'] = 0.6 * institution_amt
283            if provider_amt == 0:
284                xmltext = """<payment_item_detail>
285<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
286<item_detail item_id="1" item_name="%(institution_item_name)s 1" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
287<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="8" acct_num="2034761924" />
288</item_details>
289</payment_item_detail>""" % xmldict
290            elif tech_fee == 0:
291                xmltext = """<payment_item_detail>
292<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
293<item_detail item_id="1" item_name="%(institution_item_name)s 1" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
294<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="8" acct_num="2034761924" />
295<item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
296</item_details>
297</payment_item_detail>""" % xmldict
298            else:
299                xmltext = """<payment_item_detail>
300<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
301<item_detail item_id="1" item_name="%(institution_item_name)s 1" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
302<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="8" acct_num="2034761924" />
303<item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
304<item_detail item_id="4" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="10" acct_num="0032256360" />
305</item_details>
306</payment_item_detail>""" % xmldict
307
308
309        # Some payments are treated completely separately. The following lines
310        # override the configuration above.
311
312        if self.context.p_category == 'dep_sug':
313            self.pay_item_id = '102' # We use school fee item id
314            # amount_auth is being ignored. However, the sum of all split payments
315            # must coincide with the amount_auth configured in students/utils.py
316            xmldict['amt1'] = 100 * 1000
317            xmldict['amt2'] = 100 * 500
318            xmldict['amt3'] = 100 * 900
319            xmldict['amt4'] = 100 * 500
320
321            xmltext = """<payment_item_detail>
322<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
323<item_detail item_id="1" item_name="SUG" item_amt="%(amt1)d" bank_id="11" acct_num="0038079930" />
324<item_detail item_id="2" item_name="Students Welfare" item_amt="%(amt2)d" bank_id="11" acct_num="0037892949" />
325<item_detail item_id="3" item_name="Anti-Cult Book" item_amt="%(amt3)d" bank_id="11" acct_num="0037892949" />
326<item_detail item_id="4" item_name="NADESSTU" item_amt="%(amt4)d" bank_id="11" acct_num="0036375968" />
327</item_details>
328</payment_item_detail>""" % xmldict
329
330        if self.context.p_category == 'sbs_1':
331            self.pay_item_id = '120'
332            # amount_auth is being ignored. However, the sum of all split payments
333            # must coincide with the amount_auth configured in students/utils.py
334            xmldict['amt1'] = 100 * 800
335            xmldict['amt2'] = 100 * 1000
336            xmldict['amt3'] = 100 * 500
337
338            xmltext = """<payment_item_detail>
339<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
340<item_detail item_id="1" item_name="SBS Dues I" item_amt="%(amt1)d" bank_id="11" acct_num="0010772626" />
341<item_detail item_id="2" item_name="Journal fee" item_amt="%(amt2)d" bank_id="11" acct_num="0010772626" />
342<item_detail item_id="3" item_name="ABSOBS" item_amt="%(amt3)d" bank_id="8" acct_num="2008185712" />
343</item_details>
344</payment_item_detail>""" % xmldict
345
346        if self.context.p_category == 'sbs_2':
347            self.pay_item_id = '123'
348            # amount_auth is being ignored. However, the sum of all split payments
349            # must coincide with the amount_auth configured in students/utils.py
350            xmldict['amt1'] = 100 * 300
351            xmldict['amt2'] = 100 * 500
352            xmltext = """<payment_item_detail>
353<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
354<item_detail item_id="1" item_name="SBS Dues II" item_amt="%(amt1)d" bank_id="11" acct_num="0010772626" />
355<item_detail item_id="2" item_name="ABSOBS" item_amt="%(amt2)d" bank_id="8" acct_num="2008185712" />
356</item_details>
357</payment_item_detail>""" % xmldict
358
359        if self.context.p_category == 'mkt':
360            self.pay_item_id = '127'
361            # amount_auth is being ignored. However, the sum of all split payments
362            # must coincide with the amount_auth configured in students/utils.py
363            xmldict['amt1'] = 100 * 500
364            xmldict['amt2'] = 100 * 500
365            xmltext = """<payment_item_detail>
366<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
367<item_detail item_id="1" item_name="MKT Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0048297823" />
368<item_detail item_id="2" item_name="NAMS" item_amt="%(amt2)d" bank_id="8" acct_num="2032309812" />
369</item_details>
370</payment_item_detail>""" % xmldict
371
372        if self.context.p_category == 'mcn':
373            self.pay_item_id = '129'
374            # amount_auth is being ignored. However, the sum of all split payments
375            # must coincide with the amount_auth configured in students/utils.py
376            xmldict['amt1'] = 100 * 500
377            xmldict['amt2'] = 100 * 500
378            xmltext = """<payment_item_detail>
379<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
380<item_detail item_id="1" item_name="MCN Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0010789213" />
381<item_detail item_id="2" item_name="AMCOS" item_amt="%(amt2)d" bank_id="8" acct_num="3020253234" />
382</item_details>
383</payment_item_detail>""" % xmldict
384
385        if self.context.p_category == 'otm':
386            self.pay_item_id = '131'
387            # amount_auth is being ignored. However, the sum of all split payments
388            # must coincide with the amount_auth configured in students/utils.py
389            xmldict['amt1'] = 100 * 500
390            xmldict['amt2'] = 100 * 500
391            xmltext = """<payment_item_detail>
392<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
393<item_detail item_id="1" item_name="OTM Dues" item_amt="%(amt1)d" bank_id="8" acct_num="3068446702" />
394<item_detail item_id="2" item_name="NAOTM" item_amt="%(amt2)d" bank_id="11" acct_num="0036652027" />
395</item_details>
396</payment_item_detail>""" % xmldict
397
398        if self.context.p_category == 'acct':
399            self.pay_item_id = '134'
400            # amount_auth is being ignored. However, the sum of all split payments
401            # must coincide with the amount_auth configured in students/utils.py
402            xmldict['amt1'] = 100 * 3000
403            xmldict['amt2'] = 100 * 500
404            xmldict['amt3'] = 100 * 500
405            xmltext = """<payment_item_detail>
406<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
407<item_detail item_id="1" item_name="Profession Accreditation" item_amt="%(amt1)d" bank_id="11" acct_num="0040285084" />
408<item_detail item_id="2" item_name="ACCT Dues" item_amt="%(amt2)d" bank_id="11" acct_num="0036184955" />
409<item_detail item_id="3" item_name="NAPAS" item_amt="%(amt3)d" bank_id="8" acct_num="2008498661" />
410</item_details>
411</payment_item_detail>""" % xmldict
412
413        if self.context.p_category == 'bam':
414            self.pay_item_id = '136'
415            # amount_auth is being ignored. However, the sum of all split payments
416            # must coincide with the amount_auth configured in students/utils.py
417            xmldict['amt1'] = 100 * 500
418            xmldict['amt2'] = 100 * 500
419            xmltext = """<payment_item_detail>
420<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
421<item_detail item_id="1" item_name="BAM Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0010788058" />
422<item_detail item_id="2" item_name="NABAS" item_amt="%(amt2)d" bank_id="8" acct_num="2006936848" />
423</item_details>
424</payment_item_detail>""" % xmldict
425
426        if self.context.p_category == 'pom':
427            self.pay_item_id = '138'
428            # amount_auth is being ignored. However, the sum of all split payments
429            # must coincide with the amount_auth configured in students/utils.py
430            xmldict['amt1'] = 100 * 500
431            xmldict['amt2'] = 100 * 500
432            xmltext = """<payment_item_detail>
433<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
434<item_detail item_id="1" item_name="POM Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0096851444" />
435<item_detail item_id="2" item_name="NAMS" item_amt="%(amt2)d" bank_id="8" acct_num="2033423003" />
436</item_details>
437</payment_item_detail>""" % xmldict
438
439        if self.context.p_category == 'hrm':
440            self.pay_item_id = '140'
441            # amount_auth is being ignored. However, the sum of all split payments
442            # must coincide with the amount_auth configured in students/utils.py
443            xmldict['amt1'] = 100 * 500
444            xmldict['amt2'] = 100 * 500
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="HRM Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0096858546" />
448<item_detail item_id="2" item_name="NAMS" item_amt="%(amt2)d" bank_id="8" acct_num="2033423003" />
449</item_details>
450</payment_item_detail>""" % xmldict
451
452        if self.context.p_category == 'ndgrad':
453            self.pay_item_id = '152'
454            # amount_auth is being ignored. However, the sum of all split payments
455            # must coincide with the amount_auth configured in students/utils.py
456            xmldict['amt1'] = 100 * 3000
457            xmldict['amt2'] = 100 * 5000
458            xmldict['amt3'] = 100 * 1000
459            xmldict['amt4'] = 100 * 3500
460            xmltext = """<payment_item_detail>
461<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
462<item_detail item_id="1" item_name="Collection of Results" item_amt="%(amt1)d" bank_id="117" acct_num="1012808851" />
463<item_detail item_id="2" item_name="Collection of Certificate" item_amt="%(amt2)d" bank_id="117" acct_num="1012808851" />
464<item_detail item_id="3" item_name="Alumni" item_amt="%(amt3)d" bank_id="8" acct_num="2011810346" />
465<item_detail item_id="4" item_name="Convocation" item_amt="%(amt4)d" bank_id="8" acct_num="2006612782" />
466</item_details>
467</payment_item_detail>""" % xmldict
468
469        if self.context.p_category == 'hndgrad':
470            self.pay_item_id = '153'
471            # amount_auth is being ignored. However, the sum of all split payments
472            # must coincide with the amount_auth configured in students/utils.py
473            xmldict['amt1'] = 100 * 5000
474            xmldict['amt2'] = 100 * 7500
475            xmldict['amt3'] = 100 * 1000
476            xmldict['amt4'] = 100 * 3500
477            xmltext = """<payment_item_detail>
478<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
479<item_detail item_id="1" item_name="Collection of Results" item_amt="%(amt1)d" bank_id="117" acct_num="1012808851" />
480<item_detail item_id="2" item_name="Collection of Certificate" item_amt="%(amt2)d" bank_id="117" acct_num="1012808851" />
481<item_detail item_id="3" item_name="Alumni" item_amt="%(amt3)d" bank_id="8" acct_num="2011810346" />
482<item_detail item_id="4" item_name="Convocation" item_amt="%(amt4)d" bank_id="8" acct_num="2006612782" />
483</item_details>
484</payment_item_detail>""" % xmldict
485
486        if self.context.p_category == 'sas_1':
487            self.pay_item_id = '158'
488            # amount_auth is being ignored. However, the sum of all split payments
489            # must coincide with the amount_auth configured in students/utils.py
490            xmldict['amt1'] = 100 * 500
491            xmldict['amt2'] = 100 * 500
492            xmldict['amt3'] = 100 * 500
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="SAS Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0038956822" />
496<item_detail item_id="2" item_name="Handbook Fee" item_amt="%(amt2)d" bank_id="11" acct_num="0010772626" />
497<item_detail item_id="3" item_name="Association Due" item_amt="%(amt3)d" bank_id="8" acct_num="3069091989" />
498</item_details>
499</payment_item_detail>""" % xmldict
500
501        if self.context.p_category == 'sas_2':
502            self.pay_item_id = '159'
503            # amount_auth is being ignored. However, the sum of all split payments
504            # must coincide with the amount_auth configured in students/utils.py
505            xmldict['amt1'] = 100 * 500
506            xmldict['amt2'] = 100 * 500
507            xmltext = """<payment_item_detail>
508<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
509<item_detail item_id="1" item_name="SAS Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0038956822" />
510<item_detail item_id="2" item_name="Association Due" item_amt="%(amt2)d" bank_id="8" acct_num="3069091989" />
511</item_details>
512</payment_item_detail>""" % xmldict
513
514        if self.context.p_category == 'com':
515            self.pay_item_id = '160'
516            # amount_auth is being ignored. However, the sum of all split payments
517            # must coincide with the amount_auth configured in students/utils.py
518            xmldict['amt1'] = 100 * 500
519            xmldict['amt2'] = 100 * 500
520            xmltext = """<payment_item_detail>
521<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
522<item_detail item_id="1" item_name="Departmental Due" item_amt="%(amt1)d" bank_id="11" acct_num="0010787594" />
523<item_detail item_id="2" item_name="NACOS " item_amt="%(amt2)d" bank_id="8" acct_num="3047146881" />
524</item_details>
525</payment_item_detail>""" % xmldict
526
527        if self.context.p_category == 'sta':
528            self.pay_item_id = '161'
529            # amount_auth is being ignored. However, the sum of all split payments
530            # must coincide with the amount_auth configured in students/utils.py
531            xmldict['amt1'] = 100 * 500
532            xmldict['amt2'] = 100 * 500
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="Departmental Due" item_amt="%(amt1)d" bank_id="11" acct_num="0048794281" />
536<item_detail item_id="2" item_name="NASS " item_amt="%(amt2)d" bank_id="8" acct_num="203000173" />
537</item_details>
538</payment_item_detail>""" % xmldict
539
540        if self.context.p_category == 'slt_1':
541            self.pay_item_id = '162'
542            # amount_auth is being ignored. However, the sum of all split payments
543            # must coincide with the amount_auth configured in students/utils.py
544            xmldict['amt1'] = 100 * 500
545            xmldict['amt2'] = 100 * 500
546            xmldict['amt3'] = 100 * 3000
547            xmldict['amt4'] = 100 * 500
548            xmldict['amt5'] = 100 * 3000
549            xmldict['amt6'] = 100 * 2000
550            xmltext = """<payment_item_detail>
551<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
552<item_detail item_id="1" item_name="Departmental Due" item_amt="%(amt1)d" bank_id="8" acct_num="2033492885" />
553<item_detail item_id="2" item_name="Association Due" item_amt="%(amt2)d" bank_id="11" acct_num="0115800071" />
554<item_detail item_id="3" item_name="Professional Due" item_amt="%(amt3)d" bank_id="8" acct_num="2033492885" />
555<item_detail item_id="4" item_name="Prospectus" item_amt="%(amt4)d" bank_id="8" acct_num="2033492885" />
556<item_detail item_id="5" item_name="Practical Manual" item_amt="%(amt4)d" bank_id="8" acct_num="2033492885" />
557<item_detail item_id="6" item_name="Lab. Coat" item_amt="%(amt4)d" bank_id="8" acct_num="2033492885" />
558</item_details>
559</payment_item_detail>""" % xmldict
560
561        if self.context.p_category == 'slt_2':
562            self.pay_item_id = '163'
563            # amount_auth is being ignored. However, the sum of all split payments
564            # must coincide with the amount_auth configured in students/utils.py
565            xmldict['amt1'] = 100 * 500
566            xmldict['amt2'] = 100 * 500
567            xmldict['amt3'] = 100 * 3000
568            xmltext = """<payment_item_detail>
569<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
570<item_detail item_id="1" item_name="Departmental Due" item_amt="%(amt1)d" bank_id="8" acct_num="2033492885" />
571<item_detail item_id="2" item_name="Association Due" item_amt="%(amt2)d" bank_id="11" acct_num="0115800071" />
572<item_detail item_id="3" item_name="Practical Manual" item_amt="%(amt3)d" bank_id="8" acct_num="2033492885" />
573</item_details>
574</payment_item_detail>""" % xmldict
575
576        if self.context.p_category == 'lis':
577            self.pay_item_id = '164'
578            # amount_auth is being ignored. However, the sum of all split payments
579            # must coincide with the amount_auth configured in students/utils.py
580            xmldict['amt1'] = 100 * 500
581            xmldict['amt2'] = 100 * 500
582            xmltext = """<payment_item_detail>
583<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
584<item_detail item_id="1" item_name="Departmental Due" item_amt="%(amt1)d" bank_id="" acct_num="0068264131" />
585<item_detail item_id="2" item_name="Association Due" item_amt="%(amt2)d" bank_id="" acct_num="" />
586</item_details>
587</payment_item_detail>""" % xmldict
588
589        if self.context.p_category == 'htm':
590            self.pay_item_id = '165'
591            # amount_auth is being ignored. However, the sum of all split payments
592            # must coincide with the amount_auth configured in students/utils.py
593            xmldict['amt1'] = 100 * 500
594            xmldict['amt2'] = 100 * 500
595            xmltext = """<payment_item_detail>
596<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
597<item_detail item_id="1" item_name="Departmental Due" item_amt="%(amt1)d" bank_id="" acct_num="0068264131" />
598<item_detail item_id="2" item_name="Association Due" item_amt="%(amt2)d" bank_id="" acct_num="" />
599</item_details>
600</payment_item_detail>""" % xmldict
601
602        if self.context.p_category == 'pa':
603            self.pay_item_id = '166'
604            # amount_auth is being ignored. However, the sum of all split payments
605            # must coincide with the amount_auth configured in students/utils.py
606            xmldict['amt1'] = 100 * 500
607            xmldict['amt2'] = 100 * 500
608            xmltext = """<payment_item_detail>
609<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
610<item_detail item_id="1" item_name="PAD" item_amt="%(amt1)d" bank_id="11" acct_num="0160125880" />
611<item_detail item_id="2" item_name="NAPAS" item_amt="%(amt2)d" bank_id="11" acct_num="0164863395" />
612</item_details>
613</payment_item_detail>""" % xmldict
614
615        if self.context.p_category == 'hostel_maintenance':
616            #if self.context.p_item != 'Balance':
617            #    provider_amt = 500.0
618            self.pay_item_id = '117'
619            xmldict['institution_acct'] = '1012808851'
620            xmldict['institution_bank_id'] = '117'
621            xmltext = """<payment_item_detail>
622<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
623<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" />
624<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" />
625<item_detail item_id="3" item_name="Hostel Due" item_amt="2000" bank_id="11" acct_num="0170897506" />
626</item_details>
627</payment_item_detail>""" % xmldict
628
629
630        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
631        self.context.provider_amt = provider_amt
632        self.context.gateway_amt = GATEWAY_AMT
633        self.context.net_amt = self.context.amount_auth - GATEWAY_AMT
634        self.amount_auth = int(100 * self.context.amount_auth)
635        hashargs = (
636            self.context.p_id +
637            PRODUCT_ID +
638            self.pay_item_id +
639            str(int(self.amount_auth)) +
640            self.site_redirect_url +
641            self.mac)
642        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
643        return
644
645class CustomInterswitchPageApplicant(InterswitchPageApplicant):
646    """ View which sends a POST request to the Interswitch
647    CollegePAY payment gateway.
648    """
649    grok.context(ICustomApplicantOnlinePayment)
650    action = POST_ACTION
651    site_name = SITE_NAME
652    currency = CURRENCY
653    pay_item_id = '101' # must be provided by Interswitch
654    product_id = PRODUCT_ID
655    mac = MAC
656
657    def update(self):
658        error = self.init_update()
659        if error:
660            self.flash(error, type='danger')
661            self.redirect(self.url(self.context, '@@index'))
662            return
663        self.context.r_company = u'interswitch'
664        xmldict = {}
665        provider_amt = 500.0
666        gateway_amt = GATEWAY_AMT
667        xmldict['institution_acct'] = '00000000'
668        xmldict['institution_bank_id'] = '00'
669        if self.applicant.__parent__.application_category in ('ndft', 'hndft'):
670            xmldict['institution_acct'] = '0072223654'
671            xmldict['institution_bank_id'] = '121'
672        elif self.applicant.__parent__.application_category in (
673            'ndpt', 'hndpt', 'ndwe', 'hndwe'):
674            xmldict['institution_acct'] = '1015220292'
675            xmldict['institution_bank_id'] = '117'
676        elif self.applicant.__parent__.prefix in ('conv', 'hndfincl', 'ndfincl'):
677            xmldict['institution_acct'] = '1012808851'
678            xmldict['institution_bank_id'] = '117'
679            self.pay_item_id = '151'
680        elif self.applicant.applicant_id.startswith('special'):
681            if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
682                self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
683                provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
684                xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
685                xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
686        if self.pay_item_id in ('122', '123', '132', '137', '141',
687                                '142', '143', '144', '146', '147',):
688                gateway_amt = round(0.015 * self.context.amount_auth, 2)
689        xmldict['detail_ref'] = self.context.p_id
690        xmldict['provider_amt'] = 100 * provider_amt
691        xmldict['provider_acct'] = PROVIDER_ACCT
692        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
693        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
694        xmldict['institution_amt'] = institution_amt = 100 * (
695            self.context.amount_auth - provider_amt - gateway_amt)
696        xmldict['institution_item_name'] = self.context.category
697        xmldict['institution_name'] = INSTITUTION_NAME
698        xmltext = """<payment_item_detail>
699<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
700<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" />
701<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" />
702</item_details>
703</payment_item_detail>""" % xmldict
704
705        # isouaba: All certificates in SPAT are part time thus any payments
706        # coming from those certificates (Application, Acceptance, school fees
707        # etc) 40% should be split to keystone account.
708        if self.applicant.__parent__.application_category in (
709            'ndpt', 'hndpt', 'ndwe', 'hndwe'):
710            xmldict['institution_amt_2'] = 0.4 * institution_amt
711            xmldict['institution_amt_1'] = 0.6 * institution_amt
712            xmltext = """<payment_item_detail>
713<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
714<item_detail item_id="1" item_name="%(institution_item_name)s 1" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
715<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="8" acct_num="2034761924" />
716<item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
717</item_details>
718</payment_item_detail>""" % xmldict
719
720        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
721        self.context.provider_amt = provider_amt
722        self.context.gateway_amt = GATEWAY_AMT
723        self.context.net_amt = self.context.amount_auth - GATEWAY_AMT
724        self.amount_auth = int(100 * self.context.amount_auth)
725        hashargs = (
726            self.context.p_id +
727            PRODUCT_ID +
728            self.pay_item_id +
729            str(int(self.amount_auth)) +
730            self.site_redirect_url +
731            self.mac)
732        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
733        return
734
735class CustomInterswitchPaymentRequestWebservicePageStudent(
736    InterswitchPaymentRequestWebservicePageStudent):
737    """Request webservice view for the CollegePAY gateway
738    """
739    grok.context(ICustomStudentOnlinePayment)
740    product_id = PRODUCT_ID
741    gateway_host = HOST
742    gateway_url = URL
743    mac = MAC
744
745class CustomInterswitchPaymentVerifyWebservicePageStudent(
746    InterswitchPaymentVerifyWebservicePageStudent):
747    """Payment verify view for the CollegePAY gateway
748    """
749    grok.context(ICustomStudentOnlinePayment)
750    product_id = PRODUCT_ID
751    gateway_host = HOST
752    gateway_url = URL
753    mac = MAC
754
755class CustomInterswitchPaymentRequestWebservicePageApplicant(
756    InterswitchPaymentRequestWebservicePageApplicant):
757    """Request webservice view for the CollegePAY gateway
758    """
759    grok.context(ICustomApplicantOnlinePayment)
760    product_id = PRODUCT_ID
761    gateway_host = HOST
762    gateway_url = URL
763    mac = MAC
764
765class CustomInterswitchPaymentVerifyWebservicePageApplicant(
766    InterswitchPaymentVerifyWebservicePageApplicant):
767    """Payment verify view for the CollegePAY gateway
768    """
769    grok.context(ICustomApplicantOnlinePayment)
770    product_id = PRODUCT_ID
771    gateway_host = HOST
772    gateway_url = URL
773    mac = MAC
Note: See TracBrowser for help on using the repository browser.