1 | ## $Id: browser.py 17936 2024-10-04 22:26:13Z 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 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
23 | InterswitchPaymentRequestWebservicePageStudent, |
---|
24 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
25 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
26 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
27 | module_activated, |
---|
28 | ) |
---|
29 | from kofacustom.nigeria.interswitch.webcheckoutbrowser import ( |
---|
30 | webcheckout_module_activated, |
---|
31 | WebCheckoutPageStudent, |
---|
32 | WebCheckoutPageApplicant, |
---|
33 | WebCheckoutConfirmTransactionStudent, |
---|
34 | WebCheckoutConfirmTransactionApplicant, |
---|
35 | ) |
---|
36 | from kofacustom.edopoly.students.interfaces import ICustomStudentOnlinePayment |
---|
37 | from kofacustom.edopoly.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
38 | from kofacustom.edopoly.interfaces import MessageFactory as _ |
---|
39 | |
---|
40 | PRODUCT_ID = '7571' # must be provided by Interswitch |
---|
41 | SITE_NAME = 'edopoly-kofa.waeup.org' |
---|
42 | PROVIDER_ACCT = '0773411069' |
---|
43 | PROVIDER_BANK_ID = '31' |
---|
44 | PROVIDER_ITEM_NAME = 'WAeAC' |
---|
45 | INSTITUTION_NAME = 'EdoPoly' |
---|
46 | CURRENCY = '566' |
---|
47 | GATEWAY_AMT = 250.0 |
---|
48 | MAC = '672ABFB2F3755A7793DE545BDA00F44878DF59140B43A1E7DF16245D299F3108AFF65502F16D95256B3242B43CBC3F512A208EB1BA977080D65328800C49912C' |
---|
49 | |
---|
50 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay' |
---|
51 | #POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay' |
---|
52 | HOST = 'webpay.interswitchng.com' |
---|
53 | #HOST = 'sandbox.interswitchng.com' |
---|
54 | URL = '/paydirect/api/v1/gettransaction.json' |
---|
55 | #URL = '/webpay/api/v1/gettransaction.json' |
---|
56 | |
---|
57 | httplib.HTTPSConnection.debuglevel = 0 |
---|
58 | HTTPS = True |
---|
59 | |
---|
60 | SPECIAL_PAYMENT_PARAMS = { |
---|
61 | |
---|
62 | 'conv_nd': ('101', 1000.0, '0031913976', '121'), |
---|
63 | 'conv_hnd': ('101', 1000.0, '0031913976', '121'), |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
68 | """ View which sends a POST request to the Interswitch |
---|
69 | CollegePAY payment gateway. |
---|
70 | """ |
---|
71 | grok.context(ICustomStudentOnlinePayment) |
---|
72 | action = POST_ACTION |
---|
73 | site_name = SITE_NAME |
---|
74 | currency = CURRENCY |
---|
75 | product_id = PRODUCT_ID |
---|
76 | mac = MAC |
---|
77 | |
---|
78 | def update(self): |
---|
79 | if not module_activated( |
---|
80 | self.context.student.current_session, self.context): |
---|
81 | self.flash(_('Forbidden'), type='danger') |
---|
82 | self.redirect(self.url(self.context, '@@index')) |
---|
83 | return |
---|
84 | error = self.init_update() |
---|
85 | if error: |
---|
86 | self.flash(error, type='danger') |
---|
87 | self.redirect(self.url(self.context, '@@index')) |
---|
88 | return |
---|
89 | self.context.r_company = u'interswitch' |
---|
90 | student = self.student |
---|
91 | xmldict = self.xmldict |
---|
92 | # Provider data |
---|
93 | xmldict['detail_ref'] = self.context.p_id |
---|
94 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
95 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
96 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
97 | provider_amt = 0.0 |
---|
98 | if not self.context.p_item == 'Balance': |
---|
99 | if self.context.p_category == 'ict_entre': |
---|
100 | provider_amt = 3000.0 |
---|
101 | if self.context.p_category == 'clearance': |
---|
102 | provider_amt = 1500.0 |
---|
103 | # temporarily disabled |
---|
104 | #if self.context.p_category in ('transcript', 'certificate'): |
---|
105 | # provider_amt = 2000.0 |
---|
106 | # Institution data |
---|
107 | xmldict['institution_acct'] = '0068241848' |
---|
108 | xmldict['institution_bank_id'] = '121' |
---|
109 | if self.context.p_category == 'union': |
---|
110 | xmldict['institution_acct'] = '0066437412' |
---|
111 | if self.context.p_category == 'nhis': |
---|
112 | xmldict['institution_acct'] = '0075379404' |
---|
113 | if self.context.p_category == 'cyber': |
---|
114 | xmldict['institution_acct'] = '1220055070' |
---|
115 | xmldict['institution_bank_id'] = '117' |
---|
116 | if self.context.p_category == 'ispon': |
---|
117 | xmldict['institution_acct'] = '1220055104' |
---|
118 | xmldict['institution_bank_id'] = '117' |
---|
119 | xmldict['institution_amt'] = '0.0' |
---|
120 | self.pay_item_id = '101' # must be provided by Interswitch |
---|
121 | xmldict['provider_amt'] = 100 * provider_amt |
---|
122 | xmldict['institution_item_name'] = self.context.category |
---|
123 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
124 | xmldict['institution_amt'] = 100 * ( |
---|
125 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
126 | # Interswitch amount is not part of the xml data |
---|
127 | if provider_amt == 0: |
---|
128 | xmltext = """<payment_item_detail> |
---|
129 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
130 | <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" /> |
---|
131 | </item_details> |
---|
132 | </payment_item_detail>""" % xmldict |
---|
133 | else: |
---|
134 | xmltext = """<payment_item_detail> |
---|
135 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
136 | <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" /> |
---|
137 | <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" /> |
---|
138 | </item_details> |
---|
139 | </payment_item_detail>""" % xmldict |
---|
140 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
141 | self.context.provider_amt = provider_amt |
---|
142 | self.context.gateway_amt = GATEWAY_AMT |
---|
143 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
144 | hashargs = ( |
---|
145 | self.context.p_id + |
---|
146 | PRODUCT_ID + |
---|
147 | self.pay_item_id + |
---|
148 | str(int(self.amount_auth)) + |
---|
149 | self.site_redirect_url + |
---|
150 | self.mac) |
---|
151 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
152 | return |
---|
153 | |
---|
154 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
155 | """ View which sends a POST request to the Interswitch |
---|
156 | CollegePAY payment gateway. |
---|
157 | """ |
---|
158 | grok.context(ICustomApplicantOnlinePayment) |
---|
159 | action = POST_ACTION |
---|
160 | site_name = SITE_NAME |
---|
161 | currency = CURRENCY |
---|
162 | pay_item_id = '101' # must be provided by Interswitch |
---|
163 | product_id = PRODUCT_ID |
---|
164 | mac = MAC |
---|
165 | |
---|
166 | def update(self): |
---|
167 | if not module_activated( |
---|
168 | self.context.__parent__.__parent__.year, self.context): |
---|
169 | self.flash(_('Forbidden'), type='danger') |
---|
170 | self.redirect(self.url(self.context, '@@index')) |
---|
171 | return |
---|
172 | error = self.init_update() |
---|
173 | if error: |
---|
174 | self.flash(error, type='danger') |
---|
175 | self.redirect(self.url(self.context, '@@index')) |
---|
176 | return |
---|
177 | self.context.r_company = u'interswitch' |
---|
178 | xmldict = {} |
---|
179 | provider_amt = 1000.0 |
---|
180 | if self.context.p_category != 'application': |
---|
181 | provider_amt = 0.0 |
---|
182 | xmldict['institution_acct'] = '0068241848' |
---|
183 | xmldict['institution_bank_id'] = '121' |
---|
184 | xmldict['detail_ref'] = self.context.p_id |
---|
185 | xmldict['provider_amt'] = 100 * provider_amt |
---|
186 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
187 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
188 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
189 | xmldict['institution_amt'] = 100 * ( |
---|
190 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
191 | xmldict['institution_item_name'] = self.context.category |
---|
192 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
193 | if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys(): |
---|
194 | self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0] |
---|
195 | xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[ |
---|
196 | self.context.p_category][2] |
---|
197 | xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[ |
---|
198 | self.context.p_category][3] |
---|
199 | provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1] |
---|
200 | xmldict['institution_amt'] = 100 * ( |
---|
201 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
202 | xmldict['provider_amt'] = 100 * provider_amt |
---|
203 | # Interswitch amount is not part of the xml data |
---|
204 | if provider_amt == 0: |
---|
205 | xmltext = """<payment_item_detail> |
---|
206 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
207 | <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" /> |
---|
208 | </item_details> |
---|
209 | </payment_item_detail>""" % xmldict |
---|
210 | else: |
---|
211 | xmltext = """<payment_item_detail> |
---|
212 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
213 | <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" /> |
---|
214 | <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" /> |
---|
215 | </item_details> |
---|
216 | </payment_item_detail>""" % xmldict |
---|
217 | |
---|
218 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
219 | self.context.provider_amt = provider_amt |
---|
220 | self.context.gateway_amt = GATEWAY_AMT |
---|
221 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
222 | hashargs = ( |
---|
223 | self.context.p_id + |
---|
224 | PRODUCT_ID + |
---|
225 | self.pay_item_id + |
---|
226 | str(int(self.amount_auth)) + |
---|
227 | self.site_redirect_url + |
---|
228 | self.mac) |
---|
229 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
230 | return |
---|
231 | |
---|
232 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
233 | InterswitchPaymentRequestWebservicePageStudent): |
---|
234 | """Request webservice view for the CollegePAY gateway |
---|
235 | """ |
---|
236 | grok.context(ICustomStudentOnlinePayment) |
---|
237 | product_id = PRODUCT_ID |
---|
238 | gateway_host = HOST |
---|
239 | gateway_url = URL |
---|
240 | mac = MAC |
---|
241 | |
---|
242 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
243 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
244 | """Payment verify view for the CollegePAY gateway |
---|
245 | """ |
---|
246 | grok.context(ICustomStudentOnlinePayment) |
---|
247 | product_id = PRODUCT_ID |
---|
248 | gateway_host = HOST |
---|
249 | gateway_url = URL |
---|
250 | mac = MAC |
---|
251 | |
---|
252 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
253 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
254 | """Request webservice view for the CollegePAY gateway |
---|
255 | """ |
---|
256 | grok.context(ICustomApplicantOnlinePayment) |
---|
257 | product_id = PRODUCT_ID |
---|
258 | gateway_host = HOST |
---|
259 | gateway_url = URL |
---|
260 | mac = MAC |
---|
261 | |
---|
262 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
263 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
264 | """Payment verify view for the CollegePAY gateway |
---|
265 | """ |
---|
266 | grok.context(ICustomApplicantOnlinePayment) |
---|
267 | product_id = PRODUCT_ID |
---|
268 | gateway_host = HOST |
---|
269 | gateway_url = URL |
---|
270 | mac = MAC |
---|
271 | |
---|
272 | # WebCheckout customizations |
---|
273 | |
---|
274 | MERCHANT_CODE = 'MX104253' |
---|
275 | PAY_ITEM_ID = 'Default_Payable_MX104253' |
---|
276 | |
---|
277 | class CustomWebCheckoutPageStudent(WebCheckoutPageStudent): |
---|
278 | """ View which sends a POST request to the Interswitch |
---|
279 | WebCheckout payment gateway. |
---|
280 | """ |
---|
281 | action = 'https://newwebpay.interswitchng.com/collections/w/pay' |
---|
282 | #action = 'https://newwebpay.qa.interswitchng.com/collections/w/pay' |
---|
283 | currency = '566' |
---|
284 | pay_item_id = PAY_ITEM_ID |
---|
285 | merchant_code = MERCHANT_CODE |
---|
286 | gateway_amt = 0.0 |
---|
287 | product_id = PRODUCT_ID |
---|
288 | |
---|
289 | class CustomWebCheckoutPageApplicant(WebCheckoutPageApplicant): |
---|
290 | """ View which sends a POST request to the Interswitch |
---|
291 | WebCheckout payment gateway. |
---|
292 | """ |
---|
293 | |
---|
294 | action = 'https://newwebpay.interswitchng.com/collections/w/pay' |
---|
295 | currency = '566' |
---|
296 | pay_item_id = PAY_ITEM_ID |
---|
297 | merchant_code = MERCHANT_CODE |
---|
298 | |
---|
299 | class CustomWebCheckoutConfirmTransactionStudent(WebCheckoutConfirmTransactionStudent): |
---|
300 | """ Request webservice view for the WebCheckout gateway |
---|
301 | """ |
---|
302 | merchant_code = MERCHANT_CODE |
---|
303 | gateway_host = 'webpay.interswitchng.com' |
---|
304 | gateway_url = '/collections/api/v1/gettransaction.json' |
---|
305 | https = True |
---|
306 | |
---|
307 | class CustomWebCheckoutConfirmTransactionApplicant(WebCheckoutConfirmTransactionApplicant): |
---|
308 | """ Request webservice view for the WebCheckout gateway |
---|
309 | """ |
---|
310 | merchant_code = MERCHANT_CODE |
---|
311 | gateway_host = 'webpay.interswitchng.com' |
---|
312 | gateway_url = '/collections/api/v1/gettransaction.json' |
---|
313 | https = True |
---|
314 | |
---|
315 | |
---|