[10765] | 1 | ## $Id: browser.py 14336 2016-12-12 12:02:31Z 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 |
---|
[10765] | 70 | # Provider data |
---|
| 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 |
---|
| 75 | # Institution data |
---|
[14336] | 76 | xmldict['institution_acct'] = '1019684470' |
---|
| 77 | xmldict['institution_bank_id'] = '7' |
---|
| 78 | provider_amt = 500.0 |
---|
[10765] | 79 | self.pay_item_id = '0000' |
---|
| 80 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[12511] | 81 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 82 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 83 | xmldict['institution_amt'] = 100 * ( |
---|
| 84 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[14336] | 85 | if self.context.p_category == 'clearance': |
---|
| 86 | self.pay_item_id = '102' |
---|
| 87 | elif self.context.p_category == 'schoolfee': |
---|
| 88 | self.pay_item_id = '103' |
---|
[10765] | 89 | # Interswitch amount is not part of the xml data |
---|
| 90 | if provider_amt == 0: |
---|
| 91 | xmltext = """<payment_item_detail> |
---|
| 92 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 93 | <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" /> |
---|
| 94 | </item_details> |
---|
| 95 | </payment_item_detail>""" % xmldict |
---|
| 96 | else: |
---|
| 97 | xmltext = """<payment_item_detail> |
---|
| 98 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 99 | <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" /> |
---|
| 100 | <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" /> |
---|
| 101 | </item_details> |
---|
| 102 | </payment_item_detail>""" % xmldict |
---|
| 103 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 104 | self.context.provider_amt = provider_amt |
---|
| 105 | self.context.gateway_amt = GATEWAY_AMT |
---|
[12479] | 106 | |
---|
| 107 | hashargs = ( |
---|
| 108 | self.context.p_id + |
---|
| 109 | PRODUCT_ID + |
---|
| 110 | self.pay_item_id + |
---|
| 111 | str(int(self.amount_auth)) + |
---|
| 112 | self.site_redirect_url + |
---|
| 113 | self.mac) |
---|
| 114 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 115 | return |
---|
| 116 | |
---|
[11638] | 117 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[10765] | 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 |
---|
[14097] | 125 | pay_item_id = '101' |
---|
[10765] | 126 | product_id = PRODUCT_ID |
---|
[14129] | 127 | mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94' |
---|
[10765] | 128 | |
---|
| 129 | def update(self): |
---|
[12979] | 130 | error = self.init_update() |
---|
| 131 | if error: |
---|
| 132 | self.flash(error, type='danger') |
---|
| 133 | self.redirect(self.url(self.context, '@@index')) |
---|
| 134 | return |
---|
[10765] | 135 | xmldict = {} |
---|
[14092] | 136 | provider_amt = 500.0 |
---|
[14301] | 137 | xmldict['institution_acct'] = '1019684470' |
---|
[14092] | 138 | xmldict['institution_bank_id'] = '7' |
---|
[10765] | 139 | xmldict['detail_ref'] = self.context.p_id |
---|
| 140 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 141 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 142 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 143 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 144 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[12511] | 145 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 146 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 147 | # Interswitch amount is not part of the xml data |
---|
| 148 | xmltext = """<payment_item_detail> |
---|
| 149 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 150 | <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" /> |
---|
| 151 | <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" /> |
---|
| 152 | </item_details> |
---|
| 153 | </payment_item_detail>""" % xmldict |
---|
| 154 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 155 | self.context.provider_amt = provider_amt |
---|
| 156 | self.context.gateway_amt = GATEWAY_AMT |
---|
[12479] | 157 | |
---|
| 158 | hashargs = ( |
---|
| 159 | self.context.p_id + |
---|
| 160 | PRODUCT_ID + |
---|
| 161 | self.pay_item_id + |
---|
| 162 | str(int(self.amount_auth)) + |
---|
| 163 | self.site_redirect_url + |
---|
| 164 | self.mac) |
---|
| 165 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 166 | return |
---|
| 167 | |
---|
[11638] | 168 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[10765] | 169 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[13587] | 170 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 171 | """ |
---|
| 172 | grok.context(ICustomStudentOnlinePayment) |
---|
| 173 | product_id = PRODUCT_ID |
---|
| 174 | gateway_host = HOST |
---|
| 175 | gateway_url = URL |
---|
| 176 | |
---|
[13587] | 177 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 178 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
| 179 | """Payment verify view for the CollegePAY gateway |
---|
| 180 | """ |
---|
| 181 | grok.context(ICustomStudentOnlinePayment) |
---|
| 182 | product_id = PRODUCT_ID |
---|
| 183 | gateway_host = HOST |
---|
| 184 | gateway_url = URL |
---|
| 185 | |
---|
[11638] | 186 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[10765] | 187 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[13587] | 188 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 189 | """ |
---|
| 190 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 191 | product_id = PRODUCT_ID |
---|
| 192 | gateway_host = HOST |
---|
[12479] | 193 | gateway_url = URL |
---|
[14130] | 194 | mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94' |
---|
[13587] | 195 | |
---|
| 196 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 197 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 198 | """Payment verify view for the CollegePAY gateway |
---|
| 199 | """ |
---|
| 200 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 201 | product_id = PRODUCT_ID |
---|
| 202 | gateway_host = HOST |
---|
| 203 | gateway_url = URL |
---|