| 1 | ## $Id: browser.py 18233 2026-01-27 21:12:04Z 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 | ## |
|---|
| 18 | import httplib |
|---|
| 19 | import grok |
|---|
| 20 | from kofacustom.nigeria.interswitch.browser import ( |
|---|
| 21 | InterswitchPaymentRequestWebservicePageApplicant, |
|---|
| 22 | InterswitchPaymentRequestWebservicePageStudent, |
|---|
| 23 | InterswitchPaymentVerifyWebservicePageApplicant, |
|---|
| 24 | InterswitchPaymentVerifyWebservicePageStudent, |
|---|
| 25 | InterswitchPageStudent, InterswitchPageApplicant, |
|---|
| 26 | module_activated, |
|---|
| 27 | ) |
|---|
| 28 | from waeup.fceokene.students.interfaces import ICustomStudentOnlinePayment |
|---|
| 29 | from waeup.fceokene.applicants.interfaces import ICustomApplicantOnlinePayment |
|---|
| 30 | from waeup.fceokene.interfaces import MessageFactory as _ |
|---|
| 31 | |
|---|
| 32 | PRODUCT_ID = '83' |
|---|
| 33 | SITE_NAME = 'fceokene-kofa.waeup.org' |
|---|
| 34 | PROVIDER_ACCT = '2028964403' |
|---|
| 35 | PROVIDER_BANK_ID = '8' |
|---|
| 36 | PROVIDER_ITEM_NAME = 'WAeAC' |
|---|
| 37 | INSTITUTION_NAME = 'FCEOkene' |
|---|
| 38 | INSTITUTION_ACCT = '0270100161017' |
|---|
| 39 | INSTITUTION_BANK_ID = '000' |
|---|
| 40 | CURRENCY = '566' |
|---|
| 41 | GATEWAY_AMT = 150.0 |
|---|
| 42 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
|---|
| 43 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
|---|
| 44 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
|---|
| 45 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
|---|
| 46 | |
|---|
| 47 | HOST = 'webpay.interswitchng.com' |
|---|
| 48 | #HOST = 'testwebpay.interswitchng.com' |
|---|
| 49 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
|---|
| 50 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
|---|
| 51 | httplib.HTTPConnection.debuglevel = 0 |
|---|
| 52 | |
|---|
| 53 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
|---|
| 54 | """ View which sends a POST request to the Interswitch |
|---|
| 55 | CollegePAY payment gateway. |
|---|
| 56 | """ |
|---|
| 57 | grok.context(ICustomStudentOnlinePayment) |
|---|
| 58 | action = POST_ACTION |
|---|
| 59 | site_name = SITE_NAME |
|---|
| 60 | currency = CURRENCY |
|---|
| 61 | pay_item_id = '' |
|---|
| 62 | product_id = PRODUCT_ID |
|---|
| 63 | |
|---|
| 64 | def update(self): |
|---|
| 65 | if not module_activated(self.context.student.current_session): |
|---|
| 66 | return |
|---|
| 67 | error = self.init_update() |
|---|
| 68 | if error: |
|---|
| 69 | self.flash(error, type='danger') |
|---|
| 70 | self.redirect(self.url(self.context, '@@index')) |
|---|
| 71 | return |
|---|
| 72 | self.context.r_company = u'interswitch' |
|---|
| 73 | student = self.student |
|---|
| 74 | xmldict = self.xmldict |
|---|
| 75 | # Provider data |
|---|
| 76 | provider_amt = 0.0 |
|---|
| 77 | xmldict['detail_ref'] = self.context.p_id |
|---|
| 78 | xmldict['provider_acct'] = PROVIDER_ACCT |
|---|
| 79 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
|---|
| 80 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
|---|
| 81 | xmldict['provider_amt'] = 100 * provider_amt |
|---|
| 82 | # Institution data |
|---|
| 83 | xmldict['institution_acct'] = INSTITUTION_ACCT |
|---|
| 84 | xmldict['institution_bank_id'] = INSTITUTION_BANK_ID |
|---|
| 85 | xmldict['institution_item_name'] = self.category |
|---|
| 86 | xmldict['institution_name'] = INSTITUTION_NAME |
|---|
| 87 | if self.context.p_category in ('schoolfee', 'third_semester', 'reg2sandwich'): |
|---|
| 88 | self.pay_item_id = '8302' |
|---|
| 89 | provider_amt = 1600.0 |
|---|
| 90 | if self.context.student.faccode == 'SUP': |
|---|
| 91 | provider_amt = 7000.0 |
|---|
| 92 | elif 'maintenance' in self.context.p_category: |
|---|
| 93 | self.pay_item_id = '8300' |
|---|
| 94 | elif self.context.p_category == 'clearance': |
|---|
| 95 | self.pay_item_id = '8304' |
|---|
| 96 | xmldict['institution_amt'] = 100 * ( |
|---|
| 97 | self.context.amount_auth - GATEWAY_AMT - provider_amt) |
|---|
| 98 | if provider_amt: |
|---|
| 99 | xmltext = """<payment_item_detail> |
|---|
| 100 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
|---|
| 101 | <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" /> |
|---|
| 102 | <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" /> |
|---|
| 103 | </item_details> |
|---|
| 104 | </payment_item_detail>""" % xmldict |
|---|
| 105 | else: |
|---|
| 106 | xmltext = """<payment_item_detail> |
|---|
| 107 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
|---|
| 108 | <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" /> |
|---|
| 109 | </item_details> |
|---|
| 110 | </payment_item_detail>""" % xmldict |
|---|
| 111 | |
|---|
| 112 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
|---|
| 113 | self.context.provider_amt = provider_amt |
|---|
| 114 | self.context.gateway_amt = GATEWAY_AMT |
|---|
| 115 | return |
|---|
| 116 | |
|---|
| 117 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
|---|
| 118 | """ View which sends a POST request to the Interswitch |
|---|
| 119 | CollegePAY payment gateway. |
|---|
| 120 | """ |
|---|
| 121 | grok.context(ICustomApplicantOnlinePayment) |
|---|
| 122 | action = POST_ACTION |
|---|
| 123 | site_name = SITE_NAME |
|---|
| 124 | currency = CURRENCY |
|---|
| 125 | pay_item_id = '8303' |
|---|
| 126 | product_id = PRODUCT_ID |
|---|
| 127 | |
|---|
| 128 | def update(self): |
|---|
| 129 | if not module_activated(self.context.__parent__.__parent__.year): |
|---|
| 130 | return |
|---|
| 131 | error = self.init_update() |
|---|
| 132 | if error: |
|---|
| 133 | self.flash(error, type='danger') |
|---|
| 134 | self.redirect(self.url(self.context, '@@index')) |
|---|
| 135 | return |
|---|
| 136 | self.context.r_company = u'interswitch' |
|---|
| 137 | xmldict = {} |
|---|
| 138 | # Provider data |
|---|
| 139 | provider_amt = 500.0 |
|---|
| 140 | xmldict['detail_ref'] = self.context.p_id |
|---|
| 141 | xmldict['provider_amt'] = 100 * provider_amt |
|---|
| 142 | xmldict['provider_acct'] = PROVIDER_ACCT |
|---|
| 143 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
|---|
| 144 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
|---|
| 145 | # Institution data |
|---|
| 146 | xmldict['institution_acct'] = INSTITUTION_ACCT |
|---|
| 147 | xmldict['institution_bank_id'] = INSTITUTION_BANK_ID |
|---|
| 148 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - |
|---|
| 149 | provider_amt - GATEWAY_AMT) |
|---|
| 150 | xmldict['institution_item_name'] = self.context.p_category |
|---|
| 151 | xmldict['institution_name'] = INSTITUTION_NAME |
|---|
| 152 | # Interswitch amount is not part of the xml data |
|---|
| 153 | xmltext = """<payment_item_detail> |
|---|
| 154 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)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_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" /> |
|---|
| 157 | </item_details> |
|---|
| 158 | </payment_item_detail>""" % xmldict |
|---|
| 159 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
|---|
| 160 | self.context.provider_amt = provider_amt |
|---|
| 161 | self.context.gateway_amt = GATEWAY_AMT |
|---|
| 162 | return |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
|---|
| 166 | InterswitchPaymentRequestWebservicePageStudent): |
|---|
| 167 | """Request webservice view for the CollegePAY gateway |
|---|
| 168 | """ |
|---|
| 169 | grok.context(ICustomStudentOnlinePayment) |
|---|
| 170 | product_id = PRODUCT_ID |
|---|
| 171 | gateway_host = HOST |
|---|
| 172 | gateway_url = URL |
|---|
| 173 | |
|---|
| 174 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
|---|
| 175 | InterswitchPaymentVerifyWebservicePageStudent): |
|---|
| 176 | """Payment verify view for the CollegePAY gateway |
|---|
| 177 | """ |
|---|
| 178 | grok.context(ICustomStudentOnlinePayment) |
|---|
| 179 | product_id = PRODUCT_ID |
|---|
| 180 | gateway_host = HOST |
|---|
| 181 | gateway_url = URL |
|---|
| 182 | |
|---|
| 183 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
|---|
| 184 | InterswitchPaymentRequestWebservicePageApplicant): |
|---|
| 185 | """Request webservice view for the CollegePAY gateway |
|---|
| 186 | """ |
|---|
| 187 | grok.context(ICustomApplicantOnlinePayment) |
|---|
| 188 | product_id = PRODUCT_ID |
|---|
| 189 | gateway_host = HOST |
|---|
| 190 | gateway_url = URL |
|---|
| 191 | |
|---|
| 192 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
|---|
| 193 | InterswitchPaymentVerifyWebservicePageApplicant): |
|---|
| 194 | """Payment verify view for the CollegePAY gateway |
|---|
| 195 | """ |
|---|
| 196 | grok.context(ICustomApplicantOnlinePayment) |
|---|
| 197 | product_id = PRODUCT_ID |
|---|
| 198 | gateway_host = HOST |
|---|
| 199 | gateway_url = URL |
|---|