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