[16717] | 1 | ## $Id: browser.py 17478 2023-07-10 01:42:13Z 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 |
---|
[16790] | 89 | if self.context.p_category == 'clearance': |
---|
| 90 | provider_amt = 500.0 |
---|
[16869] | 91 | xmldict['institution_acct'] = '1216063205' |
---|
[17278] | 92 | if student.faccode in ('PRE', 'JUPEB'): |
---|
[17114] | 93 | xmldict['institution_acct'] = '1011431799' |
---|
[17398] | 94 | if student.current_mode.startswith('dp'): |
---|
| 95 | xmldict['institution_acct'] = '1011431799' |
---|
[17478] | 96 | if student.faccode == 'IJMB': |
---|
| 97 | xmldict['institution_acct'] = '0093658062' |
---|
[17330] | 98 | elif self.context.p_category == 'schoolfee': |
---|
[16849] | 99 | provider_amt = 2800.0 |
---|
[16850] | 100 | tech_fee = 1200.0 |
---|
[16869] | 101 | xmldict['institution_acct'] = '1011739172' |
---|
[17278] | 102 | if student.faccode in ('PRE', 'JUPEB'): |
---|
[17117] | 103 | xmldict['institution_acct'] = '2001627961' |
---|
| 104 | xmldict['institution_bank_id'] = '8' |
---|
[17459] | 105 | if student.faccode == 'DELSU': |
---|
| 106 | xmldict['institution_acct'] = '1011036493' |
---|
[17347] | 107 | if student.faccode == 'NCE': |
---|
[17399] | 108 | xmldict['institution_acct'] = '1011274462' |
---|
[17347] | 109 | provider_amt = 4000.0 |
---|
| 110 | tech_fee = 0.0 |
---|
[17478] | 111 | if student.faccode == 'IJMB': |
---|
| 112 | xmldict['institution_acct'] = '0093658062' |
---|
[17373] | 113 | if student.current_mode.startswith('dp'): |
---|
[17427] | 114 | xmldict['institution_acct'] = '2001627961' |
---|
| 115 | xmldict['institution_bank_id'] = '8' |
---|
[17330] | 116 | elif self.context.p_category == 'hostel_maintenance': |
---|
[16869] | 117 | xmldict['institution_acct'] = '1012551384' |
---|
[17330] | 118 | elif self.context.p_category == 'med_reg': |
---|
| 119 | xmldict['institution_acct'] = '1011265606' |
---|
[16736] | 120 | self.pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch |
---|
[16850] | 121 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
| 122 | # and add gateway amount and other surcharges. |
---|
| 123 | if not self.context.r_company: |
---|
| 124 | self.context.r_company = u'interswitch' |
---|
| 125 | self.context.net_amt = self.context.amount_auth |
---|
| 126 | self.context.gateway_amt = self.gateway_amt |
---|
| 127 | self.context.amount_auth += self.gateway_amt |
---|
| 128 | self.context.provider_amt = provider_amt |
---|
| 129 | self.context.amount_auth += provider_amt |
---|
| 130 | self.context.amount_auth += tech_fee |
---|
[15614] | 131 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[16849] | 132 | xmldict['tech_fee'] = 100 * tech_fee |
---|
[15614] | 133 | xmldict['institution_item_name'] = self.context.category |
---|
| 134 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[15756] | 135 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
[15614] | 136 | if provider_amt == 0: |
---|
| 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_details> |
---|
| 141 | </payment_item_detail>""" % xmldict |
---|
[16849] | 142 | elif tech_fee == 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_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" /> |
---|
| 147 | </item_details> |
---|
| 148 | </payment_item_detail>""" % xmldict |
---|
[15614] | 149 | else: |
---|
| 150 | xmltext = """<payment_item_detail> |
---|
| 151 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 152 | <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" /> |
---|
| 153 | <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" /> |
---|
[16851] | 154 | <item_detail item_id="3" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="47" acct_num="0213065415" /> |
---|
[15614] | 155 | </item_details> |
---|
| 156 | </payment_item_detail>""" % xmldict |
---|
| 157 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 158 | self.context.provider_amt = provider_amt |
---|
[15756] | 159 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[15614] | 160 | hashargs = ( |
---|
| 161 | self.context.p_id + |
---|
| 162 | PRODUCT_ID + |
---|
| 163 | self.pay_item_id + |
---|
| 164 | str(int(self.amount_auth)) + |
---|
| 165 | self.site_redirect_url + |
---|
| 166 | self.mac) |
---|
| 167 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
| 168 | return |
---|
| 169 | |
---|
| 170 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
| 171 | """ View which sends a POST request to the Interswitch |
---|
| 172 | CollegePAY payment gateway. |
---|
| 173 | """ |
---|
| 174 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 175 | action = POST_ACTION |
---|
| 176 | site_name = SITE_NAME |
---|
| 177 | currency = CURRENCY |
---|
[16736] | 178 | pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch |
---|
[15614] | 179 | product_id = PRODUCT_ID |
---|
| 180 | mac = MAC |
---|
[15756] | 181 | gateway_amt = GATEWAY_AMT |
---|
[15614] | 182 | |
---|
| 183 | def update(self): |
---|
[16592] | 184 | if not module_activated( |
---|
| 185 | self.context.__parent__.__parent__.year, self.context): |
---|
| 186 | self.flash(_('Forbidden'), type='danger') |
---|
| 187 | self.redirect(self.url(self.context, '@@index')) |
---|
| 188 | return |
---|
[15614] | 189 | error = self.init_update() |
---|
| 190 | if error: |
---|
| 191 | self.flash(error, type='danger') |
---|
| 192 | self.redirect(self.url(self.context, '@@index')) |
---|
| 193 | return |
---|
[15756] | 194 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
| 195 | # and add the gateway amount. |
---|
| 196 | if not self.context.r_company: |
---|
| 197 | self.context.net_amt = self.context.amount_auth |
---|
| 198 | self.context.amount_auth += self.gateway_amt |
---|
| 199 | self.context.gateway_amt = self.gateway_amt |
---|
| 200 | self.context.r_company = u'interswitch' |
---|
[15614] | 201 | xmldict = {} |
---|
[16733] | 202 | provider_amt = 250.0 |
---|
[16731] | 203 | xmldict['institution_acct'] = '1216063205' |
---|
| 204 | xmldict['institution_bank_id'] = '117' |
---|
[17114] | 205 | if self.context.__parent__.__parent__.prefix in ( |
---|
[17278] | 206 | 'pre', 'jupeb', 'dpft', 'dppt', |
---|
| 207 | 'ugpt', 'ijmb'): |
---|
[17059] | 208 | xmldict['institution_acct'] = '1011431799' |
---|
| 209 | xmldict['institution_bank_id'] = '117' |
---|
| 210 | provider_amt = 500.0 |
---|
[17478] | 211 | if self.context.__parent__.__parent__.prefix in ('ijmb',): |
---|
| 212 | xmldict['institution_acct'] = '0093658062' |
---|
| 213 | xmldict['institution_bank_id'] = '121' |
---|
[15614] | 214 | xmldict['detail_ref'] = self.context.p_id |
---|
| 215 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 216 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 217 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 218 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 219 | xmldict['institution_item_name'] = self.context.category |
---|
| 220 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[15756] | 221 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
| 222 | if not self.context.provider_amt: |
---|
| 223 | self.context.provider_amt = provider_amt |
---|
| 224 | self.context.amount_auth += provider_amt |
---|
[15614] | 225 | xmltext = """<payment_item_detail> |
---|
| 226 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 227 | <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" /> |
---|
| 228 | <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" /> |
---|
| 229 | </item_details> |
---|
| 230 | </payment_item_detail>""" % xmldict |
---|
| 231 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[15756] | 232 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[15614] | 233 | hashargs = ( |
---|
| 234 | self.context.p_id + |
---|
| 235 | PRODUCT_ID + |
---|
| 236 | self.pay_item_id + |
---|
| 237 | str(int(self.amount_auth)) + |
---|
| 238 | self.site_redirect_url + |
---|
| 239 | self.mac) |
---|
| 240 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
| 241 | return |
---|
| 242 | |
---|
| 243 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
| 244 | InterswitchPaymentRequestWebservicePageStudent): |
---|
| 245 | """Request webservice view for the CollegePAY gateway |
---|
| 246 | """ |
---|
| 247 | grok.context(ICustomStudentOnlinePayment) |
---|
| 248 | product_id = PRODUCT_ID |
---|
| 249 | gateway_host = HOST |
---|
| 250 | gateway_url = URL |
---|
| 251 | mac = MAC |
---|
| 252 | |
---|
| 253 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 254 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
| 255 | """Payment verify view for the CollegePAY gateway |
---|
| 256 | """ |
---|
| 257 | grok.context(ICustomStudentOnlinePayment) |
---|
| 258 | product_id = PRODUCT_ID |
---|
| 259 | gateway_host = HOST |
---|
| 260 | gateway_url = URL |
---|
| 261 | mac = MAC |
---|
| 262 | |
---|
| 263 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
| 264 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
| 265 | """Request webservice view for the CollegePAY gateway |
---|
| 266 | """ |
---|
| 267 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 268 | product_id = PRODUCT_ID |
---|
| 269 | gateway_host = HOST |
---|
| 270 | gateway_url = URL |
---|
| 271 | mac = MAC |
---|
| 272 | |
---|
| 273 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 274 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 275 | """Payment verify view for the CollegePAY gateway |
---|
| 276 | """ |
---|
| 277 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 278 | product_id = PRODUCT_ID |
---|
| 279 | gateway_host = HOST |
---|
| 280 | gateway_url = URL |
---|
[16723] | 281 | mac = MAC |
---|
| 282 | |
---|
| 283 | # PAYDirect |
---|
| 284 | |
---|
| 285 | from kofacustom.nigeria.interswitch.paydirectbrowser import ( |
---|
| 286 | PAYDirectPageStudent, PAYDirectPageApplicant, |
---|
| 287 | StudentRefNumberSlip, ApplicantRefNumberSlip, |
---|
| 288 | ) |
---|
| 289 | |
---|
| 290 | from kofacustom.nigeria.interswitch.tests import ( |
---|
| 291 | PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID) |
---|
| 292 | |
---|
| 293 | #PAYDIRECT_HOST = 'orion.interswitchng.com' |
---|
| 294 | #PAYDIRECT_URL = '/bookonhold/bookonhold.asmx' |
---|
| 295 | #MERCHANT_ID = '' |
---|
| 296 | |
---|
| 297 | class CustomPAYDirectPageStudent(PAYDirectPageStudent): |
---|
| 298 | """Inform student how to proceed |
---|
| 299 | """ |
---|
| 300 | grok.context(ICustomStudentOnlinePayment) |
---|
| 301 | gateway_amt = GATEWAY_AMT |
---|
| 302 | merchant_id = MERCHANT_ID |
---|
| 303 | gateway_url = PAYDIRECT_URL |
---|
| 304 | gateway_host = PAYDIRECT_HOST |
---|
| 305 | https = True |
---|
| 306 | |
---|
| 307 | class CustomPAYDirectPageApplicant(PAYDirectPageApplicant): |
---|
| 308 | """ Inform applicant how to proceed. |
---|
| 309 | """ |
---|
| 310 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 311 | gateway_amt = GATEWAY_AMT |
---|
| 312 | merchant_id = MERCHANT_ID |
---|
| 313 | gateway_url = PAYDIRECT_URL |
---|
| 314 | gateway_host = PAYDIRECT_HOST |
---|
| 315 | https = True |
---|
| 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 |
---|