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