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