[10765] | 1 | ## $Id: browser.py 17936 2024-10-04 22:26:13Z 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 ( |
---|
| 22 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
[11638] | 23 | InterswitchPaymentRequestWebservicePageStudent, |
---|
[13587] | 24 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
| 25 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
[11638] | 26 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
[17927] | 27 | module_activated, |
---|
[10765] | 28 | ) |
---|
[17927] | 29 | from kofacustom.nigeria.interswitch.webcheckoutbrowser import ( |
---|
| 30 | webcheckout_module_activated, |
---|
| 31 | WebCheckoutPageStudent, |
---|
| 32 | WebCheckoutPageApplicant, |
---|
| 33 | WebCheckoutConfirmTransactionStudent, |
---|
| 34 | WebCheckoutConfirmTransactionApplicant, |
---|
| 35 | ) |
---|
[15000] | 36 | from kofacustom.edopoly.students.interfaces import ICustomStudentOnlinePayment |
---|
| 37 | from kofacustom.edopoly.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
| 38 | from kofacustom.edopoly.interfaces import MessageFactory as _ |
---|
[10765] | 39 | |
---|
[15015] | 40 | PRODUCT_ID = '7571' # must be provided by Interswitch |
---|
[15000] | 41 | SITE_NAME = 'edopoly-kofa.waeup.org' |
---|
[15009] | 42 | PROVIDER_ACCT = '0773411069' |
---|
| 43 | PROVIDER_BANK_ID = '31' |
---|
| 44 | PROVIDER_ITEM_NAME = 'WAeAC' |
---|
[15000] | 45 | INSTITUTION_NAME = 'EdoPoly' |
---|
[10765] | 46 | CURRENCY = '566' |
---|
[15015] | 47 | GATEWAY_AMT = 250.0 |
---|
| 48 | MAC = '672ABFB2F3755A7793DE545BDA00F44878DF59140B43A1E7DF16245D299F3108AFF65502F16D95256B3242B43CBC3F512A208EB1BA977080D65328800C49912C' |
---|
[10765] | 49 | |
---|
[15015] | 50 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay' |
---|
| 51 | #POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay' |
---|
| 52 | HOST = 'webpay.interswitchng.com' |
---|
| 53 | #HOST = 'sandbox.interswitchng.com' |
---|
| 54 | URL = '/paydirect/api/v1/gettransaction.json' |
---|
| 55 | #URL = '/webpay/api/v1/gettransaction.json' |
---|
[14276] | 56 | |
---|
[12479] | 57 | httplib.HTTPSConnection.debuglevel = 0 |
---|
| 58 | HTTPS = True |
---|
[10765] | 59 | |
---|
[15218] | 60 | SPECIAL_PAYMENT_PARAMS = { |
---|
| 61 | |
---|
[15231] | 62 | 'conv_nd': ('101', 1000.0, '0031913976', '121'), |
---|
| 63 | 'conv_hnd': ('101', 1000.0, '0031913976', '121'), |
---|
[15218] | 64 | } |
---|
| 65 | |
---|
| 66 | |
---|
[11638] | 67 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
[10765] | 68 | """ View which sends a POST request to the Interswitch |
---|
| 69 | CollegePAY payment gateway. |
---|
| 70 | """ |
---|
| 71 | grok.context(ICustomStudentOnlinePayment) |
---|
| 72 | action = POST_ACTION |
---|
| 73 | site_name = SITE_NAME |
---|
| 74 | currency = CURRENCY |
---|
| 75 | product_id = PRODUCT_ID |
---|
[15015] | 76 | mac = MAC |
---|
[10765] | 77 | |
---|
| 78 | def update(self): |
---|
[17927] | 79 | if not module_activated( |
---|
| 80 | self.context.student.current_session, self.context): |
---|
| 81 | self.flash(_('Forbidden'), type='danger') |
---|
| 82 | self.redirect(self.url(self.context, '@@index')) |
---|
| 83 | return |
---|
[12979] | 84 | error = self.init_update() |
---|
| 85 | if error: |
---|
| 86 | self.flash(error, type='danger') |
---|
| 87 | self.redirect(self.url(self.context, '@@index')) |
---|
| 88 | return |
---|
[15777] | 89 | self.context.r_company = u'interswitch' |
---|
[11647] | 90 | student = self.student |
---|
| 91 | xmldict = self.xmldict |
---|
[10765] | 92 | # Provider data |
---|
| 93 | xmldict['detail_ref'] = self.context.p_id |
---|
| 94 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 95 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 96 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[15015] | 97 | provider_amt = 0.0 |
---|
[15031] | 98 | if not self.context.p_item == 'Balance': |
---|
| 99 | if self.context.p_category == 'ict_entre': |
---|
| 100 | provider_amt = 3000.0 |
---|
| 101 | if self.context.p_category == 'clearance': |
---|
| 102 | provider_amt = 1500.0 |
---|
[15079] | 103 | # temporarily disabled |
---|
| 104 | #if self.context.p_category in ('transcript', 'certificate'): |
---|
| 105 | # provider_amt = 2000.0 |
---|
[10765] | 106 | # Institution data |
---|
[15026] | 107 | xmldict['institution_acct'] = '0068241848' |
---|
[15009] | 108 | xmldict['institution_bank_id'] = '121' |
---|
[15105] | 109 | if self.context.p_category == 'union': |
---|
| 110 | xmldict['institution_acct'] = '0066437412' |
---|
[15949] | 111 | if self.context.p_category == 'nhis': |
---|
| 112 | xmldict['institution_acct'] = '0075379404' |
---|
[16820] | 113 | if self.context.p_category == 'cyber': |
---|
| 114 | xmldict['institution_acct'] = '1220055070' |
---|
| 115 | xmldict['institution_bank_id'] = '117' |
---|
| 116 | if self.context.p_category == 'ispon': |
---|
| 117 | xmldict['institution_acct'] = '1220055104' |
---|
| 118 | xmldict['institution_bank_id'] = '117' |
---|
[10765] | 119 | xmldict['institution_amt'] = '0.0' |
---|
[15009] | 120 | self.pay_item_id = '101' # must be provided by Interswitch |
---|
[10765] | 121 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[12511] | 122 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 123 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 124 | xmldict['institution_amt'] = 100 * ( |
---|
| 125 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
| 126 | # Interswitch amount is not part of the xml data |
---|
[15105] | 127 | if provider_amt == 0: |
---|
[10765] | 128 | xmltext = """<payment_item_detail> |
---|
| 129 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 130 | <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" /> |
---|
| 131 | </item_details> |
---|
| 132 | </payment_item_detail>""" % xmldict |
---|
| 133 | else: |
---|
| 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_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" /> |
---|
| 138 | </item_details> |
---|
| 139 | </payment_item_detail>""" % xmldict |
---|
| 140 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 141 | self.context.provider_amt = provider_amt |
---|
| 142 | self.context.gateway_amt = GATEWAY_AMT |
---|
[15777] | 143 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[12479] | 144 | hashargs = ( |
---|
| 145 | self.context.p_id + |
---|
| 146 | PRODUCT_ID + |
---|
| 147 | self.pay_item_id + |
---|
| 148 | str(int(self.amount_auth)) + |
---|
| 149 | self.site_redirect_url + |
---|
| 150 | self.mac) |
---|
| 151 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 152 | return |
---|
| 153 | |
---|
[11638] | 154 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[10765] | 155 | """ View which sends a POST request to the Interswitch |
---|
| 156 | CollegePAY payment gateway. |
---|
| 157 | """ |
---|
| 158 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 159 | action = POST_ACTION |
---|
| 160 | site_name = SITE_NAME |
---|
| 161 | currency = CURRENCY |
---|
[15015] | 162 | pay_item_id = '101' # must be provided by Interswitch |
---|
[10765] | 163 | product_id = PRODUCT_ID |
---|
[15015] | 164 | mac = MAC |
---|
[10765] | 165 | |
---|
| 166 | def update(self): |
---|
[17927] | 167 | if not module_activated( |
---|
| 168 | self.context.__parent__.__parent__.year, self.context): |
---|
| 169 | self.flash(_('Forbidden'), type='danger') |
---|
| 170 | self.redirect(self.url(self.context, '@@index')) |
---|
| 171 | return |
---|
[12979] | 172 | error = self.init_update() |
---|
| 173 | if error: |
---|
| 174 | self.flash(error, type='danger') |
---|
| 175 | self.redirect(self.url(self.context, '@@index')) |
---|
| 176 | return |
---|
[15777] | 177 | self.context.r_company = u'interswitch' |
---|
[10765] | 178 | xmldict = {} |
---|
[15015] | 179 | provider_amt = 1000.0 |
---|
[15136] | 180 | if self.context.p_category != 'application': |
---|
| 181 | provider_amt = 0.0 |
---|
[15101] | 182 | xmldict['institution_acct'] = '0068241848' |
---|
[15015] | 183 | xmldict['institution_bank_id'] = '121' |
---|
[10765] | 184 | xmldict['detail_ref'] = self.context.p_id |
---|
| 185 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 186 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 187 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 188 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[15259] | 189 | xmldict['institution_amt'] = 100 * ( |
---|
| 190 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[12511] | 191 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 192 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[15218] | 193 | if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys(): |
---|
| 194 | self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0] |
---|
[15259] | 195 | xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[ |
---|
| 196 | self.context.p_category][2] |
---|
| 197 | xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[ |
---|
| 198 | self.context.p_category][3] |
---|
[15218] | 199 | provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1] |
---|
[15259] | 200 | xmldict['institution_amt'] = 100 * ( |
---|
| 201 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
| 202 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[10765] | 203 | # Interswitch amount is not part of the xml data |
---|
[15137] | 204 | if provider_amt == 0: |
---|
| 205 | xmltext = """<payment_item_detail> |
---|
[10765] | 206 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 207 | <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" /> |
---|
[15137] | 208 | </item_details> |
---|
| 209 | </payment_item_detail>""" % xmldict |
---|
| 210 | else: |
---|
| 211 | xmltext = """<payment_item_detail> |
---|
| 212 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 213 | <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] | 214 | <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" /> |
---|
| 215 | </item_details> |
---|
| 216 | </payment_item_detail>""" % xmldict |
---|
[15137] | 217 | |
---|
[10765] | 218 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 219 | self.context.provider_amt = provider_amt |
---|
| 220 | self.context.gateway_amt = GATEWAY_AMT |
---|
[15777] | 221 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[12479] | 222 | hashargs = ( |
---|
| 223 | self.context.p_id + |
---|
| 224 | PRODUCT_ID + |
---|
| 225 | self.pay_item_id + |
---|
| 226 | str(int(self.amount_auth)) + |
---|
| 227 | self.site_redirect_url + |
---|
| 228 | self.mac) |
---|
| 229 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 230 | return |
---|
| 231 | |
---|
[11638] | 232 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[10765] | 233 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[13587] | 234 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 235 | """ |
---|
| 236 | grok.context(ICustomStudentOnlinePayment) |
---|
| 237 | product_id = PRODUCT_ID |
---|
| 238 | gateway_host = HOST |
---|
| 239 | gateway_url = URL |
---|
[15015] | 240 | mac = MAC |
---|
[10765] | 241 | |
---|
[13587] | 242 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 243 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
| 244 | """Payment verify view for the CollegePAY gateway |
---|
| 245 | """ |
---|
| 246 | grok.context(ICustomStudentOnlinePayment) |
---|
| 247 | product_id = PRODUCT_ID |
---|
| 248 | gateway_host = HOST |
---|
| 249 | gateway_url = URL |
---|
[15015] | 250 | mac = MAC |
---|
[13587] | 251 | |
---|
[11638] | 252 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[10765] | 253 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[13587] | 254 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 255 | """ |
---|
| 256 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 257 | product_id = PRODUCT_ID |
---|
| 258 | gateway_host = HOST |
---|
[12479] | 259 | gateway_url = URL |
---|
[15015] | 260 | mac = MAC |
---|
[13587] | 261 | |
---|
| 262 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 263 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 264 | """Payment verify view for the CollegePAY gateway |
---|
| 265 | """ |
---|
| 266 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 267 | product_id = PRODUCT_ID |
---|
| 268 | gateway_host = HOST |
---|
[15015] | 269 | gateway_url = URL |
---|
[17927] | 270 | mac = MAC |
---|
| 271 | |
---|
| 272 | # WebCheckout customizations |
---|
| 273 | |
---|
[17936] | 274 | MERCHANT_CODE = 'MX104253' |
---|
| 275 | PAY_ITEM_ID = 'Default_Payable_MX104253' |
---|
[17927] | 276 | |
---|
| 277 | class CustomWebCheckoutPageStudent(WebCheckoutPageStudent): |
---|
| 278 | """ View which sends a POST request to the Interswitch |
---|
| 279 | WebCheckout payment gateway. |
---|
| 280 | """ |
---|
[17936] | 281 | action = 'https://newwebpay.interswitchng.com/collections/w/pay' |
---|
| 282 | #action = 'https://newwebpay.qa.interswitchng.com/collections/w/pay' |
---|
[17927] | 283 | currency = '566' |
---|
| 284 | pay_item_id = PAY_ITEM_ID |
---|
| 285 | merchant_code = MERCHANT_CODE |
---|
| 286 | gateway_amt = 0.0 |
---|
| 287 | product_id = PRODUCT_ID |
---|
| 288 | |
---|
| 289 | class CustomWebCheckoutPageApplicant(WebCheckoutPageApplicant): |
---|
| 290 | """ View which sends a POST request to the Interswitch |
---|
| 291 | WebCheckout payment gateway. |
---|
| 292 | """ |
---|
| 293 | |
---|
| 294 | action = 'https://newwebpay.interswitchng.com/collections/w/pay' |
---|
| 295 | currency = '566' |
---|
| 296 | pay_item_id = PAY_ITEM_ID |
---|
| 297 | merchant_code = MERCHANT_CODE |
---|
| 298 | |
---|
| 299 | class CustomWebCheckoutConfirmTransactionStudent(WebCheckoutConfirmTransactionStudent): |
---|
| 300 | """ Request webservice view for the WebCheckout gateway |
---|
| 301 | """ |
---|
| 302 | merchant_code = MERCHANT_CODE |
---|
| 303 | gateway_host = 'webpay.interswitchng.com' |
---|
| 304 | gateway_url = '/collections/api/v1/gettransaction.json' |
---|
| 305 | https = True |
---|
| 306 | |
---|
| 307 | class CustomWebCheckoutConfirmTransactionApplicant(WebCheckoutConfirmTransactionApplicant): |
---|
| 308 | """ Request webservice view for the WebCheckout gateway |
---|
| 309 | """ |
---|
| 310 | merchant_code = MERCHANT_CODE |
---|
| 311 | gateway_host = 'webpay.interswitchng.com' |
---|
| 312 | gateway_url = '/collections/api/v1/gettransaction.json' |
---|
| 313 | https = True |
---|
| 314 | |
---|
| 315 | |
---|