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