[7894] | 1 | ## $Id: browser.py 13329 2015-10-15 10:46:38Z 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 | |
---|
[13329] | 53 | #All special payments moved to GTBank on 15-10-2015 |
---|
[11769] | 54 | SPECIAL_PAYMENT_PARAMS = { |
---|
[13329] | 55 | 'certificate': ('111', 200.0, 300.0, '0106259811', '10'), |
---|
| 56 | 'state_result': ('112', 200.0, 300.0, '0106259811', '10'), |
---|
| 57 | 'transcript_local': ('113', 200.0, 300.0, '0106259811', '10'), |
---|
| 58 | 'transcript_foreign': ('114', 200.0, 300.0, '0106259811', '10'), |
---|
| 59 | 'ver_result': ('115', 200.0, 300.0, '0106259811', '10'), |
---|
| 60 | 'change_course': ('116', 200.0, 300.0, '0106259811', '10'), |
---|
| 61 | 'change_inst': ('117', 200.0, 300.0, '0106259811', '10'), |
---|
| 62 | 'jamb_reject': ('118', 200.0, 300.0, '0106259811', '10'), |
---|
| 63 | 'cert_of_cert': ('119', 200.0, 300.0, '0106259811', '10'), |
---|
| 64 | 'ref_let': ('120', 200.0, 300.0, '0106259811', '10'), |
---|
| 65 | 'proc_cert': ('121', 200.0, 300.0, '0106259811', '10'), |
---|
| 66 | 'loss_idcard': ('122', 6.0, 9.0, '0106259811', '10'), |
---|
| 67 | 'loss_examcard': ('123', 3.0, 4.5, '0106259811', '10'), |
---|
| 68 | 'loss_result': ('124', 200.0, 300.0, '0106259811', '10'), |
---|
| 69 | 'loss_receipt': ('125', 200.0, 300.0, '0106259811', '10'), |
---|
| 70 | 'loss_clearance': ('126', 200.0, 300.0, '0106259811', '10'), |
---|
| 71 | 'conv_brochure': ('127', 200.0, 300.0, '0106259811', '10'), |
---|
| 72 | 'hnd_certificate': ('128', 200.0, 300.0, '0106259811', '10'), |
---|
| 73 | 'hnd_state_result': ('129', 200.0, 300.0, '0106259811', '10'), |
---|
| 74 | 'hnd_transcript_local': ('130', 200.0, 300.0, '0106259811', '10'), |
---|
| 75 | 'hnd_transcript_foreign': ('131', 200.0, 300.0, '0106259811', '10'), |
---|
| 76 | 'staff_loss_idcard': ('132', 6.0, 9.0, '0106259811', '10'), |
---|
| 77 | 'hnd_conv_brochure': ('133', 200.0, 300.0, '0106259811', '10'), |
---|
| 78 | 'pgd_state_result': ('134', 200.0, 300.0, '0106259811', '10'), |
---|
| 79 | 'pgd_conv_brochure': ('135', 200.0, 300.0, '0106259811', '10'), |
---|
| 80 | 'pgd_certificate': ('136', 200.0, 300.0, '0106259811', '10'), |
---|
| 81 | 'log_book': ('137', 3.0, 4.5, '0106259811', '10'), |
---|
| 82 | 'pgd_transcript_foreign': ('138', 200.0, 300.0, '0106259811', '10'), |
---|
| 83 | 'pgd_transcript_local': ('139', 200.0, 300.0, '0106259811', '10'), |
---|
| 84 | 'jamb_regularization': ('140', 200.0, 300.0, '0106259811', '10'), |
---|
| 85 | 'utme_registration': ('142', 6.0, 9.0, '0106259811', '10'), |
---|
| 86 | 'utme_cbt': ('143', 6.0, 9.0, '0106259811', '10'), |
---|
| 87 | 'nysc_id_card': ('144', 6.0, 9.0, '0106259811', '10'), |
---|
[11769] | 88 | } |
---|
| 89 | |
---|
[11634] | 90 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
[7894] | 91 | """ View which sends a POST request to the Interswitch |
---|
| 92 | CollegePAY payment gateway. |
---|
| 93 | """ |
---|
[8255] | 94 | grok.context(ICustomStudentOnlinePayment) |
---|
[8256] | 95 | grok.template('student_goto_interswitch') |
---|
[7894] | 96 | action = POST_ACTION |
---|
| 97 | site_name = SITE_NAME |
---|
| 98 | currency = CURRENCY |
---|
| 99 | product_id = PRODUCT_ID |
---|
[9487] | 100 | mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D' |
---|
[7894] | 101 | |
---|
| 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' |
---|
[13329] | 123 | xmldict['institution_acct'] = "0106259811" |
---|
| 124 | xmldict['institution_bank_id'] = "10" |
---|
[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 |
---|
[13329] | 129 | if not student.current_mode.endswith('_we'): |
---|
[11865] | 130 | if xmldict['faculty'] in ('CPGS',): |
---|
[13329] | 131 | xmldict['institution_acct'] = "0106259811" |
---|
| 132 | xmldict['institution_bank_id'] = '10' |
---|
[11955] | 133 | elif xmldict['faculty'] in ('IAS',): |
---|
[13329] | 134 | xmldict['institution_acct'] = "0106259811" |
---|
| 135 | xmldict['institution_bank_id'] = '10' |
---|
[11865] | 136 | self.pay_item_id = '107' |
---|
[11955] | 137 | elif xmldict['faculty'] in ('IES',): |
---|
[13329] | 138 | xmldict['institution_acct'] = "0106259811" |
---|
| 139 | xmldict['institution_bank_id'] = '10' |
---|
[11865] | 140 | self.pay_item_id = '109' |
---|
| 141 | elif xmldict['faculty'] in ('IFMS',): |
---|
[13329] | 142 | xmldict['institution_acct'] = "0106259811" |
---|
| 143 | xmldict['institution_bank_id'] = '10' |
---|
[11865] | 144 | self.pay_item_id = '106' |
---|
[11955] | 145 | elif xmldict['faculty'] in ('IOT',): |
---|
[13329] | 146 | xmldict['institution_acct'] = "0106259811" |
---|
[11865] | 147 | xmldict['institution_bank_id'] = '10' |
---|
| 148 | self.pay_item_id = '110' |
---|
| 149 | elif xmldict['faculty'] in ('IICT',): |
---|
[13329] | 150 | xmldict['institution_acct'] = "0106259811" |
---|
| 151 | xmldict['institution_bank_id'] = '10' |
---|
[11865] | 152 | self.pay_item_id = '108' |
---|
| 153 | else: |
---|
[13329] | 154 | xmldict['institution_acct'] = "0106259811" |
---|
| 155 | xmldict['institution_bank_id'] = '10' |
---|
[12061] | 156 | #Introduce a pay_item_id for part-time for the first time on this portal |
---|
| 157 | self.pay_item_id = '145' |
---|
[11769] | 158 | elif self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys(): |
---|
| 159 | self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0] |
---|
| 160 | dalash_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1] |
---|
| 161 | provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2] |
---|
| 162 | xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3] |
---|
| 163 | xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][4] |
---|
| 164 | if self.context.amount_auth <= 2000.0: |
---|
| 165 | gateway_amt = round(0.015 * self.context.amount_auth, 2) |
---|
[9617] | 166 | elif 'maintenance' in self.context.p_category: |
---|
[9626] | 167 | self.pay_item_id = '102' |
---|
[13329] | 168 | xmldict['institution_acct'] = "0106259811" |
---|
| 169 | xmldict['institution_bank_id'] = '10' |
---|
[9789] | 170 | dalash_amt = 0.0 |
---|
| 171 | provider_amt = 0.0 |
---|
[11557] | 172 | else: |
---|
| 173 | xmldict['institution_acct'] = "0000000000000" |
---|
| 174 | xmldict['institution_bank_id'] = '0' |
---|
[9617] | 175 | |
---|
[10736] | 176 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
| 177 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 178 | xmldict['institution_amt'] = 100 * ( |
---|
| 179 | self.context.amount_auth - provider_amt - |
---|
| 180 | gateway_amt - dalash_amt) |
---|
| 181 | |
---|
[9392] | 182 | hashargs = ( |
---|
| 183 | self.context.p_id + |
---|
| 184 | PRODUCT_ID + |
---|
| 185 | self.pay_item_id + |
---|
| 186 | str(int(self.amount_auth)) + |
---|
| 187 | self.site_redirect_url + |
---|
| 188 | self.mac) |
---|
| 189 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
| 190 | |
---|
[8263] | 191 | # Interswitch amount is not part of the xml data |
---|
[9617] | 192 | |
---|
[10736] | 193 | if 'maintenance' in self.context.p_category: |
---|
[9617] | 194 | xmltext = """<payment_item_detail> |
---|
[8263] | 195 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 196 | <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" /> |
---|
| 197 | </item_details> |
---|
| 198 | </payment_item_detail>""" % xmldict |
---|
[9617] | 199 | |
---|
[10736] | 200 | else: |
---|
[9617] | 201 | xmltext = """<payment_item_detail> |
---|
| 202 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)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" /> |
---|
[10736] | 204 | <item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" /> |
---|
| 205 | <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] | 206 | </item_details> |
---|
| 207 | </payment_item_detail>""" % xmldict |
---|
| 208 | |
---|
[8263] | 209 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9789] | 210 | self.context.provider_amt = provider_amt |
---|
[10736] | 211 | self.context.gateway_amt = gateway_amt |
---|
[9789] | 212 | self.context.thirdparty_amt = dalash_amt |
---|
[7894] | 213 | return |
---|
| 214 | |
---|
[11634] | 215 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[10131] | 216 | """ View which sends a POST request to the Interswitch |
---|
| 217 | CollegePAY payment gateway. |
---|
| 218 | """ |
---|
| 219 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 220 | grok.template('applicant_goto_interswitch') |
---|
| 221 | action = POST_ACTION |
---|
| 222 | site_name = SITE_NAME |
---|
| 223 | currency = CURRENCY |
---|
| 224 | pay_item_id = '103' |
---|
| 225 | product_id = PRODUCT_ID |
---|
| 226 | mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D' |
---|
| 227 | |
---|
| 228 | def update(self): |
---|
[12978] | 229 | error = self.init_update() |
---|
| 230 | if error: |
---|
| 231 | self.flash(error, type='danger') |
---|
| 232 | self.redirect(self.url(self.context, '@@index')) |
---|
| 233 | return |
---|
[10131] | 234 | xmldict = {} |
---|
[10176] | 235 | provider_amt = 300.0 |
---|
| 236 | dalash_amt = 200.0 |
---|
[11682] | 237 | gateway_amt = GATEWAY_AMT |
---|
[11769] | 238 | xmldict['institution_acct'] = '00000000000' |
---|
| 239 | xmldict['institution_bank_id'] = '00' |
---|
[10131] | 240 | if self.applicant.applicant_id.startswith('hnd'): |
---|
[13329] | 241 | xmldict['institution_acct'] = '0106259811' |
---|
| 242 | xmldict['institution_bank_id'] = '10' |
---|
[10597] | 243 | elif self.applicant.applicant_id.startswith('nd'): |
---|
[13329] | 244 | xmldict['institution_acct'] = '0106259811' |
---|
| 245 | xmldict['institution_bank_id'] = '10' |
---|
[11677] | 246 | elif self.applicant.applicant_id.startswith('rmd'): |
---|
[13329] | 247 | xmldict['institution_acct'] = '0106259811' |
---|
| 248 | xmldict['institution_bank_id'] = '10' |
---|
[10651] | 249 | elif self.applicant.applicant_id.startswith('pgft'): |
---|
[13329] | 250 | xmldict['institution_acct'] = '0106259811' |
---|
| 251 | xmldict['institution_bank_id'] = '10' |
---|
[11883] | 252 | elif self.applicant.applicant_id.startswith('prejambites') or \ |
---|
| 253 | self.applicant.applicant_id.startswith('putme'): |
---|
[13184] | 254 | xmldict['institution_acct'] = '0106259811' |
---|
[13185] | 255 | xmldict['institution_bank_id'] = '10' |
---|
[11795] | 256 | self.pay_item_id = '104' |
---|
[10597] | 257 | elif self.applicant.applicant_id.startswith('pre'): |
---|
[13329] | 258 | xmldict['institution_acct'] = '0106259811' |
---|
| 259 | xmldict['institution_bank_id'] = '10' |
---|
[10844] | 260 | elif self.applicant.applicant_id.startswith('special'): |
---|
[11769] | 261 | if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys(): |
---|
| 262 | self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0] |
---|
| 263 | dalash_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1] |
---|
| 264 | provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2] |
---|
| 265 | xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3] |
---|
| 266 | xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][4] |
---|
| 267 | if self.context.amount_auth <= 2000.0: |
---|
| 268 | gateway_amt = round(0.015 * self.context.amount_auth, 2) |
---|
[10176] | 269 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
[10131] | 270 | xmldict['detail_ref'] = self.context.p_id |
---|
| 271 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 272 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 273 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 274 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 275 | xmldict['institution_amt'] = 100 * ( |
---|
[11682] | 276 | self.context.amount_auth - provider_amt - gateway_amt - dalash_amt) |
---|
| 277 | xmldict['institution_item_name'] = self.category |
---|
[10131] | 278 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 279 | |
---|
| 280 | hashargs = ( |
---|
| 281 | self.context.p_id + |
---|
| 282 | PRODUCT_ID + |
---|
| 283 | self.pay_item_id + |
---|
| 284 | str(int(self.amount_auth)) + |
---|
| 285 | self.site_redirect_url + |
---|
| 286 | self.mac) |
---|
| 287 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
| 288 | |
---|
| 289 | # Interswitch amount is not part of the xml data |
---|
[10597] | 290 | |
---|
[11793] | 291 | xmltext = """<payment_item_detail> |
---|
[10131] | 292 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 293 | <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] | 294 | <item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" /> |
---|
| 295 | <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] | 296 | </item_details> |
---|
| 297 | </payment_item_detail>""" % xmldict |
---|
[10597] | 298 | |
---|
[10131] | 299 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 300 | self.context.provider_amt = provider_amt |
---|
[11682] | 301 | self.context.gateway_amt = gateway_amt |
---|
[10176] | 302 | self.context.thirdparty_amt = dalash_amt |
---|
[10131] | 303 | return |
---|
| 304 | |
---|
[11634] | 305 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[9789] | 306 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[7919] | 307 | """ Request webservice view for the CollegePAY gateway |
---|
| 308 | """ |
---|
[8255] | 309 | grok.context(ICustomStudentOnlinePayment) |
---|
[9789] | 310 | product_id = PRODUCT_ID |
---|
| 311 | gateway_host = HOST |
---|
[10131] | 312 | gateway_url = URL |
---|
| 313 | |
---|
[11634] | 314 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[10131] | 315 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
| 316 | """ Request webservice view for the CollegePAY gateway |
---|
| 317 | """ |
---|
| 318 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 319 | product_id = PRODUCT_ID |
---|
| 320 | gateway_host = HOST |
---|
[11557] | 321 | gateway_url = URL |
---|