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