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

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

Configure bank account.

  • Property svn:keywords set to Id
File size: 31.2 KB
Line 
1## $Id: browser.py 15577 2019-09-03 08:17:12Z 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 kofacustom.nigeria.interswitch.browser import (
22    InterswitchPaymentRequestWebservicePageApplicant,
23    InterswitchPaymentRequestWebservicePageStudent,
24    InterswitchPaymentVerifyWebservicePageApplicant,
25    InterswitchPaymentVerifyWebservicePageStudent,
26    InterswitchPageStudent, InterswitchPageApplicant,
27    )
28from kofacustom.dspg.students.interfaces import ICustomStudentOnlinePayment
29from kofacustom.dspg.applicants.interfaces import ICustomApplicantOnlinePayment
30from kofacustom.dspg.interfaces import MessageFactory as _
31
32PRODUCT_ID = '7269' # must be provided by Interswitch
33SITE_NAME = 'dspg.waeup.org'
34PROVIDER_ACCT = '2028964403'
35PROVIDER_BANK_ID = '8'
36PROVIDER_ITEM_NAME = 'WAEAC'
37INSTITUTION_NAME = 'Delta State Polytechnic Ogwashi-Uku'
38CURRENCY = '566'
39GATEWAY_AMT = 250.0
40MAC = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627'
41
42POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
43#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
44HOST = 'webpay.interswitchng.com'
45#HOST = 'sandbox.interswitchng.com'
46URL = '/paydirect/api/v1/gettransaction.json'
47#URL = '/webpay/api/v1/gettransaction.json'
48
49httplib.HTTPSConnection.debuglevel = 0
50HTTPS = True
51
52SPECIAL_PAYMENT_PARAMS = {
53
54    'carryover1': ('101', 500.0, '1012808851', '117'),
55    'carryover4': ('101', 500.0, '1012808851', '117'),
56    'carryover5': ('101', 500.0, '1012808851', '117'),
57    'carryover6': ('101', 500.0, '1012808851', '117'),
58    'carryover7': ('101', 500.0, '1012808851', '117'),
59    'carryover8': ('101', 500.0, '1012808851', '117'),
60    'carryover9': ('101', 500.0, '1012808851', '117'),
61    'carryover10': ('101', 500.0, '1012808851', '117'),
62    'carryover11': ('101', 500.0, '1012808851', '117'),
63    'carryover12': ('101', 500.0, '1012808851', '117'),
64    'balance': ('101', 500.0, '1012808851', '117'),
65
66    'certificate': ('111', 500.0, '1012808851', '117'),
67    'state_result': ('112', 500.0, '1012808851', '117'),
68    'transcript_local': ('113', 500.0, '1012808851', '117'),
69    'transcript_foreign': ('114', 500.0, '1012808851', '117'),
70    'ver_result': ('115', 500.0, '1012808851', '117'),
71    'change_course': ('116', 500.0, '1012808851', '117'),
72    'change_inst': ('117', 500.0, '1012808851', '117'),
73    'jamb_reject': ('118', 500.0, '1012808851', '117'),
74    'cert_of_cert': ('119', 500.0, '1012808851', '117'),
75    'ref_let': ('120', 500.0, '1012808851', '117'),
76    'proc_cert': ('121', 500.0, '1012808851', '117'),
77    'loss_idcard': ('122', 9.0, '1012808851', '117'),
78    'loss_examcard': ('123', 4.5, '1012808851', '117'),
79    'loss_result': ('124', 500.0, '1012808851', '117'),
80    'loss_receipt': ('125', 500.0, '1012808851', '117'),
81    'loss_clearance': ('126', 500.0, '1012808851', '117'),
82    'conv_brochure': ('127', 500.0, '1012808851', '117'),
83    'hnd_certificate': ('128', 500.0, '1012808851', '117'),
84    'hnd_state_result': ('129', 500.0, '1012808851', '117'),
85    'hnd_transcript_local': ('130', 500.0, '1012808851', '117'),
86    'hnd_transcript_foreign': ('131', 500.0, '1012808851', '117'),
87    'staff_loss_idcard': ('132', 9.0, '1012808851', '117'),
88    'hnd_conv_brochure': ('133', 500.0, '1012808851', '117'),
89    'pgd_state_result': ('134', 500.0, '1012808851', '117'),
90    'pgd_conv_brochure': ('135', 500.0, '1012808851', '117'),
91    'pgd_certificate': ('136', 500.0, '1012808851', '117'),
92    'log_book': ('137', 4.5, '1012808851', '117'),
93    'pgd_transcript_foreign': ('138', 500.0, '1012808851', '117'),
94    'pgd_transcript_local': ('139', 500.0, '1012808851', '117'),
95    'jamb_regularization': ('140', 500.0, '1012808851', '117'),
96    'utme_registration': ('142', 9.0, '1012808851', '117'),
97    'utme_cbt': ('143', 9.0, '1012808851', '117'),
98    'nysc_id_card': ('144', 9.0, '1012808851', '117'),
99    'ijmb_result': ('147', 500.0, '1012808851', '117'),
100    'conv': ('151', 500.0, '1012963301', '117'),
101    }
102
103
104# Not yet readily configured. Bank account numbers are
105# contradictory. pay_item_ids are not yet assigned.
106
107class CustomInterswitchPageStudent(InterswitchPageStudent):
108    """ View which sends a POST request to the Interswitch
109    CollegePAY payment gateway.
110    """
111    grok.context(ICustomStudentOnlinePayment)
112    action = POST_ACTION
113    site_name = SITE_NAME
114    currency = CURRENCY
115    product_id = PRODUCT_ID
116    mac = MAC
117    pay_item_id = '000'
118
119    def update(self):
120        error = self.init_update()
121        if error:
122            self.flash(error, type='danger')
123            self.redirect(self.url(self.context, '@@index'))
124            return
125        student = self.student
126        xmldict = self.xmldict
127        # Provider data
128        xmldict['detail_ref'] = self.context.p_id
129        xmldict['provider_acct'] = PROVIDER_ACCT
130        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
131        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
132        # Institution data
133        xmldict['institution_acct'] = '00000000'
134        xmldict['institution_bank_id'] = '00'
135        xmldict['institution_amt'] = '0.0'
136        provider_amt = 0.0
137        tech_fee = 0.0
138        if self.context.p_category.startswith('schoolfee'):
139            self.pay_item_id = '102'
140            provider_amt = 2800.0
141            tech_fee = 1200.0
142            if student.faccode == 'SPAT':
143                xmldict['institution_acct'] = '1015220292'
144                xmldict['institution_bank_id'] = '117'
145            elif student.current_mode in ('nd_ft', 'hnd_ft'):
146                xmldict['institution_acct'] = '1012808851'
147                xmldict['institution_bank_id'] = '117'
148        elif self.context.p_category == 'clearance':
149            self.pay_item_id = '103'
150            provider_amt = 500.0
151            if student.faccode == 'SPAT':
152                xmldict['institution_acct'] = '1015220292'
153                xmldict['institution_bank_id'] = '117'
154            elif student.current_mode in ('nd_ft', 'hnd_ft'):
155                xmldict['institution_acct'] = '5210039869'
156                xmldict['institution_bank_id'] = '51'
157        elif self.context.p_category == 'gown':
158            self.pay_item_id = '102' # We use school fee item id.
159            xmldict['institution_acct'] = '2006612782'
160            xmldict['institution_bank_id'] = '8'
161        elif self.context.p_category == 'sports':
162            self.pay_item_id = '110'
163            xmldict['institution_acct'] = '6060300688'
164            xmldict['institution_bank_id'] = '51'
165        elif self.context.p_category == 'siwes':
166            self.pay_item_id = '111'
167            xmldict['institution_acct'] = '0080527351'
168            xmldict['institution_bank_id'] = '11'
169        elif self.context.p_category == 'eed_1':
170            self.pay_item_id = '112'
171            xmldict['institution_acct'] = '0039782431'
172            xmldict['institution_bank_id'] = '11'
173        elif self.context.p_category == 'eed_2':
174            self.pay_item_id = '116'
175            xmldict['institution_acct'] = '0039782431'
176            xmldict['institution_bank_id'] = '11'
177        elif self.context.p_category == 'olevel_results_1':
178            self.pay_item_id = '113'
179            xmldict['institution_acct'] = '2015327204'
180            xmldict['institution_bank_id'] = '8'
181        elif self.context.p_category == 'olevel_results_2':
182            self.pay_item_id = '115'
183            xmldict['institution_acct'] = '2015327204'
184            xmldict['institution_bank_id'] = '8'
185        elif self.context.p_category == 'hostel_maintenance':
186            provider_amt = 500.0
187            self.pay_item_id = '117'
188            xmldict['institution_acct'] = '2011810353'
189            xmldict['institution_bank_id'] = '8'
190        elif self.context.p_category == 'lsfp_penalty':
191            self.pay_item_id = '102'
192            xmldict['institution_acct'] = '1012808851'
193            xmldict['institution_bank_id'] = '117'
194        elif self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
195            self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
196            provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
197            xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
198            xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
199        xmldict['provider_amt'] = 100 * provider_amt
200        xmldict['tech_fee'] = 100 * tech_fee
201        xmldict['institution_item_name'] = self.context.category
202        xmldict['institution_name'] = INSTITUTION_NAME
203        xmldict['institution_amt'] = institution_amt = 100 * (
204            self.context.amount_auth - provider_amt - tech_fee - GATEWAY_AMT)
205
206        if provider_amt == 0:
207            xmltext = """<payment_item_detail>
208<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
209<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" />
210</item_details>
211</payment_item_detail>""" % xmldict
212        elif tech_fee == 0:
213            xmltext = """<payment_item_detail>
214<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
215<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" />
216<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" />
217</item_details>
218</payment_item_detail>""" % xmldict
219        else:
220            xmltext = """<payment_item_detail>
221<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
222<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" />
223<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" />
224<item_detail item_id="3" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="10" acct_num="0032256360" />
225</item_details>
226</payment_item_detail>""" % xmldict
227
228        # isouaba: All certificates in SPAT are part time thus any payments
229        # coming from those certificates (Application, Acceptance, school fees
230        # etc) 40% should be split to keystone account.
231        # abraham: Please, kindly exclude the 40% going to Keystone bank for school of part-
232        # time (SPAT) O'level Results Verification payment.
233        if student.faccode == 'SPAT' and not self.context.p_category.startswith('olevel_results'):
234            xmldict['institution_amt_2'] = 0.4 * institution_amt
235            xmldict['institution_amt_1'] = 0.6 * institution_amt
236            if provider_amt == 0:
237                xmltext = """<payment_item_detail>
238<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
239<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" />
240<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="123" acct_num="1002883141" />
241</item_details>
242</payment_item_detail>""" % xmldict
243            elif tech_fee == 0:
244                xmltext = """<payment_item_detail>
245<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
246<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" />
247<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="123" acct_num="1002883141" />
248<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" />
249</item_details>
250</payment_item_detail>""" % xmldict
251            else:
252                xmltext = """<payment_item_detail>
253<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
254<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" />
255<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="123" acct_num="1002883141" />
256<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" />
257<item_detail item_id="4" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="10" acct_num="0032256360" />
258</item_details>
259</payment_item_detail>""" % xmldict
260
261
262        # Some payments are treated completely separately. The following lines
263        # override the configuration above.
264
265        if self.context.p_category == 'dep_sug':
266            self.pay_item_id = '102' # We use school fee item id
267            # amount_auth is being ignored. However, the sum of all split payments
268            # must coincide with the amount_auth configured in students/utils.py
269            xmldict['amt1'] = 100 * 1000
270            xmldict['amt2'] = 100 * 500
271            xmldict['amt3'] = 100 * 900
272            xmldict['amt4'] = 100 * 500
273
274            xmltext = """<payment_item_detail>
275<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
276<item_detail item_id="1" item_name="SUG" item_amt="%(amt1)d" bank_id="11" acct_num="0038079930" />
277<item_detail item_id="2" item_name="Students Welfare" item_amt="%(amt2)d" bank_id="11" acct_num="0037892949" />
278<item_detail item_id="3" item_name="Anti-Cult Book" item_amt="%(amt3)d" bank_id="11" acct_num="0037892949" />
279<item_detail item_id="4" item_name="NADESSTU" item_amt="%(amt4)d" bank_id="11" acct_num="0036375968" />
280</item_details>
281</payment_item_detail>""" % xmldict
282
283        if self.context.p_category == 'eng_1':
284            self.pay_item_id = '118'
285            xmltext = """<payment_item_detail>
286<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
287<item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="8" acct_num="2024473077" />
288</item_details>
289</payment_item_detail>""" % xmldict
290
291        if self.context.p_category == 'eng_2':
292            self.pay_item_id = '119'
293            xmltext = """<payment_item_detail>
294<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
295<item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="8" acct_num="2024473077" />
296</item_details>
297</payment_item_detail>""" % xmldict
298
299        if self.context.p_category == 'sbs_1':
300            self.pay_item_id = '120'
301            # amount_auth is being ignored. However, the sum of all split payments
302            # must coincide with the amount_auth configured in students/utils.py
303            xmldict['amt1'] = 100 * 800
304            xmldict['amt2'] = 100 * 1000
305            xmldict['amt3'] = 100 * 500
306
307            xmltext = """<payment_item_detail>
308<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
309<item_detail item_id="1" item_name="SBS Dues I" item_amt="%(amt1)d" bank_id="11" acct_num="0010772626" />
310<item_detail item_id="2" item_name="Journal fee" item_amt="%(amt2)d" bank_id="11" acct_num="0010772626" />
311<item_detail item_id="3" item_name="ABSOBS" item_amt="%(amt3)d" bank_id="8" acct_num="2008185712" />
312</item_details>
313</payment_item_detail>""" % xmldict
314
315        if self.context.p_category == 'sbs_2':
316            self.pay_item_id = '123'
317            # amount_auth is being ignored. However, the sum of all split payments
318            # must coincide with the amount_auth configured in students/utils.py
319            xmldict['amt1'] = 100 * 300
320            xmldict['amt2'] = 100 * 500
321            xmltext = """<payment_item_detail>
322<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
323<item_detail item_id="1" item_name="SBS Dues II" item_amt="%(amt1)d" bank_id="11" acct_num="0010772626" />
324<item_detail item_id="2" item_name="ABSOBS" item_amt="%(amt2)d" bank_id="8" acct_num="2008185712" />
325</item_details>
326</payment_item_detail>""" % xmldict
327
328        if self.context.p_category == 'bfn':
329            self.pay_item_id = '125'
330            xmltext = """<payment_item_detail>
331<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
332<item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="11" acct_num="0048039049" />
333</item_details>
334</payment_item_detail>""" % xmldict
335
336        if self.context.p_category == 'mkt':
337            self.pay_item_id = '127'
338            # amount_auth is being ignored. However, the sum of all split payments
339            # must coincide with the amount_auth configured in students/utils.py
340            xmldict['amt1'] = 100 * 500
341            xmldict['amt2'] = 100 * 500
342            xmltext = """<payment_item_detail>
343<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
344<item_detail item_id="1" item_name="MKT Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0048297823" />
345<item_detail item_id="2" item_name="NAMS" item_amt="%(amt2)d" bank_id="8" acct_num="2032309812" />
346</item_details>
347</payment_item_detail>""" % xmldict
348
349        if self.context.p_category == 'mcn':
350            self.pay_item_id = '129'
351            # amount_auth is being ignored. However, the sum of all split payments
352            # must coincide with the amount_auth configured in students/utils.py
353            xmldict['amt1'] = 100 * 500
354            xmldict['amt2'] = 100 * 500
355            xmltext = """<payment_item_detail>
356<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
357<item_detail item_id="1" item_name="MCN Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0010789213" />
358<item_detail item_id="2" item_name="AMCOS" item_amt="%(amt2)d" bank_id="8" acct_num="3020253234" />
359</item_details>
360</payment_item_detail>""" % xmldict
361
362        if self.context.p_category == 'otm':
363            self.pay_item_id = '131'
364            # amount_auth is being ignored. However, the sum of all split payments
365            # must coincide with the amount_auth configured in students/utils.py
366            xmldict['amt1'] = 100 * 500
367            xmldict['amt2'] = 100 * 500
368            xmltext = """<payment_item_detail>
369<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
370<item_detail item_id="1" item_name="OTM Dues" item_amt="%(amt1)d" bank_id="8" acct_num="3068446702" />
371<item_detail item_id="2" item_name="NAOTM" item_amt="%(amt2)d" bank_id="11" acct_num="0036652027" />
372</item_details>
373</payment_item_detail>""" % xmldict
374
375        if self.context.p_category == 'acct':
376            self.pay_item_id = '134'
377            # amount_auth is being ignored. However, the sum of all split payments
378            # must coincide with the amount_auth configured in students/utils.py
379            xmldict['amt1'] = 100 * 3000
380            xmldict['amt2'] = 100 * 500
381            xmldict['amt3'] = 100 * 500
382            xmltext = """<payment_item_detail>
383<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
384<item_detail item_id="1" item_name="Profession Accreditation" item_amt="%(amt1)d" bank_id="11" acct_num="0040285084" />
385<item_detail item_id="2" item_name="ACCT Dues" item_amt="%(amt2)d" bank_id="11" acct_num="0036184955" />
386<item_detail item_id="3" item_name="NAPAS" item_amt="%(amt3)d" bank_id="8" acct_num="2008498661" />
387</item_details>
388</payment_item_detail>""" % xmldict
389
390        if self.context.p_category == 'bam':
391            self.pay_item_id = '136'
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="BAM Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0010788058" />
399<item_detail item_id="2" item_name="NABAS" item_amt="%(amt2)d" bank_id="8" acct_num="2006936848" />
400</item_details>
401</payment_item_detail>""" % xmldict
402
403        if self.context.p_category == 'pom':
404            self.pay_item_id = '138'
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="POM Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0096851444" />
412<item_detail item_id="2" item_name="NAMS" item_amt="%(amt2)d" bank_id="8" acct_num="2033423003" />
413</item_details>
414</payment_item_detail>""" % xmldict
415
416        if self.context.p_category == 'hrm':
417            self.pay_item_id = '140'
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 * 500
421            xmldict['amt2'] = 100 * 500
422            xmltext = """<payment_item_detail>
423<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
424<item_detail item_id="1" item_name="HRM Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0096858546" />
425<item_detail item_id="2" item_name="NAMS" item_amt="%(amt2)d" bank_id="8" acct_num="2033423003" />
426</item_details>
427</payment_item_detail>""" % xmldict
428
429        if self.context.p_category == 'hndgrad':
430            self.pay_item_id = '153'
431            # amount_auth is being ignored. However, the sum of all split payments
432            # must coincide with the amount_auth configured in students/utils.py
433            xmldict['amt1'] = 100 * 3000
434            xmldict['amt2'] = 100 * 5000
435            xmldict['amt3'] = 100 * 1000
436            xmldict['amt4'] = 100 * 3500
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="Collection of Results" item_amt="%(amt1)d" bank_id="117" acct_num="1012808851" />
440<item_detail item_id="2" item_name="Collection of Certificate" item_amt="%(amt2)d" bank_id="117" acct_num="1012808851" />
441<item_detail item_id="3" item_name="Alumni" item_amt="%(amt3)d" bank_id="8" acct_num="2011810346" />
442<item_detail item_id="4" item_name="Convocation" item_amt="%(amt3)d" bank_id="8" acct_num="2006612782" />
443</item_details>
444</payment_item_detail>""" % xmldict
445
446        if self.context.p_category == 'ndgrad':
447            self.pay_item_id = '152'
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 * 3000
451            xmldict['amt2'] = 100 * 7500
452            xmldict['amt3'] = 100 * 1000
453            xmldict['amt4'] = 100 * 3500
454            xmltext = """<payment_item_detail>
455<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
456<item_detail item_id="1" item_name="Collection of Results" item_amt="%(amt1)d" bank_id="117" acct_num="1012808851" />
457<item_detail item_id="2" item_name="Collection of Certificate" item_amt="%(amt2)d" bank_id="117" acct_num="1012808851" />
458<item_detail item_id="3" item_name="Alumni" item_amt="%(amt3)d" bank_id="8" acct_num="2011810346" />
459<item_detail item_id="4" item_name="Convocation" item_amt="%(amt3)d" bank_id="8" acct_num="2006612782" />
460</item_details>
461</payment_item_detail>""" % xmldict
462
463        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
464        self.context.provider_amt = provider_amt
465        self.context.gateway_amt = GATEWAY_AMT
466        hashargs = (
467            self.context.p_id +
468            PRODUCT_ID +
469            self.pay_item_id +
470            str(int(self.amount_auth)) +
471            self.site_redirect_url +
472            self.mac)
473        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
474        return
475
476class CustomInterswitchPageApplicant(InterswitchPageApplicant):
477    """ View which sends a POST request to the Interswitch
478    CollegePAY payment gateway.
479    """
480    grok.context(ICustomApplicantOnlinePayment)
481    action = POST_ACTION
482    site_name = SITE_NAME
483    currency = CURRENCY
484    pay_item_id = '101' # must be provided by Interswitch
485    product_id = PRODUCT_ID
486    mac = MAC
487
488    def update(self):
489        error = self.init_update()
490        if error:
491            self.flash(error, type='danger')
492            self.redirect(self.url(self.context, '@@index'))
493            return
494        xmldict = {}
495        provider_amt = 500.0
496        gateway_amt = GATEWAY_AMT
497        xmldict['institution_acct'] = '00000000'
498        xmldict['institution_bank_id'] = '00'
499        if self.applicant.__parent__.application_category in ('ndft', 'hndft'):
500            xmldict['institution_acct'] = '0072223654'
501            xmldict['institution_bank_id'] = '121'
502        elif self.applicant.__parent__.application_category in (
503            'ndpt', 'hndpt', 'ndwe', 'hndwe'):
504            xmldict['institution_acct'] = '1015220292'
505            xmldict['institution_bank_id'] = '117'
506        elif self.applicant.__parent__.prefix == 'conv':
507            xmldict['institution_acct'] = '1012963301'
508            xmldict['institution_bank_id'] = '117'
509            self.pay_item_id = '151'
510        elif self.applicant.applicant_id.startswith('special'):
511            if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
512                self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
513                provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
514                xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
515                xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
516        if self.pay_item_id in ('122', '123', '132', '137', '141',
517                                '142', '143', '144', '146', '147',):
518                gateway_amt = round(0.015 * self.context.amount_auth, 2)
519        xmldict['detail_ref'] = self.context.p_id
520        xmldict['provider_amt'] = 100 * provider_amt
521        xmldict['provider_acct'] = PROVIDER_ACCT
522        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
523        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
524        xmldict['institution_amt'] = institution_amt = 100 * (
525            self.context.amount_auth - provider_amt - gateway_amt)
526        xmldict['institution_item_name'] = self.context.category
527        xmldict['institution_name'] = INSTITUTION_NAME
528        xmltext = """<payment_item_detail>
529<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
530<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" />
531<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" />
532</item_details>
533</payment_item_detail>""" % xmldict
534
535        # isouaba: All certificates in SPAT are part time thus any payments
536        # coming from those certificates (Application, Acceptance, school fees
537        # etc) 40% should be split to keystone account.
538        if self.applicant.__parent__.application_category in (
539            'ndpt', 'hndpt', 'ndwe', 'hndwe'):
540            xmldict['institution_amt_2'] = 0.4 * institution_amt
541            xmldict['institution_amt_1'] = 0.6 * institution_amt
542            xmltext = """<payment_item_detail>
543<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
544<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" />
545<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="123" acct_num="1002883141" />
546<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" />
547</item_details>
548</payment_item_detail>""" % xmldict
549
550        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
551        self.context.provider_amt = provider_amt
552        self.context.gateway_amt = GATEWAY_AMT
553
554        hashargs = (
555            self.context.p_id +
556            PRODUCT_ID +
557            self.pay_item_id +
558            str(int(self.amount_auth)) +
559            self.site_redirect_url +
560            self.mac)
561        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
562        return
563
564class CustomInterswitchPaymentRequestWebservicePageStudent(
565    InterswitchPaymentRequestWebservicePageStudent):
566    """Request webservice view for the CollegePAY gateway
567    """
568    grok.context(ICustomStudentOnlinePayment)
569    product_id = PRODUCT_ID
570    gateway_host = HOST
571    gateway_url = URL
572    mac = MAC
573
574class CustomInterswitchPaymentVerifyWebservicePageStudent(
575    InterswitchPaymentVerifyWebservicePageStudent):
576    """Payment verify view for the CollegePAY gateway
577    """
578    grok.context(ICustomStudentOnlinePayment)
579    product_id = PRODUCT_ID
580    gateway_host = HOST
581    gateway_url = URL
582    mac = MAC
583
584class CustomInterswitchPaymentRequestWebservicePageApplicant(
585    InterswitchPaymentRequestWebservicePageApplicant):
586    """Request webservice view for the CollegePAY gateway
587    """
588    grok.context(ICustomApplicantOnlinePayment)
589    product_id = PRODUCT_ID
590    gateway_host = HOST
591    gateway_url = URL
592    mac = MAC
593
594class CustomInterswitchPaymentVerifyWebservicePageApplicant(
595    InterswitchPaymentVerifyWebservicePageApplicant):
596    """Payment verify view for the CollegePAY gateway
597    """
598    grok.context(ICustomApplicantOnlinePayment)
599    product_id = PRODUCT_ID
600    gateway_host = HOST
601    gateway_url = URL
602    mac = MAC
Note: See TracBrowser for help on using the repository browser.