1 | ## $Id: browser.py 17672 2024-01-16 17:29:32Z 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.iuokada.students.interfaces import ICustomStudentOnlinePayment |
---|
30 | from kofacustom.iuokada.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
31 | from kofacustom.iuokada.interfaces import MessageFactory as _ |
---|
32 | |
---|
33 | PRODUCT_ID = '7922' |
---|
34 | SITE_NAME = 'iuokada.waeup.org' |
---|
35 | PROVIDER_ACCT = '0773411069' |
---|
36 | PROVIDER_BANK_ID = '31' |
---|
37 | PROVIDER_ITEM_NAME = 'WAeAC' |
---|
38 | INSTITUTION_NAME = 'IUOkada' |
---|
39 | CURRENCY = '566' |
---|
40 | GATEWAY_AMT = 250.0 |
---|
41 | #MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' # must be provided by Interswitch |
---|
42 | MAC = '4D8723F33D728BE3F4A77B2DFB3F57B0BCF2DD818759D54A87B2A60874067F28D94F2B91E29BFB884F920F48E0973D826835A8F2D6F74220C64EDE4DE00E45AA' |
---|
43 | |
---|
44 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay' |
---|
45 | #POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay' |
---|
46 | HOST = 'webpay.interswitchng.com' |
---|
47 | #HOST = 'sandbox.interswitchng.com' |
---|
48 | URL = '/paydirect/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 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
78 | # and add the gateway amount. |
---|
79 | if not self.context.r_company: |
---|
80 | self.context.net_amt = self.context.amount_auth |
---|
81 | self.context.amount_auth += self.gateway_amt |
---|
82 | self.context.gateway_amt = self.gateway_amt |
---|
83 | self.context.r_company = u'interswitch' |
---|
84 | student = self.student |
---|
85 | xmldict = self.xmldict |
---|
86 | # Provider data |
---|
87 | xmldict['detail_ref'] = self.context.p_id |
---|
88 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
89 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
90 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
91 | xmldict['institution_acct'] = '' |
---|
92 | xmldict['institution_bank_id'] = '' |
---|
93 | provider_amt = 0.0 |
---|
94 | self.pay_item_id = '' |
---|
95 | # Institution data |
---|
96 | if self.context.p_category in ( |
---|
97 | 'schoolfee', 'schoolfee40', 'secondinstal'): |
---|
98 | self.pay_item_id = '101' |
---|
99 | elif self.context.p_category == 'book': |
---|
100 | self.pay_item_id = '103' |
---|
101 | elif self.context.p_category == 'parentsconsult': |
---|
102 | self.pay_item_id = '104' |
---|
103 | elif self.context.p_category in ( |
---|
104 | 'municipal_fresh', 'municipal_returning', |
---|
105 | 'transcript_local', 'transcript_overseas', 'transcript'): |
---|
106 | self.pay_item_id = '105' |
---|
107 | else: |
---|
108 | self.pay_item_id = '102' |
---|
109 | if self.context.p_category in ( |
---|
110 | 'registration', 'required_combi', 'pg_other', 'jupeb_reg'): |
---|
111 | provider_amt = 5000.0 |
---|
112 | if self.context.p_category in ( |
---|
113 | 'schoolfee', 'schoolfee40') and student.is_jupeb: |
---|
114 | provider_amt = 5000.0 |
---|
115 | if self.context.p_category.startswith('jupeb'): |
---|
116 | self.pay_item_id = '102' |
---|
117 | xmldict['provider_amt'] = 100 * provider_amt |
---|
118 | xmldict['institution_item_name'] = self.context.category |
---|
119 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
120 | xmldict['institution_amt'] = 100 * self.context.net_amt - ( |
---|
121 | 100 * provider_amt) |
---|
122 | |
---|
123 | if grok.getSite().__name__ == 'iuokada-cdl': |
---|
124 | xmldict['institution_acct'] = '1229771245' |
---|
125 | xmldict['institution_bank_id'] = '117' |
---|
126 | if self.context.p_category.startswith('schoolfee'): |
---|
127 | xmldict['institution_acct'] = '1828332878' |
---|
128 | xmldict['institution_bank_id'] = '31' |
---|
129 | else: |
---|
130 | if self.context.p_option == 'access': |
---|
131 | xmldict['institution_acct'] = '0040484781' |
---|
132 | xmldict['institution_bank_id'] = '31' |
---|
133 | elif self.context.p_option == 'first': |
---|
134 | xmldict['institution_acct'] = '2021420049' |
---|
135 | xmldict['institution_bank_id'] = '8' |
---|
136 | elif self.context.p_option == 'zenith': |
---|
137 | xmldict['institution_acct'] = '1011005811' |
---|
138 | xmldict['institution_bank_id'] = '117' |
---|
139 | else: |
---|
140 | xmldict['institution_acct'] = '0040484781' |
---|
141 | xmldict['institution_bank_id'] = '31' |
---|
142 | |
---|
143 | # Overwrite above selection |
---|
144 | if self.context.p_category == 'book': |
---|
145 | xmldict['institution_acct'] = '1228744877' |
---|
146 | xmldict['institution_bank_id'] = '117' |
---|
147 | elif self.context.p_category == 'parentsconsult': |
---|
148 | xmldict['institution_acct'] = '1228747029' |
---|
149 | xmldict['institution_bank_id'] = '117' |
---|
150 | elif self.context.p_category == 'health_insurance': |
---|
151 | xmldict['institution_acct'] = '1228744884' |
---|
152 | xmldict['institution_bank_id'] = '117' |
---|
153 | |
---|
154 | if provider_amt == 0: |
---|
155 | xmltext = """<payment_item_detail> |
---|
156 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
157 | <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" /> |
---|
158 | </item_details> |
---|
159 | </payment_item_detail>""" % xmldict |
---|
160 | else: |
---|
161 | xmltext = """<payment_item_detail> |
---|
162 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
163 | <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" /> |
---|
164 | <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" /> |
---|
165 | </item_details> |
---|
166 | </payment_item_detail>""" % xmldict |
---|
167 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
168 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
169 | hashargs = ( |
---|
170 | self.context.p_id + |
---|
171 | PRODUCT_ID + |
---|
172 | self.pay_item_id + |
---|
173 | str(int(self.amount_auth)) + |
---|
174 | self.site_redirect_url + |
---|
175 | self.mac) |
---|
176 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
177 | return |
---|
178 | |
---|
179 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
180 | """ View which sends a POST request to the Interswitch |
---|
181 | CollegePAY payment gateway. |
---|
182 | """ |
---|
183 | grok.context(ICustomApplicantOnlinePayment) |
---|
184 | action = POST_ACTION |
---|
185 | site_name = SITE_NAME |
---|
186 | currency = CURRENCY |
---|
187 | product_id = PRODUCT_ID |
---|
188 | mac = MAC |
---|
189 | gateway_amt = GATEWAY_AMT |
---|
190 | |
---|
191 | def update(self): |
---|
192 | if not module_activated( |
---|
193 | self.context.__parent__.__parent__.year, self.context): |
---|
194 | self.flash(_('Forbidden'), type='danger') |
---|
195 | self.redirect(self.url(self.context, '@@index')) |
---|
196 | return |
---|
197 | error = self.init_update() |
---|
198 | if error: |
---|
199 | self.flash(error, type='danger') |
---|
200 | self.redirect(self.url(self.context, '@@index')) |
---|
201 | return |
---|
202 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
203 | # and add the gateway amount. |
---|
204 | if not self.context.r_company: |
---|
205 | self.context.net_amt = self.context.amount_auth |
---|
206 | self.context.amount_auth += self.gateway_amt |
---|
207 | self.context.gateway_amt = self.gateway_amt |
---|
208 | self.context.r_company = u'interswitch' |
---|
209 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
210 | xmldict = {} |
---|
211 | provider_amt = 0.0 |
---|
212 | self.pay_item_id = '101' |
---|
213 | xmldict['institution_acct'] = '1011005811' |
---|
214 | xmldict['institution_bank_id'] = '117' |
---|
215 | if grok.getSite().__name__ == 'iuokada-cdl': |
---|
216 | xmldict['institution_acct'] = '1229774710' |
---|
217 | xmldict['institution_bank_id'] = '117' |
---|
218 | xmldict['detail_ref'] = self.context.p_id |
---|
219 | xmldict['provider_amt'] = 100 * provider_amt |
---|
220 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
221 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
222 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
223 | xmldict['institution_item_name'] = self.context.category |
---|
224 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
225 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
226 | if not self.context.provider_amt: |
---|
227 | self.context.provider_amt = provider_amt |
---|
228 | self.context.amount_auth += provider_amt |
---|
229 | if provider_amt == 0: |
---|
230 | xmltext = """<payment_item_detail> |
---|
231 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
232 | <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" /> |
---|
233 | </item_details> |
---|
234 | </payment_item_detail>""" % xmldict |
---|
235 | else: |
---|
236 | xmltext = """<payment_item_detail> |
---|
237 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
238 | <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" /> |
---|
239 | <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" /> |
---|
240 | </item_details> |
---|
241 | </payment_item_detail>""" % xmldict |
---|
242 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
243 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
244 | hashargs = ( |
---|
245 | self.context.p_id + |
---|
246 | PRODUCT_ID + |
---|
247 | self.pay_item_id + |
---|
248 | str(int(self.amount_auth)) + |
---|
249 | self.site_redirect_url + |
---|
250 | self.mac) |
---|
251 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
252 | return |
---|
253 | |
---|
254 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
255 | InterswitchPaymentRequestWebservicePageStudent): |
---|
256 | """Request webservice view for the CollegePAY gateway |
---|
257 | """ |
---|
258 | grok.context(ICustomStudentOnlinePayment) |
---|
259 | product_id = PRODUCT_ID |
---|
260 | gateway_host = HOST |
---|
261 | gateway_url = URL |
---|
262 | mac = MAC |
---|
263 | |
---|
264 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
265 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
266 | """Payment verify view for the CollegePAY gateway |
---|
267 | """ |
---|
268 | grok.context(ICustomStudentOnlinePayment) |
---|
269 | product_id = PRODUCT_ID |
---|
270 | gateway_host = HOST |
---|
271 | gateway_url = URL |
---|
272 | mac = MAC |
---|
273 | |
---|
274 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
275 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
276 | """Request webservice view for the CollegePAY gateway |
---|
277 | """ |
---|
278 | grok.context(ICustomApplicantOnlinePayment) |
---|
279 | product_id = PRODUCT_ID |
---|
280 | gateway_host = HOST |
---|
281 | gateway_url = URL |
---|
282 | mac = MAC |
---|
283 | |
---|
284 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
285 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
286 | """Payment verify view for the CollegePAY gateway |
---|
287 | """ |
---|
288 | grok.context(ICustomApplicantOnlinePayment) |
---|
289 | product_id = PRODUCT_ID |
---|
290 | gateway_host = HOST |
---|
291 | gateway_url = URL |
---|
292 | mac = MAC |
---|
293 | |
---|
294 | |
---|
295 | # PAYDirect added on 19/05/2021 |
---|
296 | |
---|
297 | from kofacustom.nigeria.interswitch.paydirectbrowser import ( |
---|
298 | PAYDirectPageStudent, PAYDirectPageApplicant, |
---|
299 | StudentRefNumberSlip, ApplicantRefNumberSlip, |
---|
300 | ) |
---|
301 | |
---|
302 | PAYDIRECT_HOST = 'orion.interswitchng.com' |
---|
303 | PAYDIRECT_URL = '/bookonhold/bookonhold.asmx' |
---|
304 | MERCHANT_ID = '8124' |
---|
305 | |
---|
306 | class CustomPAYDirectPageStudent(PAYDirectPageStudent): |
---|
307 | """Inform student how to proceed |
---|
308 | """ |
---|
309 | grok.context(ICustomStudentOnlinePayment) |
---|
310 | gateway_amt = GATEWAY_AMT |
---|
311 | merchant_id = MERCHANT_ID |
---|
312 | gateway_url = PAYDIRECT_URL |
---|
313 | gateway_host = PAYDIRECT_HOST |
---|
314 | https = True |
---|
315 | |
---|
316 | class CustomPAYDirectPageApplicant(PAYDirectPageApplicant): |
---|
317 | """ Inform applicant how to proceed. |
---|
318 | """ |
---|
319 | grok.context(ICustomApplicantOnlinePayment) |
---|
320 | gateway_amt = GATEWAY_AMT |
---|
321 | merchant_id = MERCHANT_ID |
---|
322 | gateway_url = PAYDIRECT_URL |
---|
323 | gateway_host = PAYDIRECT_HOST |
---|
324 | https = True |
---|
325 | |
---|
326 | class CustomStudentRefNumberSlip(StudentRefNumberSlip): |
---|
327 | """Deliver a PDF slip of the context. |
---|
328 | """ |
---|
329 | merchant_id = MERCHANT_ID |
---|
330 | |
---|
331 | class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip): |
---|
332 | """Deliver a PDF slip of the context. |
---|
333 | """ |
---|
334 | merchant_id = MERCHANT_ID |
---|