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

Last change on this file since 16418 was 16418, checked in by Henrik Bettermann, 4 years ago

Add Microsoft Academy Fee split to ND2 and HND2 schoolfee payments.

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