1 | ## $Id: browser.py 17682 2024-01-29 09:01:58Z 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 | if self.context.p_category == 'clearance': |
---|
90 | provider_amt = 500.0 |
---|
91 | if student.current_mode in ('ug_ft', 'de_ft'): |
---|
92 | xmldict['institution_acct'] = '1216063205' |
---|
93 | tech_fee = 18000.0 |
---|
94 | xmldict['tech_acct'] = '0092304647' |
---|
95 | xmldict['tech_bank_id'] = '121' |
---|
96 | elif student.current_mode.startswith('dp'): |
---|
97 | xmldict['institution_acct'] = '1011431799' |
---|
98 | if student.faccode in ('PRE', 'JUPEB'): |
---|
99 | xmldict['institution_acct'] = '1011431799' |
---|
100 | elif student.faccode == 'IJMB': |
---|
101 | xmldict['institution_acct'] = '0093658062' |
---|
102 | xmldict['institution_bank_id'] = '121' |
---|
103 | if self.context.p_item == 'Balance': |
---|
104 | provider_amt = 0.0 |
---|
105 | tech_fee = 0.0 |
---|
106 | elif self.context.p_category == 'schoolfee': |
---|
107 | provider_amt = 2800.0 |
---|
108 | tech_fee = 1200.0 |
---|
109 | xmldict['institution_acct'] = '1011739172' |
---|
110 | xmldict['tech_acct'] = '0213065415' |
---|
111 | xmldict['tech_bank_id'] = '47' |
---|
112 | if student.current_mode.startswith('dp'): |
---|
113 | xmldict['institution_acct'] = '2001627961' |
---|
114 | xmldict['institution_bank_id'] = '8' |
---|
115 | if student.faccode in ('PRE', 'JUPEB'): |
---|
116 | xmldict['institution_acct'] = '2001627961' |
---|
117 | xmldict['institution_bank_id'] = '8' |
---|
118 | elif student.faccode == 'DELSU': |
---|
119 | xmldict['institution_acct'] = '1011036493' |
---|
120 | elif student.faccode == 'NCE': |
---|
121 | xmldict['institution_acct'] = '1011274462' |
---|
122 | provider_amt = 4000.0 |
---|
123 | tech_fee = 0.0 |
---|
124 | elif student.faccode == 'IJMB': |
---|
125 | xmldict['institution_acct'] = '0093658062' |
---|
126 | xmldict['institution_bank_id'] = '121' |
---|
127 | elif student.faccode in ('FMED', 'FBM'): |
---|
128 | xmldict['institution_acct'] = '1011274462' |
---|
129 | if self.context.p_item == 'Balance': |
---|
130 | provider_amt = 0.0 |
---|
131 | tech_fee = 0.0 |
---|
132 | elif self.context.p_category == 'hostel_maintenance': |
---|
133 | xmldict['institution_acct'] = '1012551384' |
---|
134 | elif self.context.p_category == 'med_reg': |
---|
135 | xmldict['institution_acct'] = '1011265606' |
---|
136 | self.pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch |
---|
137 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
138 | # and add gateway amount and other surcharges. |
---|
139 | if not self.context.r_company: |
---|
140 | self.context.r_company = u'interswitch' |
---|
141 | self.context.net_amt = self.context.amount_auth |
---|
142 | self.context.gateway_amt = self.gateway_amt |
---|
143 | self.context.amount_auth += self.gateway_amt |
---|
144 | self.context.provider_amt = provider_amt |
---|
145 | self.context.amount_auth += provider_amt |
---|
146 | self.context.amount_auth += tech_fee |
---|
147 | xmldict['provider_amt'] = 100 * provider_amt |
---|
148 | xmldict['tech_fee'] = 100 * tech_fee |
---|
149 | xmldict['institution_item_name'] = self.context.category |
---|
150 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
151 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
152 | if provider_amt == 0: |
---|
153 | xmltext = """<payment_item_detail> |
---|
154 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
155 | <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" /> |
---|
156 | </item_details> |
---|
157 | </payment_item_detail>""" % xmldict |
---|
158 | elif tech_fee == 0: |
---|
159 | xmltext = """<payment_item_detail> |
---|
160 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
161 | <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" /> |
---|
162 | <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" /> |
---|
163 | </item_details> |
---|
164 | </payment_item_detail>""" % xmldict |
---|
165 | else: |
---|
166 | xmltext = """<payment_item_detail> |
---|
167 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
168 | <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" /> |
---|
169 | <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" /> |
---|
170 | <item_detail item_id="3" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="%(tech_bank_id)s" acct_num="%(tech_acct)s"/> |
---|
171 | </item_details> |
---|
172 | </payment_item_detail>""" % xmldict |
---|
173 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
174 | self.context.provider_amt = provider_amt |
---|
175 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
176 | hashargs = ( |
---|
177 | self.context.p_id + |
---|
178 | PRODUCT_ID + |
---|
179 | self.pay_item_id + |
---|
180 | str(int(self.amount_auth)) + |
---|
181 | self.site_redirect_url + |
---|
182 | self.mac) |
---|
183 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
184 | return |
---|
185 | |
---|
186 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
187 | """ View which sends a POST request to the Interswitch |
---|
188 | CollegePAY payment gateway. |
---|
189 | """ |
---|
190 | grok.context(ICustomApplicantOnlinePayment) |
---|
191 | action = POST_ACTION |
---|
192 | site_name = SITE_NAME |
---|
193 | currency = CURRENCY |
---|
194 | pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch |
---|
195 | product_id = PRODUCT_ID |
---|
196 | mac = MAC |
---|
197 | gateway_amt = GATEWAY_AMT |
---|
198 | |
---|
199 | def update(self): |
---|
200 | if not module_activated( |
---|
201 | self.context.__parent__.__parent__.year, self.context): |
---|
202 | self.flash(_('Forbidden'), type='danger') |
---|
203 | self.redirect(self.url(self.context, '@@index')) |
---|
204 | return |
---|
205 | error = self.init_update() |
---|
206 | if error: |
---|
207 | self.flash(error, type='danger') |
---|
208 | self.redirect(self.url(self.context, '@@index')) |
---|
209 | return |
---|
210 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
211 | # and add the gateway amount. |
---|
212 | if not self.context.r_company: |
---|
213 | self.context.net_amt = self.context.amount_auth |
---|
214 | self.context.amount_auth += self.gateway_amt |
---|
215 | self.context.gateway_amt = self.gateway_amt |
---|
216 | self.context.r_company = u'interswitch' |
---|
217 | xmldict = {} |
---|
218 | provider_amt = 250.0 |
---|
219 | xmldict['institution_acct'] = '1216063205' |
---|
220 | xmldict['institution_bank_id'] = '117' |
---|
221 | if self.context.__parent__.__parent__.prefix in ( |
---|
222 | 'pre', 'jupeb', 'dpft', 'dppt', |
---|
223 | 'ugpt', 'ijmb', 'df'): |
---|
224 | xmldict['institution_acct'] = '1011431799' |
---|
225 | xmldict['institution_bank_id'] = '117' |
---|
226 | provider_amt = 500.0 |
---|
227 | if self.context.__parent__.__parent__.prefix in ('ijmb',): |
---|
228 | xmldict['institution_acct'] = '0093658062' |
---|
229 | xmldict['institution_bank_id'] = '121' |
---|
230 | xmldict['detail_ref'] = self.context.p_id |
---|
231 | xmldict['provider_amt'] = 100 * provider_amt |
---|
232 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
233 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
234 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
235 | xmldict['institution_item_name'] = self.context.category |
---|
236 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
237 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
238 | if not self.context.provider_amt: |
---|
239 | self.context.provider_amt = provider_amt |
---|
240 | self.context.amount_auth += provider_amt |
---|
241 | xmltext = """<payment_item_detail> |
---|
242 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
243 | <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" /> |
---|
244 | <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" /> |
---|
245 | </item_details> |
---|
246 | </payment_item_detail>""" % xmldict |
---|
247 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
248 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
249 | hashargs = ( |
---|
250 | self.context.p_id + |
---|
251 | PRODUCT_ID + |
---|
252 | self.pay_item_id + |
---|
253 | str(int(self.amount_auth)) + |
---|
254 | self.site_redirect_url + |
---|
255 | self.mac) |
---|
256 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
257 | return |
---|
258 | |
---|
259 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
260 | InterswitchPaymentRequestWebservicePageStudent): |
---|
261 | """Request webservice view for the CollegePAY gateway |
---|
262 | """ |
---|
263 | grok.context(ICustomStudentOnlinePayment) |
---|
264 | product_id = PRODUCT_ID |
---|
265 | gateway_host = HOST |
---|
266 | gateway_url = URL |
---|
267 | mac = MAC |
---|
268 | |
---|
269 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
270 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
271 | """Payment verify view for the CollegePAY gateway |
---|
272 | """ |
---|
273 | grok.context(ICustomStudentOnlinePayment) |
---|
274 | product_id = PRODUCT_ID |
---|
275 | gateway_host = HOST |
---|
276 | gateway_url = URL |
---|
277 | mac = MAC |
---|
278 | |
---|
279 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
280 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
281 | """Request webservice view for the CollegePAY gateway |
---|
282 | """ |
---|
283 | grok.context(ICustomApplicantOnlinePayment) |
---|
284 | product_id = PRODUCT_ID |
---|
285 | gateway_host = HOST |
---|
286 | gateway_url = URL |
---|
287 | mac = MAC |
---|
288 | |
---|
289 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
290 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
291 | """Payment verify view for the CollegePAY gateway |
---|
292 | """ |
---|
293 | grok.context(ICustomApplicantOnlinePayment) |
---|
294 | product_id = PRODUCT_ID |
---|
295 | gateway_host = HOST |
---|
296 | gateway_url = URL |
---|
297 | mac = MAC |
---|
298 | |
---|
299 | # PAYDirect |
---|
300 | |
---|
301 | from kofacustom.nigeria.interswitch.paydirectbrowser import ( |
---|
302 | PAYDirectPageStudent, PAYDirectPageApplicant, |
---|
303 | StudentRefNumberSlip, ApplicantRefNumberSlip, |
---|
304 | ) |
---|
305 | |
---|
306 | from kofacustom.nigeria.interswitch.tests import ( |
---|
307 | PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID) |
---|
308 | |
---|
309 | #PAYDIRECT_HOST = 'orion.interswitchng.com' |
---|
310 | #PAYDIRECT_URL = '/bookonhold/bookonhold.asmx' |
---|
311 | #MERCHANT_ID = '' |
---|
312 | |
---|
313 | class CustomPAYDirectPageStudent(PAYDirectPageStudent): |
---|
314 | """Inform student how to proceed |
---|
315 | """ |
---|
316 | grok.context(ICustomStudentOnlinePayment) |
---|
317 | gateway_amt = GATEWAY_AMT |
---|
318 | merchant_id = MERCHANT_ID |
---|
319 | gateway_url = PAYDIRECT_URL |
---|
320 | gateway_host = PAYDIRECT_HOST |
---|
321 | https = True |
---|
322 | |
---|
323 | class CustomPAYDirectPageApplicant(PAYDirectPageApplicant): |
---|
324 | """ Inform applicant how to proceed. |
---|
325 | """ |
---|
326 | grok.context(ICustomApplicantOnlinePayment) |
---|
327 | gateway_amt = GATEWAY_AMT |
---|
328 | merchant_id = MERCHANT_ID |
---|
329 | gateway_url = PAYDIRECT_URL |
---|
330 | gateway_host = PAYDIRECT_HOST |
---|
331 | https = True |
---|
332 | |
---|
333 | class CustomStudentRefNumberSlip(StudentRefNumberSlip): |
---|
334 | """Deliver a PDF slip of the context. |
---|
335 | """ |
---|
336 | merchant_id = MERCHANT_ID |
---|
337 | |
---|
338 | class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip): |
---|
339 | """Deliver a PDF slip of the context. |
---|
340 | """ |
---|
341 | merchant_id = MERCHANT_ID |
---|