1 | ## $Id: browser.py 17952 2024-11-05 11:51:11Z 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 kofacustom.nigeria.interswitch.browser import ( |
---|
22 | module_activated, |
---|
23 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
24 | InterswitchPaymentRequestWebservicePageStudent, |
---|
25 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
26 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
27 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
28 | ) |
---|
29 | from kofacustom.unidel.students.interfaces import ICustomStudentOnlinePayment |
---|
30 | from kofacustom.unidel.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
31 | from kofacustom.unidel.interfaces import MessageFactory as _ |
---|
32 | |
---|
33 | PRODUCT_ID = '22153701' # must be provided by Interswitch |
---|
34 | SITE_NAME = 'unidel.waeup.org' |
---|
35 | PROVIDER_ACCT = '0213065415' |
---|
36 | PROVIDER_BANK_ID = '47' |
---|
37 | PROVIDER_ITEM_NAME = 'WAeAC' |
---|
38 | INSTITUTION_NAME = 'UNIDEL' |
---|
39 | CURRENCY = '566' |
---|
40 | GATEWAY_AMT = 250.0 |
---|
41 | #MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' |
---|
42 | MAC = 'Lfj58PyWS6MvPz65zIbofZNoAn89fZAjtnsEWbTof73OyHQH7rpJPHWD2m4cekDoowJ8nqQCn6ay2lopzKBOekFsMfzkXG6KYGRuyhMQq4bK7wDNaWqpxeZl3fMumNmi' |
---|
43 | |
---|
44 | POST_ACTION = 'https://webpay.interswitchng.com/collections/w/pay' |
---|
45 | #POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay' |
---|
46 | HOST = 'webpay.interswitchng.com' |
---|
47 | #HOST = 'sandbox.interswitchng.com' |
---|
48 | URL = '/collections/api/v1/gettransaction.json' |
---|
49 | #URL = '/webpay/api/v1/gettransaction.json' |
---|
50 | |
---|
51 | httplib.HTTPSConnection.debuglevel = 0 |
---|
52 | HTTPS = True |
---|
53 | |
---|
54 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
55 | """ View which sends a POST request to the Interswitch |
---|
56 | CollegePAY payment gateway. |
---|
57 | """ |
---|
58 | grok.context(ICustomStudentOnlinePayment) |
---|
59 | action = POST_ACTION |
---|
60 | site_name = SITE_NAME |
---|
61 | currency = CURRENCY |
---|
62 | product_id = PRODUCT_ID |
---|
63 | mac = MAC |
---|
64 | gateway_amt = GATEWAY_AMT |
---|
65 | |
---|
66 | def update(self): |
---|
67 | if not module_activated( |
---|
68 | self.context.student.current_session, self.context): |
---|
69 | self.flash(_('Forbidden'), type='danger') |
---|
70 | self.redirect(self.url(self.context, '@@index')) |
---|
71 | return |
---|
72 | error = self.init_update() |
---|
73 | if error: |
---|
74 | self.flash(error, type='danger') |
---|
75 | self.redirect(self.url(self.context, '@@index')) |
---|
76 | return |
---|
77 | student = self.student |
---|
78 | xmldict = self.xmldict |
---|
79 | # Provider data |
---|
80 | xmldict['detail_ref'] = self.context.p_id |
---|
81 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
82 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
83 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
84 | # Institution data |
---|
85 | xmldict['institution_acct'] = '000000000' |
---|
86 | xmldict['institution_bank_id'] = '117' |
---|
87 | provider_amt = 0.0 |
---|
88 | tech_fee = 0.0 |
---|
89 | union_due = 0.0 |
---|
90 | if self.context.p_category == 'clearance': |
---|
91 | provider_amt = 2000.0 |
---|
92 | if student.current_mode in ('ug_ft', 'de_ft'): |
---|
93 | xmldict['institution_acct'] = '1216063205' |
---|
94 | tech_fee = 18000.0 |
---|
95 | xmldict['tech_acct'] = '0092304647' |
---|
96 | xmldict['tech_bank_id'] = '121' |
---|
97 | elif student.current_mode.startswith('dp'): |
---|
98 | xmldict['institution_acct'] = '1011431799' |
---|
99 | if student.faccode in ('PRE', 'JUPEB'): |
---|
100 | xmldict['institution_acct'] = '1011431799' |
---|
101 | elif student.faccode == 'IJMB': |
---|
102 | xmldict['institution_acct'] = '0093658062' |
---|
103 | xmldict['institution_bank_id'] = '121' |
---|
104 | if self.context.p_item == 'Balance': |
---|
105 | provider_amt = 0.0 |
---|
106 | tech_fee = 0.0 |
---|
107 | elif self.context.p_category == 'schoolfee': |
---|
108 | provider_amt = 7000.0 |
---|
109 | tech_fee = 3000.0 |
---|
110 | xmldict['institution_acct'] = '1011739172' |
---|
111 | xmldict['tech_acct'] = '0213065415' |
---|
112 | xmldict['tech_bank_id'] = '47' |
---|
113 | xmldict['union_acct'] = '1011438901' |
---|
114 | xmldict['union_bank_id'] = '117' |
---|
115 | #if student.current_mode == 'ug_ft': |
---|
116 | # union_due = 1500.0 |
---|
117 | if student.current_mode.startswith('dp'): |
---|
118 | xmldict['institution_acct'] = '2001627961' |
---|
119 | xmldict['institution_bank_id'] = '8' |
---|
120 | elif student.current_mode in ('pde', 'trc'): |
---|
121 | xmldict['institution_acct'] = '1010957205' |
---|
122 | xmldict['institution_bank_id'] = '117' |
---|
123 | elif student.faccode in ('PRE', 'JUPEB'): |
---|
124 | xmldict['institution_acct'] = '2001627961' |
---|
125 | xmldict['institution_bank_id'] = '8' |
---|
126 | elif student.faccode == 'DELSU': |
---|
127 | xmldict['institution_acct'] = '1011036493' |
---|
128 | elif student.faccode == 'NCE': |
---|
129 | xmldict['institution_acct'] = '1011274462' |
---|
130 | provider_amt = 4000.0 |
---|
131 | tech_fee = 0.0 |
---|
132 | elif student.faccode == 'IJMB': |
---|
133 | xmldict['institution_acct'] = '0093658062' |
---|
134 | xmldict['institution_bank_id'] = '121' |
---|
135 | elif student.faccode in ('FMED', 'FBM', 'FLW'): |
---|
136 | xmldict['institution_acct'] = '1011274462' |
---|
137 | elif student.certcode == 'DFFPA': |
---|
138 | xmldict['institution_acct'] = '2001627961' |
---|
139 | xmldict['institution_bank_id'] = '8' |
---|
140 | provider_amt = 4000.0 |
---|
141 | tech_fee = 0.0 |
---|
142 | if self.context.p_item == 'Balance': |
---|
143 | provider_amt = 0.0 |
---|
144 | tech_fee = 0.0 |
---|
145 | elif self.context.p_category.startswith('ijmb'): |
---|
146 | xmldict['institution_acct'] = '0093658062' |
---|
147 | xmldict['institution_bank_id'] = '121' |
---|
148 | elif self.context.p_category == 'hostel_maintenance': |
---|
149 | xmldict['institution_acct'] = '1012551384' |
---|
150 | elif self.context.p_category == 'med_reg': |
---|
151 | xmldict['institution_acct'] = '1011265606' |
---|
152 | elif self.context.p_category == 'teaching_practice': |
---|
153 | xmldict['institution_acct'] = '1005399320' |
---|
154 | xmldict['institution_bank_id'] = '8' |
---|
155 | elif self.context.p_category.startswith('transcript'): |
---|
156 | xmldict['institution_acct'] = '0010494552' |
---|
157 | xmldict['institution_bank_id'] = '129' |
---|
158 | provider_amt = 2000.0 |
---|
159 | elif self.context.p_category.startswith('union'): |
---|
160 | xmldict['institution_acct'] = '1011438901' |
---|
161 | self.pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch |
---|
162 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
163 | # and add gateway amount and other surcharges. |
---|
164 | if not self.context.r_company: |
---|
165 | self.context.r_company = u'interswitch' |
---|
166 | self.context.net_amt = self.context.amount_auth |
---|
167 | self.context.gateway_amt = self.gateway_amt |
---|
168 | self.context.amount_auth += self.gateway_amt |
---|
169 | self.context.provider_amt = provider_amt |
---|
170 | self.context.amount_auth += provider_amt |
---|
171 | self.context.amount_auth += tech_fee |
---|
172 | self.context.amount_auth += union_due |
---|
173 | xmldict['provider_amt'] = 100 * provider_amt |
---|
174 | xmldict['tech_fee'] = 100 * tech_fee |
---|
175 | xmldict['union_due'] = 100 * union_due |
---|
176 | xmldict['institution_item_name'] = self.context.category |
---|
177 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
178 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
179 | xmldict['item_id'] = 1 |
---|
180 | xmltext = """ |
---|
181 | <payment_item_detail> |
---|
182 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
183 | <item_detail item_id="%(item_id)s" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" /> |
---|
184 | """ % xmldict |
---|
185 | if provider_amt: |
---|
186 | xmldict['item_id'] += 1 |
---|
187 | xmltext += """<item_detail item_id="%(item_id)s" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" /> |
---|
188 | """ % xmldict |
---|
189 | if tech_fee: |
---|
190 | xmldict['item_id'] += 1 |
---|
191 | xmltext += """<item_detail item_id="%(item_id)s" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="%(tech_bank_id)s" acct_num="%(tech_acct)s" /> |
---|
192 | """ % xmldict |
---|
193 | if union_due: |
---|
194 | xmldict['item_id'] += 1 |
---|
195 | xmltext += """<item_detail item_id="%(item_id)s" item_name="Student Union Due" item_amt="%(union_due)d" bank_id="%(union_bank_id)s" acct_num="%(union_acct)s" /> |
---|
196 | """ % xmldict |
---|
197 | xmltext +="""</item_details> |
---|
198 | </payment_item_detail> |
---|
199 | """ |
---|
200 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
201 | self.context.provider_amt = provider_amt |
---|
202 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
203 | hashargs = ( |
---|
204 | self.context.p_id + |
---|
205 | PRODUCT_ID + |
---|
206 | self.pay_item_id + |
---|
207 | str(int(self.amount_auth)) + |
---|
208 | self.site_redirect_url + |
---|
209 | self.mac) |
---|
210 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
211 | return |
---|
212 | |
---|
213 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
214 | """ View which sends a POST request to the Interswitch |
---|
215 | CollegePAY payment gateway. |
---|
216 | """ |
---|
217 | grok.context(ICustomApplicantOnlinePayment) |
---|
218 | action = POST_ACTION |
---|
219 | site_name = SITE_NAME |
---|
220 | currency = CURRENCY |
---|
221 | pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch |
---|
222 | product_id = PRODUCT_ID |
---|
223 | mac = MAC |
---|
224 | gateway_amt = GATEWAY_AMT |
---|
225 | |
---|
226 | def update(self): |
---|
227 | if not module_activated( |
---|
228 | self.context.__parent__.__parent__.year, self.context): |
---|
229 | self.flash(_('Forbidden'), type='danger') |
---|
230 | self.redirect(self.url(self.context, '@@index')) |
---|
231 | return |
---|
232 | error = self.init_update() |
---|
233 | if error: |
---|
234 | self.flash(error, type='danger') |
---|
235 | self.redirect(self.url(self.context, '@@index')) |
---|
236 | return |
---|
237 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
238 | # and add the gateway amount. |
---|
239 | if not self.context.r_company: |
---|
240 | self.context.net_amt = self.context.amount_auth |
---|
241 | self.context.amount_auth += self.gateway_amt |
---|
242 | self.context.gateway_amt = self.gateway_amt |
---|
243 | self.context.r_company = u'interswitch' |
---|
244 | xmldict = {} |
---|
245 | provider_amt = 250.0 |
---|
246 | xmldict['institution_acct'] = '1216063205' |
---|
247 | xmldict['institution_bank_id'] = '117' |
---|
248 | if self.context.__parent__.__parent__.prefix in ( |
---|
249 | 'pre', 'jupeb', 'dpft', 'dppt', |
---|
250 | 'ugpt', 'ijmb', 'df'): |
---|
251 | xmldict['institution_acct'] = '1011431799' |
---|
252 | xmldict['institution_bank_id'] = '117' |
---|
253 | provider_amt = 500.0 |
---|
254 | if self.context.__parent__.__parent__.prefix in ('ijmb',): |
---|
255 | xmldict['institution_acct'] = '0093658062' |
---|
256 | xmldict['institution_bank_id'] = '121' |
---|
257 | if self.context.__parent__.__parent__.prefix in ('pde', 'trcdeg', 'trcnce'): |
---|
258 | xmldict['institution_acct'] = '1010957205' |
---|
259 | xmldict['institution_bank_id'] = '117' |
---|
260 | provider_amt = 500.0 |
---|
261 | xmldict['detail_ref'] = self.context.p_id |
---|
262 | xmldict['provider_amt'] = 100 * provider_amt |
---|
263 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
264 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
265 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
266 | xmldict['institution_item_name'] = self.context.category |
---|
267 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
268 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
269 | if not self.context.provider_amt: |
---|
270 | self.context.provider_amt = provider_amt |
---|
271 | self.context.amount_auth += provider_amt |
---|
272 | xmltext = """<payment_item_detail> |
---|
273 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
274 | <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" /> |
---|
275 | <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" /> |
---|
276 | </item_details> |
---|
277 | </payment_item_detail>""" % xmldict |
---|
278 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
279 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
280 | hashargs = ( |
---|
281 | self.context.p_id + |
---|
282 | PRODUCT_ID + |
---|
283 | self.pay_item_id + |
---|
284 | str(int(self.amount_auth)) + |
---|
285 | self.site_redirect_url + |
---|
286 | self.mac) |
---|
287 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
288 | return |
---|
289 | |
---|
290 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
291 | InterswitchPaymentRequestWebservicePageStudent): |
---|
292 | """Request webservice view for the CollegePAY gateway |
---|
293 | """ |
---|
294 | grok.context(ICustomStudentOnlinePayment) |
---|
295 | product_id = PRODUCT_ID |
---|
296 | gateway_host = HOST |
---|
297 | gateway_url = URL |
---|
298 | mac = MAC |
---|
299 | |
---|
300 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
301 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
302 | """Payment verify view for the CollegePAY gateway |
---|
303 | """ |
---|
304 | grok.context(ICustomStudentOnlinePayment) |
---|
305 | product_id = PRODUCT_ID |
---|
306 | gateway_host = HOST |
---|
307 | gateway_url = URL |
---|
308 | mac = MAC |
---|
309 | |
---|
310 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
311 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
312 | """Request webservice view for the CollegePAY gateway |
---|
313 | """ |
---|
314 | grok.context(ICustomApplicantOnlinePayment) |
---|
315 | product_id = PRODUCT_ID |
---|
316 | gateway_host = HOST |
---|
317 | gateway_url = URL |
---|
318 | mac = MAC |
---|
319 | |
---|
320 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
321 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
322 | """Payment verify view for the CollegePAY gateway |
---|
323 | """ |
---|
324 | grok.context(ICustomApplicantOnlinePayment) |
---|
325 | product_id = PRODUCT_ID |
---|
326 | gateway_host = HOST |
---|
327 | gateway_url = URL |
---|
328 | mac = MAC |
---|
329 | |
---|
330 | # PAYDirect |
---|
331 | |
---|
332 | from kofacustom.nigeria.interswitch.paydirectbrowser import ( |
---|
333 | PAYDirectPageStudent, PAYDirectPageApplicant, |
---|
334 | StudentRefNumberSlip, ApplicantRefNumberSlip, |
---|
335 | ) |
---|
336 | |
---|
337 | from kofacustom.nigeria.interswitch.tests import ( |
---|
338 | PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID) |
---|
339 | |
---|
340 | #PAYDIRECT_HOST = 'orion.interswitchng.com' |
---|
341 | #PAYDIRECT_URL = '/bookonhold/bookonhold.asmx' |
---|
342 | #MERCHANT_ID = '' |
---|
343 | |
---|
344 | class CustomPAYDirectPageStudent(PAYDirectPageStudent): |
---|
345 | """Inform student how to proceed |
---|
346 | """ |
---|
347 | grok.context(ICustomStudentOnlinePayment) |
---|
348 | gateway_amt = GATEWAY_AMT |
---|
349 | merchant_id = MERCHANT_ID |
---|
350 | gateway_url = PAYDIRECT_URL |
---|
351 | gateway_host = PAYDIRECT_HOST |
---|
352 | https = True |
---|
353 | |
---|
354 | class CustomPAYDirectPageApplicant(PAYDirectPageApplicant): |
---|
355 | """ Inform applicant how to proceed. |
---|
356 | """ |
---|
357 | grok.context(ICustomApplicantOnlinePayment) |
---|
358 | gateway_amt = GATEWAY_AMT |
---|
359 | merchant_id = MERCHANT_ID |
---|
360 | gateway_url = PAYDIRECT_URL |
---|
361 | gateway_host = PAYDIRECT_HOST |
---|
362 | https = True |
---|
363 | |
---|
364 | class CustomStudentRefNumberSlip(StudentRefNumberSlip): |
---|
365 | """Deliver a PDF slip of the context. |
---|
366 | """ |
---|
367 | merchant_id = MERCHANT_ID |
---|
368 | |
---|
369 | class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip): |
---|
370 | """Deliver a PDF slip of the context. |
---|
371 | """ |
---|
372 | merchant_id = MERCHANT_ID |
---|