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