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

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

Rework the entire schoolfee determination and split payment algorithm.

  • Property svn:keywords set to Id
File size: 43.2 KB
Line 
1## $Id: browser.py 16760 2022-01-28 08:17:50Z 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="51" acct_num="1012963301" />
277<item_detail item_id="5" item_name="Microsoft Academy Fee" item_amt="%(microsoft_fee)d" bank_id="117" 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="51" acct_num="1012963301" />
322<item_detail item_id="6" item_name="Microsoft Academy Fee" item_amt="%(microsoft_fee)d" bank_id="117" 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 * 1000
335            xmldict['amt2'] = 100 * 500
336            xmldict['amt3'] = 100 * 900
337            xmldict['amt4'] = 100 * 500
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 * 800
353            xmldict['amt2'] = 100 * 1000
354            xmldict['amt3'] = 100 * 500
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 * 300
369            xmldict['amt2'] = 100 * 500
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 * 500
382            xmldict['amt2'] = 100 * 500
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 * 500
395            xmldict['amt2'] = 100 * 500
396            xmltext = """<payment_item_detail>
397<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
398<item_detail item_id="1" item_name="MCN Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0010789213" />
399<item_detail item_id="2" item_name="AMCOS" item_amt="%(amt2)d" bank_id="8" acct_num="3020253234" />
400</item_details>
401</payment_item_detail>""" % xmldict
402
403        if self.context.p_category == 'otm':
404            self.pay_item_id = '131'
405            # amount_auth is being ignored. However, the sum of all split payments
406            # must coincide with the amount_auth configured in students/utils.py
407            xmldict['amt1'] = 100 * 500
408            xmldict['amt2'] = 100 * 500
409            xmltext = """<payment_item_detail>
410<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
411<item_detail item_id="1" item_name="OTM Dues" item_amt="%(amt1)d" bank_id="8" acct_num="3068446702" />
412<item_detail item_id="2" item_name="NAOTM" item_amt="%(amt2)d" bank_id="11" acct_num="0036652027" />
413</item_details>
414</payment_item_detail>""" % xmldict
415
416        if self.context.p_category == 'acct':
417            self.pay_item_id = '134'
418            # amount_auth is being ignored. However, the sum of all split payments
419            # must coincide with the amount_auth configured in students/utils.py
420            xmldict['amt1'] = 100 * 3000
421            xmldict['amt2'] = 100 * 500
422            xmldict['amt3'] = 100 * 500
423            xmltext = """<payment_item_detail>
424<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
425<item_detail item_id="1" item_name="Profession Accreditation" item_amt="%(amt1)d" bank_id="11" acct_num="0040285084" />
426<item_detail item_id="2" item_name="ACCT Dues" item_amt="%(amt2)d" bank_id="11" acct_num="0036184955" />
427<item_detail item_id="3" item_name="NAPAS" item_amt="%(amt3)d" bank_id="8" acct_num="2008498661" />
428</item_details>
429</payment_item_detail>""" % xmldict
430
431        if self.context.p_category == 'bam':
432            self.pay_item_id = '136'
433            # amount_auth is being ignored. However, the sum of all split payments
434            # must coincide with the amount_auth configured in students/utils.py
435            xmldict['amt1'] = 100 * 500
436            xmldict['amt2'] = 100 * 500
437            xmltext = """<payment_item_detail>
438<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
439<item_detail item_id="1" item_name="BAM Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0010788058" />
440<item_detail item_id="2" item_name="NABAS" item_amt="%(amt2)d" bank_id="8" acct_num="2006936848" />
441</item_details>
442</payment_item_detail>""" % xmldict
443
444        if self.context.p_category == 'pom':
445            self.pay_item_id = '138'
446            # amount_auth is being ignored. However, the sum of all split payments
447            # must coincide with the amount_auth configured in students/utils.py
448            xmldict['amt1'] = 100 * 500
449            xmldict['amt2'] = 100 * 500
450            xmltext = """<payment_item_detail>
451<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
452<item_detail item_id="1" item_name="POM Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0096851444" />
453<item_detail item_id="2" item_name="NAMS" item_amt="%(amt2)d" bank_id="8" acct_num="2033423003" />
454</item_details>
455</payment_item_detail>""" % xmldict
456
457        if self.context.p_category == 'hrm':
458            self.pay_item_id = '140'
459            # amount_auth is being ignored. However, the sum of all split payments
460            # must coincide with the amount_auth configured in students/utils.py
461            xmldict['amt1'] = 100 * 500
462            xmldict['amt2'] = 100 * 500
463            xmltext = """<payment_item_detail>
464<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
465<item_detail item_id="1" item_name="HRM Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0096858546" />
466<item_detail item_id="2" item_name="NAMS" item_amt="%(amt2)d" bank_id="8" acct_num="2033423003" />
467</item_details>
468</payment_item_detail>""" % xmldict
469
470        if self.context.p_category == 'ndgrad':
471            self.pay_item_id = '152'
472            # amount_auth is being ignored. However, the sum of all split payments
473            # must coincide with the amount_auth configured in students/utils.py
474            xmldict['amt1'] = 100 * 3000
475            xmldict['amt2'] = 100 * 5000
476            xmldict['amt3'] = 100 * 1000
477            xmldict['amt4'] = 100 * 3500
478            xmltext = """<payment_item_detail>
479<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
480<item_detail item_id="1" item_name="Collection of Results" item_amt="%(amt1)d" bank_id="117" acct_num="1012808851" />
481<item_detail item_id="2" item_name="Collection of Certificate" item_amt="%(amt2)d" bank_id="117" acct_num="1012808851" />
482<item_detail item_id="3" item_name="Alumni" item_amt="%(amt3)d" bank_id="8" acct_num="2011810346" />
483<item_detail item_id="4" item_name="Convocation" item_amt="%(amt4)d" bank_id="8" acct_num="2006612782" />
484</item_details>
485</payment_item_detail>""" % xmldict
486
487        if self.context.p_category == 'hndgrad':
488            self.pay_item_id = '153'
489            # amount_auth is being ignored. However, the sum of all split payments
490            # must coincide with the amount_auth configured in students/utils.py
491            xmldict['amt1'] = 100 * 5000
492            xmldict['amt2'] = 100 * 7500
493            xmldict['amt3'] = 100 * 1000
494            xmldict['amt4'] = 100 * 3500
495            xmltext = """<payment_item_detail>
496<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
497<item_detail item_id="1" item_name="Collection of Results" item_amt="%(amt1)d" bank_id="117" acct_num="1012808851" />
498<item_detail item_id="2" item_name="Collection of Certificate" item_amt="%(amt2)d" bank_id="117" acct_num="1012808851" />
499<item_detail item_id="3" item_name="Alumni" item_amt="%(amt3)d" bank_id="8" acct_num="2011810346" />
500<item_detail item_id="4" item_name="Convocation" item_amt="%(amt4)d" bank_id="8" acct_num="2006612782" />
501</item_details>
502</payment_item_detail>""" % xmldict
503
504        if self.context.p_category == 'sas_1':
505            self.pay_item_id = '158'
506            # amount_auth is being ignored. However, the sum of all split payments
507            # must coincide with the amount_auth configured in students/utils.py
508            xmldict['amt1'] = 100 * 500
509            xmldict['amt2'] = 100 * 500
510            xmldict['amt3'] = 100 * 500
511            xmltext = """<payment_item_detail>
512<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
513<item_detail item_id="1" item_name="SAS Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0038956822" />
514<item_detail item_id="2" item_name="Handbook Fee" item_amt="%(amt2)d" bank_id="11" acct_num="0010772626" />
515<item_detail item_id="3" item_name="Association Due" item_amt="%(amt3)d" bank_id="8" acct_num="3069091989" />
516</item_details>
517</payment_item_detail>""" % xmldict
518
519        if self.context.p_category == 'sas_2':
520            self.pay_item_id = '159'
521            # amount_auth is being ignored. However, the sum of all split payments
522            # must coincide with the amount_auth configured in students/utils.py
523            xmldict['amt1'] = 100 * 500
524            xmldict['amt2'] = 100 * 500
525            xmltext = """<payment_item_detail>
526<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
527<item_detail item_id="1" item_name="SAS Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0038956822" />
528<item_detail item_id="2" item_name="Association Due" item_amt="%(amt2)d" bank_id="8" acct_num="3069091989" />
529</item_details>
530</payment_item_detail>""" % xmldict
531
532        if self.context.p_category == 'com':
533            self.pay_item_id = '160'
534            # amount_auth is being ignored. However, the sum of all split payments
535            # must coincide with the amount_auth configured in students/utils.py
536            xmldict['amt1'] = 100 * 500
537            xmldict['amt2'] = 100 * 500
538            xmltext = """<payment_item_detail>
539<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
540<item_detail item_id="1" item_name="Departmental Due" item_amt="%(amt1)d" bank_id="11" acct_num="0010787594" />
541<item_detail item_id="2" item_name="NACOS " item_amt="%(amt2)d" bank_id="8" acct_num="3047146881" />
542</item_details>
543</payment_item_detail>""" % xmldict
544
545        if self.context.p_category == 'sta':
546            self.pay_item_id = '161'
547            # amount_auth is being ignored. However, the sum of all split payments
548            # must coincide with the amount_auth configured in students/utils.py
549            xmldict['amt1'] = 100 * 500
550            xmldict['amt2'] = 100 * 500
551            xmltext = """<payment_item_detail>
552<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
553<item_detail item_id="1" item_name="Departmental Due" item_amt="%(amt1)d" bank_id="11" acct_num="0048794281" />
554<item_detail item_id="2" item_name="NASS " item_amt="%(amt2)d" bank_id="8" acct_num="203000173" />
555</item_details>
556</payment_item_detail>""" % xmldict
557
558        if self.context.p_category == 'slt_1':
559            self.pay_item_id = '162'
560            # amount_auth is being ignored. However, the sum of all split payments
561            # must coincide with the amount_auth configured in students/utils.py
562            xmldict['amt1'] = 100 * 500
563            xmldict['amt2'] = 100 * 500
564            xmldict['amt3'] = 100 * 3000
565            xmldict['amt4'] = 100 * 500
566            xmldict['amt5'] = 100 * 3000
567            xmldict['amt6'] = 100 * 2000
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="Professional Due" item_amt="%(amt3)d" bank_id="8" acct_num="2033492885" />
573<item_detail item_id="4" item_name="Prospectus" item_amt="%(amt4)d" bank_id="8" acct_num="2033492885" />
574<item_detail item_id="5" item_name="Practical Manual" item_amt="%(amt4)d" bank_id="8" acct_num="2033492885" />
575<item_detail item_id="6" item_name="Lab. Coat" item_amt="%(amt4)d" bank_id="8" acct_num="2033492885" />
576</item_details>
577</payment_item_detail>""" % xmldict
578
579        if self.context.p_category == 'slt_2':
580            self.pay_item_id = '163'
581            # amount_auth is being ignored. However, the sum of all split payments
582            # must coincide with the amount_auth configured in students/utils.py
583            xmldict['amt1'] = 100 * 500
584            xmldict['amt2'] = 100 * 500
585            xmldict['amt3'] = 100 * 3000
586            xmltext = """<payment_item_detail>
587<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
588<item_detail item_id="1" item_name="Departmental Due" item_amt="%(amt1)d" bank_id="8" acct_num="2033492885" />
589<item_detail item_id="2" item_name="Association Due" item_amt="%(amt2)d" bank_id="11" acct_num="0115800071" />
590<item_detail item_id="3" item_name="Practical Manual" item_amt="%(amt3)d" bank_id="8" acct_num="2033492885" />
591</item_details>
592</payment_item_detail>""" % xmldict
593
594        if self.context.p_category == 'lis':
595            self.pay_item_id = '164'
596            # amount_auth is being ignored. However, the sum of all split payments
597            # must coincide with the amount_auth configured in students/utils.py
598            xmldict['amt1'] = 100 * 500
599            xmldict['amt2'] = 100 * 500
600            xmltext = """<payment_item_detail>
601<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
602<item_detail item_id="1" item_name="Departmental Due" item_amt="%(amt1)d" bank_id="" acct_num="0068264131" />
603<item_detail item_id="2" item_name="Association Due" item_amt="%(amt2)d" bank_id="" acct_num="" />
604</item_details>
605</payment_item_detail>""" % xmldict
606
607        if self.context.p_category == 'htm':
608            self.pay_item_id = '165'
609            # amount_auth is being ignored. However, the sum of all split payments
610            # must coincide with the amount_auth configured in students/utils.py
611            xmldict['amt1'] = 100 * 500
612            xmldict['amt2'] = 100 * 500
613            xmltext = """<payment_item_detail>
614<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
615<item_detail item_id="1" item_name="Departmental Due" item_amt="%(amt1)d" bank_id="" acct_num="0068264131" />
616<item_detail item_id="2" item_name="Association Due" item_amt="%(amt2)d" bank_id="" acct_num="" />
617</item_details>
618</payment_item_detail>""" % xmldict
619
620        if self.context.p_category == 'pa':
621            self.pay_item_id = '166'
622            # amount_auth is being ignored. However, the sum of all split payments
623            # must coincide with the amount_auth configured in students/utils.py
624            xmldict['amt1'] = 100 * 500
625            xmldict['amt2'] = 100 * 500
626            xmltext = """<payment_item_detail>
627<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
628<item_detail item_id="1" item_name="PAD" item_amt="%(amt1)d" bank_id="11" acct_num="0160125880" />
629<item_detail item_id="2" item_name="NAPAS" item_amt="%(amt2)d" bank_id="11" acct_num="0164863395" />
630</item_details>
631</payment_item_detail>""" % xmldict
632
633        if self.context.p_category == 'hostel_maintenance':
634            provider_amt = 500.0
635            hostel_due = 2000
636            self.pay_item_id = '117'
637            xmldict['institution_acct'] = '1012808851'
638            xmldict['institution_bank_id'] = '117'
639            xmldict['provider_amt'] = 100 * provider_amt
640            xmldict['hostel_due'] = 100 * hostel_due
641            xmldict['institution_amt'] = institution_amt = 100 * (
642                self.context.amount_auth - provider_amt - hostel_due - GATEWAY_AMT)
643            xmltext = """<payment_item_detail>
644<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
645<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" />
646<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" />
647<item_detail item_id="3" item_name="Hostel Due" item_amt="%(hostel_due)d" bank_id="11" acct_num="0170897506" />
648</item_details>
649</payment_item_detail>""" % xmldict
650
651
652        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
653        self.context.provider_amt = provider_amt
654        self.context.gateway_amt = GATEWAY_AMT
655        self.context.net_amt = self.context.amount_auth - GATEWAY_AMT
656        self.amount_auth = int(100 * self.context.amount_auth)
657        hashargs = (
658            self.context.p_id +
659            PRODUCT_ID +
660            self.pay_item_id +
661            str(int(self.amount_auth)) +
662            self.site_redirect_url +
663            self.mac)
664        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
665        return
666
667class CustomInterswitchPageApplicant(InterswitchPageApplicant):
668    """ View which sends a POST request to the Interswitch
669    CollegePAY payment gateway.
670    """
671    grok.context(ICustomApplicantOnlinePayment)
672    action = POST_ACTION
673    site_name = SITE_NAME
674    currency = CURRENCY
675    pay_item_id = '101' # must be provided by Interswitch
676    product_id = PRODUCT_ID
677    mac = MAC
678
679    def update(self):
680        error = self.init_update()
681        if error:
682            self.flash(error, type='danger')
683            self.redirect(self.url(self.context, '@@index'))
684            return
685        self.context.r_company = u'interswitch'
686        xmldict = {}
687        provider_amt = 500.0
688        gateway_amt = GATEWAY_AMT
689        xmldict['institution_acct'] = '00000000'
690        xmldict['institution_bank_id'] = '00'
691        if self.applicant.__parent__.application_category in ('ndft', 'hndft'):
692            xmldict['institution_acct'] = '0072223654'
693            xmldict['institution_bank_id'] = '121'
694        elif self.applicant.__parent__.application_category in (
695            'ndpt', 'hndpt', 'ndwe', 'hndwe'):
696            xmldict['institution_acct'] = '1015220292'
697            xmldict['institution_bank_id'] = '117'
698        elif self.applicant.__parent__.prefix in ('conv', 'hndfincl', 'ndfincl'):
699            xmldict['institution_acct'] = '1012808851'
700            xmldict['institution_bank_id'] = '117'
701            self.pay_item_id = '151'
702        elif self.applicant.applicant_id.startswith('special'):
703            if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
704                self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
705                provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
706                xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
707                xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
708        if self.pay_item_id in ('122', '123', '132', '137', '141',
709                                '142', '143', '144', '146', '147',):
710                gateway_amt = round(0.015 * self.context.amount_auth, 2)
711        xmldict['detail_ref'] = self.context.p_id
712        xmldict['provider_amt'] = 100 * provider_amt
713        xmldict['provider_acct'] = PROVIDER_ACCT
714        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
715        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
716        xmldict['institution_amt'] = institution_amt = 100 * (
717            self.context.amount_auth - provider_amt - gateway_amt)
718        xmldict['institution_item_name'] = self.context.category
719        xmldict['institution_name'] = INSTITUTION_NAME
720        xmltext = """<payment_item_detail>
721<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
722<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" />
723<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" />
724</item_details>
725</payment_item_detail>""" % xmldict
726
727        # isouaba: All certificates in SPAT are part time thus any payments
728        # coming from those certificates (Application, Acceptance, school fees
729        # etc) 40% should be split to keystone account.
730        if self.applicant.__parent__.application_category in (
731            'ndpt', 'hndpt', 'ndwe', 'hndwe'):
732            xmldict['institution_amt_2'] = 0.4 * institution_amt
733            xmldict['institution_amt_1'] = 0.6 * institution_amt
734            xmltext = """<payment_item_detail>
735<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
736<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" />
737<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="8" acct_num="2034761924" />
738<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" />
739</item_details>
740</payment_item_detail>""" % xmldict
741
742        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
743        self.context.provider_amt = provider_amt
744        self.context.gateway_amt = GATEWAY_AMT
745        self.context.net_amt = self.context.amount_auth - GATEWAY_AMT
746        self.amount_auth = int(100 * self.context.amount_auth)
747        hashargs = (
748            self.context.p_id +
749            PRODUCT_ID +
750            self.pay_item_id +
751            str(int(self.amount_auth)) +
752            self.site_redirect_url +
753            self.mac)
754        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
755        return
756
757class CustomInterswitchPaymentRequestWebservicePageStudent(
758    InterswitchPaymentRequestWebservicePageStudent):
759    """Request webservice view for the CollegePAY gateway
760    """
761    grok.context(ICustomStudentOnlinePayment)
762    product_id = PRODUCT_ID
763    gateway_host = HOST
764    gateway_url = URL
765    mac = MAC
766
767class CustomInterswitchPaymentVerifyWebservicePageStudent(
768    InterswitchPaymentVerifyWebservicePageStudent):
769    """Payment verify view for the CollegePAY gateway
770    """
771    grok.context(ICustomStudentOnlinePayment)
772    product_id = PRODUCT_ID
773    gateway_host = HOST
774    gateway_url = URL
775    mac = MAC
776
777class CustomInterswitchPaymentRequestWebservicePageApplicant(
778    InterswitchPaymentRequestWebservicePageApplicant):
779    """Request webservice view for the CollegePAY gateway
780    """
781    grok.context(ICustomApplicantOnlinePayment)
782    product_id = PRODUCT_ID
783    gateway_host = HOST
784    gateway_url = URL
785    mac = MAC
786
787class CustomInterswitchPaymentVerifyWebservicePageApplicant(
788    InterswitchPaymentVerifyWebservicePageApplicant):
789    """Payment verify view for the CollegePAY gateway
790    """
791    grok.context(ICustomApplicantOnlinePayment)
792    product_id = PRODUCT_ID
793    gateway_host = HOST
794    gateway_url = URL
795    mac = MAC
Note: See TracBrowser for help on using the repository browser.