[10765] | 1 | ## $Id: browser.py 14342 2016-12-14 11:06:52Z 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 |
---|
[12479] | 19 | import hashlib |
---|
[10765] | 20 | import grok |
---|
| 21 | from kofacustom.nigeria.interswitch.browser import ( |
---|
| 22 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
[11638] | 23 | InterswitchPaymentRequestWebservicePageStudent, |
---|
[13587] | 24 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
| 25 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
[11638] | 26 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
[10765] | 27 | ) |
---|
[14035] | 28 | from kofacustom.coewarri.students.interfaces import ICustomStudentOnlinePayment |
---|
| 29 | from kofacustom.coewarri.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
| 30 | from kofacustom.coewarri.interfaces import MessageFactory as _ |
---|
[10765] | 31 | |
---|
[14129] | 32 | PRODUCT_ID = '6667' |
---|
[14035] | 33 | SITE_NAME = 'coewarri-kofa.waeup.org' |
---|
[14092] | 34 | PROVIDER_ACCT = '0137712635' |
---|
| 35 | PROVIDER_BANK_ID = '10' |
---|
[10765] | 36 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
[14035] | 37 | INSTITUTION_NAME = 'COE Warri' |
---|
[10765] | 38 | CURRENCY = '566' |
---|
[14118] | 39 | GATEWAY_AMT = 300.0 |
---|
[14098] | 40 | |
---|
[14129] | 41 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay' |
---|
| 42 | #POST_ACTION = 'https://stageserv.interswitchng.com/test_paydirect/pay' |
---|
| 43 | HOST = 'webpay.interswitchng.com' |
---|
| 44 | #HOST = 'stageserv.interswitchng.com' |
---|
| 45 | URL = '/paydirect/api/v1/gettransaction.json' |
---|
| 46 | #URL = '/test_paydirect/api/v1/gettransaction.json' |
---|
[14097] | 47 | |
---|
[12479] | 48 | httplib.HTTPSConnection.debuglevel = 0 |
---|
| 49 | HTTPS = True |
---|
[10765] | 50 | |
---|
[11638] | 51 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
[10765] | 52 | """ View which sends a POST request to the Interswitch |
---|
| 53 | CollegePAY payment gateway. |
---|
| 54 | """ |
---|
| 55 | grok.context(ICustomStudentOnlinePayment) |
---|
| 56 | action = POST_ACTION |
---|
| 57 | site_name = SITE_NAME |
---|
| 58 | currency = CURRENCY |
---|
| 59 | product_id = PRODUCT_ID |
---|
[14336] | 60 | mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94' |
---|
[10765] | 61 | |
---|
| 62 | def update(self): |
---|
[12979] | 63 | error = self.init_update() |
---|
| 64 | if error: |
---|
| 65 | self.flash(error, type='danger') |
---|
| 66 | self.redirect(self.url(self.context, '@@index')) |
---|
| 67 | return |
---|
[11647] | 68 | student = self.student |
---|
| 69 | xmldict = self.xmldict |
---|
[14342] | 70 | self.pay_item_id = '0000' |
---|
[10765] | 71 | # Provider data |
---|
| 72 | xmldict['detail_ref'] = self.context.p_id |
---|
| 73 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 74 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 75 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[14342] | 76 | provider_amt = 500.0 |
---|
[10765] | 77 | # Institution data |
---|
[14336] | 78 | xmldict['institution_acct'] = '1019684470' |
---|
| 79 | xmldict['institution_bank_id'] = '7' |
---|
[12511] | 80 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 81 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[14336] | 82 | if self.context.p_category == 'clearance': |
---|
| 83 | self.pay_item_id = '102' |
---|
[14342] | 84 | elif self.context.p_category.startswith('schoolfee'): |
---|
[14336] | 85 | self.pay_item_id = '103' |
---|
[14342] | 86 | if self.context.p_category in ('schoolfee', 'schoolfee_1'): |
---|
| 87 | provider_amt = 4000.0 |
---|
| 88 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 89 | xmldict['institution_amt'] = 100 * ( |
---|
| 90 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
| 91 | |
---|
[10765] | 92 | # Interswitch amount is not part of the xml data |
---|
| 93 | if provider_amt == 0: |
---|
| 94 | xmltext = """<payment_item_detail> |
---|
| 95 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 96 | <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" /> |
---|
| 97 | </item_details> |
---|
| 98 | </payment_item_detail>""" % xmldict |
---|
| 99 | else: |
---|
| 100 | xmltext = """<payment_item_detail> |
---|
| 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" /> |
---|
| 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" /> |
---|
| 104 | </item_details> |
---|
| 105 | </payment_item_detail>""" % xmldict |
---|
| 106 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 107 | self.context.provider_amt = provider_amt |
---|
| 108 | self.context.gateway_amt = GATEWAY_AMT |
---|
[12479] | 109 | |
---|
| 110 | hashargs = ( |
---|
| 111 | self.context.p_id + |
---|
| 112 | PRODUCT_ID + |
---|
| 113 | self.pay_item_id + |
---|
| 114 | str(int(self.amount_auth)) + |
---|
| 115 | self.site_redirect_url + |
---|
| 116 | self.mac) |
---|
| 117 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 118 | return |
---|
| 119 | |
---|
[11638] | 120 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[10765] | 121 | """ View which sends a POST request to the Interswitch |
---|
| 122 | CollegePAY payment gateway. |
---|
| 123 | """ |
---|
| 124 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 125 | action = POST_ACTION |
---|
| 126 | site_name = SITE_NAME |
---|
| 127 | currency = CURRENCY |
---|
[14097] | 128 | pay_item_id = '101' |
---|
[10765] | 129 | product_id = PRODUCT_ID |
---|
[14129] | 130 | mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94' |
---|
[10765] | 131 | |
---|
| 132 | def update(self): |
---|
[12979] | 133 | error = self.init_update() |
---|
| 134 | if error: |
---|
| 135 | self.flash(error, type='danger') |
---|
| 136 | self.redirect(self.url(self.context, '@@index')) |
---|
| 137 | return |
---|
[10765] | 138 | xmldict = {} |
---|
[14092] | 139 | provider_amt = 500.0 |
---|
[14301] | 140 | xmldict['institution_acct'] = '1019684470' |
---|
[14092] | 141 | xmldict['institution_bank_id'] = '7' |
---|
[10765] | 142 | xmldict['detail_ref'] = self.context.p_id |
---|
| 143 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 144 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 145 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 146 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 147 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[12511] | 148 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 149 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 150 | # Interswitch amount is not part of the xml data |
---|
| 151 | xmltext = """<payment_item_detail> |
---|
| 152 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)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_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" /> |
---|
| 155 | </item_details> |
---|
| 156 | </payment_item_detail>""" % xmldict |
---|
| 157 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 158 | self.context.provider_amt = provider_amt |
---|
| 159 | self.context.gateway_amt = GATEWAY_AMT |
---|
[12479] | 160 | |
---|
| 161 | hashargs = ( |
---|
| 162 | self.context.p_id + |
---|
| 163 | PRODUCT_ID + |
---|
| 164 | self.pay_item_id + |
---|
| 165 | str(int(self.amount_auth)) + |
---|
| 166 | self.site_redirect_url + |
---|
| 167 | self.mac) |
---|
| 168 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 169 | return |
---|
| 170 | |
---|
[11638] | 171 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[10765] | 172 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[13587] | 173 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 174 | """ |
---|
| 175 | grok.context(ICustomStudentOnlinePayment) |
---|
| 176 | product_id = PRODUCT_ID |
---|
| 177 | gateway_host = HOST |
---|
| 178 | gateway_url = URL |
---|
[14342] | 179 | mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94' |
---|
[10765] | 180 | |
---|
[13587] | 181 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 182 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
| 183 | """Payment verify view for the CollegePAY gateway |
---|
| 184 | """ |
---|
| 185 | grok.context(ICustomStudentOnlinePayment) |
---|
| 186 | product_id = PRODUCT_ID |
---|
| 187 | gateway_host = HOST |
---|
| 188 | gateway_url = URL |
---|
[14342] | 189 | mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94' |
---|
[13587] | 190 | |
---|
[11638] | 191 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[10765] | 192 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[13587] | 193 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 194 | """ |
---|
| 195 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 196 | product_id = PRODUCT_ID |
---|
| 197 | gateway_host = HOST |
---|
[12479] | 198 | gateway_url = URL |
---|
[14130] | 199 | mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94' |
---|
[13587] | 200 | |
---|
| 201 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 202 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 203 | """Payment verify view for the CollegePAY gateway |
---|
| 204 | """ |
---|
| 205 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 206 | product_id = PRODUCT_ID |
---|
| 207 | gateway_host = HOST |
---|
[14342] | 208 | gateway_url = URL |
---|
| 209 | mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94' |
---|