[7894] | 1 | ## $Id: browser.py 13590 2016-01-11 09:15:57Z 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 |
---|
[13301] | 20 | from zope.component import getUtility |
---|
| 21 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
[9782] | 22 | from kofacustom.nigeria.interswitch.browser import ( |
---|
| 23 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
[11633] | 24 | InterswitchPaymentRequestWebservicePageStudent, |
---|
[13582] | 25 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
| 26 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
[11633] | 27 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
[9782] | 28 | ) |
---|
[8263] | 29 | from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment |
---|
| 30 | from waeup.uniben.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
[8020] | 31 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
[7894] | 32 | |
---|
| 33 | PRODUCT_ID = '57' |
---|
[8263] | 34 | SITE_NAME = 'uniben-kofa.waeup.org' |
---|
[8424] | 35 | PROVIDER_ACCT = '1010764827' |
---|
| 36 | PROVIDER_BANK_ID = '117' |
---|
[8263] | 37 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
| 38 | INSTITUTION_NAME = 'Uniben' |
---|
[7894] | 39 | CURRENCY = '566' |
---|
[9775] | 40 | GATEWAY_AMT = 150.0 |
---|
[8401] | 41 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
---|
[8293] | 42 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
---|
[8385] | 43 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
[8293] | 44 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
[7894] | 45 | |
---|
[8293] | 46 | HOST = 'webpay.interswitchng.com' |
---|
| 47 | #HOST = 'testwebpay.interswitchng.com' |
---|
| 48 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
| 49 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
[7898] | 50 | httplib.HTTPConnection.debuglevel = 0 |
---|
| 51 | |
---|
[11633] | 52 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
[7894] | 53 | """ View which sends a POST request to the Interswitch |
---|
| 54 | CollegePAY payment gateway. |
---|
| 55 | """ |
---|
[8255] | 56 | grok.context(ICustomStudentOnlinePayment) |
---|
[7894] | 57 | action = POST_ACTION |
---|
| 58 | site_name = SITE_NAME |
---|
| 59 | currency = CURRENCY |
---|
| 60 | product_id = PRODUCT_ID |
---|
| 61 | |
---|
| 62 | def update(self): |
---|
[11644] | 63 | error = self.init_update() |
---|
| 64 | if error: |
---|
| 65 | self.flash(error, type='danger') |
---|
| 66 | self.redirect(self.url(self.context, '@@index')) |
---|
| 67 | return |
---|
| 68 | student = self.student |
---|
| 69 | xmldict = self.xmldict |
---|
[8263] | 70 | # Provider data |
---|
| 71 | xmldict['detail_ref'] = self.context.p_id |
---|
| 72 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 73 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 74 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 75 | # Institution data |
---|
[9385] | 76 | xmldict['institution_acct'] = '000000000000' |
---|
| 77 | xmldict['institution_bank_id'] = '00' |
---|
[9384] | 78 | xmldict['institution_amt'] = '0.0' |
---|
[9869] | 79 | provider_amt = 0.0 |
---|
| 80 | self.pay_item_id = '0000' |
---|
[9384] | 81 | if self.context.p_category == 'schoolfee': |
---|
[9869] | 82 | if not self.context.p_item == 'Balance': |
---|
| 83 | provider_amt = 1500.0 |
---|
[9384] | 84 | if student.current_mode.endswith('_ft'): |
---|
[9389] | 85 | self.pay_item_id = '5700' |
---|
[11478] | 86 | if student.current_mode in ('ug_ft','de_ft','ume_ft'): |
---|
[9460] | 87 | xmldict['institution_acct'] = '2017506430' |
---|
| 88 | xmldict['institution_bank_id'] = '8' |
---|
[11478] | 89 | elif student.current_mode in ('dp_ft','dp_pt','ct_pt','ct_ft'): |
---|
[12471] | 90 | xmldict['institution_acct'] = '0058653774' |
---|
| 91 | xmldict['institution_bank_id'] = '72' |
---|
[9460] | 92 | elif student.current_mode in ('pg_ft'): |
---|
[11478] | 93 | xmldict['institution_acct'] = '6230033428' |
---|
[9384] | 94 | xmldict['institution_bank_id'] = '51' |
---|
| 95 | elif student.current_mode.endswith('_pt'): |
---|
[9389] | 96 | self.pay_item_id = '5701' |
---|
[11478] | 97 | if student.current_mode in ('ug_pt','de_pt'): |
---|
[9460] | 98 | xmldict['institution_acct'] = '0122009929' |
---|
[9384] | 99 | xmldict['institution_bank_id'] = '16' |
---|
[11725] | 100 | elif student.current_mode in ('pg_pt', 'special_pg_pt'): |
---|
[12471] | 101 | xmldict['institution_acct'] = '4150033274' |
---|
| 102 | xmldict['institution_bank_id'] = '51' |
---|
[13333] | 103 | elif student.faccode == 'JUPEB': |
---|
| 104 | self.pay_item_id = '5718' |
---|
[13456] | 105 | xmldict['institution_acct'] = '0231462068' |
---|
| 106 | xmldict['institution_bank_id'] = '16' |
---|
[9384] | 107 | elif self.context.p_category == 'clearance': |
---|
[9389] | 108 | self.pay_item_id = '5702' |
---|
[9775] | 109 | provider_amt = 1500.0 |
---|
[9796] | 110 | if student.faccode == 'FCETA': |
---|
| 111 | xmldict['institution_acct'] = '5210007943' |
---|
| 112 | xmldict['institution_bank_id'] = '51' |
---|
[11478] | 113 | else: |
---|
| 114 | xmldict['institution_bank_id'] = '10' |
---|
[9742] | 115 | xmldict['institution_acct'] = '0031716047' |
---|
[9727] | 116 | elif self.context.p_category == 'gown': |
---|
[9515] | 117 | self.pay_item_id = '5704' |
---|
[11478] | 118 | xmldict['institution_bank_id'] = '16' |
---|
| 119 | xmldict['institution_acct'] = '0122011401' |
---|
[13301] | 120 | elif self.context.p_category.startswith('bed_allocation'): |
---|
| 121 | self.pay_item_id = '5716' |
---|
| 122 | students_utils = getUtility(IStudentsUtils) |
---|
| 123 | stage = students_utils.getAccommodationDetails(student)['bt'] |
---|
| 124 | stage = stage.split('_')[2] |
---|
| 125 | if stage == 'fr': |
---|
| 126 | union_dues = 500.0 |
---|
| 127 | else: |
---|
| 128 | union_dues = 300.0 |
---|
| 129 | xmldict['institution_bank_id'] = '129' |
---|
| 130 | xmldict['institution_acct'] = '0014419432' |
---|
| 131 | xmldict['union_dues'] = 100 * union_dues |
---|
[9727] | 132 | elif self.context.p_category.startswith('hostel_maintenance'): |
---|
| 133 | self.pay_item_id = '5705' |
---|
[12471] | 134 | xmldict['institution_bank_id'] = '129' |
---|
| 135 | xmldict['institution_acct'] = '0014419432' |
---|
[9384] | 136 | |
---|
| 137 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 138 | xmldict['institution_item_name'] = self.category |
---|
[8263] | 139 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[9384] | 140 | xmldict['institution_amt'] = 100 * ( |
---|
[9775] | 141 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[13301] | 142 | |
---|
| 143 | if self.context.p_category == 'bed_allocation': |
---|
| 144 | xmldict['institution_amt'] = 100 * ( |
---|
| 145 | self.context.amount_auth - GATEWAY_AMT - union_dues) |
---|
[9515] | 146 | xmltext = """<payment_item_detail> |
---|
[8263] | 147 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 148 | <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" /> |
---|
[13301] | 149 | <item_detail item_id="2" item_name="UNION DUES" item_amt="%(union_dues)d" bank_id="31" acct_num="0005986952" /> |
---|
[9515] | 150 | </item_details> |
---|
| 151 | </payment_item_detail>""" % xmldict |
---|
[13301] | 152 | elif provider_amt == 0: |
---|
| 153 | xmltext = """<payment_item_detail> |
---|
| 154 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 155 | <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" /> |
---|
| 156 | </item_details> |
---|
| 157 | </payment_item_detail>""" % xmldict |
---|
[13111] | 158 | elif self.context.p_category == 'schoolfee' and \ |
---|
| 159 | student.current_mode == 'ug_ft': |
---|
| 160 | xmldict['institution_amt'] = 100 * ( |
---|
| 161 | self.context.amount_auth - provider_amt - GATEWAY_AMT - 3000) |
---|
| 162 | xmltext = """<payment_item_detail> |
---|
| 163 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 164 | <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" /> |
---|
| 165 | <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" /> |
---|
[13183] | 166 | <item_detail item_id="3" item_name="T-SHIP" item_amt="200000" bank_id="72" acct_num="0061647254" /> |
---|
| 167 | <item_detail item_id="4" item_name="MTN-NET LIBRARY" item_amt="100000" bank_id="8" acct_num="20177722298" /> |
---|
[13111] | 168 | </item_details> |
---|
| 169 | </payment_item_detail>""" % xmldict |
---|
[9515] | 170 | else: |
---|
| 171 | xmltext = """<payment_item_detail> |
---|
| 172 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 173 | <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] | 174 | <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" /> |
---|
| 175 | </item_details> |
---|
| 176 | </payment_item_detail>""" % xmldict |
---|
| 177 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9775] | 178 | self.context.provider_amt = provider_amt |
---|
| 179 | self.context.gateway_amt = GATEWAY_AMT |
---|
[7894] | 180 | return |
---|
| 181 | |
---|
[11633] | 182 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[8256] | 183 | """ View which sends a POST request to the Interswitch |
---|
| 184 | CollegePAY payment gateway. |
---|
| 185 | """ |
---|
| 186 | grok.context(ICustomApplicantOnlinePayment) |
---|
[8263] | 187 | action = POST_ACTION |
---|
| 188 | site_name = SITE_NAME |
---|
| 189 | currency = CURRENCY |
---|
[8274] | 190 | pay_item_id = '5703' |
---|
[8263] | 191 | product_id = PRODUCT_ID |
---|
[8256] | 192 | |
---|
| 193 | def update(self): |
---|
[11644] | 194 | error = self.init_update() |
---|
| 195 | if error: |
---|
| 196 | self.flash(error, type='danger') |
---|
| 197 | self.redirect(self.url(self.context, '@@index')) |
---|
| 198 | return |
---|
[8256] | 199 | xmldict = {} |
---|
[9775] | 200 | provider_amt = 400.0 |
---|
[13250] | 201 | if self.applicant.applicant_id[:3] in ('pga', 'pgd'): # CERHI |
---|
[13243] | 202 | xmldict['institution_acct'] = '1014312532' |
---|
| 203 | xmldict['institution_bank_id'] = '117' |
---|
[13245] | 204 | elif self.applicant.applicant_id.startswith('pg'): |
---|
[8568] | 205 | xmldict['institution_acct'] = '0031716030' |
---|
| 206 | xmldict['institution_bank_id'] = '10' |
---|
[9636] | 207 | elif self.applicant.applicant_id.startswith('dp'): |
---|
| 208 | xmldict['institution_acct'] = '9201805071' |
---|
| 209 | xmldict['institution_bank_id'] = '17' |
---|
[10741] | 210 | elif self.applicant.applicant_id.startswith('pt'): |
---|
| 211 | xmldict['institution_acct'] = '9201805071' |
---|
| 212 | xmldict['institution_bank_id'] = '17' |
---|
[13141] | 213 | elif self.applicant.applicant_id.startswith('pre'): |
---|
| 214 | xmldict['institution_acct'] = '1014315131' |
---|
| 215 | xmldict['institution_bank_id'] = '117' |
---|
| 216 | elif self.applicant.applicant_id.startswith('cbt'): |
---|
| 217 | xmldict['institution_acct'] = '5030058259' |
---|
| 218 | xmldict['institution_bank_id'] = '51' |
---|
[13143] | 219 | provider_amt = 200.0 |
---|
[13567] | 220 | elif self.applicant.applicant_id.startswith('afak'): |
---|
[13562] | 221 | xmldict['institution_acct'] = '1014446565' |
---|
| 222 | xmldict['institution_bank_id'] = '117' |
---|
[8545] | 223 | else: |
---|
[13186] | 224 | xmldict['institution_acct'] = '1014326805' |
---|
| 225 | xmldict['institution_bank_id'] = '117' |
---|
[8263] | 226 | xmldict['detail_ref'] = self.context.p_id |
---|
[8545] | 227 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[8263] | 228 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 229 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 230 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[9775] | 231 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[8263] | 232 | xmldict['institution_item_name'] = self.context.p_category |
---|
| 233 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 234 | # Interswitch amount is not part of the xml data |
---|
| 235 | xmltext = """<payment_item_detail> |
---|
| 236 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 237 | <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" /> |
---|
| 238 | <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" /> |
---|
| 239 | </item_details> |
---|
| 240 | </payment_item_detail>""" % xmldict |
---|
| 241 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9775] | 242 | self.context.provider_amt = provider_amt |
---|
| 243 | self.context.gateway_amt = GATEWAY_AMT |
---|
[8256] | 244 | return |
---|
| 245 | |
---|
[11633] | 246 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[9782] | 247 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[13582] | 248 | """Request webservice view for the CollegePAY gateway |
---|
[7919] | 249 | """ |
---|
[8255] | 250 | grok.context(ICustomStudentOnlinePayment) |
---|
[9782] | 251 | product_id = PRODUCT_ID |
---|
| 252 | gateway_host = HOST |
---|
| 253 | gateway_url = URL |
---|
[7919] | 254 | |
---|
[13582] | 255 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 256 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
[13590] | 257 | """Payment verify view for the CollegePAY gateway |
---|
[13582] | 258 | """ |
---|
| 259 | grok.context(ICustomStudentOnlinePayment) |
---|
| 260 | product_id = PRODUCT_ID |
---|
| 261 | gateway_host = HOST |
---|
| 262 | gateway_url = URL |
---|
| 263 | |
---|
[11633] | 264 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[9782] | 265 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[13582] | 266 | """Request webservice view for the CollegePAY gateway |
---|
[8256] | 267 | """ |
---|
| 268 | grok.context(ICustomApplicantOnlinePayment) |
---|
[9782] | 269 | product_id = PRODUCT_ID |
---|
| 270 | gateway_host = HOST |
---|
[11478] | 271 | gateway_url = URL |
---|
[13582] | 272 | |
---|
| 273 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 274 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 275 | """Payment verify view for the CollegePAY gateway |
---|
| 276 | """ |
---|
| 277 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 278 | product_id = PRODUCT_ID |
---|
| 279 | gateway_host = HOST |
---|
| 280 | gateway_url = URL |
---|