[16639] | 1 | ## $Id: browser.py 17345 2023-03-10 09:13:25Z henrik $ |
---|
[15614] | 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 |
---|
| 19 | import hashlib |
---|
| 20 | import grok |
---|
| 21 | from kofacustom.nigeria.interswitch.browser import ( |
---|
[16593] | 22 | module_activated, |
---|
[15614] | 23 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
| 24 | InterswitchPaymentRequestWebservicePageStudent, |
---|
| 25 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
| 26 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
| 27 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
| 28 | ) |
---|
[16615] | 29 | from kofacustom.edocons.students.interfaces import ICustomStudentOnlinePayment |
---|
| 30 | from kofacustom.edocons.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
| 31 | from kofacustom.edocons.interfaces import MessageFactory as _ |
---|
[15614] | 32 | |
---|
[16638] | 33 | PRODUCT_ID = '22133007' # must be provided by Interswitch |
---|
[16796] | 34 | SITE_NAME = 'ecns.waeup.org' |
---|
[16638] | 35 | PROVIDER_ACCT = '0213065415' |
---|
| 36 | PROVIDER_BANK_ID = '47' |
---|
[16589] | 37 | PROVIDER_ITEM_NAME = 'WAeAC' |
---|
[16615] | 38 | INSTITUTION_NAME = 'EDOCONS' |
---|
[15614] | 39 | CURRENCY = '566' |
---|
[16635] | 40 | GATEWAY_AMT = 300.0 |
---|
[16638] | 41 | #MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' # must be provided by Interswitch |
---|
[16656] | 42 | MAC ='chSVbuS0CN6yg08QaX2DrlhjOpGqtxd3JojMrIrpPMArNQx4C2AcczZyGjXnhmHGzfiHe9diKGB8fTIIzifzpv20a28EYOLqdWDaB2uMyxwrnTf3ncbOx35gLIavrx1r' |
---|
[15614] | 43 | |
---|
[16638] | 44 | POST_ACTION = 'https://webpay.interswitchng.com/collections/w/pay' |
---|
| 45 | #POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay' |
---|
| 46 | HOST = 'webpay.interswitchng.com' |
---|
| 47 | #HOST = 'sandbox.interswitchng.com' |
---|
| 48 | URL = '/collections/api/v1/gettransaction.json' |
---|
| 49 | #URL = '/webpay/api/v1/gettransaction.json' |
---|
[15614] | 50 | |
---|
| 51 | httplib.HTTPSConnection.debuglevel = 0 |
---|
| 52 | HTTPS = True |
---|
| 53 | |
---|
| 54 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
| 55 | """ View which sends a POST request to the Interswitch |
---|
| 56 | CollegePAY payment gateway. |
---|
| 57 | """ |
---|
| 58 | grok.context(ICustomStudentOnlinePayment) |
---|
| 59 | action = POST_ACTION |
---|
| 60 | site_name = SITE_NAME |
---|
| 61 | currency = CURRENCY |
---|
| 62 | product_id = PRODUCT_ID |
---|
[15756] | 63 | mac = MAC |
---|
| 64 | gateway_amt = GATEWAY_AMT |
---|
[15614] | 65 | |
---|
| 66 | def update(self): |
---|
[16593] | 67 | if not module_activated( |
---|
| 68 | self.context.student.current_session, self.context): |
---|
| 69 | self.flash(_('Forbidden'), type='danger') |
---|
| 70 | self.redirect(self.url(self.context, '@@index')) |
---|
| 71 | return |
---|
[15614] | 72 | error = self.init_update() |
---|
| 73 | if error: |
---|
| 74 | self.flash(error, type='danger') |
---|
| 75 | self.redirect(self.url(self.context, '@@index')) |
---|
| 76 | return |
---|
[15756] | 77 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
| 78 | # and add the gateway amount. |
---|
| 79 | if not self.context.r_company: |
---|
| 80 | self.context.net_amt = self.context.amount_auth |
---|
| 81 | self.context.amount_auth += self.gateway_amt |
---|
| 82 | self.context.gateway_amt = self.gateway_amt |
---|
| 83 | self.context.r_company = u'interswitch' |
---|
[15614] | 84 | student = self.student |
---|
| 85 | xmldict = self.xmldict |
---|
| 86 | # Provider data |
---|
| 87 | xmldict['detail_ref'] = self.context.p_id |
---|
| 88 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 89 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 90 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 91 | # Institution data |
---|
[16707] | 92 | xmldict['institution_acct'] = '1489560452' |
---|
| 93 | xmldict['institution_bank_id'] = '31' |
---|
[15614] | 94 | provider_amt = 0.0 |
---|
[16806] | 95 | self.pay_item_id = 'Default_Payable_MX26002' # must be provided by Interswitch |
---|
[15614] | 96 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 97 | xmldict['institution_item_name'] = self.context.category |
---|
| 98 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[15756] | 99 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
| 100 | if not self.context.provider_amt: |
---|
| 101 | self.context.provider_amt = provider_amt |
---|
| 102 | self.context.amount_auth += provider_amt |
---|
[15614] | 103 | if provider_amt == 0: |
---|
| 104 | xmltext = """<payment_item_detail> |
---|
| 105 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 106 | <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" /> |
---|
| 107 | </item_details> |
---|
| 108 | </payment_item_detail>""" % xmldict |
---|
| 109 | else: |
---|
| 110 | xmltext = """<payment_item_detail> |
---|
| 111 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 112 | <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" /> |
---|
| 113 | <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" /> |
---|
| 114 | </item_details> |
---|
| 115 | </payment_item_detail>""" % xmldict |
---|
| 116 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 117 | self.context.provider_amt = provider_amt |
---|
[15756] | 118 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[15614] | 119 | hashargs = ( |
---|
| 120 | self.context.p_id + |
---|
| 121 | PRODUCT_ID + |
---|
| 122 | self.pay_item_id + |
---|
| 123 | str(int(self.amount_auth)) + |
---|
| 124 | self.site_redirect_url + |
---|
| 125 | self.mac) |
---|
| 126 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
| 127 | return |
---|
| 128 | |
---|
| 129 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
| 130 | """ View which sends a POST request to the Interswitch |
---|
| 131 | CollegePAY payment gateway. |
---|
| 132 | """ |
---|
| 133 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 134 | action = POST_ACTION |
---|
| 135 | site_name = SITE_NAME |
---|
| 136 | currency = CURRENCY |
---|
[16806] | 137 | pay_item_id = 'Default_Payable_MX26002' # must be provided by Interswitch |
---|
[15614] | 138 | product_id = PRODUCT_ID |
---|
| 139 | mac = MAC |
---|
[15756] | 140 | gateway_amt = GATEWAY_AMT |
---|
[15614] | 141 | |
---|
| 142 | def update(self): |
---|
[16593] | 143 | if not module_activated( |
---|
| 144 | self.context.__parent__.__parent__.year, self.context): |
---|
| 145 | self.flash(_('Forbidden'), type='danger') |
---|
| 146 | self.redirect(self.url(self.context, '@@index')) |
---|
| 147 | return |
---|
[15614] | 148 | error = self.init_update() |
---|
| 149 | if error: |
---|
| 150 | self.flash(error, type='danger') |
---|
| 151 | self.redirect(self.url(self.context, '@@index')) |
---|
| 152 | return |
---|
[15756] | 153 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
| 154 | # and add the gateway amount. |
---|
| 155 | if not self.context.r_company: |
---|
| 156 | self.context.net_amt = self.context.amount_auth |
---|
| 157 | self.context.amount_auth += self.gateway_amt |
---|
| 158 | self.context.gateway_amt = self.gateway_amt |
---|
| 159 | self.context.r_company = u'interswitch' |
---|
[15614] | 160 | xmldict = {} |
---|
[16640] | 161 | provider_amt = 0.0 |
---|
[17045] | 162 | midwife_amt = 200.0 |
---|
[16638] | 163 | xmldict['institution_acct'] = '1489560452' |
---|
| 164 | xmldict['institution_bank_id'] = '31' |
---|
[17040] | 165 | if self.context.__parent__.__parent__.prefix.startswith('tsc'): |
---|
[17045] | 166 | midwife_amt = 0.0 |
---|
[17040] | 167 | xmldict['institution_acct'] = '1000907711' |
---|
| 168 | xmldict['institution_bank_id'] = '7' |
---|
[15614] | 169 | xmldict['detail_ref'] = self.context.p_id |
---|
| 170 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 171 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 172 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 173 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 174 | xmldict['institution_item_name'] = self.context.category |
---|
| 175 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[16638] | 176 | xmldict['midwife_amt'] = 100 * midwife_amt |
---|
| 177 | xmldict['institution_amt'] = 100 * (self.context.net_amt - midwife_amt) |
---|
[15756] | 178 | if not self.context.provider_amt: |
---|
| 179 | self.context.provider_amt = provider_amt |
---|
| 180 | self.context.amount_auth += provider_amt |
---|
[17045] | 181 | if provider_amt and midwife_amt: |
---|
[16640] | 182 | xmltext = """<payment_item_detail> |
---|
[15614] | 183 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 184 | <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" /> |
---|
[17045] | 185 | <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" /> |
---|
| 186 | <item_detail item_id="3" item_name="Nursing and Midwifery Committee" item_amt="%(midwife_amt)d" bank_id="8" acct_num="2004854377" /> |
---|
[15614] | 187 | </item_details> |
---|
| 188 | </payment_item_detail>""" % xmldict |
---|
[17045] | 189 | elif provider_amt and not midwife_amt: |
---|
| 190 | xmltext = """<payment_item_detail> |
---|
| 191 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 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" /> |
---|
| 193 | <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" /> |
---|
| 194 | </item_details> |
---|
| 195 | </payment_item_detail>""" % xmldict |
---|
[17345] | 196 | elif not provider_amt and midwife_amt: |
---|
[16640] | 197 | xmltext = """<payment_item_detail> |
---|
| 198 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 199 | <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" /> |
---|
| 200 | <item_detail item_id="2" item_name="Nursing and Midwifery Committee" item_amt="%(midwife_amt)d" bank_id="8" acct_num="2004854377" /> |
---|
| 201 | </item_details> |
---|
| 202 | </payment_item_detail>""" % xmldict |
---|
[17345] | 203 | else: |
---|
| 204 | xmltext = """<payment_item_detail> |
---|
| 205 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 206 | <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" /> |
---|
| 207 | </item_details> |
---|
| 208 | </payment_item_detail>""" % xmldict |
---|
[15614] | 209 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[15756] | 210 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[15614] | 211 | hashargs = ( |
---|
| 212 | self.context.p_id + |
---|
| 213 | PRODUCT_ID + |
---|
| 214 | self.pay_item_id + |
---|
| 215 | str(int(self.amount_auth)) + |
---|
| 216 | self.site_redirect_url + |
---|
| 217 | self.mac) |
---|
| 218 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
| 219 | return |
---|
| 220 | |
---|
| 221 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
| 222 | InterswitchPaymentRequestWebservicePageStudent): |
---|
| 223 | """Request webservice view for the CollegePAY gateway |
---|
| 224 | """ |
---|
| 225 | grok.context(ICustomStudentOnlinePayment) |
---|
| 226 | product_id = PRODUCT_ID |
---|
| 227 | gateway_host = HOST |
---|
| 228 | gateway_url = URL |
---|
| 229 | mac = MAC |
---|
| 230 | |
---|
| 231 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 232 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
| 233 | """Payment verify view for the CollegePAY gateway |
---|
| 234 | """ |
---|
| 235 | grok.context(ICustomStudentOnlinePayment) |
---|
| 236 | product_id = PRODUCT_ID |
---|
| 237 | gateway_host = HOST |
---|
| 238 | gateway_url = URL |
---|
| 239 | mac = MAC |
---|
| 240 | |
---|
| 241 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
| 242 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
| 243 | """Request webservice view for the CollegePAY gateway |
---|
| 244 | """ |
---|
| 245 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 246 | product_id = PRODUCT_ID |
---|
| 247 | gateway_host = HOST |
---|
| 248 | gateway_url = URL |
---|
| 249 | mac = MAC |
---|
| 250 | |
---|
| 251 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 252 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 253 | """Payment verify view for the CollegePAY gateway |
---|
| 254 | """ |
---|
| 255 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 256 | product_id = PRODUCT_ID |
---|
| 257 | gateway_host = HOST |
---|
| 258 | gateway_url = URL |
---|
[16698] | 259 | mac = MAC |
---|
| 260 | |
---|
| 261 | # PAYDirect |
---|
| 262 | |
---|
| 263 | from kofacustom.nigeria.interswitch.paydirectbrowser import ( |
---|
| 264 | PAYDirectPageStudent, PAYDirectPageApplicant, |
---|
| 265 | StudentRefNumberSlip, ApplicantRefNumberSlip, |
---|
| 266 | ) |
---|
| 267 | |
---|
[16716] | 268 | #from kofacustom.nigeria.interswitch.tests import ( |
---|
| 269 | # PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID) |
---|
[16698] | 270 | |
---|
[16716] | 271 | PAYDIRECT_HOST = 'orion.interswitchng.com' |
---|
| 272 | PAYDIRECT_URL = '/bookonhold/bookonhold.asmx' |
---|
[16806] | 273 | MERCHANT_ID = 'MX26002' |
---|
[16698] | 274 | |
---|
| 275 | class CustomPAYDirectPageStudent(PAYDirectPageStudent): |
---|
| 276 | """Inform student how to proceed |
---|
| 277 | """ |
---|
| 278 | grok.context(ICustomStudentOnlinePayment) |
---|
| 279 | gateway_amt = GATEWAY_AMT |
---|
| 280 | merchant_id = MERCHANT_ID |
---|
| 281 | gateway_url = PAYDIRECT_URL |
---|
| 282 | gateway_host = PAYDIRECT_HOST |
---|
| 283 | https = True |
---|
| 284 | |
---|
| 285 | class CustomPAYDirectPageApplicant(PAYDirectPageApplicant): |
---|
| 286 | """ Inform applicant how to proceed. |
---|
| 287 | """ |
---|
| 288 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 289 | gateway_amt = GATEWAY_AMT |
---|
| 290 | merchant_id = MERCHANT_ID |
---|
| 291 | gateway_url = PAYDIRECT_URL |
---|
| 292 | gateway_host = PAYDIRECT_HOST |
---|
| 293 | https = True |
---|
| 294 | |
---|
| 295 | class CustomStudentRefNumberSlip(StudentRefNumberSlip): |
---|
| 296 | """Deliver a PDF slip of the context. |
---|
| 297 | """ |
---|
| 298 | merchant_id = MERCHANT_ID |
---|
| 299 | |
---|
| 300 | class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip): |
---|
| 301 | """Deliver a PDF slip of the context. |
---|
| 302 | """ |
---|
| 303 | merchant_id = MERCHANT_ID |
---|