1 | ## $Id: browser.py 18034 2025-03-10 16:40: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 | ## |
---|
18 | import httplib |
---|
19 | import hashlib |
---|
20 | import grok |
---|
21 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
22 | from zope.component import getUtility |
---|
23 | from kofacustom.nigeria.interswitch.browser import ( |
---|
24 | module_activated, |
---|
25 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
26 | InterswitchPaymentRequestWebservicePageStudent, |
---|
27 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
28 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
29 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
30 | ) |
---|
31 | from kofacustom.iuokada.students.interfaces import ICustomStudentOnlinePayment |
---|
32 | from kofacustom.iuokada.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
33 | from kofacustom.iuokada.interfaces import MessageFactory as _ |
---|
34 | |
---|
35 | PRODUCT_ID = '7922' |
---|
36 | SITE_NAME = 'iuokada.waeup.org' |
---|
37 | PROVIDER_ACCT = '0773411069' |
---|
38 | PROVIDER_BANK_ID = '31' |
---|
39 | PROVIDER_ITEM_NAME = 'WAeAC' |
---|
40 | INSTITUTION_NAME = 'IUOkada' |
---|
41 | CURRENCY = '566' |
---|
42 | GATEWAY_AMT = 250.0 |
---|
43 | #MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' # must be provided by Interswitch |
---|
44 | MAC = '4D8723F33D728BE3F4A77B2DFB3F57B0BCF2DD818759D54A87B2A60874067F28D94F2B91E29BFB884F920F48E0973D826835A8F2D6F74220C64EDE4DE00E45AA' |
---|
45 | |
---|
46 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay' |
---|
47 | #POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay' |
---|
48 | HOST = 'webpay.interswitchng.com' |
---|
49 | #HOST = 'sandbox.interswitchng.com' |
---|
50 | URL = '/paydirect/api/v1/gettransaction.json' |
---|
51 | #URL = '/webpay/api/v1/gettransaction.json' |
---|
52 | |
---|
53 | httplib.HTTPSConnection.debuglevel = 0 |
---|
54 | HTTPS = True |
---|
55 | |
---|
56 | BANK_ACCOUNTS = { |
---|
57 | 'access': ('1228744877', '117'), |
---|
58 | 'parentsconsult': ('1228747029', '117'), |
---|
59 | 'health_insurance': ('1228744884', '117'), |
---|
60 | 'municipal_returning': ('0040621193','31'), |
---|
61 | 'clearance': ('0040621193','31'), |
---|
62 | 'develop': ('0040621193','31'), |
---|
63 | 'medical_screening': ('1311220657','117'), |
---|
64 | 'conv': ('0040621193','31'), |
---|
65 | 'registration_fresh': ('0040621193','31'), |
---|
66 | 'science': ('0040621193','31'), |
---|
67 | 'id_card': ('0040621193','31'), |
---|
68 | 'alumni': ('1311974981','117'), |
---|
69 | 'lab_support': ('0040621193','31'), |
---|
70 | 'registration_return': ('0040621193','31'), |
---|
71 | 'book': ('1228744877','117'), |
---|
72 | 'waecneco': ('0040621193','31'), |
---|
73 | 'jambver': ('0040621193','31'), |
---|
74 | 'pg_other': ('0040621193','31'), |
---|
75 | 'municipal_fresh': ('0040621193','31'), |
---|
76 | 'matric': ('0040621193','31') |
---|
77 | } |
---|
78 | |
---|
79 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
80 | """ View which sends a POST request to the Interswitch |
---|
81 | CollegePAY payment gateway. |
---|
82 | """ |
---|
83 | grok.context(ICustomStudentOnlinePayment) |
---|
84 | action = POST_ACTION |
---|
85 | site_name = SITE_NAME |
---|
86 | currency = CURRENCY |
---|
87 | product_id = PRODUCT_ID |
---|
88 | mac = MAC |
---|
89 | gateway_amt = GATEWAY_AMT |
---|
90 | |
---|
91 | def update(self): |
---|
92 | student_utils = getUtility(IStudentsUtils) |
---|
93 | if not module_activated( |
---|
94 | self.context.student.current_session, self.context): |
---|
95 | self.flash(_('Forbidden'), type='danger') |
---|
96 | self.redirect(self.url(self.context, '@@index')) |
---|
97 | return |
---|
98 | error = self.init_update() |
---|
99 | if error: |
---|
100 | self.flash(error, type='danger') |
---|
101 | self.redirect(self.url(self.context, '@@index')) |
---|
102 | return |
---|
103 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
104 | # and add the gateway amount. |
---|
105 | if not self.context.r_company: |
---|
106 | self.context.net_amt = self.context.amount_auth |
---|
107 | self.context.amount_auth += self.gateway_amt |
---|
108 | self.context.gateway_amt = self.gateway_amt |
---|
109 | self.context.r_company = u'interswitch' |
---|
110 | student = self.student |
---|
111 | xmldict = self.xmldict |
---|
112 | # Provider data |
---|
113 | xmldict['detail_ref'] = self.context.p_id |
---|
114 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
115 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
116 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
117 | xmldict['institution_acct'] = '' |
---|
118 | xmldict['institution_bank_id'] = '' |
---|
119 | provider_amt = 0.0 |
---|
120 | self.pay_item_id = '' |
---|
121 | # Institution data |
---|
122 | if self.context.p_category in ( |
---|
123 | 'schoolfee', 'schoolfee40', 'secondinstal'): |
---|
124 | self.pay_item_id = '101' |
---|
125 | else: |
---|
126 | # we use the same item_id for all sundry payments |
---|
127 | self.pay_item_id = '102' |
---|
128 | if self.context.p_category in ( |
---|
129 | 'registration', 'registration_fresh', 'registration_return', |
---|
130 | 'required_combi', 'pg_other', 'jupeb_reg'): |
---|
131 | provider_amt = 5000.0 |
---|
132 | if self.context.p_category in ( |
---|
133 | 'schoolfee', 'schoolfee40') and student.is_jupeb: |
---|
134 | provider_amt = 5000.0 |
---|
135 | if self.context.p_category.startswith('jupeb'): |
---|
136 | self.pay_item_id = '102' |
---|
137 | xmldict['provider_amt'] = 100 * provider_amt |
---|
138 | xmldict['institution_item_name'] = self.context.category |
---|
139 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
140 | xmldict['institution_amt'] = 100 * self.context.net_amt - ( |
---|
141 | 100 * provider_amt) |
---|
142 | |
---|
143 | if grok.getSite().__name__ == 'iuokada-cdl': |
---|
144 | xmldict['institution_acct'] = '1229771245' |
---|
145 | xmldict['institution_bank_id'] = '117' |
---|
146 | if self.context.p_category.startswith('schoolfee'): |
---|
147 | xmldict['institution_acct'] = '1828332878' |
---|
148 | xmldict['institution_bank_id'] = '31' |
---|
149 | else: |
---|
150 | if self.context.p_option == 'access': |
---|
151 | xmldict['institution_acct'] = '0040484781' |
---|
152 | xmldict['institution_bank_id'] = '31' |
---|
153 | elif self.context.p_option == 'first': |
---|
154 | xmldict['institution_acct'] = '2021420049' |
---|
155 | xmldict['institution_bank_id'] = '8' |
---|
156 | elif self.context.p_option == 'zenith': |
---|
157 | xmldict['institution_acct'] = '1011005811' |
---|
158 | xmldict['institution_bank_id'] = '117' |
---|
159 | else: |
---|
160 | xmldict['institution_acct'] = '0040484781' |
---|
161 | xmldict['institution_bank_id'] = '31' |
---|
162 | |
---|
163 | # Overwrite above selection |
---|
164 | sundry_acct = BANK_ACCOUNTS.get(self.context.p_category, None) |
---|
165 | if sundry_acct is True: |
---|
166 | xmldict['institution_acct'] = sundry_acct[0] |
---|
167 | xmldict['institution_bank_id'] = sundry_acct[0] |
---|
168 | |
---|
169 | if provider_amt == 0: |
---|
170 | xmltext = """<payment_item_detail> |
---|
171 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
172 | <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" /> |
---|
173 | </item_details> |
---|
174 | </payment_item_detail>""" % xmldict |
---|
175 | else: |
---|
176 | xmltext = """<payment_item_detail> |
---|
177 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
178 | <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" /> |
---|
179 | <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" /> |
---|
180 | </item_details> |
---|
181 | </payment_item_detail>""" % xmldict |
---|
182 | |
---|
183 | # Overwrite xmltext above because we have to split required combi |
---|
184 | if self.context.p_category == 'required_combi': |
---|
185 | rp = student_utils._collect_required_payment_items(self.context.student) |
---|
186 | academic_session = student_utils._getSessionConfiguration(self.context.p_session) |
---|
187 | xmltext = """<payment_item_detail> |
---|
188 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
189 | <item_detail item_id="1" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />""" % xmldict |
---|
190 | item_id = 2 |
---|
191 | for cat in rp: |
---|
192 | fee_name = cat + '_fee' |
---|
193 | item_name = cat |
---|
194 | item_amt = 100 * getattr(academic_session, fee_name, 0.0) |
---|
195 | if item_name.startswith('registration'): |
---|
196 | item_amt -= 100 * provider_amt |
---|
197 | bank_id = BANK_ACCOUNTS[cat][1] |
---|
198 | acct_num = BANK_ACCOUNTS[cat][0] |
---|
199 | xmltext += """ |
---|
200 | <item_detail item_id="%s" item_name="%s" item_amt="%d" bank_id="%s" acct_num="%s" />""" % (item_id, item_name, item_amt, bank_id, acct_num) |
---|
201 | item_id += 1 |
---|
202 | xmltext += """ |
---|
203 | </item_details> |
---|
204 | </payment_item_detail>""" % xmldict |
---|
205 | |
---|
206 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
207 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
208 | hashargs = ( |
---|
209 | self.context.p_id + |
---|
210 | PRODUCT_ID + |
---|
211 | self.pay_item_id + |
---|
212 | str(int(self.amount_auth)) + |
---|
213 | self.site_redirect_url + |
---|
214 | self.mac) |
---|
215 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
216 | return |
---|
217 | |
---|
218 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
219 | """ View which sends a POST request to the Interswitch |
---|
220 | CollegePAY payment gateway. |
---|
221 | """ |
---|
222 | grok.context(ICustomApplicantOnlinePayment) |
---|
223 | action = POST_ACTION |
---|
224 | site_name = SITE_NAME |
---|
225 | currency = CURRENCY |
---|
226 | product_id = PRODUCT_ID |
---|
227 | mac = MAC |
---|
228 | gateway_amt = GATEWAY_AMT |
---|
229 | |
---|
230 | def update(self): |
---|
231 | if not module_activated( |
---|
232 | self.context.__parent__.__parent__.year, self.context): |
---|
233 | self.flash(_('Forbidden'), type='danger') |
---|
234 | self.redirect(self.url(self.context, '@@index')) |
---|
235 | return |
---|
236 | error = self.init_update() |
---|
237 | if error: |
---|
238 | self.flash(error, type='danger') |
---|
239 | self.redirect(self.url(self.context, '@@index')) |
---|
240 | return |
---|
241 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
242 | # and add the gateway amount. |
---|
243 | if not self.context.r_company: |
---|
244 | self.context.net_amt = self.context.amount_auth |
---|
245 | self.context.amount_auth += self.gateway_amt |
---|
246 | self.context.gateway_amt = self.gateway_amt |
---|
247 | self.context.r_company = u'interswitch' |
---|
248 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
249 | xmldict = {} |
---|
250 | provider_amt = 0.0 |
---|
251 | self.pay_item_id = '101' |
---|
252 | xmldict['institution_acct'] = '1011005811' |
---|
253 | xmldict['institution_bank_id'] = '117' |
---|
254 | if grok.getSite().__name__ == 'iuokada-cdl': |
---|
255 | xmldict['institution_acct'] = '1229774710' |
---|
256 | xmldict['institution_bank_id'] = '117' |
---|
257 | xmldict['detail_ref'] = self.context.p_id |
---|
258 | xmldict['provider_amt'] = 100 * provider_amt |
---|
259 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
260 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
261 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
262 | xmldict['institution_item_name'] = self.context.category |
---|
263 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
264 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
265 | if not self.context.provider_amt: |
---|
266 | self.context.provider_amt = provider_amt |
---|
267 | self.context.amount_auth += provider_amt |
---|
268 | if provider_amt == 0: |
---|
269 | xmltext = """<payment_item_detail> |
---|
270 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
271 | <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" /> |
---|
272 | </item_details> |
---|
273 | </payment_item_detail>""" % xmldict |
---|
274 | else: |
---|
275 | xmltext = """<payment_item_detail> |
---|
276 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
277 | <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" /> |
---|
278 | <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" /> |
---|
279 | </item_details> |
---|
280 | </payment_item_detail>""" % xmldict |
---|
281 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
282 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
283 | hashargs = ( |
---|
284 | self.context.p_id + |
---|
285 | PRODUCT_ID + |
---|
286 | self.pay_item_id + |
---|
287 | str(int(self.amount_auth)) + |
---|
288 | self.site_redirect_url + |
---|
289 | self.mac) |
---|
290 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
291 | return |
---|
292 | |
---|
293 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
294 | InterswitchPaymentRequestWebservicePageStudent): |
---|
295 | """Request webservice view for the CollegePAY gateway |
---|
296 | """ |
---|
297 | grok.context(ICustomStudentOnlinePayment) |
---|
298 | product_id = PRODUCT_ID |
---|
299 | gateway_host = HOST |
---|
300 | gateway_url = URL |
---|
301 | mac = MAC |
---|
302 | |
---|
303 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
304 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
305 | """Payment verify view for the CollegePAY gateway |
---|
306 | """ |
---|
307 | grok.context(ICustomStudentOnlinePayment) |
---|
308 | product_id = PRODUCT_ID |
---|
309 | gateway_host = HOST |
---|
310 | gateway_url = URL |
---|
311 | mac = MAC |
---|
312 | |
---|
313 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
314 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
315 | """Request webservice view for the CollegePAY gateway |
---|
316 | """ |
---|
317 | grok.context(ICustomApplicantOnlinePayment) |
---|
318 | product_id = PRODUCT_ID |
---|
319 | gateway_host = HOST |
---|
320 | gateway_url = URL |
---|
321 | mac = MAC |
---|
322 | |
---|
323 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
324 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
325 | """Payment verify view for the CollegePAY gateway |
---|
326 | """ |
---|
327 | grok.context(ICustomApplicantOnlinePayment) |
---|
328 | product_id = PRODUCT_ID |
---|
329 | gateway_host = HOST |
---|
330 | gateway_url = URL |
---|
331 | mac = MAC |
---|
332 | |
---|
333 | |
---|
334 | # PAYDirect added on 19/05/2021 |
---|
335 | |
---|
336 | from kofacustom.nigeria.interswitch.paydirectbrowser import ( |
---|
337 | PAYDirectPageStudent, PAYDirectPageApplicant, |
---|
338 | StudentRefNumberSlip, ApplicantRefNumberSlip, |
---|
339 | ) |
---|
340 | |
---|
341 | PAYDIRECT_HOST = 'orion.interswitchng.com' |
---|
342 | PAYDIRECT_URL = '/bookonhold/bookonhold.asmx' |
---|
343 | MERCHANT_ID = '8124' |
---|
344 | |
---|
345 | class CustomPAYDirectPageStudent(PAYDirectPageStudent): |
---|
346 | """Inform student how to proceed |
---|
347 | """ |
---|
348 | grok.context(ICustomStudentOnlinePayment) |
---|
349 | gateway_amt = GATEWAY_AMT |
---|
350 | merchant_id = MERCHANT_ID |
---|
351 | gateway_url = PAYDIRECT_URL |
---|
352 | gateway_host = PAYDIRECT_HOST |
---|
353 | https = True |
---|
354 | |
---|
355 | class CustomPAYDirectPageApplicant(PAYDirectPageApplicant): |
---|
356 | """ Inform applicant how to proceed. |
---|
357 | """ |
---|
358 | grok.context(ICustomApplicantOnlinePayment) |
---|
359 | gateway_amt = GATEWAY_AMT |
---|
360 | merchant_id = MERCHANT_ID |
---|
361 | gateway_url = PAYDIRECT_URL |
---|
362 | gateway_host = PAYDIRECT_HOST |
---|
363 | https = True |
---|
364 | |
---|
365 | class CustomStudentRefNumberSlip(StudentRefNumberSlip): |
---|
366 | """Deliver a PDF slip of the context. |
---|
367 | """ |
---|
368 | merchant_id = MERCHANT_ID |
---|
369 | |
---|
370 | class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip): |
---|
371 | """Deliver a PDF slip of the context. |
---|
372 | """ |
---|
373 | merchant_id = MERCHANT_ID |
---|