[16717] | 1 | ## $Id: browser.py 16983 2022-07-05 07:50:56Z 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 ( |
---|
[16592] | 22 | module_activated, |
---|
[15614] | 23 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
| 24 | InterswitchPaymentRequestWebservicePageStudent, |
---|
| 25 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
| 26 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
| 27 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
| 28 | ) |
---|
[16983] | 29 | from kofacustom.lpng.students.interfaces import ICustomStudentOnlinePayment |
---|
| 30 | from kofacustom.lpng.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
| 31 | from kofacustom.lpng.interfaces import MessageFactory as _ |
---|
[15614] | 32 | |
---|
| 33 | PRODUCT_ID = '' # must be provided by Interswitch |
---|
[16983] | 34 | SITE_NAME = 'lpng.waeup.org' |
---|
[15614] | 35 | PROVIDER_ACCT = '00000000' |
---|
| 36 | PROVIDER_BANK_ID = '00' |
---|
[16592] | 37 | PROVIDER_ITEM_NAME = 'WAeAC' |
---|
[16983] | 38 | INSTITUTION_NAME = 'LPNG' |
---|
[15614] | 39 | CURRENCY = '566' |
---|
| 40 | GATEWAY_AMT = 150.0 |
---|
| 41 | MAC = '' # must be provided by Interswitch |
---|
| 42 | |
---|
[16724] | 43 | #POST_ACTION = 'https://webpay.interswitchng.com/collections/w/pay' |
---|
[15614] | 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' |
---|
| 49 | |
---|
| 50 | httplib.HTTPSConnection.debuglevel = 0 |
---|
| 51 | HTTPS = True |
---|
| 52 | |
---|
| 53 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
| 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 |
---|
[15756] | 62 | mac = MAC |
---|
| 63 | gateway_amt = GATEWAY_AMT |
---|
[15614] | 64 | |
---|
| 65 | def update(self): |
---|
[16592] | 66 | if not module_activated( |
---|
| 67 | self.context.student.current_session, self.context): |
---|
| 68 | self.flash(_('Forbidden'), type='danger') |
---|
| 69 | self.redirect(self.url(self.context, '@@index')) |
---|
| 70 | return |
---|
[15614] | 71 | error = self.init_update() |
---|
| 72 | if error: |
---|
| 73 | self.flash(error, type='danger') |
---|
| 74 | self.redirect(self.url(self.context, '@@index')) |
---|
| 75 | return |
---|
[15756] | 76 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
| 77 | # and add the gateway amount. |
---|
| 78 | if not self.context.r_company: |
---|
| 79 | self.context.net_amt = self.context.amount_auth |
---|
| 80 | self.context.amount_auth += self.gateway_amt |
---|
| 81 | self.context.gateway_amt = self.gateway_amt |
---|
| 82 | self.context.r_company = u'interswitch' |
---|
[15614] | 83 | student = self.student |
---|
| 84 | xmldict = self.xmldict |
---|
| 85 | # Provider data |
---|
| 86 | xmldict['detail_ref'] = self.context.p_id |
---|
| 87 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 88 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 89 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 90 | # Institution data |
---|
| 91 | xmldict['institution_acct'] = '00000000' |
---|
| 92 | xmldict['institution_bank_id'] = '00' |
---|
| 93 | provider_amt = 0.0 |
---|
| 94 | self.pay_item_id = '0000' # must be provided by Interswitch |
---|
| 95 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 96 | xmldict['institution_item_name'] = self.context.category |
---|
| 97 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[15756] | 98 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
| 99 | if not self.context.provider_amt: |
---|
| 100 | self.context.provider_amt = provider_amt |
---|
| 101 | self.context.amount_auth += provider_amt |
---|
[15614] | 102 | if provider_amt == 0: |
---|
| 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_details> |
---|
| 107 | </payment_item_detail>""" % xmldict |
---|
| 108 | else: |
---|
| 109 | xmltext = """<payment_item_detail> |
---|
| 110 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 111 | <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" /> |
---|
| 112 | <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" /> |
---|
| 113 | </item_details> |
---|
| 114 | </payment_item_detail>""" % xmldict |
---|
| 115 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 116 | self.context.provider_amt = provider_amt |
---|
[15756] | 117 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[15614] | 118 | hashargs = ( |
---|
| 119 | self.context.p_id + |
---|
| 120 | PRODUCT_ID + |
---|
| 121 | self.pay_item_id + |
---|
| 122 | str(int(self.amount_auth)) + |
---|
| 123 | self.site_redirect_url + |
---|
| 124 | self.mac) |
---|
| 125 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
| 126 | return |
---|
| 127 | |
---|
| 128 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
| 129 | """ View which sends a POST request to the Interswitch |
---|
| 130 | CollegePAY payment gateway. |
---|
| 131 | """ |
---|
| 132 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 133 | action = POST_ACTION |
---|
| 134 | site_name = SITE_NAME |
---|
| 135 | currency = CURRENCY |
---|
| 136 | pay_item_id = '0000' # must be provided by Interswitch |
---|
| 137 | product_id = PRODUCT_ID |
---|
| 138 | mac = MAC |
---|
[15756] | 139 | gateway_amt = GATEWAY_AMT |
---|
[15614] | 140 | |
---|
| 141 | def update(self): |
---|
[16592] | 142 | if not module_activated( |
---|
| 143 | self.context.__parent__.__parent__.year, self.context): |
---|
| 144 | self.flash(_('Forbidden'), type='danger') |
---|
| 145 | self.redirect(self.url(self.context, '@@index')) |
---|
| 146 | return |
---|
[15614] | 147 | error = self.init_update() |
---|
| 148 | if error: |
---|
| 149 | self.flash(error, type='danger') |
---|
| 150 | self.redirect(self.url(self.context, '@@index')) |
---|
| 151 | return |
---|
[15756] | 152 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
| 153 | # and add the gateway amount. |
---|
| 154 | if not self.context.r_company: |
---|
| 155 | self.context.net_amt = self.context.amount_auth |
---|
| 156 | self.context.amount_auth += self.gateway_amt |
---|
| 157 | self.context.gateway_amt = self.gateway_amt |
---|
| 158 | self.context.r_company = u'interswitch' |
---|
[15614] | 159 | xmldict = {} |
---|
| 160 | provider_amt = 400.0 |
---|
| 161 | xmldict['institution_acct'] = '00000000000' |
---|
| 162 | xmldict['institution_bank_id'] = '00' |
---|
| 163 | xmldict['detail_ref'] = self.context.p_id |
---|
| 164 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 165 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 166 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 167 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 168 | xmldict['institution_item_name'] = self.context.category |
---|
| 169 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[15756] | 170 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
| 171 | if not self.context.provider_amt: |
---|
| 172 | self.context.provider_amt = provider_amt |
---|
| 173 | self.context.amount_auth += provider_amt |
---|
[15614] | 174 | xmltext = """<payment_item_detail> |
---|
| 175 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 176 | <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" /> |
---|
| 177 | <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" /> |
---|
| 178 | </item_details> |
---|
| 179 | </payment_item_detail>""" % xmldict |
---|
| 180 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[15756] | 181 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[15614] | 182 | hashargs = ( |
---|
| 183 | self.context.p_id + |
---|
| 184 | PRODUCT_ID + |
---|
| 185 | self.pay_item_id + |
---|
| 186 | str(int(self.amount_auth)) + |
---|
| 187 | self.site_redirect_url + |
---|
| 188 | self.mac) |
---|
| 189 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
| 190 | return |
---|
| 191 | |
---|
| 192 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
| 193 | InterswitchPaymentRequestWebservicePageStudent): |
---|
| 194 | """Request webservice view for the CollegePAY gateway |
---|
| 195 | """ |
---|
| 196 | grok.context(ICustomStudentOnlinePayment) |
---|
| 197 | product_id = PRODUCT_ID |
---|
| 198 | gateway_host = HOST |
---|
| 199 | gateway_url = URL |
---|
| 200 | mac = MAC |
---|
| 201 | |
---|
| 202 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 203 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
| 204 | """Payment verify view for the CollegePAY gateway |
---|
| 205 | """ |
---|
| 206 | grok.context(ICustomStudentOnlinePayment) |
---|
| 207 | product_id = PRODUCT_ID |
---|
| 208 | gateway_host = HOST |
---|
| 209 | gateway_url = URL |
---|
| 210 | mac = MAC |
---|
| 211 | |
---|
| 212 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
| 213 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
| 214 | """Request webservice view for the CollegePAY gateway |
---|
| 215 | """ |
---|
| 216 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 217 | product_id = PRODUCT_ID |
---|
| 218 | gateway_host = HOST |
---|
| 219 | gateway_url = URL |
---|
| 220 | mac = MAC |
---|
| 221 | |
---|
| 222 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 223 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 224 | """Payment verify view for the CollegePAY gateway |
---|
| 225 | """ |
---|
| 226 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 227 | product_id = PRODUCT_ID |
---|
| 228 | gateway_host = HOST |
---|
| 229 | gateway_url = URL |
---|
| 230 | mac = MAC |
---|