1 | ## $Id: browser.py 11683 2014-06-11 14:38:25Z 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 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
27 | ) |
---|
28 | from waeup.kwarapoly.students.interfaces import ICustomStudentOnlinePayment |
---|
29 | from waeup.kwarapoly.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
30 | from waeup.kwarapoly.interfaces import MessageFactory as _ |
---|
31 | |
---|
32 | PRODUCT_ID = '3930' |
---|
33 | SITE_NAME = 'kwarapoly.waeup.org' |
---|
34 | PROVIDER_ACCT = '1010764827' |
---|
35 | PROVIDER_BANK_ID = '117' |
---|
36 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
37 | INSTITUTION_NAME = 'KwaraPoly' |
---|
38 | CURRENCY = '566' |
---|
39 | GATEWAY_AMT = 300.0 |
---|
40 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
---|
41 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
---|
42 | |
---|
43 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
44 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
45 | |
---|
46 | HOST = 'webpay.interswitchng.com' |
---|
47 | #HOST = 'testwebpay.interswitchng.com' |
---|
48 | |
---|
49 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
50 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
51 | httplib.HTTPConnection.debuglevel = 0 |
---|
52 | |
---|
53 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
54 | """ View which sends a POST request to the Interswitch |
---|
55 | CollegePAY payment gateway. |
---|
56 | """ |
---|
57 | grok.context(ICustomStudentOnlinePayment) |
---|
58 | grok.template('student_goto_interswitch') |
---|
59 | action = POST_ACTION |
---|
60 | site_name = SITE_NAME |
---|
61 | currency = CURRENCY |
---|
62 | product_id = PRODUCT_ID |
---|
63 | mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D' |
---|
64 | |
---|
65 | def interswitch_img_url(self): |
---|
66 | return interswitch_img_url(self) |
---|
67 | |
---|
68 | def update(self): |
---|
69 | error = self.init_update() |
---|
70 | if error: |
---|
71 | self.flash(error, type='danger') |
---|
72 | self.redirect(self.url(self.context, '@@index')) |
---|
73 | return |
---|
74 | student = self.student |
---|
75 | xmldict = self.xmldict |
---|
76 | # Provider data |
---|
77 | xmldict['detail_ref'] = self.context.p_id |
---|
78 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
79 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
80 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
81 | # Institution data |
---|
82 | xmldict['institution_item_name'] = self.category |
---|
83 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
84 | xmldict['institution_amt'] = 0.0 |
---|
85 | dalash_amt = 200.0 |
---|
86 | provider_amt = 300.0 |
---|
87 | gateway_amt = GATEWAY_AMT |
---|
88 | self.pay_item_id = '000' |
---|
89 | xmldict['institution_acct'] = "7000016724" |
---|
90 | xmldict['institution_bank_id'] = "9" |
---|
91 | if self.context.p_category == 'schoolfee': |
---|
92 | self.pay_item_id = '101' |
---|
93 | dalash_amt = 1800.0 |
---|
94 | provider_amt = 1200.0 |
---|
95 | if xmldict['faculty'] in ('CPGS',): |
---|
96 | xmldict['institution_acct'] = "1771180233" |
---|
97 | xmldict['institution_bank_id'] = '120' |
---|
98 | elif xmldict['faculty'] in ('IBAS',): |
---|
99 | xmldict['institution_acct'] = "2013910271" |
---|
100 | xmldict['institution_bank_id'] = '8' |
---|
101 | self.pay_item_id = '107' |
---|
102 | elif xmldict['faculty'] in ('IETS',): |
---|
103 | xmldict['institution_acct'] = "2013910271" |
---|
104 | xmldict['institution_bank_id'] = '8' |
---|
105 | self.pay_item_id = '109' |
---|
106 | elif xmldict['faculty'] in ('IFMS',): |
---|
107 | xmldict['institution_acct'] = "0106259811" |
---|
108 | xmldict['institution_bank_id'] = '10' |
---|
109 | self.pay_item_id = '106' |
---|
110 | elif xmldict['faculty'] in ('ITCH',): |
---|
111 | xmldict['institution_acct'] = "1771180233" |
---|
112 | xmldict['institution_bank_id'] = '120' |
---|
113 | self.pay_item_id = '110' |
---|
114 | elif xmldict['faculty'] in ('IICT',): |
---|
115 | xmldict['institution_acct'] = "2013910271" |
---|
116 | xmldict['institution_bank_id'] = '8' |
---|
117 | self.pay_item_id = '108' |
---|
118 | elif self.context.p_category == 'certificate': |
---|
119 | self.pay_item_id = '111' |
---|
120 | elif self.context.p_category == 'state_result': |
---|
121 | self.pay_item_id = '112' |
---|
122 | elif self.context.p_category == 'transcript_local': |
---|
123 | self.pay_item_id = '113' |
---|
124 | elif self.context.p_category == 'transcript_foreign': |
---|
125 | self.pay_item_id = '114' |
---|
126 | elif self.context.p_category == 'ver_result': |
---|
127 | self.pay_item_id = '115' |
---|
128 | elif self.context.p_category == 'change_course': |
---|
129 | self.pay_item_id = '116' |
---|
130 | elif self.context.p_category == 'change_inst': |
---|
131 | self.pay_item_id = '117' |
---|
132 | elif self.context.p_category == 'jamb_reject': |
---|
133 | self.pay_item_id = '118' |
---|
134 | elif self.context.p_category == 'cert_of_cert': |
---|
135 | self.pay_item_id = '119' |
---|
136 | elif self.context.p_category == 'ref_let': |
---|
137 | self.pay_item_id = '120' |
---|
138 | elif self.context.p_category == 'proc_cert': |
---|
139 | self.pay_item_id = '121' |
---|
140 | elif self.context.p_category == 'loss_idcard': |
---|
141 | self.pay_item_id = '122' |
---|
142 | dalash_amt = 6.0 |
---|
143 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
144 | provider_amt = 9.0 |
---|
145 | gateway_amt = 15.0 |
---|
146 | elif self.context.p_category == 'loss_examcard': |
---|
147 | self.pay_item_id = '123' |
---|
148 | dalash_amt = 3.0 |
---|
149 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
150 | provider_amt = 4.5 |
---|
151 | gateway_amt = 7.5 |
---|
152 | elif self.context.p_category == 'loss_result': |
---|
153 | self.pay_item_id = '124' |
---|
154 | elif self.context.p_category == 'loss_receipt': |
---|
155 | self.pay_item_id = '125' |
---|
156 | elif self.context.p_category == 'loss_clearance': |
---|
157 | self.pay_item_id = '126' |
---|
158 | elif self.context.p_category == 'conv_brochure': |
---|
159 | self.pay_item_id = '127' |
---|
160 | elif self.context.p_category == 'hnd_certificate': |
---|
161 | self.pay_item_id = '128' |
---|
162 | elif self.context.p_category == 'hnd_state_result': |
---|
163 | self.pay_item_id = '129' |
---|
164 | elif self.context.p_category == 'hnd_transcript_local': |
---|
165 | self.pay_item_id = '130' |
---|
166 | elif self.context.p_category == 'hnd_transcript_foreign': |
---|
167 | self.pay_item_id = '131' |
---|
168 | elif self.context.p_category == 'staff_loss_idcard': |
---|
169 | self.pay_item_id = '132' |
---|
170 | dalash_amt = 6.0 |
---|
171 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
172 | provider_amt = 9.0 |
---|
173 | gateway_amt = 15.0 |
---|
174 | elif self.context.p_category == 'hnd_conv_brochure': |
---|
175 | self.pay_item_id = '133' |
---|
176 | elif self.context.p_category == 'pgd_state_result': |
---|
177 | self.pay_item_id = '134' |
---|
178 | elif self.context.p_category == 'pgd_conv_brochure': |
---|
179 | self.pay_item_id = '135' |
---|
180 | elif self.context.p_category == 'pgd_certificate': |
---|
181 | self.pay_item_id = '136' |
---|
182 | elif 'maintenance' in self.context.p_category: |
---|
183 | self.pay_item_id = '102' |
---|
184 | xmldict['institution_acct'] = "0039050937" |
---|
185 | xmldict['institution_bank_id'] = '31' |
---|
186 | dalash_amt = 0.0 |
---|
187 | provider_amt = 0.0 |
---|
188 | else: |
---|
189 | xmldict['institution_acct'] = "0000000000000" |
---|
190 | xmldict['institution_bank_id'] = '0' |
---|
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 | xmltext = """<payment_item_detail> |
---|
211 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
212 | <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" /> |
---|
213 | </item_details> |
---|
214 | </payment_item_detail>""" % xmldict |
---|
215 | |
---|
216 | else: |
---|
217 | xmltext = """<payment_item_detail> |
---|
218 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
219 | <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" /> |
---|
220 | <item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" /> |
---|
221 | <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" /> |
---|
222 | </item_details> |
---|
223 | </payment_item_detail>""" % xmldict |
---|
224 | |
---|
225 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
226 | self.context.provider_amt = provider_amt |
---|
227 | self.context.gateway_amt = gateway_amt |
---|
228 | self.context.thirdparty_amt = dalash_amt |
---|
229 | return |
---|
230 | |
---|
231 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
232 | """ View which sends a POST request to the Interswitch |
---|
233 | CollegePAY payment gateway. |
---|
234 | """ |
---|
235 | grok.context(ICustomApplicantOnlinePayment) |
---|
236 | grok.template('applicant_goto_interswitch') |
---|
237 | action = POST_ACTION |
---|
238 | site_name = SITE_NAME |
---|
239 | currency = CURRENCY |
---|
240 | pay_item_id = '103' |
---|
241 | product_id = PRODUCT_ID |
---|
242 | mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D' |
---|
243 | |
---|
244 | def interswitch_img_url(self): |
---|
245 | return interswitch_img_url(self) |
---|
246 | |
---|
247 | def update(self): |
---|
248 | super(CustomInterswitchPageApplicant, self).update() |
---|
249 | xmldict = {} |
---|
250 | provider_amt = 300.0 |
---|
251 | dalash_amt = 200.0 |
---|
252 | gateway_amt = GATEWAY_AMT |
---|
253 | if self.applicant.applicant_id.startswith('hnd'): |
---|
254 | xmldict['institution_acct'] = '1771440667' |
---|
255 | xmldict['institution_bank_id'] = '120' |
---|
256 | elif self.applicant.applicant_id.startswith('nd'): |
---|
257 | xmldict['institution_acct'] = '1771440667' |
---|
258 | xmldict['institution_bank_id'] = '120' |
---|
259 | elif self.applicant.applicant_id.startswith('rmd'): |
---|
260 | xmldict['institution_acct'] = '1771440667' |
---|
261 | xmldict['institution_bank_id'] = '120' |
---|
262 | elif self.applicant.applicant_id.startswith('pgft'): |
---|
263 | xmldict['institution_acct'] = '7000016724' |
---|
264 | xmldict['institution_bank_id'] = '9' |
---|
265 | elif self.applicant.applicant_id.startswith('prejambites'): |
---|
266 | xmldict['institution_acct'] = '0106259811' |
---|
267 | xmldict['institution_bank_id'] = '10' |
---|
268 | self.pay_item_id = '104' |
---|
269 | provider_amt = 0.0 |
---|
270 | dalash_amt = 0.0 |
---|
271 | elif self.applicant.applicant_id.startswith('pre'): |
---|
272 | xmldict['institution_acct'] = '2013910271' |
---|
273 | xmldict['institution_bank_id'] = '8' |
---|
274 | provider_amt = 0.0 |
---|
275 | dalash_amt = 0.0 |
---|
276 | elif self.applicant.applicant_id.startswith('special'): |
---|
277 | xmldict['institution_acct'] = "7000016724" |
---|
278 | xmldict['institution_bank_id'] = '9' |
---|
279 | if self.applicant.special_application == 'certificate': |
---|
280 | self.pay_item_id = '111' |
---|
281 | elif self.applicant.special_application == 'state_result': |
---|
282 | self.pay_item_id = '112' |
---|
283 | elif self.applicant.special_application == 'transcript_local': |
---|
284 | self.pay_item_id = '113' |
---|
285 | elif self.applicant.special_application == 'transcript_foreign': |
---|
286 | self.pay_item_id = '114' |
---|
287 | elif self.applicant.special_application == 'ver_result': |
---|
288 | self.pay_item_id = '115' |
---|
289 | elif self.applicant.special_application == 'change_course': |
---|
290 | self.pay_item_id = '116' |
---|
291 | elif self.applicant.special_application == 'change_inst': |
---|
292 | self.pay_item_id = '117' |
---|
293 | elif self.applicant.special_application == 'jamb_reject': |
---|
294 | self.pay_item_id = '118' |
---|
295 | elif self.applicant.special_application == 'cert_of_cert': |
---|
296 | self.pay_item_id = '119' |
---|
297 | elif self.applicant.special_application == 'ref_let': |
---|
298 | self.pay_item_id = '120' |
---|
299 | elif self.applicant.special_application == 'proc_cert': |
---|
300 | self.pay_item_id = '121' |
---|
301 | elif self.applicant.special_application == 'loss_idcard': |
---|
302 | self.pay_item_id = '122' |
---|
303 | dalash_amt = 6.0 |
---|
304 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
305 | provider_amt = 9.0 |
---|
306 | gateway_amt = 15.0 |
---|
307 | elif self.applicant.special_application == 'loss_examcard': |
---|
308 | self.pay_item_id = '123' |
---|
309 | dalash_amt = 3.0 |
---|
310 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
311 | provider_amt = 4.5 |
---|
312 | gateway_amt = 7.5 |
---|
313 | elif self.applicant.special_application == 'loss_result': |
---|
314 | self.pay_item_id = '124' |
---|
315 | elif self.applicant.special_application == 'loss_receipt': |
---|
316 | self.pay_item_id = '125' |
---|
317 | elif self.applicant.special_application == 'loss_clearance': |
---|
318 | self.pay_item_id = '126' |
---|
319 | elif self.applicant.special_application == 'conv_brochure': |
---|
320 | self.pay_item_id = '127' |
---|
321 | elif self.applicant.special_application == 'hnd_certificate': |
---|
322 | self.pay_item_id = '128' |
---|
323 | elif self.applicant.special_application == 'hnd_state_result': |
---|
324 | self.pay_item_id = '129' |
---|
325 | elif self.applicant.special_application == 'hnd_transcript_local': |
---|
326 | self.pay_item_id = '130' |
---|
327 | elif self.applicant.special_application == 'hnd_transcript_foreign': |
---|
328 | self.pay_item_id = '131' |
---|
329 | elif self.applicant.special_application == 'staff_loss_idcard': |
---|
330 | self.pay_item_id = '132' |
---|
331 | dalash_amt = 6.0 |
---|
332 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
333 | provider_amt = 9.0 |
---|
334 | gateway_amt = 15.0 |
---|
335 | elif self.context.p_category == 'hnd_conv_brochure': |
---|
336 | self.pay_item_id = '133' |
---|
337 | elif self.context.p_category == 'pgd_state_result': |
---|
338 | self.pay_item_id = '134' |
---|
339 | elif self.context.p_category == 'pgd_conv_brochure': |
---|
340 | self.pay_item_id = '135' |
---|
341 | elif self.context.p_category == 'pgd_certificate': |
---|
342 | self.pay_item_id = '136' |
---|
343 | else: |
---|
344 | xmldict['institution_acct'] = '00000000000' |
---|
345 | xmldict['institution_bank_id'] = '00' |
---|
346 | else: |
---|
347 | xmldict['institution_acct'] = '00000000000' |
---|
348 | xmldict['institution_bank_id'] = '00' |
---|
349 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
350 | xmldict['detail_ref'] = self.context.p_id |
---|
351 | xmldict['provider_amt'] = 100 * provider_amt |
---|
352 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
353 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
354 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
355 | xmldict['institution_amt'] = 100 * ( |
---|
356 | self.context.amount_auth - provider_amt - gateway_amt - dalash_amt) |
---|
357 | xmldict['institution_item_name'] = self.category |
---|
358 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
359 | |
---|
360 | hashargs = ( |
---|
361 | self.context.p_id + |
---|
362 | PRODUCT_ID + |
---|
363 | self.pay_item_id + |
---|
364 | str(int(self.amount_auth)) + |
---|
365 | self.site_redirect_url + |
---|
366 | self.mac) |
---|
367 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
368 | |
---|
369 | # Interswitch amount is not part of the xml data |
---|
370 | |
---|
371 | if not self.applicant.applicant_id.startswith('pre'): |
---|
372 | xmltext = """<payment_item_detail> |
---|
373 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
374 | <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" /> |
---|
375 | <item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" /> |
---|
376 | <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" /> |
---|
377 | </item_details> |
---|
378 | </payment_item_detail>""" % xmldict |
---|
379 | |
---|
380 | else: |
---|
381 | xmltext = """<payment_item_detail> |
---|
382 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
383 | <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" /> |
---|
384 | </item_details> |
---|
385 | </payment_item_detail>""" % xmldict |
---|
386 | |
---|
387 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
388 | self.context.provider_amt = provider_amt |
---|
389 | self.context.gateway_amt = gateway_amt |
---|
390 | self.context.thirdparty_amt = dalash_amt |
---|
391 | return |
---|
392 | |
---|
393 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
394 | InterswitchPaymentRequestWebservicePageStudent): |
---|
395 | """ Request webservice view for the CollegePAY gateway |
---|
396 | """ |
---|
397 | grok.context(ICustomStudentOnlinePayment) |
---|
398 | product_id = PRODUCT_ID |
---|
399 | gateway_host = HOST |
---|
400 | gateway_url = URL |
---|
401 | |
---|
402 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
403 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
404 | """ Request webservice view for the CollegePAY gateway |
---|
405 | """ |
---|
406 | grok.context(ICustomApplicantOnlinePayment) |
---|
407 | product_id = PRODUCT_ID |
---|
408 | gateway_host = HOST |
---|
409 | gateway_url = URL |
---|