[10765] | 1 | ## $Id: browser.py 14658 2017-03-27 10:39:43Z 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' |
---|
[14658] | 39 | GATEWAY_AMT = 250.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 |
---|
[14640] | 77 | provider_amt = 0.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' |
---|
[14640] | 85 | provider_amt = 500.0 |
---|
[14342] | 86 | elif self.context.p_category.startswith('schoolfee'): |
---|
[14336] | 87 | self.pay_item_id = '103' |
---|
[14640] | 88 | if self.context.p_category in ('schoolfee', 'schoolfee_1') \ |
---|
| 89 | and not self.context.p_item == 'Balance': |
---|
[14342] | 90 | provider_amt = 4000.0 |
---|
| 91 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 92 | xmldict['institution_amt'] = 100 * ( |
---|
| 93 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
| 94 | |
---|
[10765] | 95 | # Interswitch amount is not part of the xml data |
---|
| 96 | if provider_amt == 0: |
---|
| 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_details> |
---|
| 101 | </payment_item_detail>""" % xmldict |
---|
| 102 | else: |
---|
| 103 | xmltext = """<payment_item_detail> |
---|
| 104 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 105 | <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" /> |
---|
| 106 | <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" /> |
---|
| 107 | </item_details> |
---|
| 108 | </payment_item_detail>""" % xmldict |
---|
| 109 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 110 | self.context.provider_amt = provider_amt |
---|
| 111 | self.context.gateway_amt = GATEWAY_AMT |
---|
[12479] | 112 | |
---|
| 113 | hashargs = ( |
---|
| 114 | self.context.p_id + |
---|
| 115 | PRODUCT_ID + |
---|
| 116 | self.pay_item_id + |
---|
| 117 | str(int(self.amount_auth)) + |
---|
| 118 | self.site_redirect_url + |
---|
| 119 | self.mac) |
---|
| 120 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 121 | return |
---|
| 122 | |
---|
[11638] | 123 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[10765] | 124 | """ View which sends a POST request to the Interswitch |
---|
| 125 | CollegePAY payment gateway. |
---|
| 126 | """ |
---|
| 127 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 128 | action = POST_ACTION |
---|
| 129 | site_name = SITE_NAME |
---|
| 130 | currency = CURRENCY |
---|
[14097] | 131 | pay_item_id = '101' |
---|
[10765] | 132 | product_id = PRODUCT_ID |
---|
[14344] | 133 | mac = MAC |
---|
[10765] | 134 | |
---|
| 135 | def update(self): |
---|
[12979] | 136 | error = self.init_update() |
---|
| 137 | if error: |
---|
| 138 | self.flash(error, type='danger') |
---|
| 139 | self.redirect(self.url(self.context, '@@index')) |
---|
| 140 | return |
---|
[10765] | 141 | xmldict = {} |
---|
[14092] | 142 | provider_amt = 500.0 |
---|
[14301] | 143 | xmldict['institution_acct'] = '1019684470' |
---|
[14092] | 144 | xmldict['institution_bank_id'] = '7' |
---|
[10765] | 145 | xmldict['detail_ref'] = self.context.p_id |
---|
| 146 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 147 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 148 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 149 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 150 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[12511] | 151 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 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 |
---|
| 161 | self.context.provider_amt = provider_amt |
---|
| 162 | self.context.gateway_amt = GATEWAY_AMT |
---|
[12479] | 163 | |
---|
| 164 | hashargs = ( |
---|
| 165 | self.context.p_id + |
---|
| 166 | PRODUCT_ID + |
---|
| 167 | self.pay_item_id + |
---|
| 168 | str(int(self.amount_auth)) + |
---|
| 169 | self.site_redirect_url + |
---|
| 170 | self.mac) |
---|
| 171 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 172 | return |
---|
| 173 | |
---|
[11638] | 174 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[10765] | 175 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[13587] | 176 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 177 | """ |
---|
| 178 | grok.context(ICustomStudentOnlinePayment) |
---|
| 179 | product_id = PRODUCT_ID |
---|
| 180 | gateway_host = HOST |
---|
| 181 | gateway_url = URL |
---|
[14344] | 182 | mac = MAC |
---|
[10765] | 183 | |
---|
[13587] | 184 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 185 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
| 186 | """Payment verify view for the CollegePAY gateway |
---|
| 187 | """ |
---|
| 188 | grok.context(ICustomStudentOnlinePayment) |
---|
| 189 | product_id = PRODUCT_ID |
---|
| 190 | gateway_host = HOST |
---|
| 191 | gateway_url = URL |
---|
[14344] | 192 | mac = MAC |
---|
[13587] | 193 | |
---|
[11638] | 194 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[10765] | 195 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[13587] | 196 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 197 | """ |
---|
| 198 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 199 | product_id = PRODUCT_ID |
---|
| 200 | gateway_host = HOST |
---|
[12479] | 201 | gateway_url = URL |
---|
[14344] | 202 | mac = MAC |
---|
[13587] | 203 | |
---|
| 204 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 205 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 206 | """Payment verify view for the CollegePAY gateway |
---|
| 207 | """ |
---|
| 208 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 209 | product_id = PRODUCT_ID |
---|
| 210 | gateway_host = HOST |
---|
[14342] | 211 | gateway_url = URL |
---|
[14344] | 212 | mac = MAC |
---|