1 | ## $Id: browser.py 17900 2024-08-21 08:09:35Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2017 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 | |
---|
19 | import os |
---|
20 | import csv |
---|
21 | from kofacustom.nigeria.etranzact.applicantsbrowser import ( |
---|
22 | EtranzactPageApplicant, EtranzactReceiveResponseApplicant, |
---|
23 | EtranzactRequestPaymentStatusPageApplicant) |
---|
24 | from kofacustom.nigeria.etranzact.studentsbrowser import ( |
---|
25 | EtranzactPageStudent, EtranzactReceiveResponseStudent, |
---|
26 | EtranzactRequestPaymentStatusPageStudent, webconnect_module_activated) |
---|
27 | from kofacustom.nigeria.etranzact.payoutletbrowser import ( |
---|
28 | EtranzactEnterPinPageStudent, EtranzactEnterPinPageApplicant, |
---|
29 | EtranzactQueryHistoryPageStudent, EtranzactQueryHistoryPageApplicant, |
---|
30 | payoutlet_module_activated) |
---|
31 | from kofacustom.nigeria.etranzact.payoutletwebservice import NigeriaPaymentDataWebservice |
---|
32 | from kofacustom.nigeria.etranzact.credobrowser import ( |
---|
33 | CredoPageStudent, CredoPageApplicant, |
---|
34 | CredoVerifyPaymentStatusPageStudent, CredoVerifyPaymentStatusPageApplicant) |
---|
35 | |
---|
36 | # Temporarily we can use the test portal like in kofacustom.nigeria |
---|
37 | |
---|
38 | from kofacustom.nigeria.etranzact.tests import ( |
---|
39 | HOST, HTTPS) |
---|
40 | |
---|
41 | HOST = 'www.etranzactng.net' |
---|
42 | HTTPS = True |
---|
43 | GATEWAY_AMT = 0.0 # is beeing added by Etranzact |
---|
44 | LOGO_URL = 'https://iuokada.waeup.org/static_custom/iou_logo.png' |
---|
45 | |
---|
46 | WEBCONNECT_STUD_PARAMS = { |
---|
47 | 'schoolfee': ('7007139588','QIgl9a35R30A1RGK'), |
---|
48 | 'schoolfee40': ('7007139589','3coU0eolOEbEUeO3'), |
---|
49 | 'secondinstal': ('7007139590','zGpEjy6CdPxCHqen'), |
---|
50 | 'transcript_local': ('7007139592','ndgxUtzJgHRkvXlB'), |
---|
51 | 'transcript': ('7007139592','ndgxUtzJgHRkvXlB'), |
---|
52 | 'transcript_overseas': ('7007139592','ndgxUtzJgHRkvXlB'), |
---|
53 | 'registration': ('7007139599','KGHjZ2hRbaDJGBX8'), |
---|
54 | 'book': ('7007139600','rrKE2Ua7eu8TF0Is'), |
---|
55 | 'parentsconsult': ('7007139598','HsqjOlAB5xfQNDyo'), |
---|
56 | 'sundry': ('7007139591','0XkOFShPnWn8tY5O'), |
---|
57 | 'health_insurance':('7007140478', 'Be24m7O7iODZXcYF'), |
---|
58 | } |
---|
59 | |
---|
60 | def determine_appl_params(payment): |
---|
61 | terminal_id = '' |
---|
62 | secret_key = '' |
---|
63 | if payment.__parent__.__parent__.prefix.startswith('pg'): |
---|
64 | terminal_id = '7007139606' |
---|
65 | secret_key = 'E64s3IN9cXRJeltY' |
---|
66 | else: |
---|
67 | terminal_id = '7007139604' |
---|
68 | secret_key = 'vlEEJxvJBjC468g1' |
---|
69 | return terminal_id, secret_key |
---|
70 | |
---|
71 | def determine_stud_params(payment): |
---|
72 | terminal_id = '' |
---|
73 | secret_key = '' |
---|
74 | for key in WEBCONNECT_STUD_PARAMS.keys(): |
---|
75 | if payment.p_category == key: |
---|
76 | terminal_id = WEBCONNECT_STUD_PARAMS[key][0] |
---|
77 | secret_key = WEBCONNECT_STUD_PARAMS[key][1] |
---|
78 | if not terminal_id: |
---|
79 | terminal_id = WEBCONNECT_STUD_PARAMS['sundry'][0] |
---|
80 | secret_key = WEBCONNECT_STUD_PARAMS['sundry'][1] |
---|
81 | return terminal_id, secret_key |
---|
82 | |
---|
83 | class CustomEtranzactPageApplicant(EtranzactPageApplicant): |
---|
84 | |
---|
85 | host = HOST |
---|
86 | https = HTTPS |
---|
87 | logo_url = LOGO_URL |
---|
88 | gateway_amt = GATEWAY_AMT |
---|
89 | |
---|
90 | @property |
---|
91 | def terminal_id(self): |
---|
92 | return determine_appl_params(self.context)[0] |
---|
93 | |
---|
94 | @property |
---|
95 | def secret_key(self): |
---|
96 | return determine_appl_params(self.context)[1] |
---|
97 | |
---|
98 | def update(self): |
---|
99 | if not webconnect_module_activated( |
---|
100 | self.context.__parent__.__parent__.year, self.context): |
---|
101 | self.flash('Forbidden', type='danger') |
---|
102 | self.redirect(self.url(self.context, '@@index')) |
---|
103 | return |
---|
104 | # Already now it becomes an Etranzact payment. We set the net amount |
---|
105 | # and add the gateway amount. |
---|
106 | if not self.context.r_company: |
---|
107 | self.context.net_amt = self.context.amount_auth |
---|
108 | self.context.amount_auth += self.gateway_amt |
---|
109 | self.context.gateway_amt = self.gateway_amt |
---|
110 | self.context.r_company = u'etranzact' |
---|
111 | self.amount = "%.1f" % self.context.amount_auth |
---|
112 | error = self.init_update() |
---|
113 | if error: |
---|
114 | self.flash(error, type='danger') |
---|
115 | self.redirect(self.url(self.context, '@@index')) |
---|
116 | return |
---|
117 | return |
---|
118 | |
---|
119 | class CustomEtranzactReceiveResponseApplicant(EtranzactReceiveResponseApplicant): |
---|
120 | |
---|
121 | @property |
---|
122 | def terminal_id(self): |
---|
123 | return determine_appl_params(self.context)[0] |
---|
124 | |
---|
125 | @property |
---|
126 | def secret_key(self): |
---|
127 | return determine_appl_params(self.context)[1] |
---|
128 | |
---|
129 | class CustomEtranzactRequestPaymentStatusPageApplicant( |
---|
130 | EtranzactRequestPaymentStatusPageApplicant): |
---|
131 | |
---|
132 | host = HOST |
---|
133 | https = HTTPS |
---|
134 | logo_url = LOGO_URL |
---|
135 | |
---|
136 | @property |
---|
137 | def terminal_id(self): |
---|
138 | return determine_appl_params(self.context)[0] |
---|
139 | |
---|
140 | @property |
---|
141 | def secret_key(self): |
---|
142 | return determine_appl_params(self.context)[1] |
---|
143 | |
---|
144 | class CustomEtranzactPageStudent(EtranzactPageStudent): |
---|
145 | |
---|
146 | host = HOST |
---|
147 | https = HTTPS |
---|
148 | logo_url = LOGO_URL |
---|
149 | gateway_amt = GATEWAY_AMT |
---|
150 | |
---|
151 | @property |
---|
152 | def terminal_id(self): |
---|
153 | return determine_stud_params(self.context)[0] |
---|
154 | |
---|
155 | @property |
---|
156 | def secret_key(self): |
---|
157 | return determine_stud_params(self.context)[1] |
---|
158 | |
---|
159 | def update(self): |
---|
160 | if not webconnect_module_activated( |
---|
161 | self.context.student.current_session, self.context): |
---|
162 | self.flash(_('Forbidden'), type='danger') |
---|
163 | self.redirect(self.url(self.context, '@@index')) |
---|
164 | return |
---|
165 | # Already now it becomes an Etranzact payment. We set the net amount |
---|
166 | # and add the gateway amount. |
---|
167 | if not self.context.r_company: |
---|
168 | self.context.net_amt = self.context.amount_auth |
---|
169 | self.context.amount_auth += self.gateway_amt |
---|
170 | self.context.gateway_amt = self.gateway_amt |
---|
171 | self.context.r_company = u'etranzact' |
---|
172 | self.amount = "%.1f" % self.context.amount_auth |
---|
173 | error = self.init_update() |
---|
174 | if error: |
---|
175 | self.flash(error, type='danger') |
---|
176 | self.redirect(self.url(self.context, '@@index')) |
---|
177 | return |
---|
178 | return |
---|
179 | |
---|
180 | class CustomEtranzactReceiveResponseStudent(EtranzactReceiveResponseStudent): |
---|
181 | |
---|
182 | @property |
---|
183 | def terminal_id(self): |
---|
184 | return determine_stud_params(self.context)[0] |
---|
185 | |
---|
186 | @property |
---|
187 | def secret_key(self): |
---|
188 | return determine_stud_params(self.context)[1] |
---|
189 | |
---|
190 | class CustomEtranzactRequestPaymentStatusPageStudent( |
---|
191 | EtranzactRequestPaymentStatusPageStudent): |
---|
192 | |
---|
193 | host = HOST |
---|
194 | https = HTTPS |
---|
195 | logo_url = LOGO_URL |
---|
196 | |
---|
197 | @property |
---|
198 | def terminal_id(self): |
---|
199 | return determine_stud_params(self.context)[0] |
---|
200 | |
---|
201 | @property |
---|
202 | def secret_key(self): |
---|
203 | return determine_stud_params(self.context)[1] |
---|
204 | |
---|
205 | |
---|
206 | |
---|
207 | |
---|
208 | |
---|
209 | # Payoutlet customizations |
---|
210 | |
---|
211 | class CustomEtranzactEnterPinPageStudent(EtranzactEnterPinPageStudent): |
---|
212 | """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageStudent` |
---|
213 | """ |
---|
214 | gateway_amt = GATEWAY_AMT |
---|
215 | |
---|
216 | def update(self): |
---|
217 | if not payoutlet_module_activated( |
---|
218 | self.context.student.current_session, self.context): |
---|
219 | self.flash(_('Forbidden'), type='danger') |
---|
220 | self.redirect(self.url(self.context, '@@index')) |
---|
221 | return |
---|
222 | # Already now it becomes an Etranzact payment. We set the net amount |
---|
223 | # and add the gateway amount. |
---|
224 | if not self.context.r_company: |
---|
225 | self.context.net_amt = self.context.amount_auth |
---|
226 | self.context.amount_auth += self.gateway_amt |
---|
227 | self.context.gateway_amt = self.gateway_amt |
---|
228 | self.context.r_company = u'etranzact' |
---|
229 | return |
---|
230 | |
---|
231 | class CustomEtranzactEnterPinPageApplicant(EtranzactEnterPinPageApplicant): |
---|
232 | """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageApplicant` |
---|
233 | """ |
---|
234 | gateway_amt = GATEWAY_AMT |
---|
235 | |
---|
236 | def update(self): |
---|
237 | if not payoutlet_module_activated( |
---|
238 | self.context.__parent__.__parent__.year, self.context): |
---|
239 | self.flash(_('Forbidden'), type='danger') |
---|
240 | self.redirect(self.url(self.context, '@@index')) |
---|
241 | return |
---|
242 | # Already now it becomes an Etranzact payment. We set the net amount |
---|
243 | # and add the gateway amount. |
---|
244 | if not self.context.r_company: |
---|
245 | self.context.net_amt = self.context.amount_auth |
---|
246 | self.context.amount_auth += self.gateway_amt |
---|
247 | self.context.gateway_amt = self.gateway_amt |
---|
248 | self.context.r_company = u'etranzact' |
---|
249 | return |
---|
250 | |
---|
251 | class CustomEtranzactQueryHistoryPageStudent(EtranzactQueryHistoryPageStudent): |
---|
252 | """ Query history of Etranzact payments |
---|
253 | """ |
---|
254 | terminal_id = '7007134590' |
---|
255 | host = HOST |
---|
256 | https = HTTPS |
---|
257 | |
---|
258 | class CustomEtranzactQueryHistoryPageApplicant(EtranzactQueryHistoryPageApplicant): |
---|
259 | """ Query history of Etranzact payments |
---|
260 | """ |
---|
261 | terminal_id = '7009158847' |
---|
262 | host = HOST |
---|
263 | https = HTTPS |
---|
264 | |
---|
265 | class CustomPaymentDataWebservice(NigeriaPaymentDataWebservice): |
---|
266 | """A simple webservice to publish payment and payer details on request from |
---|
267 | accepted IP addresses without authentication. |
---|
268 | """ |
---|
269 | #ACCEPTED_IP = ('195.219.3.181', '195.219.3.184') |
---|
270 | ACCEPTED_IP = None |
---|
271 | |
---|
272 | CATEGORY_MAPPING = { |
---|
273 | 'IUO_SCHOOL_FEES_FULL_PAYMENT': ('schoolfee',), |
---|
274 | 'IUO_SCHOOL_FEES_FIRST_INSTALLMENT': ('schoolfee40',), |
---|
275 | 'IUO_SCHOOL_FEES_OTHER_INSTALLMENT': ('secondinstal',), |
---|
276 | |
---|
277 | 'IUO_SUNDRY_FEES': ('combi',), |
---|
278 | |
---|
279 | 'IUO_MATRICULATION_FEE': ('matric',), |
---|
280 | 'IUO_LATE_REGISTRATION_FEE': ('late_registration',), |
---|
281 | 'IUO_WAEC/NECO_VERIFICATION_FEE': ('waecneco',), |
---|
282 | 'IUO_JAMB_VERIFICATION': ('jambver',), |
---|
283 | 'IUO_CONVOCATION_FEE': ('conv',), |
---|
284 | 'IUO_ALUMNI_FEE': ('alumni',), |
---|
285 | 'IUO_SCIENCE_BENCE_FEE': ('science',), |
---|
286 | 'IUO_LETTER_OF_IDENTIFICATION_FEE': ('lo_ident',), |
---|
287 | 'IUO_CHANGE_OF_COURSE_FEE': ('change_course',), |
---|
288 | 'IUO_IUITS_FEE': ('iuits',), |
---|
289 | 'IUO_FINES_FEE': ('fine',), |
---|
290 | 'IUO_PHARMACY_LAB_SUPPORT_FEE': ('pharmlab',), |
---|
291 | 'IUO_MAKEUP_FEE': ('resit1', 'resit2', 'resit3', 'resit4', |
---|
292 | 'resit5', 'resit6', 'resit7', 'resit8', |
---|
293 | 'resit9',), |
---|
294 | 'IUO_CLINICAL_FEE_MEDICAL_STUDENTS': ('clinical',), |
---|
295 | 'IUO_TRANSCRIPT_FEE_INTERNATIONAL': ('transcript_overseas',), |
---|
296 | 'IUO_TRANCRIPT_FEE_LOCAL': ('transcript_local', 'transcript'), |
---|
297 | 'IUO_ACCEPTANCE_FEE': ('clearance',), |
---|
298 | 'IUO_CLEARANCE_FEE': ('grad_clearance',), |
---|
299 | 'IUO_ID_CARD_FEE': ('id_card',), |
---|
300 | 'IUO_REGISTRATION_FEE': ('registration', 'registration_fresh', |
---|
301 | 'registration_return',), |
---|
302 | 'IUO_DEVELOPMENT_FEE': ('develop',), |
---|
303 | 'IUO_MUNICIPAL_FEE': ('municipal_fresh','municipal_returning'), |
---|
304 | 'IUO_BOOK_DEPOSIT': ('book',), |
---|
305 | 'IUO_PARENTS_CONSULTATIVE_FORUM_FEE': ('parentsconsult',), |
---|
306 | |
---|
307 | 'IUO_APPLICATION_FORM_UNDERGRADUATE': ('application',), |
---|
308 | 'IUO_APPLICATION_FORM_POSTGRADUATE': ('application',), |
---|
309 | |
---|
310 | 'IUO_MAKE_UP_REGISTRATION_FEE': ('makeup_admin',), |
---|
311 | 'IUO_STUDENT_HEALTH_INSURANCE': ('health_insurance',), |
---|
312 | |
---|
313 | 'IUO_COMBI_PAYMENT': ('combi',), |
---|
314 | |
---|
315 | 'JUPEB_FORM_FEE': ('jupeb_form',), |
---|
316 | 'JUPEB_ACCEPTANCE_FEE': ('jupeb_acc',), |
---|
317 | 'JUPEB_SCIENCE_COURSE': ('jupeb_sci',), |
---|
318 | 'JUPEB_ARTS_COURSE': ('jupeb_arts',), |
---|
319 | 'JUPEB_HOSTEL_FEE': ('jupeb_hostel',), |
---|
320 | 'JUPEB_REGISTRATION_FEE': ('jupeb_reg',), |
---|
321 | } |
---|
322 | |
---|
323 | # Credo customizations |
---|
324 | |
---|
325 | SECRET_API_KEY = "1PRI1279pI28Y9kCqZs9PlvM6ZjjZx4dXBdV8a" |
---|
326 | API_PUBLIC_KEY = "1PUB1279tj5IbnXbUFd78YT3ew8XHeyLJP3tEm" |
---|
327 | CREDO_HOST = "api.credocentral.com" |
---|
328 | |
---|
329 | scodes_path = os.path.join( |
---|
330 | os.path.dirname(__file__), 'servicecodes.csv') |
---|
331 | reader = csv.DictReader(open(scodes_path, 'rb')) |
---|
332 | SCODES = {line['p_category']:line['serviceCode'] for line in reader} |
---|
333 | |
---|
334 | class CustomCredoPageStudent(CredoPageStudent): |
---|
335 | |
---|
336 | host = CREDO_HOST |
---|
337 | api_public_key = API_PUBLIC_KEY |
---|
338 | |
---|
339 | @property |
---|
340 | def serviceCode(self): |
---|
341 | return SCODES.get(self.context.p_category, None) |
---|
342 | |
---|
343 | class CustomCredoPageApplicant(CredoPageApplicant): |
---|
344 | |
---|
345 | host = CREDO_HOST |
---|
346 | api_public_key = API_PUBLIC_KEY |
---|
347 | |
---|
348 | @property |
---|
349 | def serviceCode(self): |
---|
350 | return SCODES.get(self.context.p_category, None) |
---|
351 | |
---|
352 | class CustomCredoVerifyPaymentStatusPageStudent(CredoVerifyPaymentStatusPageStudent): |
---|
353 | |
---|
354 | host = CREDO_HOST |
---|
355 | secret_api_key = SECRET_API_KEY |
---|
356 | |
---|
357 | class CustomCredoVerifyPaymentStatusPageApplicant(CredoVerifyPaymentStatusPageApplicant): |
---|
358 | |
---|
359 | host = CREDO_HOST |
---|
360 | secret_api_key = SECRET_API_KEY |
---|