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

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

Implement GNS Pack payments. This is a good example how sophisticated such requirements are.

  • Property svn:keywords set to Id
File size: 32.0 KB
Line 
1## $Id: browser.py 16309 2020-11-10 14:33:53Z 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, '1012808851', '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        self.context.r_company = u'interswitch'
126        student = self.student
127        xmldict = self.xmldict
128        # Provider data
129        xmldict['detail_ref'] = self.context.p_id
130        xmldict['provider_acct'] = PROVIDER_ACCT
131        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
132        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
133        # Institution data
134        xmldict['institution_acct'] = '00000000'
135        xmldict['institution_bank_id'] = '00'
136        xmldict['institution_amt'] = '0.0'
137        provider_amt = 0.0
138        tech_fee = 0.0
139        if self.context.p_category.startswith('schoolfee'):
140            self.pay_item_id = '102'
141            if self.context.p_item != 'Balance':
142                provider_amt = 2800.0
143                tech_fee = 1200.0
144            if student.faccode == 'SPAT':
145                xmldict['institution_acct'] = '1015220292'
146                xmldict['institution_bank_id'] = '117'
147            elif student.current_mode in ('nd_ft', 'hnd_ft'):
148                xmldict['institution_acct'] = '1012808851'
149                xmldict['institution_bank_id'] = '117'
150        elif self.context.p_category == 'clearance':
151            self.pay_item_id = '103'
152            if self.context.p_item != 'Balance':
153                provider_amt = 500.0
154            if student.faccode == 'SPAT':
155                xmldict['institution_acct'] = '1015220292'
156                xmldict['institution_bank_id'] = '117'
157            elif student.current_mode in ('nd_ft', 'hnd_ft'):
158                xmldict['institution_acct'] = '0072223654'
159                xmldict['institution_bank_id'] = '121'
160        elif self.context.p_category == 'gown':
161            self.pay_item_id = '102' # We use school fee item id.
162            xmldict['institution_acct'] = '2006612782'
163            xmldict['institution_bank_id'] = '8'
164        elif self.context.p_category == 'sports':
165            self.pay_item_id = '110'
166            xmldict['institution_acct'] = '6060300688'
167            xmldict['institution_bank_id'] = '51'
168        elif self.context.p_category == 'siwes':
169            self.pay_item_id = '111'
170            xmldict['institution_acct'] = '0080527351'
171            xmldict['institution_bank_id'] = '11'
172        elif self.context.p_category == 'eed_1':
173            self.pay_item_id = '112'
174            xmldict['institution_acct'] = '0039782431'
175            xmldict['institution_bank_id'] = '11'
176        elif self.context.p_category == 'eed_2':
177            self.pay_item_id = '116'
178            xmldict['institution_acct'] = '0039782431'
179            xmldict['institution_bank_id'] = '11'
180        elif self.context.p_category == 'olevel_results_1':
181            self.pay_item_id = '113'
182            xmldict['institution_acct'] = '2015327204'
183            xmldict['institution_bank_id'] = '8'
184        elif self.context.p_category == 'olevel_results_2':
185            self.pay_item_id = '115'
186            xmldict['institution_acct'] = '2015327204'
187            xmldict['institution_bank_id'] = '8'
188        elif self.context.p_category == 'gns_1':
189            self.pay_item_id = '154'
190            xmldict['institution_acct'] = '2017447652'
191            xmldict['institution_bank_id'] = '8'
192        elif self.context.p_category == 'gns_2':
193            self.pay_item_id = '155'
194            xmldict['institution_acct'] = '2017447652'
195            xmldict['institution_bank_id'] = '8'
196        elif self.context.p_category == 'hostel_maintenance':
197            if self.context.p_item != 'Balance':
198                provider_amt = 500.0
199            self.pay_item_id = '117'
200            xmldict['institution_acct'] = '2011810353'
201            xmldict['institution_bank_id'] = '8'
202        elif self.context.p_category == 'lsfp_penalty':
203            self.pay_item_id = '102'
204            xmldict['institution_acct'] = '1012808851'
205            xmldict['institution_bank_id'] = '117'
206        elif self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
207            self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
208            provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
209            xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
210            xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
211        xmldict['provider_amt'] = 100 * provider_amt
212        xmldict['tech_fee'] = 100 * tech_fee
213        xmldict['institution_item_name'] = self.context.category
214        xmldict['institution_name'] = INSTITUTION_NAME
215        xmldict['institution_amt'] = institution_amt = 100 * (
216            self.context.amount_auth - provider_amt - tech_fee - GATEWAY_AMT)
217
218        if provider_amt == 0:
219            xmltext = """<payment_item_detail>
220<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
221<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" />
222</item_details>
223</payment_item_detail>""" % xmldict
224        elif tech_fee == 0:
225            xmltext = """<payment_item_detail>
226<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
227<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" />
228<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" />
229</item_details>
230</payment_item_detail>""" % xmldict
231        else:
232            xmltext = """<payment_item_detail>
233<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
234<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" />
235<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" />
236<item_detail item_id="3" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="10" acct_num="0032256360" />
237</item_details>
238</payment_item_detail>""" % xmldict
239
240        # isouaba: All certificates in SPAT are part time thus any payments
241        # coming from those certificates (Application, Acceptance, school fees
242        # etc) 40% should be split to keystone account.
243        # abraham: Please, kindly exclude the 40% going to Keystone bank for school of part-
244        # time (SPAT) O'level Results Verification payment.
245        if student.faccode == 'SPAT' and not self.context.p_category.startswith('olevel_results'):
246            xmldict['institution_amt_2'] = 0.4 * institution_amt
247            xmldict['institution_amt_1'] = 0.6 * institution_amt
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 1" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
252<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="8" acct_num="2034761924" />
253</item_details>
254</payment_item_detail>""" % xmldict
255            elif tech_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 1" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
259<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="8" acct_num="2034761924" />
260<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" />
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 1" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
267<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="8" acct_num="2034761924" />
268<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" />
269<item_detail item_id="4" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="10" acct_num="0032256360" />
270</item_details>
271</payment_item_detail>""" % xmldict
272
273
274        # Some payments are treated completely separately. The following lines
275        # override the configuration above.
276
277        if self.context.p_category == 'dep_sug':
278            self.pay_item_id = '102' # We use school fee item id
279            # amount_auth is being ignored. However, the sum of all split payments
280            # must coincide with the amount_auth configured in students/utils.py
281            xmldict['amt1'] = 100 * 1000
282            xmldict['amt2'] = 100 * 500
283            xmldict['amt3'] = 100 * 900
284            xmldict['amt4'] = 100 * 500
285
286            xmltext = """<payment_item_detail>
287<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
288<item_detail item_id="1" item_name="SUG" item_amt="%(amt1)d" bank_id="11" acct_num="0038079930" />
289<item_detail item_id="2" item_name="Students Welfare" item_amt="%(amt2)d" bank_id="11" acct_num="0037892949" />
290<item_detail item_id="3" item_name="Anti-Cult Book" item_amt="%(amt3)d" bank_id="11" acct_num="0037892949" />
291<item_detail item_id="4" item_name="NADESSTU" item_amt="%(amt4)d" bank_id="11" acct_num="0036375968" />
292</item_details>
293</payment_item_detail>""" % xmldict
294
295        if self.context.p_category == 'eng_1':
296            self.pay_item_id = '118'
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" item_amt="%(institution_amt)d" bank_id="8" acct_num="2024473077" />
300</item_details>
301</payment_item_detail>""" % xmldict
302
303        if self.context.p_category == 'eng_2':
304            self.pay_item_id = '119'
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" item_amt="%(institution_amt)d" bank_id="8" acct_num="2024473077" />
308</item_details>
309</payment_item_detail>""" % xmldict
310
311        if self.context.p_category == 'sbs_1':
312            self.pay_item_id = '120'
313            # amount_auth is being ignored. However, the sum of all split payments
314            # must coincide with the amount_auth configured in students/utils.py
315            xmldict['amt1'] = 100 * 800
316            xmldict['amt2'] = 100 * 1000
317            xmldict['amt3'] = 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="SBS Dues I" item_amt="%(amt1)d" bank_id="11" acct_num="0010772626" />
322<item_detail item_id="2" item_name="Journal fee" item_amt="%(amt2)d" bank_id="11" acct_num="0010772626" />
323<item_detail item_id="3" item_name="ABSOBS" item_amt="%(amt3)d" bank_id="8" acct_num="2008185712" />
324</item_details>
325</payment_item_detail>""" % xmldict
326
327        if self.context.p_category == 'sbs_2':
328            self.pay_item_id = '123'
329            # amount_auth is being ignored. However, the sum of all split payments
330            # must coincide with the amount_auth configured in students/utils.py
331            xmldict['amt1'] = 100 * 300
332            xmldict['amt2'] = 100 * 500
333            xmltext = """<payment_item_detail>
334<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
335<item_detail item_id="1" item_name="SBS Dues II" item_amt="%(amt1)d" bank_id="11" acct_num="0010772626" />
336<item_detail item_id="2" item_name="ABSOBS" item_amt="%(amt2)d" bank_id="8" acct_num="2008185712" />
337</item_details>
338</payment_item_detail>""" % xmldict
339
340        if self.context.p_category == 'bfn':
341            self.pay_item_id = '125'
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="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="11" acct_num="0048039049" />
345</item_details>
346</payment_item_detail>""" % xmldict
347
348        if self.context.p_category == 'mkt':
349            self.pay_item_id = '127'
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 * 500
353            xmldict['amt2'] = 100 * 500
354            xmltext = """<payment_item_detail>
355<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
356<item_detail item_id="1" item_name="MKT Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0048297823" />
357<item_detail item_id="2" item_name="NAMS" item_amt="%(amt2)d" bank_id="8" acct_num="2032309812" />
358</item_details>
359</payment_item_detail>""" % xmldict
360
361        if self.context.p_category == 'mcn':
362            self.pay_item_id = '129'
363            # amount_auth is being ignored. However, the sum of all split payments
364            # must coincide with the amount_auth configured in students/utils.py
365            xmldict['amt1'] = 100 * 500
366            xmldict['amt2'] = 100 * 500
367            xmltext = """<payment_item_detail>
368<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
369<item_detail item_id="1" item_name="MCN Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0010789213" />
370<item_detail item_id="2" item_name="AMCOS" item_amt="%(amt2)d" bank_id="8" acct_num="3020253234" />
371</item_details>
372</payment_item_detail>""" % xmldict
373
374        if self.context.p_category == 'otm':
375            self.pay_item_id = '131'
376            # amount_auth is being ignored. However, the sum of all split payments
377            # must coincide with the amount_auth configured in students/utils.py
378            xmldict['amt1'] = 100 * 500
379            xmldict['amt2'] = 100 * 500
380            xmltext = """<payment_item_detail>
381<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
382<item_detail item_id="1" item_name="OTM Dues" item_amt="%(amt1)d" bank_id="8" acct_num="3068446702" />
383<item_detail item_id="2" item_name="NAOTM" item_amt="%(amt2)d" bank_id="11" acct_num="0036652027" />
384</item_details>
385</payment_item_detail>""" % xmldict
386
387        if self.context.p_category == 'acct':
388            self.pay_item_id = '134'
389            # amount_auth is being ignored. However, the sum of all split payments
390            # must coincide with the amount_auth configured in students/utils.py
391            xmldict['amt1'] = 100 * 3000
392            xmldict['amt2'] = 100 * 500
393            xmldict['amt3'] = 100 * 500
394            xmltext = """<payment_item_detail>
395<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
396<item_detail item_id="1" item_name="Profession Accreditation" item_amt="%(amt1)d" bank_id="11" acct_num="0040285084" />
397<item_detail item_id="2" item_name="ACCT Dues" item_amt="%(amt2)d" bank_id="11" acct_num="0036184955" />
398<item_detail item_id="3" item_name="NAPAS" item_amt="%(amt3)d" bank_id="8" acct_num="2008498661" />
399</item_details>
400</payment_item_detail>""" % xmldict
401
402        if self.context.p_category == 'bam':
403            self.pay_item_id = '136'
404            # amount_auth is being ignored. However, the sum of all split payments
405            # must coincide with the amount_auth configured in students/utils.py
406            xmldict['amt1'] = 100 * 500
407            xmldict['amt2'] = 100 * 500
408            xmltext = """<payment_item_detail>
409<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
410<item_detail item_id="1" item_name="BAM Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0010788058" />
411<item_detail item_id="2" item_name="NABAS" item_amt="%(amt2)d" bank_id="8" acct_num="2006936848" />
412</item_details>
413</payment_item_detail>""" % xmldict
414
415        if self.context.p_category == 'pom':
416            self.pay_item_id = '138'
417            # amount_auth is being ignored. However, the sum of all split payments
418            # must coincide with the amount_auth configured in students/utils.py
419            xmldict['amt1'] = 100 * 500
420            xmldict['amt2'] = 100 * 500
421            xmltext = """<payment_item_detail>
422<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
423<item_detail item_id="1" item_name="POM Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0096851444" />
424<item_detail item_id="2" item_name="NAMS" item_amt="%(amt2)d" bank_id="8" acct_num="2033423003" />
425</item_details>
426</payment_item_detail>""" % xmldict
427
428        if self.context.p_category == 'hrm':
429            self.pay_item_id = '140'
430            # amount_auth is being ignored. However, the sum of all split payments
431            # must coincide with the amount_auth configured in students/utils.py
432            xmldict['amt1'] = 100 * 500
433            xmldict['amt2'] = 100 * 500
434            xmltext = """<payment_item_detail>
435<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
436<item_detail item_id="1" item_name="HRM Dues" item_amt="%(amt1)d" bank_id="11" acct_num="0096858546" />
437<item_detail item_id="2" item_name="NAMS" item_amt="%(amt2)d" bank_id="8" acct_num="2033423003" />
438</item_details>
439</payment_item_detail>""" % xmldict
440
441        if self.context.p_category == 'ndgrad':
442            self.pay_item_id = '152'
443            # amount_auth is being ignored. However, the sum of all split payments
444            # must coincide with the amount_auth configured in students/utils.py
445            xmldict['amt1'] = 100 * 3000
446            xmldict['amt2'] = 100 * 5000
447            xmldict['amt3'] = 100 * 1000
448            xmldict['amt4'] = 100 * 3500
449            xmltext = """<payment_item_detail>
450<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
451<item_detail item_id="1" item_name="Collection of Results" item_amt="%(amt1)d" bank_id="117" acct_num="1012808851" />
452<item_detail item_id="2" item_name="Collection of Certificate" item_amt="%(amt2)d" bank_id="117" acct_num="1012808851" />
453<item_detail item_id="3" item_name="Alumni" item_amt="%(amt3)d" bank_id="8" acct_num="2011810346" />
454<item_detail item_id="4" item_name="Convocation" item_amt="%(amt4)d" bank_id="8" acct_num="2006612782" />
455</item_details>
456</payment_item_detail>""" % xmldict
457
458        if self.context.p_category == 'hndgrad':
459            self.pay_item_id = '153'
460            # amount_auth is being ignored. However, the sum of all split payments
461            # must coincide with the amount_auth configured in students/utils.py
462            xmldict['amt1'] = 100 * 5000
463            xmldict['amt2'] = 100 * 7500
464            xmldict['amt3'] = 100 * 1000
465            xmldict['amt4'] = 100 * 3500
466            xmltext = """<payment_item_detail>
467<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
468<item_detail item_id="1" item_name="Collection of Results" item_amt="%(amt1)d" bank_id="117" acct_num="1012808851" />
469<item_detail item_id="2" item_name="Collection of Certificate" item_amt="%(amt2)d" bank_id="117" acct_num="1012808851" />
470<item_detail item_id="3" item_name="Alumni" item_amt="%(amt3)d" bank_id="8" acct_num="2011810346" />
471<item_detail item_id="4" item_name="Convocation" item_amt="%(amt4)d" bank_id="8" acct_num="2006612782" />
472</item_details>
473</payment_item_detail>""" % xmldict
474
475        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
476        self.context.provider_amt = provider_amt
477        self.context.gateway_amt = GATEWAY_AMT
478        self.amount_auth = int(100 * self.context.amount_auth)
479        hashargs = (
480            self.context.p_id +
481            PRODUCT_ID +
482            self.pay_item_id +
483            str(int(self.amount_auth)) +
484            self.site_redirect_url +
485            self.mac)
486        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
487        return
488
489class CustomInterswitchPageApplicant(InterswitchPageApplicant):
490    """ View which sends a POST request to the Interswitch
491    CollegePAY payment gateway.
492    """
493    grok.context(ICustomApplicantOnlinePayment)
494    action = POST_ACTION
495    site_name = SITE_NAME
496    currency = CURRENCY
497    pay_item_id = '101' # must be provided by Interswitch
498    product_id = PRODUCT_ID
499    mac = MAC
500
501    def update(self):
502        error = self.init_update()
503        if error:
504            self.flash(error, type='danger')
505            self.redirect(self.url(self.context, '@@index'))
506            return
507        self.context.r_company = u'interswitch'
508        xmldict = {}
509        provider_amt = 500.0
510        gateway_amt = GATEWAY_AMT
511        xmldict['institution_acct'] = '00000000'
512        xmldict['institution_bank_id'] = '00'
513        if self.applicant.__parent__.application_category in ('ndft', 'hndft'):
514            xmldict['institution_acct'] = '0072223654'
515            xmldict['institution_bank_id'] = '121'
516        elif self.applicant.__parent__.application_category in (
517            'ndpt', 'hndpt', 'ndwe', 'hndwe'):
518            xmldict['institution_acct'] = '1015220292'
519            xmldict['institution_bank_id'] = '117'
520        elif self.applicant.__parent__.prefix in ('conv', 'hndfincl', 'ndfincl'):
521            xmldict['institution_acct'] = '1012808851'
522            xmldict['institution_bank_id'] = '117'
523            self.pay_item_id = '151'
524        elif self.applicant.applicant_id.startswith('special'):
525            if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
526                self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
527                provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
528                xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
529                xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
530        if self.pay_item_id in ('122', '123', '132', '137', '141',
531                                '142', '143', '144', '146', '147',):
532                gateway_amt = round(0.015 * self.context.amount_auth, 2)
533        xmldict['detail_ref'] = self.context.p_id
534        xmldict['provider_amt'] = 100 * provider_amt
535        xmldict['provider_acct'] = PROVIDER_ACCT
536        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
537        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
538        xmldict['institution_amt'] = institution_amt = 100 * (
539            self.context.amount_auth - provider_amt - gateway_amt)
540        xmldict['institution_item_name'] = self.context.category
541        xmldict['institution_name'] = INSTITUTION_NAME
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" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
545<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" />
546</item_details>
547</payment_item_detail>""" % xmldict
548
549        # isouaba: All certificates in SPAT are part time thus any payments
550        # coming from those certificates (Application, Acceptance, school fees
551        # etc) 40% should be split to keystone account.
552        if self.applicant.__parent__.application_category in (
553            'ndpt', 'hndpt', 'ndwe', 'hndwe'):
554            xmldict['institution_amt_2'] = 0.4 * institution_amt
555            xmldict['institution_amt_1'] = 0.6 * institution_amt
556            xmltext = """<payment_item_detail>
557<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
558<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" />
559<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="8" acct_num="2034761924" />
560<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" />
561</item_details>
562</payment_item_detail>""" % xmldict
563
564        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
565        self.context.provider_amt = provider_amt
566        self.context.gateway_amt = GATEWAY_AMT
567        self.amount_auth = int(100 * self.context.amount_auth)
568        hashargs = (
569            self.context.p_id +
570            PRODUCT_ID +
571            self.pay_item_id +
572            str(int(self.amount_auth)) +
573            self.site_redirect_url +
574            self.mac)
575        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
576        return
577
578class CustomInterswitchPaymentRequestWebservicePageStudent(
579    InterswitchPaymentRequestWebservicePageStudent):
580    """Request webservice view for the CollegePAY gateway
581    """
582    grok.context(ICustomStudentOnlinePayment)
583    product_id = PRODUCT_ID
584    gateway_host = HOST
585    gateway_url = URL
586    mac = MAC
587
588class CustomInterswitchPaymentVerifyWebservicePageStudent(
589    InterswitchPaymentVerifyWebservicePageStudent):
590    """Payment verify view for the CollegePAY gateway
591    """
592    grok.context(ICustomStudentOnlinePayment)
593    product_id = PRODUCT_ID
594    gateway_host = HOST
595    gateway_url = URL
596    mac = MAC
597
598class CustomInterswitchPaymentRequestWebservicePageApplicant(
599    InterswitchPaymentRequestWebservicePageApplicant):
600    """Request webservice view for the CollegePAY gateway
601    """
602    grok.context(ICustomApplicantOnlinePayment)
603    product_id = PRODUCT_ID
604    gateway_host = HOST
605    gateway_url = URL
606    mac = MAC
607
608class CustomInterswitchPaymentVerifyWebservicePageApplicant(
609    InterswitchPaymentVerifyWebservicePageApplicant):
610    """Payment verify view for the CollegePAY gateway
611    """
612    grok.context(ICustomApplicantOnlinePayment)
613    product_id = PRODUCT_ID
614    gateway_host = HOST
615    gateway_url = URL
616    mac = MAC
Note: See TracBrowser for help on using the repository browser.