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