[16717] | 1 | ## $Id: browser.py 17933 2024-10-02 07:18:26Z henrik $ |
---|
[15614] | 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 ( |
---|
[16592] | 22 | module_activated, |
---|
[15614] | 23 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
| 24 | InterswitchPaymentRequestWebservicePageStudent, |
---|
| 25 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
| 26 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
| 27 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
| 28 | ) |
---|
[16721] | 29 | from kofacustom.unidel.students.interfaces import ICustomStudentOnlinePayment |
---|
| 30 | from kofacustom.unidel.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
| 31 | from kofacustom.unidel.interfaces import MessageFactory as _ |
---|
[15614] | 32 | |
---|
[16736] | 33 | PRODUCT_ID = '22153701' # must be provided by Interswitch |
---|
[16723] | 34 | SITE_NAME = 'unidel.waeup.org' |
---|
[16732] | 35 | PROVIDER_ACCT = '0213065415' |
---|
| 36 | PROVIDER_BANK_ID = '47' |
---|
[16592] | 37 | PROVIDER_ITEM_NAME = 'WAeAC' |
---|
[16723] | 38 | INSTITUTION_NAME = 'UNIDEL' |
---|
[15614] | 39 | CURRENCY = '566' |
---|
[16736] | 40 | GATEWAY_AMT = 250.0 |
---|
| 41 | #MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' |
---|
| 42 | MAC = 'Lfj58PyWS6MvPz65zIbofZNoAn89fZAjtnsEWbTof73OyHQH7rpJPHWD2m4cekDoowJ8nqQCn6ay2lopzKBOekFsMfzkXG6KYGRuyhMQq4bK7wDNaWqpxeZl3fMumNmi' |
---|
[15614] | 43 | |
---|
[16736] | 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' |
---|
[15614] | 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 |
---|
[15756] | 63 | mac = MAC |
---|
| 64 | gateway_amt = GATEWAY_AMT |
---|
[15614] | 65 | |
---|
| 66 | def update(self): |
---|
[16592] | 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 |
---|
[15614] | 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 |
---|
[16869] | 85 | xmldict['institution_acct'] = '000000000' |
---|
[17330] | 86 | xmldict['institution_bank_id'] = '117' |
---|
[15614] | 87 | provider_amt = 0.0 |
---|
[16850] | 88 | tech_fee = 0.0 |
---|
[16790] | 89 | if self.context.p_category == 'clearance': |
---|
[17913] | 90 | provider_amt = 2000.0 |
---|
[17599] | 91 | if student.current_mode in ('ug_ft', 'de_ft'): |
---|
| 92 | xmldict['institution_acct'] = '1216063205' |
---|
[17620] | 93 | tech_fee = 18000.0 |
---|
[17599] | 94 | xmldict['tech_acct'] = '0092304647' |
---|
| 95 | xmldict['tech_bank_id'] = '121' |
---|
[17682] | 96 | elif student.current_mode.startswith('dp'): |
---|
| 97 | xmldict['institution_acct'] = '1011431799' |
---|
[17613] | 98 | if student.faccode in ('PRE', 'JUPEB'): |
---|
| 99 | xmldict['institution_acct'] = '1011431799' |
---|
[17682] | 100 | elif student.faccode == 'IJMB': |
---|
[17613] | 101 | xmldict['institution_acct'] = '0093658062' |
---|
[17646] | 102 | xmldict['institution_bank_id'] = '121' |
---|
[17620] | 103 | if self.context.p_item == 'Balance': |
---|
| 104 | provider_amt = 0.0 |
---|
| 105 | tech_fee = 0.0 |
---|
[17330] | 106 | elif self.context.p_category == 'schoolfee': |
---|
[17931] | 107 | provider_amt = 6650.0 |
---|
| 108 | tech_fee = 2850.0 |
---|
| 109 | if student.is_fresh: |
---|
| 110 | provider_amt = 7000.0 |
---|
| 111 | tech_fee = 3000.0 |
---|
[16869] | 112 | xmldict['institution_acct'] = '1011739172' |
---|
[17599] | 113 | xmldict['tech_acct'] = '0213065415' |
---|
| 114 | xmldict['tech_bank_id'] = '47' |
---|
[17682] | 115 | if student.current_mode.startswith('dp'): |
---|
| 116 | xmldict['institution_acct'] = '2001627961' |
---|
| 117 | xmldict['institution_bank_id'] = '8' |
---|
[17278] | 118 | if student.faccode in ('PRE', 'JUPEB'): |
---|
[17117] | 119 | xmldict['institution_acct'] = '2001627961' |
---|
| 120 | xmldict['institution_bank_id'] = '8' |
---|
[17682] | 121 | elif student.faccode == 'DELSU': |
---|
[17459] | 122 | xmldict['institution_acct'] = '1011036493' |
---|
[17682] | 123 | elif student.faccode == 'NCE': |
---|
[17399] | 124 | xmldict['institution_acct'] = '1011274462' |
---|
[17347] | 125 | provider_amt = 4000.0 |
---|
| 126 | tech_fee = 0.0 |
---|
[17682] | 127 | elif student.faccode == 'IJMB': |
---|
[17478] | 128 | xmldict['institution_acct'] = '0093658062' |
---|
[17646] | 129 | xmldict['institution_bank_id'] = '121' |
---|
[17931] | 130 | elif student.faccode in ('FMED', 'FBM', 'FLW'): |
---|
[17682] | 131 | xmldict['institution_acct'] = '1011274462' |
---|
[17715] | 132 | elif student.certcode == 'DFFPA': |
---|
| 133 | xmldict['institution_acct'] = '2001627961' |
---|
| 134 | xmldict['institution_bank_id'] = '8' |
---|
| 135 | provider_amt = 4000.0 |
---|
| 136 | tech_fee = 0.0 |
---|
[17620] | 137 | if self.context.p_item == 'Balance': |
---|
| 138 | provider_amt = 0.0 |
---|
| 139 | tech_fee = 0.0 |
---|
[17839] | 140 | elif self.context.p_category.startswith('ijmb'): |
---|
| 141 | xmldict['institution_acct'] = '0093658062' |
---|
| 142 | xmldict['institution_bank_id'] = '121' |
---|
[17330] | 143 | elif self.context.p_category == 'hostel_maintenance': |
---|
[16869] | 144 | xmldict['institution_acct'] = '1012551384' |
---|
[17330] | 145 | elif self.context.p_category == 'med_reg': |
---|
| 146 | xmldict['institution_acct'] = '1011265606' |
---|
[17698] | 147 | elif self.context.p_category == 'teaching_practice': |
---|
| 148 | xmldict['institution_acct'] = '1005399320' |
---|
| 149 | xmldict['institution_bank_id'] = '8' |
---|
[17894] | 150 | elif self.context.p_category.startswith('transcript'): |
---|
[17891] | 151 | xmldict['institution_acct'] = '0010494552' |
---|
| 152 | xmldict['institution_bank_id'] = '129' |
---|
| 153 | provider_amt = 2000.0 |
---|
[17933] | 154 | elif self.context.p_category.startswith('union'): |
---|
| 155 | xmldict['institution_acct'] = '1011438901' |
---|
[16736] | 156 | self.pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch |
---|
[16850] | 157 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
| 158 | # and add gateway amount and other surcharges. |
---|
| 159 | if not self.context.r_company: |
---|
| 160 | self.context.r_company = u'interswitch' |
---|
| 161 | self.context.net_amt = self.context.amount_auth |
---|
| 162 | self.context.gateway_amt = self.gateway_amt |
---|
| 163 | self.context.amount_auth += self.gateway_amt |
---|
| 164 | self.context.provider_amt = provider_amt |
---|
| 165 | self.context.amount_auth += provider_amt |
---|
| 166 | self.context.amount_auth += tech_fee |
---|
[15614] | 167 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[16849] | 168 | xmldict['tech_fee'] = 100 * tech_fee |
---|
[15614] | 169 | xmldict['institution_item_name'] = self.context.category |
---|
| 170 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[15756] | 171 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
[15614] | 172 | if provider_amt == 0: |
---|
| 173 | xmltext = """<payment_item_detail> |
---|
| 174 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 175 | <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" /> |
---|
| 176 | </item_details> |
---|
| 177 | </payment_item_detail>""" % xmldict |
---|
[16849] | 178 | elif tech_fee == 0: |
---|
| 179 | xmltext = """<payment_item_detail> |
---|
| 180 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 181 | <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" /> |
---|
| 182 | <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" /> |
---|
| 183 | </item_details> |
---|
| 184 | </payment_item_detail>""" % xmldict |
---|
[15614] | 185 | else: |
---|
| 186 | xmltext = """<payment_item_detail> |
---|
| 187 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 188 | <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" /> |
---|
| 189 | <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" /> |
---|
[17599] | 190 | <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"/> |
---|
[15614] | 191 | </item_details> |
---|
| 192 | </payment_item_detail>""" % xmldict |
---|
| 193 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 194 | self.context.provider_amt = provider_amt |
---|
[15756] | 195 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[15614] | 196 | hashargs = ( |
---|
| 197 | self.context.p_id + |
---|
| 198 | PRODUCT_ID + |
---|
| 199 | self.pay_item_id + |
---|
| 200 | str(int(self.amount_auth)) + |
---|
| 201 | self.site_redirect_url + |
---|
| 202 | self.mac) |
---|
| 203 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
| 204 | return |
---|
| 205 | |
---|
| 206 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
| 207 | """ View which sends a POST request to the Interswitch |
---|
| 208 | CollegePAY payment gateway. |
---|
| 209 | """ |
---|
| 210 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 211 | action = POST_ACTION |
---|
| 212 | site_name = SITE_NAME |
---|
| 213 | currency = CURRENCY |
---|
[16736] | 214 | pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch |
---|
[15614] | 215 | product_id = PRODUCT_ID |
---|
| 216 | mac = MAC |
---|
[15756] | 217 | gateway_amt = GATEWAY_AMT |
---|
[15614] | 218 | |
---|
| 219 | def update(self): |
---|
[16592] | 220 | if not module_activated( |
---|
| 221 | self.context.__parent__.__parent__.year, self.context): |
---|
| 222 | self.flash(_('Forbidden'), type='danger') |
---|
| 223 | self.redirect(self.url(self.context, '@@index')) |
---|
| 224 | return |
---|
[15614] | 225 | error = self.init_update() |
---|
| 226 | if error: |
---|
| 227 | self.flash(error, type='danger') |
---|
| 228 | self.redirect(self.url(self.context, '@@index')) |
---|
| 229 | return |
---|
[15756] | 230 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
| 231 | # and add the gateway amount. |
---|
| 232 | if not self.context.r_company: |
---|
| 233 | self.context.net_amt = self.context.amount_auth |
---|
| 234 | self.context.amount_auth += self.gateway_amt |
---|
| 235 | self.context.gateway_amt = self.gateway_amt |
---|
| 236 | self.context.r_company = u'interswitch' |
---|
[15614] | 237 | xmldict = {} |
---|
[16733] | 238 | provider_amt = 250.0 |
---|
[16731] | 239 | xmldict['institution_acct'] = '1216063205' |
---|
| 240 | xmldict['institution_bank_id'] = '117' |
---|
[17114] | 241 | if self.context.__parent__.__parent__.prefix in ( |
---|
[17278] | 242 | 'pre', 'jupeb', 'dpft', 'dppt', |
---|
[17506] | 243 | 'ugpt', 'ijmb', 'df'): |
---|
[17059] | 244 | xmldict['institution_acct'] = '1011431799' |
---|
| 245 | xmldict['institution_bank_id'] = '117' |
---|
| 246 | provider_amt = 500.0 |
---|
[17478] | 247 | if self.context.__parent__.__parent__.prefix in ('ijmb',): |
---|
| 248 | xmldict['institution_acct'] = '0093658062' |
---|
| 249 | xmldict['institution_bank_id'] = '121' |
---|
[15614] | 250 | xmldict['detail_ref'] = self.context.p_id |
---|
| 251 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 252 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 253 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 254 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 255 | xmldict['institution_item_name'] = self.context.category |
---|
| 256 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[15756] | 257 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
| 258 | if not self.context.provider_amt: |
---|
| 259 | self.context.provider_amt = provider_amt |
---|
| 260 | self.context.amount_auth += provider_amt |
---|
[15614] | 261 | xmltext = """<payment_item_detail> |
---|
| 262 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 263 | <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" /> |
---|
| 264 | <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" /> |
---|
| 265 | </item_details> |
---|
| 266 | </payment_item_detail>""" % xmldict |
---|
| 267 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[15756] | 268 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[15614] | 269 | hashargs = ( |
---|
| 270 | self.context.p_id + |
---|
| 271 | PRODUCT_ID + |
---|
| 272 | self.pay_item_id + |
---|
| 273 | str(int(self.amount_auth)) + |
---|
| 274 | self.site_redirect_url + |
---|
| 275 | self.mac) |
---|
| 276 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
| 277 | return |
---|
| 278 | |
---|
| 279 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
| 280 | InterswitchPaymentRequestWebservicePageStudent): |
---|
| 281 | """Request webservice view for the CollegePAY gateway |
---|
| 282 | """ |
---|
| 283 | grok.context(ICustomStudentOnlinePayment) |
---|
| 284 | product_id = PRODUCT_ID |
---|
| 285 | gateway_host = HOST |
---|
| 286 | gateway_url = URL |
---|
| 287 | mac = MAC |
---|
| 288 | |
---|
| 289 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 290 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
| 291 | """Payment verify view for the CollegePAY gateway |
---|
| 292 | """ |
---|
| 293 | grok.context(ICustomStudentOnlinePayment) |
---|
| 294 | product_id = PRODUCT_ID |
---|
| 295 | gateway_host = HOST |
---|
| 296 | gateway_url = URL |
---|
| 297 | mac = MAC |
---|
| 298 | |
---|
| 299 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
| 300 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
| 301 | """Request webservice view for the CollegePAY gateway |
---|
| 302 | """ |
---|
| 303 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 304 | product_id = PRODUCT_ID |
---|
| 305 | gateway_host = HOST |
---|
| 306 | gateway_url = URL |
---|
| 307 | mac = MAC |
---|
| 308 | |
---|
| 309 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 310 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 311 | """Payment verify view for the CollegePAY gateway |
---|
| 312 | """ |
---|
| 313 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 314 | product_id = PRODUCT_ID |
---|
| 315 | gateway_host = HOST |
---|
| 316 | gateway_url = URL |
---|
[16723] | 317 | mac = MAC |
---|
| 318 | |
---|
| 319 | # PAYDirect |
---|
| 320 | |
---|
| 321 | from kofacustom.nigeria.interswitch.paydirectbrowser import ( |
---|
| 322 | PAYDirectPageStudent, PAYDirectPageApplicant, |
---|
| 323 | StudentRefNumberSlip, ApplicantRefNumberSlip, |
---|
| 324 | ) |
---|
| 325 | |
---|
| 326 | from kofacustom.nigeria.interswitch.tests import ( |
---|
| 327 | PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID) |
---|
| 328 | |
---|
| 329 | #PAYDIRECT_HOST = 'orion.interswitchng.com' |
---|
| 330 | #PAYDIRECT_URL = '/bookonhold/bookonhold.asmx' |
---|
| 331 | #MERCHANT_ID = '' |
---|
| 332 | |
---|
| 333 | class CustomPAYDirectPageStudent(PAYDirectPageStudent): |
---|
| 334 | """Inform student how to proceed |
---|
| 335 | """ |
---|
| 336 | grok.context(ICustomStudentOnlinePayment) |
---|
| 337 | gateway_amt = GATEWAY_AMT |
---|
| 338 | merchant_id = MERCHANT_ID |
---|
| 339 | gateway_url = PAYDIRECT_URL |
---|
| 340 | gateway_host = PAYDIRECT_HOST |
---|
| 341 | https = True |
---|
| 342 | |
---|
| 343 | class CustomPAYDirectPageApplicant(PAYDirectPageApplicant): |
---|
| 344 | """ Inform applicant how to proceed. |
---|
| 345 | """ |
---|
| 346 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 347 | gateway_amt = GATEWAY_AMT |
---|
| 348 | merchant_id = MERCHANT_ID |
---|
| 349 | gateway_url = PAYDIRECT_URL |
---|
| 350 | gateway_host = PAYDIRECT_HOST |
---|
| 351 | https = True |
---|
| 352 | |
---|
| 353 | class CustomStudentRefNumberSlip(StudentRefNumberSlip): |
---|
| 354 | """Deliver a PDF slip of the context. |
---|
| 355 | """ |
---|
| 356 | merchant_id = MERCHANT_ID |
---|
| 357 | |
---|
| 358 | class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip): |
---|
| 359 | """Deliver a PDF slip of the context. |
---|
| 360 | """ |
---|
| 361 | merchant_id = MERCHANT_ID |
---|