1 | ## $Id: browser.py 14616 2017-03-09 10:42:42Z 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 | ## |
---|
18 | import httplib |
---|
19 | import hashlib |
---|
20 | import grok |
---|
21 | from zope.interface import Interface |
---|
22 | from zope.component import queryAdapter |
---|
23 | from kofacustom.nigeria.interswitch.browser import ( |
---|
24 | InterswitchPaymentRequestWebservicePageStudent, |
---|
25 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
26 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
27 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
28 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
29 | ) |
---|
30 | from waeup.kwarapoly.students.interfaces import ICustomStudentOnlinePayment |
---|
31 | from waeup.kwarapoly.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
32 | from waeup.kwarapoly.interfaces import MessageFactory as _ |
---|
33 | |
---|
34 | PRODUCT_ID = '3930' |
---|
35 | SITE_NAME = 'kwarapoly.waeup.org' |
---|
36 | PROVIDER_ACCT = '1010764827' |
---|
37 | PROVIDER_BANK_ID = '117' |
---|
38 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
39 | INSTITUTION_NAME = 'KwaraPoly' |
---|
40 | CURRENCY = '566' |
---|
41 | GATEWAY_AMT = 300.0 |
---|
42 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
---|
43 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
---|
44 | |
---|
45 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
46 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
47 | |
---|
48 | HOST = 'webpay.interswitchng.com' |
---|
49 | #HOST = 'testwebpay.interswitchng.com' |
---|
50 | |
---|
51 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
52 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
53 | httplib.HTTPConnection.debuglevel = 0 |
---|
54 | |
---|
55 | #All special payments moved to GTBank on 15-10-2015 |
---|
56 | SPECIAL_PAYMENT_PARAMS = { |
---|
57 | 'certificate': ('111', 200.0, 300.0, '0838798044', '76'), |
---|
58 | 'state_result': ('112', 200.0, 300.0, '0838798044', '76'), |
---|
59 | 'transcript_local': ('113', 200.0, 300.0, '0838798044', '76'), |
---|
60 | 'transcript_foreign': ('114', 200.0, 300.0, '0838798044', '76'), |
---|
61 | 'ver_result': ('115', 200.0, 300.0, '0838798044', '76'), |
---|
62 | 'change_course': ('116', 200.0, 300.0, '0838798044', '76'), |
---|
63 | 'change_inst': ('117', 200.0, 300.0, '0838798044', '76'), |
---|
64 | 'jamb_reject': ('118', 200.0, 300.0, '0838798044', '76'), |
---|
65 | 'cert_of_cert': ('119', 200.0, 300.0, '0838798044', '76'), |
---|
66 | 'ref_let': ('120', 200.0, 300.0, '0838798044', '76'), |
---|
67 | 'proc_cert': ('121', 200.0, 300.0, '0838798044', '76'), |
---|
68 | 'loss_idcard': ('122', 6.0, 9.0, '0838798044', '76'), |
---|
69 | 'loss_examcard': ('123', 3.0, 4.5, '0838798044', '76'), |
---|
70 | 'loss_result': ('124', 200.0, 300.0, '0838798044', '76'), |
---|
71 | 'loss_receipt': ('125', 200.0, 300.0, '0838798044', '76'), |
---|
72 | 'loss_clearance': ('126', 200.0, 300.0, '0838798044', '76'), |
---|
73 | 'conv_brochure': ('127', 200.0, 300.0, '0838798044', '76'), |
---|
74 | 'hnd_certificate': ('128', 200.0, 300.0, '0838798044', '76'), |
---|
75 | 'hnd_state_result': ('129', 200.0, 300.0, '0838798044', '76'), |
---|
76 | 'hnd_transcript_local': ('130', 200.0, 300.0, '0838798044', '76'), |
---|
77 | 'hnd_transcript_foreign': ('131', 200.0, 300.0, '0838798044', '76'), |
---|
78 | 'staff_loss_idcard': ('132', 6.0, 9.0, '0838798044', '76'), |
---|
79 | 'hnd_conv_brochure': ('133', 200.0, 300.0, '0838798044', '76'), |
---|
80 | 'pgd_state_result': ('134', 200.0, 300.0, '0838798044', '76'), |
---|
81 | 'pgd_conv_brochure': ('135', 200.0, 300.0, '0838798044', '76'), |
---|
82 | 'pgd_certificate': ('136', 200.0, 300.0, '0838798044', '76'), |
---|
83 | 'log_book': ('137', 3.0, 4.5, '0838798044', '76'), |
---|
84 | 'pgd_transcript_foreign': ('138', 200.0, 300.0, '0838798044', '76'), |
---|
85 | 'pgd_transcript_local': ('139', 200.0, 300.0, '0838798044', '76'), |
---|
86 | 'jamb_regularization': ('140', 200.0, 300.0, '0838798044', '76'), |
---|
87 | 'utme_registration': ('142', 6.0, 9.0, '0838798044', '76'), |
---|
88 | 'utme_cbt': ('143', 6.0, 9.0, '0838798044', '76'), |
---|
89 | 'nysc_id_card': ('144', 6.0, 9.0, '0838798044', '76'), |
---|
90 | 'ijmb_result': ('147', 200.0, 300.0, '0838798044', '76'), |
---|
91 | } |
---|
92 | |
---|
93 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
94 | """ View which sends a POST request to the Interswitch |
---|
95 | CollegePAY payment gateway. |
---|
96 | """ |
---|
97 | grok.context(ICustomStudentOnlinePayment) |
---|
98 | grok.template('student_goto_interswitch') |
---|
99 | action = POST_ACTION |
---|
100 | site_name = SITE_NAME |
---|
101 | currency = CURRENCY |
---|
102 | product_id = PRODUCT_ID |
---|
103 | mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D' |
---|
104 | |
---|
105 | def update(self): |
---|
106 | error = self.init_update() |
---|
107 | if error: |
---|
108 | self.flash(error, type='danger') |
---|
109 | self.redirect(self.url(self.context, '@@index')) |
---|
110 | return |
---|
111 | student = self.student |
---|
112 | xmldict = self.xmldict |
---|
113 | # Provider data |
---|
114 | xmldict['detail_ref'] = self.context.p_id |
---|
115 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
116 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
117 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
118 | # Institution data |
---|
119 | xmldict['institution_item_name'] = self.category |
---|
120 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
121 | xmldict['institution_amt'] = 0.0 |
---|
122 | dalash_amt = 200.0 |
---|
123 | provider_amt = 300.0 |
---|
124 | gateway_amt = GATEWAY_AMT |
---|
125 | self.pay_item_id = '000' |
---|
126 | xmldict['institution_acct'] = '0838798044' |
---|
127 | xmldict['institution_bank_id'] = '76' |
---|
128 | if self.context.p_item == 'Balance': |
---|
129 | self.pay_item_id = '000' |
---|
130 | dalash_amt = 0.0 |
---|
131 | provider_amt = 0.0 |
---|
132 | xmldict['institution_acct'] = '0838798044' |
---|
133 | xmldict['institution_bank_id'] = '76' |
---|
134 | elif self.context.p_category == 'schoolfee' \ |
---|
135 | or self.context.p_category.startswith('carryover'): |
---|
136 | self.pay_item_id = '101' |
---|
137 | dalash_amt = 1800.0 |
---|
138 | provider_amt = 1200.0 |
---|
139 | if not student.current_mode.endswith('_we'): |
---|
140 | if xmldict['faculty'] in ('CPGS',): |
---|
141 | xmldict['institution_acct'] = '0838798044' |
---|
142 | xmldict['institution_bank_id'] = '76' |
---|
143 | elif xmldict['faculty'] in ('IAS',): |
---|
144 | xmldict['institution_acct'] = '0838798044' |
---|
145 | xmldict['institution_bank_id'] = '76' |
---|
146 | self.pay_item_id = '107' |
---|
147 | elif xmldict['faculty'] in ('IES',): |
---|
148 | xmldict['institution_acct'] = '0838798044' |
---|
149 | xmldict['institution_bank_id'] = '76' |
---|
150 | self.pay_item_id = '109' |
---|
151 | elif xmldict['faculty'] in ('IFMS',): |
---|
152 | xmldict['institution_acct'] = '0838798044' |
---|
153 | xmldict['institution_bank_id'] = '76' |
---|
154 | self.pay_item_id = '106' |
---|
155 | elif xmldict['faculty'] in ('IOT',): |
---|
156 | xmldict['institution_acct'] = '0838798044' |
---|
157 | xmldict['institution_bank_id'] = '76' |
---|
158 | self.pay_item_id = '110' |
---|
159 | elif xmldict['faculty'] in ('IICT',): |
---|
160 | xmldict['institution_acct'] = '0838798044' |
---|
161 | xmldict['institution_bank_id'] = '76' |
---|
162 | self.pay_item_id = '108' |
---|
163 | else: |
---|
164 | xmldict['institution_acct'] = '0838798044' |
---|
165 | xmldict['institution_bank_id'] = '76' |
---|
166 | #Introduce a pay_item_id for part-time for the first time on this portal |
---|
167 | self.pay_item_id = '145' |
---|
168 | elif self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys(): |
---|
169 | self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0] |
---|
170 | dalash_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1] |
---|
171 | provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2] |
---|
172 | xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3] |
---|
173 | xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][4] |
---|
174 | elif 'maintenance' in self.context.p_category: |
---|
175 | self.pay_item_id = '102' |
---|
176 | xmldict['institution_acct'] = '0838798044' |
---|
177 | xmldict['institution_bank_id'] = '76' |
---|
178 | dalash_amt = 0.0 |
---|
179 | provider_amt = 0.0 |
---|
180 | elif 'clearance' in self.context.p_category: |
---|
181 | self.pay_item_id = '146' |
---|
182 | xmldict['institution_acct'] = '0838798044' |
---|
183 | xmldict['institution_bank_id'] = '76' |
---|
184 | else: |
---|
185 | xmldict['institution_acct'] = "0000000000000" |
---|
186 | xmldict['institution_bank_id'] = '0' |
---|
187 | |
---|
188 | if self.pay_item_id in ('122', '123', '132', '137', '141', |
---|
189 | '142', '143', '144', '146', '147',): |
---|
190 | gateway_amt = round(0.015 * self.context.amount_auth, 2) |
---|
191 | |
---|
192 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
193 | xmldict['provider_amt'] = 100 * provider_amt |
---|
194 | xmldict['institution_amt'] = 100 * ( |
---|
195 | self.context.amount_auth - provider_amt - |
---|
196 | gateway_amt - dalash_amt) |
---|
197 | |
---|
198 | hashargs = ( |
---|
199 | self.context.p_id + |
---|
200 | PRODUCT_ID + |
---|
201 | self.pay_item_id + |
---|
202 | str(int(self.amount_auth)) + |
---|
203 | self.site_redirect_url + |
---|
204 | self.mac) |
---|
205 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
206 | |
---|
207 | # Interswitch amount is not part of the xml data |
---|
208 | |
---|
209 | if 'maintenance' in self.context.p_category \ |
---|
210 | or self.context.p_item == 'Balance': |
---|
211 | xmltext = """<payment_item_detail> |
---|
212 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
213 | <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" /> |
---|
214 | </item_details> |
---|
215 | </payment_item_detail>""" % xmldict |
---|
216 | |
---|
217 | else: |
---|
218 | xmltext = """<payment_item_detail> |
---|
219 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
220 | <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" /> |
---|
221 | <item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" /> |
---|
222 | <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" /> |
---|
223 | </item_details> |
---|
224 | </payment_item_detail>""" % xmldict |
---|
225 | |
---|
226 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
227 | self.context.provider_amt = provider_amt |
---|
228 | self.context.gateway_amt = gateway_amt |
---|
229 | self.context.thirdparty_amt = dalash_amt |
---|
230 | return |
---|
231 | |
---|
232 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
233 | """ View which sends a POST request to the Interswitch |
---|
234 | CollegePAY payment gateway. |
---|
235 | """ |
---|
236 | grok.context(ICustomApplicantOnlinePayment) |
---|
237 | grok.template('applicant_goto_interswitch') |
---|
238 | action = POST_ACTION |
---|
239 | site_name = SITE_NAME |
---|
240 | currency = CURRENCY |
---|
241 | pay_item_id = '103' |
---|
242 | product_id = PRODUCT_ID |
---|
243 | mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D' |
---|
244 | |
---|
245 | def update(self): |
---|
246 | error = self.init_update() |
---|
247 | if error: |
---|
248 | self.flash(error, type='danger') |
---|
249 | self.redirect(self.url(self.context, '@@index')) |
---|
250 | return |
---|
251 | xmldict = {} |
---|
252 | provider_amt = 300.0 |
---|
253 | dalash_amt = 200.0 |
---|
254 | gateway_amt = GATEWAY_AMT |
---|
255 | xmldict['institution_acct'] = '00000000000' |
---|
256 | xmldict['institution_bank_id'] = '00' |
---|
257 | if self.applicant.applicant_id.startswith('hnd'): |
---|
258 | xmldict['institution_acct'] = '0838798044' |
---|
259 | xmldict['institution_bank_id'] = '76' |
---|
260 | elif self.applicant.applicant_id.startswith('nd'): |
---|
261 | xmldict['institution_acct'] = '0838798044' |
---|
262 | xmldict['institution_bank_id'] = '76' |
---|
263 | elif self.applicant.applicant_id.startswith('rmd'): |
---|
264 | xmldict['institution_acct'] = '0838798044' |
---|
265 | xmldict['institution_bank_id'] = '76' |
---|
266 | elif self.applicant.applicant_id.startswith('pgft'): |
---|
267 | xmldict['institution_acct'] = '0838798044' |
---|
268 | xmldict['institution_bank_id'] = '76' |
---|
269 | elif self.applicant.applicant_id.startswith('putme'): |
---|
270 | xmldict['institution_acct'] = '0838798044' |
---|
271 | xmldict['institution_bank_id'] = '76' |
---|
272 | self.pay_item_id = '104' |
---|
273 | elif self.applicant.applicant_id.startswith('pre'): |
---|
274 | xmldict['institution_acct'] = '0838798044' |
---|
275 | xmldict['institution_bank_id'] = '76' |
---|
276 | provider_amt = 262.5 |
---|
277 | dalash_amt = 0.0 |
---|
278 | gateway_amt = 37.5 |
---|
279 | self.pay_item_id = '104' |
---|
280 | elif self.applicant.applicant_id.startswith('special'): |
---|
281 | if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys(): |
---|
282 | self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0] |
---|
283 | dalash_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1] |
---|
284 | provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2] |
---|
285 | xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3] |
---|
286 | xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][4] |
---|
287 | |
---|
288 | if self.pay_item_id in ('122', '123', '132', '137', '141', |
---|
289 | '142', '143', '144', '146', '147',): |
---|
290 | gateway_amt = round(0.015 * self.context.amount_auth, 2) |
---|
291 | |
---|
292 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
293 | xmldict['detail_ref'] = self.context.p_id |
---|
294 | xmldict['provider_amt'] = 100 * provider_amt |
---|
295 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
296 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
297 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
298 | xmldict['institution_amt'] = 100 * ( |
---|
299 | self.context.amount_auth - provider_amt - gateway_amt - dalash_amt) |
---|
300 | xmldict['institution_item_name'] = self.category |
---|
301 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
302 | |
---|
303 | hashargs = ( |
---|
304 | self.context.p_id + |
---|
305 | PRODUCT_ID + |
---|
306 | self.pay_item_id + |
---|
307 | str(int(self.amount_auth)) + |
---|
308 | self.site_redirect_url + |
---|
309 | self.mac) |
---|
310 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
311 | |
---|
312 | # Interswitch amount is not part of the xml data |
---|
313 | |
---|
314 | xmltext = """<payment_item_detail> |
---|
315 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
316 | <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" /> |
---|
317 | <item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" /> |
---|
318 | <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" /> |
---|
319 | </item_details> |
---|
320 | </payment_item_detail>""" % xmldict |
---|
321 | |
---|
322 | if self.applicant.applicant_id.startswith('pre'): |
---|
323 | xmltext = """<payment_item_detail> |
---|
324 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
325 | <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" /> |
---|
326 | <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" /> |
---|
327 | </item_details> |
---|
328 | </payment_item_detail>""" % xmldict |
---|
329 | |
---|
330 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
331 | self.context.provider_amt = provider_amt |
---|
332 | self.context.gateway_amt = gateway_amt |
---|
333 | self.context.thirdparty_amt = dalash_amt |
---|
334 | return |
---|
335 | |
---|
336 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
337 | InterswitchPaymentRequestWebservicePageStudent): |
---|
338 | """Request webservice view for the CollegePAY gateway |
---|
339 | """ |
---|
340 | grok.context(ICustomStudentOnlinePayment) |
---|
341 | product_id = PRODUCT_ID |
---|
342 | gateway_host = HOST |
---|
343 | gateway_url = URL |
---|
344 | |
---|
345 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
346 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
347 | """Payment verify view for the CollegePAY gateway |
---|
348 | """ |
---|
349 | grok.context(ICustomStudentOnlinePayment) |
---|
350 | product_id = PRODUCT_ID |
---|
351 | gateway_host = HOST |
---|
352 | gateway_url = URL |
---|
353 | |
---|
354 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
355 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
356 | """Request webservice view for the CollegePAY gateway |
---|
357 | """ |
---|
358 | grok.context(ICustomApplicantOnlinePayment) |
---|
359 | product_id = PRODUCT_ID |
---|
360 | gateway_host = HOST |
---|
361 | gateway_url = URL |
---|
362 | |
---|
363 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
364 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
365 | """Payment verify view for the CollegePAY gateway |
---|
366 | """ |
---|
367 | grok.context(ICustomApplicantOnlinePayment) |
---|
368 | product_id = PRODUCT_ID |
---|
369 | gateway_host = HOST |
---|
370 | gateway_url = URL |
---|