[7894] | 1 | ## $Id: browser.py 14059 2016-08-08 10:41:45Z 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' |
---|
[13771] | 39 | INSTITUTION_ACCT = '2017506430' |
---|
| 40 | INSTITUTION_BANK_ID = '8' |
---|
[7894] | 41 | CURRENCY = '566' |
---|
[9775] | 42 | GATEWAY_AMT = 150.0 |
---|
[8401] | 43 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
---|
[8293] | 44 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
---|
[8385] | 45 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
[8293] | 46 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
[7894] | 47 | |
---|
[8293] | 48 | HOST = 'webpay.interswitchng.com' |
---|
| 49 | #HOST = 'testwebpay.interswitchng.com' |
---|
| 50 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
| 51 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
[7898] | 52 | httplib.HTTPConnection.debuglevel = 0 |
---|
| 53 | |
---|
[11633] | 54 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
[7894] | 55 | """ View which sends a POST request to the Interswitch |
---|
| 56 | CollegePAY payment gateway. |
---|
| 57 | """ |
---|
[8255] | 58 | grok.context(ICustomStudentOnlinePayment) |
---|
[7894] | 59 | action = POST_ACTION |
---|
| 60 | site_name = SITE_NAME |
---|
| 61 | currency = CURRENCY |
---|
| 62 | product_id = PRODUCT_ID |
---|
| 63 | |
---|
| 64 | def update(self): |
---|
[11644] | 65 | error = self.init_update() |
---|
| 66 | if error: |
---|
| 67 | self.flash(error, type='danger') |
---|
| 68 | self.redirect(self.url(self.context, '@@index')) |
---|
| 69 | return |
---|
| 70 | student = self.student |
---|
| 71 | xmldict = self.xmldict |
---|
[8263] | 72 | # Provider data |
---|
| 73 | xmldict['detail_ref'] = self.context.p_id |
---|
| 74 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 75 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 76 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 77 | # Institution data |
---|
[13771] | 78 | xmldict['institution_acct'] = INSTITUTION_ACCT |
---|
| 79 | xmldict['institution_bank_id'] = INSTITUTION_BANK_ID |
---|
[9384] | 80 | xmldict['institution_amt'] = '0.0' |
---|
[9869] | 81 | provider_amt = 0.0 |
---|
| 82 | self.pay_item_id = '0000' |
---|
[9384] | 83 | if self.context.p_category == 'schoolfee': |
---|
[9869] | 84 | if not self.context.p_item == 'Balance': |
---|
| 85 | provider_amt = 1500.0 |
---|
[9384] | 86 | if student.current_mode.endswith('_ft'): |
---|
[9389] | 87 | self.pay_item_id = '5700' |
---|
[14026] | 88 | elif student.current_mode[-3:] in ('_pt', '_sw'): |
---|
[9389] | 89 | self.pay_item_id = '5701' |
---|
[13333] | 90 | elif student.faccode == 'JUPEB': |
---|
| 91 | self.pay_item_id = '5718' |
---|
[9384] | 92 | elif self.context.p_category == 'clearance': |
---|
[9389] | 93 | self.pay_item_id = '5702' |
---|
[9775] | 94 | provider_amt = 1500.0 |
---|
[9727] | 95 | elif self.context.p_category == 'gown': |
---|
[9515] | 96 | self.pay_item_id = '5704' |
---|
[13785] | 97 | elif self.context.p_category.startswith('hostel_maintenance'): |
---|
| 98 | self.pay_item_id = '5705' |
---|
[13301] | 99 | elif self.context.p_category.startswith('bed_allocation'): |
---|
| 100 | self.pay_item_id = '5716' |
---|
[13785] | 101 | elif self.context.p_category == 'jupeb': |
---|
| 102 | self.pay_item_id = '5717' |
---|
[9384] | 103 | |
---|
| 104 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 105 | xmldict['institution_item_name'] = self.category |
---|
[8263] | 106 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[9384] | 107 | xmldict['institution_amt'] = 100 * ( |
---|
[9775] | 108 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[13301] | 109 | |
---|
[13771] | 110 | if provider_amt == 0: |
---|
[9515] | 111 | xmltext = """<payment_item_detail> |
---|
[8263] | 112 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 113 | <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] | 114 | </item_details> |
---|
| 115 | </payment_item_detail>""" % xmldict |
---|
| 116 | else: |
---|
| 117 | xmltext = """<payment_item_detail> |
---|
| 118 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 119 | <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] | 120 | <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" /> |
---|
| 121 | </item_details> |
---|
| 122 | </payment_item_detail>""" % xmldict |
---|
| 123 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9775] | 124 | self.context.provider_amt = provider_amt |
---|
| 125 | self.context.gateway_amt = GATEWAY_AMT |
---|
[7894] | 126 | return |
---|
| 127 | |
---|
[11633] | 128 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[8256] | 129 | """ View which sends a POST request to the Interswitch |
---|
| 130 | CollegePAY payment gateway. |
---|
| 131 | """ |
---|
| 132 | grok.context(ICustomApplicantOnlinePayment) |
---|
[8263] | 133 | action = POST_ACTION |
---|
| 134 | site_name = SITE_NAME |
---|
| 135 | currency = CURRENCY |
---|
[8274] | 136 | pay_item_id = '5703' |
---|
[8263] | 137 | product_id = PRODUCT_ID |
---|
[8256] | 138 | |
---|
| 139 | def update(self): |
---|
[11644] | 140 | error = self.init_update() |
---|
| 141 | if error: |
---|
| 142 | self.flash(error, type='danger') |
---|
| 143 | self.redirect(self.url(self.context, '@@index')) |
---|
| 144 | return |
---|
[8256] | 145 | xmldict = {} |
---|
[9775] | 146 | provider_amt = 400.0 |
---|
[13771] | 147 | if self.applicant.applicant_id.startswith('cbt'): |
---|
[13143] | 148 | provider_amt = 200.0 |
---|
[13771] | 149 | xmldict['institution_acct'] = INSTITUTION_ACCT |
---|
| 150 | xmldict['institution_bank_id'] = INSTITUTION_BANK_ID |
---|
[14059] | 151 | if self.applicant.applicant_id.startswith('afk'): |
---|
| 152 | xmldict['institution_acct'] = 1014774176 |
---|
| 153 | xmldict['institution_bank_id'] = 117 |
---|
[8263] | 154 | xmldict['detail_ref'] = self.context.p_id |
---|
[8545] | 155 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[8263] | 156 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 157 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 158 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[13771] | 159 | xmldict['institution_amt'] = 100 * ( |
---|
| 160 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[13818] | 161 | xmldict['institution_item_name'] = self.category |
---|
[8263] | 162 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 163 | # Interswitch amount is not part of the xml data |
---|
| 164 | xmltext = """<payment_item_detail> |
---|
| 165 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 166 | <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" /> |
---|
| 167 | <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" /> |
---|
| 168 | </item_details> |
---|
| 169 | </payment_item_detail>""" % xmldict |
---|
| 170 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9775] | 171 | self.context.provider_amt = provider_amt |
---|
| 172 | self.context.gateway_amt = GATEWAY_AMT |
---|
[8256] | 173 | return |
---|
| 174 | |
---|
[11633] | 175 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[9782] | 176 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[13582] | 177 | """Request webservice view for the CollegePAY gateway |
---|
[7919] | 178 | """ |
---|
[8255] | 179 | grok.context(ICustomStudentOnlinePayment) |
---|
[9782] | 180 | product_id = PRODUCT_ID |
---|
| 181 | gateway_host = HOST |
---|
| 182 | gateway_url = URL |
---|
[7919] | 183 | |
---|
[13582] | 184 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 185 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
[13590] | 186 | """Payment verify view for the CollegePAY gateway |
---|
[13582] | 187 | """ |
---|
| 188 | grok.context(ICustomStudentOnlinePayment) |
---|
| 189 | product_id = PRODUCT_ID |
---|
| 190 | gateway_host = HOST |
---|
| 191 | gateway_url = URL |
---|
| 192 | |
---|
[11633] | 193 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[9782] | 194 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[13582] | 195 | """Request webservice view for the CollegePAY gateway |
---|
[8256] | 196 | """ |
---|
| 197 | grok.context(ICustomApplicantOnlinePayment) |
---|
[9782] | 198 | product_id = PRODUCT_ID |
---|
| 199 | gateway_host = HOST |
---|
[11478] | 200 | gateway_url = URL |
---|
[13582] | 201 | |
---|
| 202 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 203 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 204 | """Payment verify view for the CollegePAY gateway |
---|
| 205 | """ |
---|
| 206 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 207 | product_id = PRODUCT_ID |
---|
| 208 | gateway_host = HOST |
---|
| 209 | gateway_url = URL |
---|