[7894] | 1 | ## $Id: browser.py 9751 2012-12-01 06:48:28Z 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 |
---|
| 22 | from zope.component import getUtility, queryAdapter |
---|
[9751] | 23 | from kofacustom.nigeria.interswitch.helpers import query_interswitch |
---|
[7894] | 24 | from waeup.kofa.browser.layout import KofaPage, UtilityView |
---|
[9751] | 25 | from waeup.kofa.interfaces import IKofaUtils |
---|
[8281] | 26 | from waeup.kofa.utils.helpers import to_timezone |
---|
[8421] | 27 | from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent |
---|
| 28 | from waeup.kofa.applicants.viewlets import ApprovePaymentActionButton as APABApplicant |
---|
[9347] | 29 | from waeup.kwarapoly.students.interfaces import ICustomStudentOnlinePayment |
---|
| 30 | from waeup.kwarapoly.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
| 31 | from waeup.kwarapoly.interfaces import MessageFactory as _ |
---|
[7894] | 32 | |
---|
[9487] | 33 | PRODUCT_ID = '3930' |
---|
[9347] | 34 | SITE_NAME = 'kwarapoly-kofa.waeup.org' |
---|
[9387] | 35 | PROVIDER_ACCT = '1010764827' |
---|
| 36 | PROVIDER_BANK_ID = '117' |
---|
[8263] | 37 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
[9347] | 38 | INSTITUTION_NAME = 'KwaraPoly' |
---|
[7894] | 39 | CURRENCY = '566' |
---|
[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 | |
---|
[9464] | 53 | def interswitch_img_url(view): |
---|
| 54 | static = view.static |
---|
| 55 | if static is None or static.get( |
---|
| 56 | 'interswitch_verve_mastercard.gif', None) is None: |
---|
| 57 | static = queryAdapter( |
---|
[9751] | 58 | view.request, Interface, name='waeup.kwarapoly.interswitch') |
---|
[9464] | 59 | return static['interswitch_verve_mastercard.gif']() |
---|
| 60 | |
---|
[8421] | 61 | class InterswitchActionButtonStudent(APABStudent): |
---|
[8259] | 62 | grok.order(1) |
---|
[8255] | 63 | grok.context(ICustomStudentOnlinePayment) |
---|
[8430] | 64 | grok.require('waeup.payStudent') |
---|
[7894] | 65 | icon = 'actionicon_pay.png' |
---|
| 66 | text = _('CollegePAY') |
---|
| 67 | target = 'goto_interswitch' |
---|
| 68 | |
---|
| 69 | @property |
---|
| 70 | def target_url(self): |
---|
| 71 | if self.context.p_state != 'unpaid': |
---|
| 72 | return '' |
---|
| 73 | return self.view.url(self.view.context, self.target) |
---|
| 74 | |
---|
[8421] | 75 | class InterswitchActionButtonApplicant(APABApplicant): |
---|
[8259] | 76 | grok.order(1) |
---|
[8256] | 77 | grok.context(ICustomApplicantOnlinePayment) |
---|
[8430] | 78 | grok.require('waeup.payApplicant') |
---|
[8256] | 79 | icon = 'actionicon_pay.png' |
---|
| 80 | text = _('CollegePAY') |
---|
| 81 | target = 'goto_interswitch' |
---|
| 82 | |
---|
| 83 | @property |
---|
| 84 | def target_url(self): |
---|
| 85 | if self.context.p_state != 'unpaid': |
---|
| 86 | return '' |
---|
| 87 | return self.view.url(self.view.context, self.target) |
---|
| 88 | |
---|
[8421] | 89 | class InterswitchRequestWebserviceActionButtonStudent(APABStudent): |
---|
[8259] | 90 | grok.order(2) |
---|
[8255] | 91 | grok.context(ICustomStudentOnlinePayment) |
---|
[8430] | 92 | grok.require('waeup.payStudent') |
---|
[7919] | 93 | icon = 'actionicon_call.png' |
---|
[8421] | 94 | text = _('Requery CollegePAY') |
---|
[7919] | 95 | target = 'request_webservice' |
---|
| 96 | |
---|
[8421] | 97 | class InterswitchRequestWebserviceActionButtonApplicant(APABApplicant): |
---|
[8259] | 98 | grok.order(2) |
---|
[8256] | 99 | grok.context(ICustomApplicantOnlinePayment) |
---|
[8430] | 100 | grok.require('waeup.payApplicant') |
---|
[8256] | 101 | icon = 'actionicon_call.png' |
---|
[8421] | 102 | text = _('Requery CollegePAY') |
---|
[8256] | 103 | target = 'request_webservice' |
---|
[7919] | 104 | |
---|
[8256] | 105 | class InterswitchPageStudent(KofaPage): |
---|
[7894] | 106 | """ View which sends a POST request to the Interswitch |
---|
| 107 | CollegePAY payment gateway. |
---|
| 108 | """ |
---|
[8255] | 109 | grok.context(ICustomStudentOnlinePayment) |
---|
[7894] | 110 | grok.name('goto_interswitch') |
---|
[8256] | 111 | grok.template('student_goto_interswitch') |
---|
[7894] | 112 | grok.require('waeup.payStudent') |
---|
| 113 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
| 114 | submit_button = _('Submit') |
---|
| 115 | action = POST_ACTION |
---|
| 116 | site_name = SITE_NAME |
---|
| 117 | currency = CURRENCY |
---|
| 118 | product_id = PRODUCT_ID |
---|
[9487] | 119 | mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D' |
---|
[7894] | 120 | |
---|
[9464] | 121 | def interswitch_img_url(self): |
---|
| 122 | return interswitch_img_url(self) |
---|
| 123 | |
---|
[7894] | 124 | def update(self): |
---|
[8256] | 125 | #if self.context.p_state != 'unpaid': |
---|
| 126 | if self.context.p_state == 'paid': |
---|
[7894] | 127 | self.flash(_("Payment ticket can't be re-send to CollegePAY.")) |
---|
| 128 | self.redirect(self.url(self.context, '@@index')) |
---|
| 129 | return |
---|
[8256] | 130 | |
---|
[8745] | 131 | student = self.student = self.context.student |
---|
| 132 | certificate = getattr(student['studycourse'],'certificate',None) |
---|
[8276] | 133 | self.amount_auth = 100 * self.context.amount_auth |
---|
[7894] | 134 | xmldict = {} |
---|
| 135 | if certificate is not None: |
---|
| 136 | xmldict['department'] = certificate.__parent__.__parent__.code |
---|
| 137 | xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code |
---|
| 138 | else: |
---|
| 139 | xmldict['department'] = None |
---|
| 140 | xmldict['faculty'] = None |
---|
[9408] | 141 | self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category] |
---|
[8281] | 142 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 143 | self.local_date_time = to_timezone( |
---|
| 144 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
[8256] | 145 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
[8263] | 146 | # Provider data |
---|
| 147 | xmldict['detail_ref'] = self.context.p_id |
---|
| 148 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 149 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 150 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[9387] | 151 | xmldict['provider_amt'] = 100 * 1200 |
---|
[8263] | 152 | # Institution data |
---|
[9616] | 153 | xmldict['institution_acct'] = "0000000000000" |
---|
| 154 | xmldict['institution_bank_id'] = '0' |
---|
| 155 | xmldict['institution_item_name'] = self.category |
---|
[8263] | 156 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[9617] | 157 | xmldict['institution_amt'] = 100 * (self.context.amount_auth -300) |
---|
[9616] | 158 | xmldict['dalash_amt'] = 0 |
---|
| 159 | self.pay_item_id = '000' |
---|
[9737] | 160 | if self.context.p_category == 'schoolfee': |
---|
[9616] | 161 | self.pay_item_id = '101' |
---|
| 162 | # Dalash data |
---|
| 163 | xmldict['dalash_amt'] = 100 * 1800 |
---|
| 164 | if xmldict['faculty'] in ('CPGS',): |
---|
| 165 | xmldict['institution_acct'] = "1771180233" |
---|
| 166 | xmldict['institution_bank_id'] = '120' |
---|
| 167 | elif xmldict['faculty'] in ('IBAS',): |
---|
| 168 | xmldict['institution_acct'] = "0006772436" |
---|
| 169 | xmldict['institution_bank_id'] = '121' |
---|
| 170 | elif xmldict['faculty'] in ('IETS',): |
---|
| 171 | xmldict['institution_acct'] = "0106259811" |
---|
| 172 | xmldict['institution_bank_id'] = '10' |
---|
| 173 | elif xmldict['faculty'] in ('IFMS',): |
---|
| 174 | xmldict['institution_acct'] = "2013910271" |
---|
| 175 | xmldict['institution_bank_id'] = '8' |
---|
| 176 | elif xmldict['faculty'] in ('ITCH',): |
---|
| 177 | #acct. number changed from Zenith to FBN by gbenga Nov. 11, 2012 |
---|
| 178 | xmldict['institution_acct'] = "2013910271" |
---|
| 179 | xmldict['institution_bank_id'] = '8' |
---|
| 180 | xmldict['institution_amt'] = 100 * ( |
---|
| 181 | self.context.amount_auth - 1200 - 300 - 1800) |
---|
[9392] | 182 | |
---|
[9617] | 183 | elif 'maintenance' in self.context.p_category: |
---|
[9626] | 184 | self.pay_item_id = '102' |
---|
[9617] | 185 | xmldict['institution_acct'] = "0039050937" |
---|
| 186 | xmldict['institution_bank_id'] = '31' |
---|
| 187 | |
---|
[9392] | 188 | hashargs = ( |
---|
| 189 | self.context.p_id + |
---|
| 190 | PRODUCT_ID + |
---|
| 191 | self.pay_item_id + |
---|
| 192 | str(int(self.amount_auth)) + |
---|
| 193 | self.site_redirect_url + |
---|
| 194 | self.mac) |
---|
| 195 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
| 196 | |
---|
[8263] | 197 | # Interswitch amount is not part of the xml data |
---|
[9617] | 198 | |
---|
[9725] | 199 | if self.context.p_category in ('schoolfee', 'co1', 'co2', 'co3'): |
---|
[9617] | 200 | xmltext = """<payment_item_detail> |
---|
[8263] | 201 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 202 | <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" /> |
---|
[9387] | 203 | <item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)s" bank_id="117" acct_num="1013196791" /> |
---|
[9129] | 204 | <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" /> |
---|
[8263] | 205 | </item_details> |
---|
| 206 | </payment_item_detail>""" % xmldict |
---|
[9617] | 207 | |
---|
| 208 | elif 'maintenance' in self.context.p_category: |
---|
| 209 | xmltext = """<payment_item_detail> |
---|
| 210 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 211 | <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" /> |
---|
| 212 | </item_details> |
---|
| 213 | </payment_item_detail>""" % xmldict |
---|
| 214 | |
---|
[8263] | 215 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[7894] | 216 | return |
---|
| 217 | |
---|
[8263] | 218 | class InterswitchPageApplicant(KofaPage): |
---|
[8256] | 219 | """ View which sends a POST request to the Interswitch |
---|
| 220 | CollegePAY payment gateway. |
---|
| 221 | """ |
---|
| 222 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 223 | grok.require('waeup.payApplicant') |
---|
| 224 | grok.template('applicant_goto_interswitch') |
---|
[8263] | 225 | grok.name('goto_interswitch') |
---|
| 226 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
| 227 | submit_button = _('Submit') |
---|
| 228 | action = POST_ACTION |
---|
| 229 | site_name = SITE_NAME |
---|
| 230 | currency = CURRENCY |
---|
[9392] | 231 | pay_item_id = '' |
---|
[8263] | 232 | product_id = PRODUCT_ID |
---|
[8256] | 233 | |
---|
[9464] | 234 | def interswitch_img_url(self): |
---|
| 235 | return interswitch_img_url(self) |
---|
| 236 | |
---|
[8256] | 237 | def update(self): |
---|
[8263] | 238 | if self.context.p_state != 'unpaid': |
---|
| 239 | self.flash(_("Payment ticket can't be re-send to CollegePAY.")) |
---|
| 240 | self.redirect(self.url(self.context, '@@index')) |
---|
| 241 | return |
---|
[8831] | 242 | if self.context.__parent__.__parent__.expired \ |
---|
| 243 | and self.context.__parent__.__parent__.strict_deadline: |
---|
[8706] | 244 | self.flash(_("Payment ticket can't be send to CollegePAY. " |
---|
| 245 | "Application period has expired.")) |
---|
| 246 | self.redirect(self.url(self.context, '@@index')) |
---|
| 247 | return |
---|
[8256] | 248 | self.applicant = self.context.__parent__ |
---|
[8276] | 249 | self.amount_auth = 100 * self.context.amount_auth |
---|
[8256] | 250 | xmldict = {} |
---|
[9408] | 251 | self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category] |
---|
[8281] | 252 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 253 | self.local_date_time = to_timezone( |
---|
| 254 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
[8256] | 255 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
[8641] | 256 | xmldict['detail_ref'] = self.context.p_id |
---|
[8263] | 257 | # Provider data |
---|
[8644] | 258 | xmldict['provider_amt'] = 100 * 500 |
---|
[8263] | 259 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 260 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 261 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 262 | # Institution data |
---|
[8644] | 263 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - 500 - 150) |
---|
[9387] | 264 | xmldict['institution_acct'] = '0' |
---|
| 265 | xmldict['institution_bank_id'] = '0' |
---|
[8263] | 266 | xmldict['institution_item_name'] = self.context.p_category |
---|
| 267 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 268 | # Interswitch amount is not part of the xml data |
---|
| 269 | xmltext = """<payment_item_detail> |
---|
| 270 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 271 | <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" /> |
---|
| 272 | <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" /> |
---|
| 273 | </item_details> |
---|
| 274 | </payment_item_detail>""" % xmldict |
---|
| 275 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[8256] | 276 | return |
---|
| 277 | |
---|
[7894] | 278 | |
---|
[8256] | 279 | class InterswitchPaymentRequestWebservicePageStudent(UtilityView, grok.View): |
---|
[7919] | 280 | """ Request webservice view for the CollegePAY gateway |
---|
| 281 | """ |
---|
[8255] | 282 | grok.context(ICustomStudentOnlinePayment) |
---|
[7919] | 283 | grok.name('request_webservice') |
---|
| 284 | grok.require('waeup.payStudent') |
---|
| 285 | |
---|
| 286 | def update(self): |
---|
| 287 | if self.context.p_state == 'paid': |
---|
| 288 | self.flash(_('This ticket has already been paid.')) |
---|
| 289 | return |
---|
[8745] | 290 | student = self.context.student |
---|
[9751] | 291 | success, msg, log = query_interswitch( |
---|
| 292 | self.context, PRODUCT_ID, HOST, URL) |
---|
[8745] | 293 | student.writeLogMessage(self, log) |
---|
[8430] | 294 | if not success: |
---|
| 295 | self.flash(msg) |
---|
| 296 | return |
---|
| 297 | success, msg, log = self.context.doAfterStudentPayment() |
---|
| 298 | if log is not None: |
---|
[8745] | 299 | student.writeLogMessage(self, log) |
---|
[8430] | 300 | self.flash(msg) |
---|
[8256] | 301 | return |
---|
[7919] | 302 | |
---|
[8256] | 303 | def render(self): |
---|
| 304 | self.redirect(self.url(self.context, '@@index')) |
---|
| 305 | return |
---|
[7926] | 306 | |
---|
[8256] | 307 | class InterswitchPaymentRequestWebservicePageApplicant(UtilityView, grok.View): |
---|
| 308 | """ Request webservice view for the CollegePAY gateway |
---|
| 309 | """ |
---|
| 310 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 311 | grok.name('request_webservice') |
---|
| 312 | grok.require('waeup.payApplicant') |
---|
[7919] | 313 | |
---|
[8256] | 314 | def update(self): |
---|
| 315 | if self.context.p_state == 'paid': |
---|
| 316 | self.flash(_('This ticket has already been paid.')) |
---|
[7919] | 317 | return |
---|
[8256] | 318 | applicant = self.context.__parent__ |
---|
[9751] | 319 | success, msg, log = query_interswitch( |
---|
| 320 | self.context, PRODUCT_ID, HOST, URL) |
---|
[8745] | 321 | applicant.writeLogMessage(self, log) |
---|
[8430] | 322 | if not success: |
---|
| 323 | self.flash(msg) |
---|
| 324 | return |
---|
| 325 | success, msg, log = self.context.doAfterApplicantPayment() |
---|
| 326 | if log is not None: |
---|
[8745] | 327 | applicant.writeLogMessage(self, log) |
---|
[8430] | 328 | self.flash(msg) |
---|
[7919] | 329 | return |
---|
| 330 | |
---|
| 331 | def render(self): |
---|
| 332 | self.redirect(self.url(self.context, '@@index')) |
---|
[9108] | 333 | return |
---|