[7894] | 1 | ## $Id: browser.py 13589 2016-01-11 09:15:08Z 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 |
---|
[9784] | 20 | from kofacustom.nigeria.interswitch.browser import ( |
---|
| 21 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
[11635] | 22 | InterswitchPaymentRequestWebservicePageStudent, |
---|
[13589] | 23 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
| 24 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
[11635] | 25 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
[9784] | 26 | ) |
---|
[8460] | 27 | from waeup.fceokene.students.interfaces import ICustomStudentOnlinePayment |
---|
| 28 | from waeup.fceokene.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
| 29 | from waeup.fceokene.interfaces import MessageFactory as _ |
---|
[7894] | 30 | |
---|
[8644] | 31 | PRODUCT_ID = '83' |
---|
[8460] | 32 | SITE_NAME = 'fceokene-kofa.waeup.org' |
---|
[8641] | 33 | PROVIDER_ACCT = '0026781725' |
---|
| 34 | PROVIDER_BANK_ID = '31' |
---|
[8263] | 35 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
[8460] | 36 | INSTITUTION_NAME = 'FCEOkene' |
---|
[7894] | 37 | CURRENCY = '566' |
---|
[9780] | 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 | |
---|
[11635] | 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 |
---|
[9613] | 58 | pay_item_id = '' |
---|
[7894] | 59 | product_id = PRODUCT_ID |
---|
| 60 | |
---|
| 61 | def update(self): |
---|
[11649] | 62 | error = self.init_update() |
---|
| 63 | if error: |
---|
| 64 | self.flash(error, type='danger') |
---|
| 65 | self.redirect(self.url(self.context, '@@index')) |
---|
| 66 | return |
---|
| 67 | student = self.student |
---|
| 68 | xmldict = self.xmldict |
---|
[8263] | 69 | # Provider data |
---|
[9780] | 70 | provider_amt = 1600.0 |
---|
[8263] | 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 |
---|
[9780] | 75 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[8263] | 76 | # Institution data |
---|
[9780] | 77 | fceokene_split_amt = 1400.0 |
---|
[9613] | 78 | xmldict['fceokene_acct'] = "0000000000000" |
---|
| 79 | xmldict['institution_bank_id'] = '0' |
---|
| 80 | xmldict['institution_item_name'] = self.category |
---|
| 81 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[11919] | 82 | if self.context.p_category in ('schoolfee', 'third_semester'): |
---|
[9613] | 83 | self.pay_item_id = '8302' |
---|
[12799] | 84 | if student.current_mode in ('ct_ft',): |
---|
| 85 | xmldict['institution_acct'] = "1012044039" |
---|
| 86 | xmldict['institution_bank_id'] = '117' |
---|
[9943] | 87 | if student.current_mode in ('nce_sw','prence',): |
---|
[12661] | 88 | xmldict['institution_acct'] = "1013780934" |
---|
[9613] | 89 | xmldict['institution_bank_id'] = '117' |
---|
[9943] | 90 | elif student.current_mode in ('nce_ft',) and \ |
---|
[9613] | 91 | student['studycourse'].current_verdict == 'O': |
---|
[12661] | 92 | xmldict['institution_acct'] = "1013780934" |
---|
[9613] | 93 | xmldict['institution_bank_id'] = '117' |
---|
[9943] | 94 | elif student.current_mode in ('nce_ft',): |
---|
[12661] | 95 | xmldict['institution_acct'] = "1013780934" |
---|
[9613] | 96 | xmldict['institution_bank_id'] = '117' |
---|
| 97 | elif student.current_mode in ('pd_ft',): |
---|
[12661] | 98 | xmldict['institution_acct'] = "1013780934" |
---|
[9613] | 99 | xmldict['institution_bank_id'] = '117' |
---|
[10011] | 100 | #undergraduate schoolfee added |
---|
| 101 | elif student.current_mode in ('ug_ft',): |
---|
[12662] | 102 | xmldict['institution_acct'] = "2010952698" |
---|
[10011] | 103 | xmldict['institution_bank_id'] = '8' |
---|
[9780] | 104 | xmldict['fceokene_split'] = 100 * fceokene_split_amt |
---|
[9613] | 105 | xmldict['institution_amt'] = 100 * ( |
---|
[9780] | 106 | self.context.amount_auth - provider_amt - |
---|
| 107 | GATEWAY_AMT - fceokene_split_amt) |
---|
[9613] | 108 | elif 'maintenance' in self.context.p_category: |
---|
[9780] | 109 | fceokene_split_amt = 0.0 |
---|
| 110 | provider_amt = 0.0 |
---|
[9613] | 111 | self.pay_item_id = '8300' |
---|
| 112 | xmldict['institution_amt'] = 100 * ( |
---|
[9780] | 113 | self.context.amount_auth - GATEWAY_AMT) |
---|
[12661] | 114 | xmldict['institution_acct'] = "1013780934" |
---|
[9129] | 115 | xmldict['institution_bank_id'] = '117' |
---|
[9956] | 116 | elif self.context.p_category == 'clearance': |
---|
| 117 | fceokene_split_amt = 0.0 |
---|
| 118 | provider_amt = 0.0 |
---|
| 119 | self.pay_item_id = '8304' |
---|
| 120 | xmldict['institution_amt'] = 100 * ( |
---|
| 121 | self.context.amount_auth - GATEWAY_AMT) |
---|
[12662] | 122 | xmldict['institution_acct'] = "2010952698" |
---|
[9956] | 123 | xmldict['institution_bank_id'] = '8' |
---|
| 124 | |
---|
[8263] | 125 | # Interswitch amount is not part of the xml data |
---|
[11919] | 126 | if self.context.p_category in ('schoolfee', 'third_semester'): |
---|
[9613] | 127 | xmltext = """<payment_item_detail> |
---|
[8263] | 128 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 129 | <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" /> |
---|
[12661] | 130 | <item_detail item_id="2" item_name="FCEOkene Split" item_amt="%(fceokene_split)d" bank_id="117" acct_num="1013780934" /> |
---|
[9129] | 131 | <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] | 132 | </item_details> |
---|
| 133 | </payment_item_detail>""" % xmldict |
---|
[9613] | 134 | |
---|
[9956] | 135 | else: |
---|
[9613] | 136 | xmltext = """<payment_item_detail> |
---|
| 137 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 138 | <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" /> |
---|
| 139 | </item_details> |
---|
| 140 | </payment_item_detail>""" % xmldict |
---|
| 141 | |
---|
[8263] | 142 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9780] | 143 | self.context.provider_amt = provider_amt |
---|
| 144 | self.context.gateway_amt = GATEWAY_AMT |
---|
| 145 | self.context.thirdparty_amt = fceokene_split_amt |
---|
[7894] | 146 | return |
---|
| 147 | |
---|
[11635] | 148 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[8256] | 149 | """ View which sends a POST request to the Interswitch |
---|
| 150 | CollegePAY payment gateway. |
---|
| 151 | """ |
---|
| 152 | grok.context(ICustomApplicantOnlinePayment) |
---|
[8263] | 153 | action = POST_ACTION |
---|
| 154 | site_name = SITE_NAME |
---|
| 155 | currency = CURRENCY |
---|
[8644] | 156 | pay_item_id = '8303' |
---|
[8263] | 157 | product_id = PRODUCT_ID |
---|
[8256] | 158 | |
---|
| 159 | def update(self): |
---|
[12976] | 160 | error = self.init_update() |
---|
| 161 | if error: |
---|
| 162 | self.flash(error, type='danger') |
---|
| 163 | self.redirect(self.url(self.context, '@@index')) |
---|
| 164 | return |
---|
[8256] | 165 | xmldict = {} |
---|
[8263] | 166 | # Provider data |
---|
[9780] | 167 | provider_amt = 500.0 |
---|
[11635] | 168 | xmldict['detail_ref'] = self.context.p_id |
---|
[9780] | 169 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[8263] | 170 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 171 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 172 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 173 | # Institution data |
---|
[10528] | 174 | if getattr( |
---|
| 175 | self.applicant.__parent__, 'prefix', None) in ('pude', 'putme'): |
---|
[12662] | 176 | xmldict['institution_acct'] = '2010952698' |
---|
[10528] | 177 | xmldict['institution_bank_id'] = '8' |
---|
| 178 | else: |
---|
[12661] | 179 | xmldict['institution_acct'] = '1013780934' |
---|
[10528] | 180 | xmldict['institution_bank_id'] = '117' |
---|
[9780] | 181 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - |
---|
| 182 | provider_amt - GATEWAY_AMT) |
---|
[8263] | 183 | xmldict['institution_item_name'] = self.context.p_category |
---|
| 184 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 185 | # Interswitch amount is not part of the xml data |
---|
| 186 | xmltext = """<payment_item_detail> |
---|
| 187 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 188 | <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" /> |
---|
| 189 | <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" /> |
---|
| 190 | </item_details> |
---|
| 191 | </payment_item_detail>""" % xmldict |
---|
| 192 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9780] | 193 | self.context.provider_amt = provider_amt |
---|
| 194 | self.context.gateway_amt = GATEWAY_AMT |
---|
[8256] | 195 | return |
---|
| 196 | |
---|
[7894] | 197 | |
---|
[11635] | 198 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[9784] | 199 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[13589] | 200 | """Request webservice view for the CollegePAY gateway |
---|
[7919] | 201 | """ |
---|
[8255] | 202 | grok.context(ICustomStudentOnlinePayment) |
---|
[9784] | 203 | product_id = PRODUCT_ID |
---|
| 204 | gateway_host = HOST |
---|
| 205 | gateway_url = URL |
---|
[7919] | 206 | |
---|
[13589] | 207 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 208 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
| 209 | """Payment verify view for the CollegePAY gateway |
---|
| 210 | """ |
---|
| 211 | grok.context(ICustomStudentOnlinePayment) |
---|
| 212 | product_id = PRODUCT_ID |
---|
| 213 | gateway_host = HOST |
---|
| 214 | gateway_url = URL |
---|
| 215 | |
---|
[11635] | 216 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[9784] | 217 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[13589] | 218 | """Request webservice view for the CollegePAY gateway |
---|
[8256] | 219 | """ |
---|
| 220 | grok.context(ICustomApplicantOnlinePayment) |
---|
[9784] | 221 | product_id = PRODUCT_ID |
---|
| 222 | gateway_host = HOST |
---|
| 223 | gateway_url = URL |
---|
[13589] | 224 | |
---|
| 225 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 226 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 227 | """Payment verify view for the CollegePAY gateway |
---|
| 228 | """ |
---|
| 229 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 230 | product_id = PRODUCT_ID |
---|
| 231 | gateway_host = HOST |
---|
| 232 | gateway_url = URL |
---|