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

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

Configure Lab. Maintenance Levy

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