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