[10765] | 1 | ## $Id: browser.py 15794 2019-11-11 06:51:45Z 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 | ) |
---|
[15563] | 28 | from kofacustom.iuokada.students.interfaces import ICustomStudentOnlinePayment |
---|
| 29 | from kofacustom.iuokada.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
| 30 | from kofacustom.iuokada.interfaces import MessageFactory as _ |
---|
[10765] | 31 | |
---|
[15728] | 32 | PRODUCT_ID = '7922' |
---|
[15563] | 33 | SITE_NAME = 'iuokada-kofa.waeup.org' |
---|
[15645] | 34 | PROVIDER_ACCT = '0773411069' |
---|
| 35 | PROVIDER_BANK_ID = '31' |
---|
| 36 | PROVIDER_ITEM_NAME = 'WAeAC' |
---|
[15563] | 37 | INSTITUTION_NAME = 'IUOkada' |
---|
[10765] | 38 | CURRENCY = '566' |
---|
[15728] | 39 | GATEWAY_AMT = 250.0 |
---|
| 40 | #MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' # must be provided by Interswitch |
---|
| 41 | MAC = '4D8723F33D728BE3F4A77B2DFB3F57B0BCF2DD818759D54A87B2A60874067F28D94F2B91E29BFB884F920F48E0973D826835A8F2D6F74220C64EDE4DE00E45AA' |
---|
[10765] | 42 | |
---|
[15728] | 43 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay' |
---|
| 44 | #POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay' |
---|
| 45 | HOST = 'webpay.interswitchng.com' |
---|
| 46 | #HOST = 'sandbox.interswitchng.com' |
---|
| 47 | URL = '/paydirect/api/v1/gettransaction.json' |
---|
| 48 | #URL = '/webpay/api/v1/gettransaction.json' |
---|
[14276] | 49 | |
---|
[12479] | 50 | httplib.HTTPSConnection.debuglevel = 0 |
---|
| 51 | HTTPS = True |
---|
[10765] | 52 | |
---|
[11638] | 53 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
[10765] | 54 | """ View which sends a POST request to the Interswitch |
---|
| 55 | CollegePAY payment gateway. |
---|
| 56 | """ |
---|
| 57 | grok.context(ICustomStudentOnlinePayment) |
---|
| 58 | action = POST_ACTION |
---|
| 59 | site_name = SITE_NAME |
---|
| 60 | currency = CURRENCY |
---|
| 61 | product_id = PRODUCT_ID |
---|
[15269] | 62 | mac = MAC |
---|
[15773] | 63 | gateway_amt = GATEWAY_AMT |
---|
[10765] | 64 | |
---|
| 65 | def update(self): |
---|
[12979] | 66 | error = self.init_update() |
---|
| 67 | if error: |
---|
| 68 | self.flash(error, type='danger') |
---|
| 69 | self.redirect(self.url(self.context, '@@index')) |
---|
| 70 | return |
---|
[15773] | 71 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
| 72 | # and add the gateway amount. |
---|
| 73 | if not self.context.r_company: |
---|
| 74 | self.context.net_amt = self.context.amount_auth |
---|
| 75 | self.context.amount_auth += self.gateway_amt |
---|
| 76 | self.context.gateway_amt = self.gateway_amt |
---|
| 77 | self.context.r_company = u'interswitch' |
---|
[11647] | 78 | student = self.student |
---|
| 79 | xmldict = self.xmldict |
---|
[10765] | 80 | # Provider data |
---|
| 81 | xmldict['detail_ref'] = self.context.p_id |
---|
| 82 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 83 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 84 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[15728] | 85 | xmldict['institution_acct'] = '' |
---|
| 86 | xmldict['institution_bank_id'] = '' |
---|
[15773] | 87 | provider_amt = 0.0 |
---|
[15728] | 88 | self.pay_item_id = '' |
---|
[10765] | 89 | # Institution data |
---|
[15728] | 90 | if self.context.p_category in ( |
---|
| 91 | 'schoolfee', 'schoolfee40', 'secondinstal'): |
---|
| 92 | xmldict['institution_acct'] = '1011005811' |
---|
| 93 | xmldict['institution_bank_id'] = '117' |
---|
| 94 | self.pay_item_id = '101' |
---|
| 95 | elif self.context.p_category == 'book': |
---|
| 96 | xmldict['institution_acct'] = '1013249587' |
---|
| 97 | xmldict['institution_bank_id'] = '117' |
---|
| 98 | self.pay_item_id = '103' |
---|
| 99 | elif self.context.p_category == 'parentsconsult': |
---|
| 100 | xmldict['institution_acct'] = '1012355544' |
---|
| 101 | xmldict['institution_bank_id'] = '117' |
---|
| 102 | self.pay_item_id = '104' |
---|
[15794] | 103 | elif self.context.p_category in ( |
---|
| 104 | 'municipal_fresh', 'municipal_returning', |
---|
| 105 | 'transcript_local', 'transcript_overseas'): |
---|
| 106 | xmldict['institution_acct'] = '0040621193' |
---|
| 107 | xmldict['institution_bank_id'] = '31' |
---|
| 108 | self.pay_item_id = '105' |
---|
[15728] | 109 | else: |
---|
| 110 | xmldict['institution_acct'] = '1011050158' |
---|
| 111 | xmldict['institution_bank_id'] = '117' |
---|
| 112 | self.pay_item_id = '102' |
---|
| 113 | if self.context.p_category == 'registration': |
---|
| 114 | provider_amt = 5000.0 |
---|
[10765] | 115 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[12511] | 116 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 117 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[15773] | 118 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
| 119 | if not self.context.provider_amt: |
---|
| 120 | self.context.provider_amt = provider_amt |
---|
| 121 | self.context.amount_auth += provider_amt |
---|
[10765] | 122 | if provider_amt == 0: |
---|
| 123 | xmltext = """<payment_item_detail> |
---|
| 124 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 125 | <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" /> |
---|
| 126 | </item_details> |
---|
| 127 | </payment_item_detail>""" % xmldict |
---|
| 128 | else: |
---|
| 129 | xmltext = """<payment_item_detail> |
---|
| 130 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 131 | <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" /> |
---|
| 132 | <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" /> |
---|
| 133 | </item_details> |
---|
| 134 | </payment_item_detail>""" % xmldict |
---|
| 135 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[15773] | 136 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[12479] | 137 | hashargs = ( |
---|
| 138 | self.context.p_id + |
---|
| 139 | PRODUCT_ID + |
---|
| 140 | self.pay_item_id + |
---|
| 141 | str(int(self.amount_auth)) + |
---|
| 142 | self.site_redirect_url + |
---|
| 143 | self.mac) |
---|
| 144 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 145 | return |
---|
| 146 | |
---|
[11638] | 147 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[10765] | 148 | """ View which sends a POST request to the Interswitch |
---|
| 149 | CollegePAY payment gateway. |
---|
| 150 | """ |
---|
| 151 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 152 | action = POST_ACTION |
---|
| 153 | site_name = SITE_NAME |
---|
| 154 | currency = CURRENCY |
---|
| 155 | product_id = PRODUCT_ID |
---|
[15269] | 156 | mac = MAC |
---|
[15773] | 157 | gateway_amt = GATEWAY_AMT |
---|
[10765] | 158 | |
---|
| 159 | def update(self): |
---|
[12979] | 160 | error = self.init_update() |
---|
| 161 | if error: |
---|
| 162 | self.flash(error, type='danger') |
---|
| 163 | self.redirect(self.url(self.context, '@@index')) |
---|
| 164 | return |
---|
[15773] | 165 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
| 166 | # and add the gateway amount. |
---|
| 167 | if not self.context.r_company: |
---|
| 168 | self.context.net_amt = self.context.amount_auth |
---|
| 169 | self.context.amount_auth += self.gateway_amt |
---|
| 170 | self.context.gateway_amt = self.gateway_amt |
---|
| 171 | self.context.r_company = u'interswitch' |
---|
| 172 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[10765] | 173 | xmldict = {} |
---|
[15773] | 174 | provider_amt = 0.0 |
---|
[15786] | 175 | self.pay_item_id = '101' |
---|
[15783] | 176 | xmldict['institution_acct'] = '1011005811' |
---|
| 177 | xmldict['institution_bank_id'] = '117' |
---|
[10765] | 178 | xmldict['detail_ref'] = self.context.p_id |
---|
| 179 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 180 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 181 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 182 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[12511] | 183 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 184 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[15773] | 185 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
| 186 | if not self.context.provider_amt: |
---|
| 187 | self.context.provider_amt = provider_amt |
---|
| 188 | self.context.amount_auth += provider_amt |
---|
[15784] | 189 | if provider_amt == 0: |
---|
| 190 | xmltext = """<payment_item_detail> |
---|
[15785] | 191 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
[10765] | 192 | <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" /> |
---|
[15784] | 193 | </item_details> |
---|
| 194 | </payment_item_detail>""" % xmldict |
---|
| 195 | else: |
---|
| 196 | xmltext = """<payment_item_detail> |
---|
[15785] | 197 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
[15784] | 198 | <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" /> |
---|
[10765] | 199 | <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" /> |
---|
| 200 | </item_details> |
---|
| 201 | </payment_item_detail>""" % xmldict |
---|
| 202 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[15773] | 203 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[12479] | 204 | hashargs = ( |
---|
| 205 | self.context.p_id + |
---|
| 206 | PRODUCT_ID + |
---|
[15786] | 207 | self.pay_item_id + |
---|
[12479] | 208 | str(int(self.amount_auth)) + |
---|
| 209 | self.site_redirect_url + |
---|
| 210 | self.mac) |
---|
| 211 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 212 | return |
---|
| 213 | |
---|
[11638] | 214 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[10765] | 215 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[13587] | 216 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 217 | """ |
---|
| 218 | grok.context(ICustomStudentOnlinePayment) |
---|
| 219 | product_id = PRODUCT_ID |
---|
| 220 | gateway_host = HOST |
---|
| 221 | gateway_url = URL |
---|
[15269] | 222 | mac = MAC |
---|
[10765] | 223 | |
---|
[13587] | 224 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 225 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
| 226 | """Payment verify view for the CollegePAY gateway |
---|
| 227 | """ |
---|
| 228 | grok.context(ICustomStudentOnlinePayment) |
---|
| 229 | product_id = PRODUCT_ID |
---|
| 230 | gateway_host = HOST |
---|
| 231 | gateway_url = URL |
---|
[15269] | 232 | mac = MAC |
---|
[13587] | 233 | |
---|
[11638] | 234 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[10765] | 235 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[13587] | 236 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 237 | """ |
---|
| 238 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 239 | product_id = PRODUCT_ID |
---|
| 240 | gateway_host = HOST |
---|
[12479] | 241 | gateway_url = URL |
---|
[15269] | 242 | mac = MAC |
---|
[13587] | 243 | |
---|
| 244 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 245 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 246 | """Payment verify view for the CollegePAY gateway |
---|
| 247 | """ |
---|
| 248 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 249 | product_id = PRODUCT_ID |
---|
| 250 | gateway_host = HOST |
---|
[15269] | 251 | gateway_url = URL |
---|
| 252 | mac = MAC |
---|