[7894] | 1 | ## $Id: browser.py 11769 2014-07-24 07:16:53Z 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 | ## |
---|
[7898] | 18 | import httplib |
---|
[9392] | 19 | import hashlib |
---|
[7894] | 20 | import grok |
---|
[9464] | 21 | from zope.interface import Interface |
---|
[11636] | 22 | from zope.component import queryAdapter |
---|
[9789] | 23 | from kofacustom.nigeria.interswitch.browser import ( |
---|
[10131] | 24 | InterswitchPaymentRequestWebservicePageStudent, |
---|
[11634] | 25 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
| 26 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
[9789] | 27 | ) |
---|
[9347] | 28 | from waeup.kwarapoly.students.interfaces import ICustomStudentOnlinePayment |
---|
| 29 | from waeup.kwarapoly.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
| 30 | from waeup.kwarapoly.interfaces import MessageFactory as _ |
---|
[7894] | 31 | |
---|
[9487] | 32 | PRODUCT_ID = '3930' |
---|
[10131] | 33 | SITE_NAME = 'kwarapoly.waeup.org' |
---|
[9387] | 34 | PROVIDER_ACCT = '1010764827' |
---|
| 35 | PROVIDER_BANK_ID = '117' |
---|
[8263] | 36 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
[9347] | 37 | INSTITUTION_NAME = 'KwaraPoly' |
---|
[7894] | 38 | CURRENCY = '566' |
---|
[9789] | 39 | GATEWAY_AMT = 300.0 |
---|
[8401] | 40 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
---|
[8293] | 41 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
---|
[9392] | 42 | |
---|
[9487] | 43 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
| 44 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
[7894] | 45 | |
---|
[9487] | 46 | HOST = 'webpay.interswitchng.com' |
---|
| 47 | #HOST = 'testwebpay.interswitchng.com' |
---|
[9392] | 48 | |
---|
[9487] | 49 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
| 50 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
[7898] | 51 | httplib.HTTPConnection.debuglevel = 0 |
---|
| 52 | |
---|
[11769] | 53 | |
---|
| 54 | SPECIAL_PAYMENT_PARAMS = { |
---|
| 55 | 'certificate': ('111', 200.0, 300.0, '7000016724', '9'), |
---|
| 56 | 'state_result': ('112', 200.0, 300.0, '7000016724', '9'), |
---|
| 57 | 'transcript_local': ('113', 200.0, 300.0, '7000016724', '9'), |
---|
| 58 | 'transcript_foreign': ('114', 200.0, 300.0, '7000016724', '9'), |
---|
| 59 | 'ver_result': ('115', 200.0, 300.0, '7000016724', '9'), |
---|
| 60 | 'change_course': ('116', 200.0, 300.0, '7000016724', '9'), |
---|
| 61 | 'change_inst': ('117', 200.0, 300.0, '7000016724', '9'), |
---|
| 62 | 'jamb_reject': ('118', 200.0, 300.0, '7000016724', '9'), |
---|
| 63 | 'cert_of_cert': ('119', 200.0, 300.0, '7000016724', '9'), |
---|
| 64 | 'ref_let': ('120', 200.0, 300.0, '7000016724', '9'), |
---|
| 65 | 'proc_cert': ('121', 200.0, 300.0, '7000016724', '9'), |
---|
| 66 | 'loss_idcard': ('122', 6.0, 9.0, '7000016724', '9'), |
---|
| 67 | 'loss_examcard': ('123', 3.0, 4.5, '7000016724', '9'), |
---|
| 68 | 'loss_result': ('124', 200.0, 300.0, '7000016724', '9'), |
---|
| 69 | 'loss_receipt': ('125', 200.0, 300.0, '7000016724', '9'), |
---|
| 70 | 'loss_clearance': ('126', 200.0, 300.0, '7000016724', '9'), |
---|
| 71 | 'conv_brochure': ('127', 200.0, 300.0, '7000016724', '9'), |
---|
| 72 | 'hnd_certificate': ('128', 200.0, 300.0, '7000016724', '9'), |
---|
| 73 | 'hnd_state_result': ('129', 200.0, 300.0, '7000016724', '9'), |
---|
| 74 | 'hnd_transcript_local': ('130', 200.0, 300.0, '7000016724', '9'), |
---|
| 75 | 'hnd_transcript_foreign': ('131', 200.0, 300.0, '7000016724', '9'), |
---|
| 76 | 'staff_loss_idcard': ('132', 6.0, 9.0, '7000016724', '9'), |
---|
| 77 | 'hnd_conv_brochure': ('133', 200.0, 300.0, '7000016724', '9'), |
---|
| 78 | 'pgd_state_result': ('134', 200.0, 300.0, '7000016724', '9'), |
---|
| 79 | 'pgd_conv_brochure': ('135', 200.0, 300.0, '7000016724', '9'), |
---|
| 80 | 'pgd_certificate': ('136', 200.0, 300.0, '7000016724', '9'), |
---|
| 81 | 'log_book': ('137', 3.0, 4.5, '1010508401', '117'), |
---|
| 82 | 'pgd_transcript_foreign': ('138', 200.0, 300.0, '7000016724', '9'), |
---|
| 83 | 'pgd_transcript_local': ('139', 200.0, 300.0, '7000016724', '9'), |
---|
| 84 | 'jamb_regularization': ('140', 200.0, 300.0, '0838798020', '76'), |
---|
| 85 | } |
---|
| 86 | |
---|
[11634] | 87 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
[7894] | 88 | """ View which sends a POST request to the Interswitch |
---|
| 89 | CollegePAY payment gateway. |
---|
| 90 | """ |
---|
[8255] | 91 | grok.context(ICustomStudentOnlinePayment) |
---|
[8256] | 92 | grok.template('student_goto_interswitch') |
---|
[7894] | 93 | action = POST_ACTION |
---|
| 94 | site_name = SITE_NAME |
---|
| 95 | currency = CURRENCY |
---|
| 96 | product_id = PRODUCT_ID |
---|
[9487] | 97 | mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D' |
---|
[7894] | 98 | |
---|
[9464] | 99 | def interswitch_img_url(self): |
---|
| 100 | return interswitch_img_url(self) |
---|
| 101 | |
---|
[7894] | 102 | def update(self): |
---|
[11646] | 103 | error = self.init_update() |
---|
| 104 | if error: |
---|
| 105 | self.flash(error, type='danger') |
---|
| 106 | self.redirect(self.url(self.context, '@@index')) |
---|
| 107 | return |
---|
| 108 | student = self.student |
---|
| 109 | xmldict = self.xmldict |
---|
[8263] | 110 | # Provider data |
---|
| 111 | xmldict['detail_ref'] = self.context.p_id |
---|
| 112 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 113 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 114 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 115 | # Institution data |
---|
[9616] | 116 | xmldict['institution_item_name'] = self.category |
---|
[8263] | 117 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[10736] | 118 | xmldict['institution_amt'] = 0.0 |
---|
| 119 | dalash_amt = 200.0 |
---|
| 120 | provider_amt = 300.0 |
---|
| 121 | gateway_amt = GATEWAY_AMT |
---|
[9616] | 122 | self.pay_item_id = '000' |
---|
[11557] | 123 | xmldict['institution_acct'] = "7000016724" |
---|
| 124 | xmldict['institution_bank_id'] = "9" |
---|
[9737] | 125 | if self.context.p_category == 'schoolfee': |
---|
[9616] | 126 | self.pay_item_id = '101' |
---|
[9789] | 127 | dalash_amt = 1800.0 |
---|
[10736] | 128 | provider_amt = 1200.0 |
---|
[9616] | 129 | if xmldict['faculty'] in ('CPGS',): |
---|
[11760] | 130 | xmldict['institution_acct'] = "1771586608" #changed account no. from 1771180233 |
---|
[9616] | 131 | xmldict['institution_bank_id'] = '120' |
---|
| 132 | elif xmldict['faculty'] in ('IBAS',): |
---|
[10667] | 133 | xmldict['institution_acct'] = "2013910271" |
---|
| 134 | xmldict['institution_bank_id'] = '8' |
---|
| 135 | self.pay_item_id = '107' |
---|
[9616] | 136 | elif xmldict['faculty'] in ('IETS',): |
---|
[10667] | 137 | xmldict['institution_acct'] = "2013910271" |
---|
| 138 | xmldict['institution_bank_id'] = '8' |
---|
| 139 | self.pay_item_id = '109' |
---|
| 140 | elif xmldict['faculty'] in ('IFMS',): |
---|
[9616] | 141 | xmldict['institution_acct'] = "0106259811" |
---|
| 142 | xmldict['institution_bank_id'] = '10' |
---|
[10667] | 143 | self.pay_item_id = '106' |
---|
[9616] | 144 | elif xmldict['faculty'] in ('ITCH',): |
---|
[11760] | 145 | xmldict['institution_acct'] = "1771586608" #changed account no. from 1771180233 |
---|
[10667] | 146 | xmldict['institution_bank_id'] = '120' |
---|
| 147 | self.pay_item_id = '110' |
---|
| 148 | elif xmldict['faculty'] in ('IICT',): |
---|
[9616] | 149 | xmldict['institution_acct'] = "2013910271" |
---|
| 150 | xmldict['institution_bank_id'] = '8' |
---|
[10667] | 151 | self.pay_item_id = '108' |
---|
[11769] | 152 | elif self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys(): |
---|
| 153 | self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0] |
---|
| 154 | dalash_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1] |
---|
| 155 | provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2] |
---|
| 156 | xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3] |
---|
| 157 | xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][4] |
---|
| 158 | if self.context.amount_auth <= 2000.0: |
---|
| 159 | gateway_amt = round(0.015 * self.context.amount_auth, 2) |
---|
[9617] | 160 | elif 'maintenance' in self.context.p_category: |
---|
[9626] | 161 | self.pay_item_id = '102' |
---|
[9617] | 162 | xmldict['institution_acct'] = "0039050937" |
---|
| 163 | xmldict['institution_bank_id'] = '31' |
---|
[9789] | 164 | dalash_amt = 0.0 |
---|
| 165 | provider_amt = 0.0 |
---|
[11557] | 166 | else: |
---|
| 167 | xmldict['institution_acct'] = "0000000000000" |
---|
| 168 | xmldict['institution_bank_id'] = '0' |
---|
[9617] | 169 | |
---|
[10736] | 170 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
| 171 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 172 | xmldict['institution_amt'] = 100 * ( |
---|
| 173 | self.context.amount_auth - provider_amt - |
---|
| 174 | gateway_amt - dalash_amt) |
---|
| 175 | |
---|
[9392] | 176 | hashargs = ( |
---|
| 177 | self.context.p_id + |
---|
| 178 | PRODUCT_ID + |
---|
| 179 | self.pay_item_id + |
---|
| 180 | str(int(self.amount_auth)) + |
---|
| 181 | self.site_redirect_url + |
---|
| 182 | self.mac) |
---|
| 183 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
| 184 | |
---|
[8263] | 185 | # Interswitch amount is not part of the xml data |
---|
[9617] | 186 | |
---|
[10736] | 187 | if 'maintenance' in self.context.p_category: |
---|
[9617] | 188 | xmltext = """<payment_item_detail> |
---|
[8263] | 189 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 190 | <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" /> |
---|
| 191 | </item_details> |
---|
| 192 | </payment_item_detail>""" % xmldict |
---|
[9617] | 193 | |
---|
[10736] | 194 | else: |
---|
[9617] | 195 | xmltext = """<payment_item_detail> |
---|
| 196 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 197 | <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" /> |
---|
[10736] | 198 | <item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" /> |
---|
| 199 | <item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" /> |
---|
[9617] | 200 | </item_details> |
---|
| 201 | </payment_item_detail>""" % xmldict |
---|
| 202 | |
---|
[8263] | 203 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9789] | 204 | self.context.provider_amt = provider_amt |
---|
[10736] | 205 | self.context.gateway_amt = gateway_amt |
---|
[9789] | 206 | self.context.thirdparty_amt = dalash_amt |
---|
[7894] | 207 | return |
---|
| 208 | |
---|
[11634] | 209 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[10131] | 210 | """ View which sends a POST request to the Interswitch |
---|
| 211 | CollegePAY payment gateway. |
---|
| 212 | """ |
---|
| 213 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 214 | grok.template('applicant_goto_interswitch') |
---|
| 215 | action = POST_ACTION |
---|
| 216 | site_name = SITE_NAME |
---|
| 217 | currency = CURRENCY |
---|
| 218 | pay_item_id = '103' |
---|
| 219 | product_id = PRODUCT_ID |
---|
| 220 | mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D' |
---|
| 221 | |
---|
| 222 | def interswitch_img_url(self): |
---|
| 223 | return interswitch_img_url(self) |
---|
| 224 | |
---|
| 225 | def update(self): |
---|
[11634] | 226 | super(CustomInterswitchPageApplicant, self).update() |
---|
[10131] | 227 | xmldict = {} |
---|
[10176] | 228 | provider_amt = 300.0 |
---|
| 229 | dalash_amt = 200.0 |
---|
[11682] | 230 | gateway_amt = GATEWAY_AMT |
---|
[11769] | 231 | xmldict['institution_acct'] = '00000000000' |
---|
| 232 | xmldict['institution_bank_id'] = '00' |
---|
[10131] | 233 | if self.applicant.applicant_id.startswith('hnd'): |
---|
[11677] | 234 | xmldict['institution_acct'] = '1771440667' |
---|
| 235 | xmldict['institution_bank_id'] = '120' |
---|
[10597] | 236 | elif self.applicant.applicant_id.startswith('nd'): |
---|
[11677] | 237 | xmldict['institution_acct'] = '1771440667' |
---|
| 238 | xmldict['institution_bank_id'] = '120' |
---|
| 239 | elif self.applicant.applicant_id.startswith('rmd'): |
---|
| 240 | xmldict['institution_acct'] = '1771440667' |
---|
| 241 | xmldict['institution_bank_id'] = '120' |
---|
[10651] | 242 | elif self.applicant.applicant_id.startswith('pgft'): |
---|
| 243 | xmldict['institution_acct'] = '7000016724' |
---|
| 244 | xmldict['institution_bank_id'] = '9' |
---|
[10597] | 245 | elif self.applicant.applicant_id.startswith('prejambites'): |
---|
| 246 | xmldict['institution_acct'] = '0106259811' |
---|
| 247 | xmldict['institution_bank_id'] = '10' |
---|
| 248 | self.pay_item_id = '104' |
---|
| 249 | provider_amt = 0.0 |
---|
| 250 | dalash_amt = 0.0 |
---|
| 251 | elif self.applicant.applicant_id.startswith('pre'): |
---|
| 252 | xmldict['institution_acct'] = '2013910271' |
---|
| 253 | xmldict['institution_bank_id'] = '8' |
---|
| 254 | provider_amt = 0.0 |
---|
| 255 | dalash_amt = 0.0 |
---|
[10844] | 256 | elif self.applicant.applicant_id.startswith('special'): |
---|
[11769] | 257 | if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys(): |
---|
| 258 | self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0] |
---|
| 259 | dalash_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1] |
---|
| 260 | provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2] |
---|
| 261 | xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3] |
---|
| 262 | xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][4] |
---|
| 263 | if self.context.amount_auth <= 2000.0: |
---|
| 264 | gateway_amt = round(0.015 * self.context.amount_auth, 2) |
---|
[10176] | 265 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
[10131] | 266 | xmldict['detail_ref'] = self.context.p_id |
---|
| 267 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 268 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 269 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 270 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 271 | xmldict['institution_amt'] = 100 * ( |
---|
[11682] | 272 | self.context.amount_auth - provider_amt - gateway_amt - dalash_amt) |
---|
| 273 | xmldict['institution_item_name'] = self.category |
---|
[10131] | 274 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 275 | |
---|
| 276 | hashargs = ( |
---|
| 277 | self.context.p_id + |
---|
| 278 | PRODUCT_ID + |
---|
| 279 | self.pay_item_id + |
---|
| 280 | str(int(self.amount_auth)) + |
---|
| 281 | self.site_redirect_url + |
---|
| 282 | self.mac) |
---|
| 283 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
| 284 | |
---|
| 285 | # Interswitch amount is not part of the xml data |
---|
[10597] | 286 | |
---|
| 287 | if not self.applicant.applicant_id.startswith('pre'): |
---|
| 288 | xmltext = """<payment_item_detail> |
---|
[10131] | 289 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 290 | <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" /> |
---|
[10176] | 291 | <item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" /> |
---|
| 292 | <item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" /> |
---|
[10131] | 293 | </item_details> |
---|
| 294 | </payment_item_detail>""" % xmldict |
---|
[10597] | 295 | |
---|
| 296 | else: |
---|
| 297 | xmltext = """<payment_item_detail> |
---|
| 298 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 299 | <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" /> |
---|
| 300 | </item_details> |
---|
| 301 | </payment_item_detail>""" % xmldict |
---|
| 302 | |
---|
[10131] | 303 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 304 | self.context.provider_amt = provider_amt |
---|
[11682] | 305 | self.context.gateway_amt = gateway_amt |
---|
[10176] | 306 | self.context.thirdparty_amt = dalash_amt |
---|
[10131] | 307 | return |
---|
| 308 | |
---|
[11634] | 309 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[9789] | 310 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[7919] | 311 | """ Request webservice view for the CollegePAY gateway |
---|
| 312 | """ |
---|
[8255] | 313 | grok.context(ICustomStudentOnlinePayment) |
---|
[9789] | 314 | product_id = PRODUCT_ID |
---|
| 315 | gateway_host = HOST |
---|
[10131] | 316 | gateway_url = URL |
---|
| 317 | |
---|
[11634] | 318 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[10131] | 319 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
| 320 | """ Request webservice view for the CollegePAY gateway |
---|
| 321 | """ |
---|
| 322 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 323 | product_id = PRODUCT_ID |
---|
| 324 | gateway_host = HOST |
---|
[11557] | 325 | gateway_url = URL |
---|