[7894] | 1 | ## $Id: browser.py 11478 2014-03-07 18:12:42Z 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 |
---|
[7894] | 19 | import grok |
---|
[8281] | 20 | from zope.component import getUtility |
---|
[9782] | 21 | from kofacustom.nigeria.interswitch.browser import ( |
---|
| 22 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
| 23 | InterswitchPaymentRequestWebservicePageStudent |
---|
| 24 | ) |
---|
[9783] | 25 | from waeup.kofa.browser.layout import KofaPage |
---|
[9749] | 26 | from waeup.kofa.interfaces import IKofaUtils |
---|
[8281] | 27 | from waeup.kofa.utils.helpers import to_timezone |
---|
[8263] | 28 | from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment |
---|
| 29 | from waeup.uniben.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
[8020] | 30 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
[7894] | 31 | |
---|
| 32 | PRODUCT_ID = '57' |
---|
[8263] | 33 | SITE_NAME = 'uniben-kofa.waeup.org' |
---|
[8424] | 34 | PROVIDER_ACCT = '1010764827' |
---|
| 35 | PROVIDER_BANK_ID = '117' |
---|
[8263] | 36 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
| 37 | INSTITUTION_NAME = 'Uniben' |
---|
[7894] | 38 | CURRENCY = '566' |
---|
[9775] | 39 | GATEWAY_AMT = 150.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' |
---|
[8385] | 42 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
[8293] | 43 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
[7894] | 44 | |
---|
[8293] | 45 | HOST = 'webpay.interswitchng.com' |
---|
| 46 | #HOST = 'testwebpay.interswitchng.com' |
---|
| 47 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
| 48 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
[7898] | 49 | httplib.HTTPConnection.debuglevel = 0 |
---|
| 50 | |
---|
[8256] | 51 | class InterswitchPageStudent(KofaPage): |
---|
[7894] | 52 | """ View which sends a POST request to the Interswitch |
---|
| 53 | CollegePAY payment gateway. |
---|
| 54 | """ |
---|
[8255] | 55 | grok.context(ICustomStudentOnlinePayment) |
---|
[7894] | 56 | grok.name('goto_interswitch') |
---|
[8256] | 57 | grok.template('student_goto_interswitch') |
---|
[7894] | 58 | grok.require('waeup.payStudent') |
---|
| 59 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
| 60 | submit_button = _('Submit') |
---|
| 61 | action = POST_ACTION |
---|
| 62 | site_name = SITE_NAME |
---|
| 63 | currency = CURRENCY |
---|
| 64 | product_id = PRODUCT_ID |
---|
| 65 | |
---|
| 66 | def update(self): |
---|
[8256] | 67 | #if self.context.p_state != 'unpaid': |
---|
| 68 | if self.context.p_state == 'paid': |
---|
[7894] | 69 | self.flash(_("Payment ticket can't be re-send to CollegePAY.")) |
---|
| 70 | self.redirect(self.url(self.context, '@@index')) |
---|
| 71 | return |
---|
[8256] | 72 | |
---|
[8741] | 73 | student = self.student = self.context.student |
---|
| 74 | certificate = getattr(student['studycourse'],'certificate',None) |
---|
[10111] | 75 | if certificate is None: |
---|
| 76 | self.flash(_("Study course data are incomplete.")) |
---|
| 77 | self.redirect(self.url(self.context, '@@index')) |
---|
| 78 | return |
---|
[8276] | 79 | self.amount_auth = 100 * self.context.amount_auth |
---|
[7894] | 80 | xmldict = {} |
---|
| 81 | if certificate is not None: |
---|
| 82 | xmldict['department'] = certificate.__parent__.__parent__.code |
---|
| 83 | xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code |
---|
| 84 | else: |
---|
| 85 | xmldict['department'] = None |
---|
| 86 | xmldict['faculty'] = None |
---|
[9407] | 87 | self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category] |
---|
[8281] | 88 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 89 | self.local_date_time = to_timezone( |
---|
| 90 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
[8256] | 91 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
[8263] | 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 |
---|
| 97 | # Institution data |
---|
[9385] | 98 | xmldict['institution_acct'] = '000000000000' |
---|
| 99 | xmldict['institution_bank_id'] = '00' |
---|
[9384] | 100 | xmldict['institution_amt'] = '0.0' |
---|
[9869] | 101 | provider_amt = 0.0 |
---|
| 102 | self.pay_item_id = '0000' |
---|
[9384] | 103 | if self.context.p_category == 'schoolfee': |
---|
[9869] | 104 | if not self.context.p_item == 'Balance': |
---|
| 105 | provider_amt = 1500.0 |
---|
[9384] | 106 | if student.current_mode.endswith('_ft'): |
---|
[9389] | 107 | self.pay_item_id = '5700' |
---|
[11478] | 108 | if student.current_mode in ('ug_ft','de_ft','ume_ft'): |
---|
[9460] | 109 | xmldict['institution_acct'] = '2017506430' |
---|
| 110 | xmldict['institution_bank_id'] = '8' |
---|
[11478] | 111 | elif student.current_mode in ('dp_ft','dp_pt','ct_pt','ct_ft'): |
---|
| 112 | xmldict['institution_acct'] = '0009598853' |
---|
[9460] | 113 | xmldict['institution_bank_id'] = '17' |
---|
| 114 | elif student.current_mode in ('pg_ft'): |
---|
[11478] | 115 | xmldict['institution_acct'] = '6230033428' |
---|
[9384] | 116 | xmldict['institution_bank_id'] = '51' |
---|
| 117 | elif student.current_mode.endswith('_pt'): |
---|
[9389] | 118 | self.pay_item_id = '5701' |
---|
[11478] | 119 | if student.current_mode in ('ug_pt','de_pt'): |
---|
[9460] | 120 | xmldict['institution_acct'] = '0122009929' |
---|
[9384] | 121 | xmldict['institution_bank_id'] = '16' |
---|
[9460] | 122 | elif student.current_mode in ('pg_pt'): |
---|
[11478] | 123 | xmldict['institution_acct'] = '1013766956' |
---|
| 124 | xmldict['institution_bank_id'] = '117' |
---|
[9384] | 125 | elif self.context.p_category == 'clearance': |
---|
[9389] | 126 | self.pay_item_id = '5702' |
---|
[9775] | 127 | provider_amt = 1500.0 |
---|
[9796] | 128 | if student.faccode == 'FCETA': |
---|
| 129 | xmldict['institution_acct'] = '5210007943' |
---|
| 130 | xmldict['institution_bank_id'] = '51' |
---|
[11478] | 131 | else: |
---|
| 132 | xmldict['institution_bank_id'] = '10' |
---|
[9742] | 133 | xmldict['institution_acct'] = '0031716047' |
---|
[9727] | 134 | elif self.context.p_category == 'gown': |
---|
[9515] | 135 | self.pay_item_id = '5704' |
---|
[11478] | 136 | xmldict['institution_bank_id'] = '16' |
---|
| 137 | xmldict['institution_acct'] = '0122011401' |
---|
[9727] | 138 | elif self.context.p_category.startswith('hostel_maintenance'): |
---|
| 139 | self.pay_item_id = '5705' |
---|
[11478] | 140 | xmldict['institution_bank_id'] = '17' |
---|
| 141 | xmldict['institution_acct'] = '0009598925' |
---|
[9384] | 142 | |
---|
| 143 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 144 | xmldict['institution_item_name'] = self.category |
---|
[8263] | 145 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[9384] | 146 | xmldict['institution_amt'] = 100 * ( |
---|
[9775] | 147 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[8263] | 148 | # Interswitch amount is not part of the xml data |
---|
[9515] | 149 | if provider_amt == 0: |
---|
| 150 | xmltext = """<payment_item_detail> |
---|
[8263] | 151 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 152 | <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" /> |
---|
[9515] | 153 | </item_details> |
---|
| 154 | </payment_item_detail>""" % xmldict |
---|
| 155 | else: |
---|
| 156 | xmltext = """<payment_item_detail> |
---|
| 157 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 158 | <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" /> |
---|
[8263] | 159 | <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" /> |
---|
| 160 | </item_details> |
---|
| 161 | </payment_item_detail>""" % xmldict |
---|
| 162 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9775] | 163 | self.context.provider_amt = provider_amt |
---|
| 164 | self.context.gateway_amt = GATEWAY_AMT |
---|
[7894] | 165 | return |
---|
| 166 | |
---|
[8263] | 167 | class InterswitchPageApplicant(KofaPage): |
---|
[8256] | 168 | """ View which sends a POST request to the Interswitch |
---|
| 169 | CollegePAY payment gateway. |
---|
| 170 | """ |
---|
| 171 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 172 | grok.require('waeup.payApplicant') |
---|
| 173 | grok.template('applicant_goto_interswitch') |
---|
[8263] | 174 | grok.name('goto_interswitch') |
---|
| 175 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
| 176 | submit_button = _('Submit') |
---|
| 177 | action = POST_ACTION |
---|
| 178 | site_name = SITE_NAME |
---|
| 179 | currency = CURRENCY |
---|
[8274] | 180 | pay_item_id = '5703' |
---|
[8263] | 181 | product_id = PRODUCT_ID |
---|
[8256] | 182 | |
---|
| 183 | def update(self): |
---|
[8263] | 184 | if self.context.p_state != 'unpaid': |
---|
| 185 | self.flash(_("Payment ticket can't be re-send to CollegePAY.")) |
---|
| 186 | self.redirect(self.url(self.context, '@@index')) |
---|
| 187 | return |
---|
[8829] | 188 | if self.context.__parent__.__parent__.expired \ |
---|
| 189 | and self.context.__parent__.__parent__.strict_deadline: |
---|
[8694] | 190 | self.flash(_("Payment ticket can't be send to CollegePAY. " |
---|
| 191 | "Application period has expired.")) |
---|
| 192 | self.redirect(self.url(self.context, '@@index')) |
---|
| 193 | return |
---|
[8256] | 194 | self.applicant = self.context.__parent__ |
---|
[8276] | 195 | self.amount_auth = 100 * self.context.amount_auth |
---|
[8256] | 196 | xmldict = {} |
---|
[9407] | 197 | self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category] |
---|
[8281] | 198 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 199 | self.local_date_time = to_timezone( |
---|
| 200 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
[8256] | 201 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
[9775] | 202 | provider_amt = 400.0 |
---|
[8545] | 203 | if self.applicant.applicant_id.startswith('pg'): |
---|
[8568] | 204 | xmldict['institution_acct'] = '0031716030' |
---|
| 205 | xmldict['institution_bank_id'] = '10' |
---|
[9636] | 206 | elif self.applicant.applicant_id.startswith('dp'): |
---|
| 207 | xmldict['institution_acct'] = '9201805071' |
---|
| 208 | xmldict['institution_bank_id'] = '17' |
---|
[10741] | 209 | elif self.applicant.applicant_id.startswith('pt'): |
---|
| 210 | xmldict['institution_acct'] = '9201805071' |
---|
| 211 | xmldict['institution_bank_id'] = '17' |
---|
[8545] | 212 | else: |
---|
[8568] | 213 | xmldict['institution_acct'] = '6220032503' |
---|
| 214 | xmldict['institution_bank_id'] = '51' |
---|
[8263] | 215 | xmldict['detail_ref'] = self.context.p_id |
---|
[8545] | 216 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[8263] | 217 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 218 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 219 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[9775] | 220 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[8263] | 221 | xmldict['institution_item_name'] = self.context.p_category |
---|
| 222 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 223 | # Interswitch amount is not part of the xml data |
---|
| 224 | xmltext = """<payment_item_detail> |
---|
| 225 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 226 | <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" /> |
---|
| 227 | <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" /> |
---|
| 228 | </item_details> |
---|
| 229 | </payment_item_detail>""" % xmldict |
---|
| 230 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9775] | 231 | self.context.provider_amt = provider_amt |
---|
| 232 | self.context.gateway_amt = GATEWAY_AMT |
---|
[8256] | 233 | return |
---|
| 234 | |
---|
[9782] | 235 | class InterswitchPaymentRequestWebservicePageStudent( |
---|
| 236 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[7919] | 237 | """ Request webservice view for the CollegePAY gateway |
---|
| 238 | """ |
---|
[8255] | 239 | grok.context(ICustomStudentOnlinePayment) |
---|
[9782] | 240 | product_id = PRODUCT_ID |
---|
| 241 | gateway_host = HOST |
---|
| 242 | gateway_url = URL |
---|
[7919] | 243 | |
---|
[9782] | 244 | class InterswitchPaymentRequestWebservicePageApplicant( |
---|
| 245 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[8256] | 246 | """ Request webservice view for the CollegePAY gateway |
---|
| 247 | """ |
---|
| 248 | grok.context(ICustomApplicantOnlinePayment) |
---|
[9782] | 249 | product_id = PRODUCT_ID |
---|
| 250 | gateway_host = HOST |
---|
[11478] | 251 | gateway_url = URL |
---|