[10765] | 1 | ## $Id: browser.py 16270 2020-10-05 13:19: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 | ) |
---|
[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' |
---|
[15563] | 34 | SITE_NAME = 'iuokada-kofa.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 | xmldict['institution_acct'] = '1011005811' |
---|
| 99 | xmldict['institution_bank_id'] = '117' |
---|
| 100 | self.pay_item_id = '101' |
---|
| 101 | elif self.context.p_category == 'book': |
---|
| 102 | xmldict['institution_acct'] = '1013249587' |
---|
| 103 | xmldict['institution_bank_id'] = '117' |
---|
| 104 | self.pay_item_id = '103' |
---|
| 105 | elif self.context.p_category == 'parentsconsult': |
---|
| 106 | xmldict['institution_acct'] = '1012355544' |
---|
| 107 | xmldict['institution_bank_id'] = '117' |
---|
| 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 | xmldict['institution_acct'] = '0040621193' |
---|
| 113 | xmldict['institution_bank_id'] = '31' |
---|
| 114 | self.pay_item_id = '105' |
---|
[15728] | 115 | else: |
---|
| 116 | xmldict['institution_acct'] = '1011050158' |
---|
| 117 | xmldict['institution_bank_id'] = '117' |
---|
| 118 | self.pay_item_id = '102' |
---|
[16233] | 119 | if self.context.p_category in ( |
---|
| 120 | 'registration', 'required_combi', 'pg_other'): |
---|
[15728] | 121 | provider_amt = 5000.0 |
---|
[16047] | 122 | if self.context.p_category in ( |
---|
| 123 | 'schoolfee', 'schoolfee40') and student.is_jupeb: |
---|
| 124 | provider_amt = 5000.0 |
---|
[10765] | 125 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[12511] | 126 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 127 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[16270] | 128 | xmldict['institution_amt'] = 100 * self.context.net_amt - ( |
---|
| 129 | 100 * provider_amt) |
---|
[10765] | 130 | if provider_amt == 0: |
---|
| 131 | xmltext = """<payment_item_detail> |
---|
| 132 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 133 | <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" /> |
---|
| 134 | </item_details> |
---|
| 135 | </payment_item_detail>""" % xmldict |
---|
| 136 | else: |
---|
| 137 | xmltext = """<payment_item_detail> |
---|
| 138 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 139 | <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" /> |
---|
| 140 | <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" /> |
---|
| 141 | </item_details> |
---|
| 142 | </payment_item_detail>""" % xmldict |
---|
| 143 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[15773] | 144 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[12479] | 145 | hashargs = ( |
---|
| 146 | self.context.p_id + |
---|
| 147 | PRODUCT_ID + |
---|
| 148 | self.pay_item_id + |
---|
| 149 | str(int(self.amount_auth)) + |
---|
| 150 | self.site_redirect_url + |
---|
| 151 | self.mac) |
---|
| 152 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 153 | return |
---|
| 154 | |
---|
[11638] | 155 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[10765] | 156 | """ View which sends a POST request to the Interswitch |
---|
| 157 | CollegePAY payment gateway. |
---|
| 158 | """ |
---|
| 159 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 160 | action = POST_ACTION |
---|
| 161 | site_name = SITE_NAME |
---|
| 162 | currency = CURRENCY |
---|
| 163 | product_id = PRODUCT_ID |
---|
[15269] | 164 | mac = MAC |
---|
[15773] | 165 | gateway_amt = GATEWAY_AMT |
---|
[10765] | 166 | |
---|
| 167 | def update(self): |
---|
[15999] | 168 | if not module_activated( |
---|
| 169 | self.context.__parent__.__parent__.year, self.context): |
---|
| 170 | self.flash(_('Forbidden'), type='danger') |
---|
| 171 | self.redirect(self.url(self.context, '@@index')) |
---|
| 172 | return |
---|
[12979] | 173 | error = self.init_update() |
---|
| 174 | if error: |
---|
| 175 | self.flash(error, type='danger') |
---|
| 176 | self.redirect(self.url(self.context, '@@index')) |
---|
| 177 | return |
---|
[15773] | 178 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
| 179 | # and add the gateway amount. |
---|
| 180 | if not self.context.r_company: |
---|
| 181 | self.context.net_amt = self.context.amount_auth |
---|
| 182 | self.context.amount_auth += self.gateway_amt |
---|
| 183 | self.context.gateway_amt = self.gateway_amt |
---|
| 184 | self.context.r_company = u'interswitch' |
---|
| 185 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[10765] | 186 | xmldict = {} |
---|
[15773] | 187 | provider_amt = 0.0 |
---|
[15786] | 188 | self.pay_item_id = '101' |
---|
[15783] | 189 | xmldict['institution_acct'] = '1011005811' |
---|
| 190 | xmldict['institution_bank_id'] = '117' |
---|
[10765] | 191 | xmldict['detail_ref'] = self.context.p_id |
---|
| 192 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 193 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 194 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 195 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[12511] | 196 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 197 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[15773] | 198 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
| 199 | if not self.context.provider_amt: |
---|
| 200 | self.context.provider_amt = provider_amt |
---|
| 201 | self.context.amount_auth += provider_amt |
---|
[15784] | 202 | if provider_amt == 0: |
---|
| 203 | xmltext = """<payment_item_detail> |
---|
[15785] | 204 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
[10765] | 205 | <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] | 206 | </item_details> |
---|
| 207 | </payment_item_detail>""" % xmldict |
---|
| 208 | else: |
---|
| 209 | xmltext = """<payment_item_detail> |
---|
[15785] | 210 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
[15784] | 211 | <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] | 212 | <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" /> |
---|
| 213 | </item_details> |
---|
| 214 | </payment_item_detail>""" % xmldict |
---|
| 215 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[15773] | 216 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[12479] | 217 | hashargs = ( |
---|
| 218 | self.context.p_id + |
---|
| 219 | PRODUCT_ID + |
---|
[15786] | 220 | self.pay_item_id + |
---|
[12479] | 221 | str(int(self.amount_auth)) + |
---|
| 222 | self.site_redirect_url + |
---|
| 223 | self.mac) |
---|
| 224 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 225 | return |
---|
| 226 | |
---|
[11638] | 227 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[10765] | 228 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[13587] | 229 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 230 | """ |
---|
| 231 | grok.context(ICustomStudentOnlinePayment) |
---|
| 232 | product_id = PRODUCT_ID |
---|
| 233 | gateway_host = HOST |
---|
| 234 | gateway_url = URL |
---|
[15269] | 235 | mac = MAC |
---|
[10765] | 236 | |
---|
[13587] | 237 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 238 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
| 239 | """Payment verify view for the CollegePAY gateway |
---|
| 240 | """ |
---|
| 241 | grok.context(ICustomStudentOnlinePayment) |
---|
| 242 | product_id = PRODUCT_ID |
---|
| 243 | gateway_host = HOST |
---|
| 244 | gateway_url = URL |
---|
[15269] | 245 | mac = MAC |
---|
[13587] | 246 | |
---|
[11638] | 247 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[10765] | 248 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[13587] | 249 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 250 | """ |
---|
| 251 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 252 | product_id = PRODUCT_ID |
---|
| 253 | gateway_host = HOST |
---|
[12479] | 254 | gateway_url = URL |
---|
[15269] | 255 | mac = MAC |
---|
[13587] | 256 | |
---|
| 257 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 258 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 259 | """Payment verify view for the CollegePAY gateway |
---|
| 260 | """ |
---|
| 261 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 262 | product_id = PRODUCT_ID |
---|
| 263 | gateway_host = HOST |
---|
[15269] | 264 | gateway_url = URL |
---|
| 265 | mac = MAC |
---|