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