[10765] | 1 | ## $Id: browser.py 15949 2020-01-24 06:26:37Z 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 | ) |
---|
[15000] | 28 | from kofacustom.edopoly.students.interfaces import ICustomStudentOnlinePayment |
---|
| 29 | from kofacustom.edopoly.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
| 30 | from kofacustom.edopoly.interfaces import MessageFactory as _ |
---|
[10765] | 31 | |
---|
[15015] | 32 | PRODUCT_ID = '7571' # must be provided by Interswitch |
---|
[15000] | 33 | SITE_NAME = 'edopoly-kofa.waeup.org' |
---|
[15009] | 34 | PROVIDER_ACCT = '0773411069' |
---|
| 35 | PROVIDER_BANK_ID = '31' |
---|
| 36 | PROVIDER_ITEM_NAME = 'WAeAC' |
---|
[15000] | 37 | INSTITUTION_NAME = 'EdoPoly' |
---|
[10765] | 38 | CURRENCY = '566' |
---|
[15015] | 39 | GATEWAY_AMT = 250.0 |
---|
| 40 | MAC = '672ABFB2F3755A7793DE545BDA00F44878DF59140B43A1E7DF16245D299F3108AFF65502F16D95256B3242B43CBC3F512A208EB1BA977080D65328800C49912C' |
---|
[10765] | 41 | |
---|
[15015] | 42 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay' |
---|
| 43 | #POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay' |
---|
| 44 | HOST = 'webpay.interswitchng.com' |
---|
| 45 | #HOST = 'sandbox.interswitchng.com' |
---|
| 46 | URL = '/paydirect/api/v1/gettransaction.json' |
---|
| 47 | #URL = '/webpay/api/v1/gettransaction.json' |
---|
[14276] | 48 | |
---|
[12479] | 49 | httplib.HTTPSConnection.debuglevel = 0 |
---|
| 50 | HTTPS = True |
---|
[10765] | 51 | |
---|
[15218] | 52 | SPECIAL_PAYMENT_PARAMS = { |
---|
| 53 | |
---|
[15231] | 54 | 'conv_nd': ('101', 1000.0, '0031913976', '121'), |
---|
| 55 | 'conv_hnd': ('101', 1000.0, '0031913976', '121'), |
---|
[15218] | 56 | } |
---|
| 57 | |
---|
| 58 | |
---|
[11638] | 59 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
[10765] | 60 | """ View which sends a POST request to the Interswitch |
---|
| 61 | CollegePAY payment gateway. |
---|
| 62 | """ |
---|
| 63 | grok.context(ICustomStudentOnlinePayment) |
---|
| 64 | action = POST_ACTION |
---|
| 65 | site_name = SITE_NAME |
---|
| 66 | currency = CURRENCY |
---|
| 67 | product_id = PRODUCT_ID |
---|
[15015] | 68 | mac = MAC |
---|
[10765] | 69 | |
---|
| 70 | def update(self): |
---|
[12979] | 71 | error = self.init_update() |
---|
| 72 | if error: |
---|
| 73 | self.flash(error, type='danger') |
---|
| 74 | self.redirect(self.url(self.context, '@@index')) |
---|
| 75 | return |
---|
[15777] | 76 | self.context.r_company = u'interswitch' |
---|
[11647] | 77 | student = self.student |
---|
| 78 | xmldict = self.xmldict |
---|
[10765] | 79 | # Provider data |
---|
| 80 | xmldict['detail_ref'] = self.context.p_id |
---|
| 81 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 82 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 83 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[15015] | 84 | provider_amt = 0.0 |
---|
[15031] | 85 | if not self.context.p_item == 'Balance': |
---|
| 86 | if self.context.p_category == 'ict_entre': |
---|
| 87 | provider_amt = 3000.0 |
---|
| 88 | if self.context.p_category == 'clearance': |
---|
| 89 | provider_amt = 1500.0 |
---|
[15079] | 90 | # temporarily disabled |
---|
| 91 | #if self.context.p_category in ('transcript', 'certificate'): |
---|
| 92 | # provider_amt = 2000.0 |
---|
[10765] | 93 | # Institution data |
---|
[15026] | 94 | xmldict['institution_acct'] = '0068241848' |
---|
[15009] | 95 | xmldict['institution_bank_id'] = '121' |
---|
[15105] | 96 | if self.context.p_category == 'union': |
---|
| 97 | xmldict['institution_acct'] = '0066437412' |
---|
[15949] | 98 | if self.context.p_category == 'nhis': |
---|
| 99 | xmldict['institution_acct'] = '0075379404' |
---|
[10765] | 100 | xmldict['institution_amt'] = '0.0' |
---|
[15009] | 101 | self.pay_item_id = '101' # must be provided by Interswitch |
---|
[10765] | 102 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[12511] | 103 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 104 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 105 | xmldict['institution_amt'] = 100 * ( |
---|
| 106 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
| 107 | # Interswitch amount is not part of the xml data |
---|
[15105] | 108 | if provider_amt == 0: |
---|
[10765] | 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_details> |
---|
| 113 | </payment_item_detail>""" % xmldict |
---|
| 114 | else: |
---|
| 115 | xmltext = """<payment_item_detail> |
---|
| 116 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 117 | <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" /> |
---|
| 118 | <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" /> |
---|
| 119 | </item_details> |
---|
| 120 | </payment_item_detail>""" % xmldict |
---|
| 121 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 122 | self.context.provider_amt = provider_amt |
---|
| 123 | self.context.gateway_amt = GATEWAY_AMT |
---|
[15777] | 124 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[12479] | 125 | hashargs = ( |
---|
| 126 | self.context.p_id + |
---|
| 127 | PRODUCT_ID + |
---|
| 128 | self.pay_item_id + |
---|
| 129 | str(int(self.amount_auth)) + |
---|
| 130 | self.site_redirect_url + |
---|
| 131 | self.mac) |
---|
| 132 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 133 | return |
---|
| 134 | |
---|
[11638] | 135 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[10765] | 136 | """ View which sends a POST request to the Interswitch |
---|
| 137 | CollegePAY payment gateway. |
---|
| 138 | """ |
---|
| 139 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 140 | action = POST_ACTION |
---|
| 141 | site_name = SITE_NAME |
---|
| 142 | currency = CURRENCY |
---|
[15015] | 143 | pay_item_id = '101' # must be provided by Interswitch |
---|
[10765] | 144 | product_id = PRODUCT_ID |
---|
[15015] | 145 | mac = MAC |
---|
[10765] | 146 | |
---|
| 147 | def update(self): |
---|
[12979] | 148 | error = self.init_update() |
---|
| 149 | if error: |
---|
| 150 | self.flash(error, type='danger') |
---|
| 151 | self.redirect(self.url(self.context, '@@index')) |
---|
| 152 | return |
---|
[15777] | 153 | self.context.r_company = u'interswitch' |
---|
[10765] | 154 | xmldict = {} |
---|
[15015] | 155 | provider_amt = 1000.0 |
---|
[15136] | 156 | if self.context.p_category != 'application': |
---|
| 157 | provider_amt = 0.0 |
---|
[15101] | 158 | xmldict['institution_acct'] = '0068241848' |
---|
[15015] | 159 | xmldict['institution_bank_id'] = '121' |
---|
[10765] | 160 | xmldict['detail_ref'] = self.context.p_id |
---|
| 161 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 162 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 163 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 164 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[15259] | 165 | xmldict['institution_amt'] = 100 * ( |
---|
| 166 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[12511] | 167 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 168 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[15218] | 169 | if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys(): |
---|
| 170 | self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0] |
---|
[15259] | 171 | xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[ |
---|
| 172 | self.context.p_category][2] |
---|
| 173 | xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[ |
---|
| 174 | self.context.p_category][3] |
---|
[15218] | 175 | provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1] |
---|
[15259] | 176 | xmldict['institution_amt'] = 100 * ( |
---|
| 177 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
| 178 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[10765] | 179 | # Interswitch amount is not part of the xml data |
---|
[15137] | 180 | if provider_amt == 0: |
---|
| 181 | xmltext = """<payment_item_detail> |
---|
[10765] | 182 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 183 | <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" /> |
---|
[15137] | 184 | </item_details> |
---|
| 185 | </payment_item_detail>""" % xmldict |
---|
| 186 | else: |
---|
| 187 | xmltext = """<payment_item_detail> |
---|
| 188 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 189 | <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] | 190 | <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" /> |
---|
| 191 | </item_details> |
---|
| 192 | </payment_item_detail>""" % xmldict |
---|
[15137] | 193 | |
---|
[10765] | 194 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 195 | self.context.provider_amt = provider_amt |
---|
| 196 | self.context.gateway_amt = GATEWAY_AMT |
---|
[15777] | 197 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[12479] | 198 | hashargs = ( |
---|
| 199 | self.context.p_id + |
---|
| 200 | PRODUCT_ID + |
---|
| 201 | self.pay_item_id + |
---|
| 202 | str(int(self.amount_auth)) + |
---|
| 203 | self.site_redirect_url + |
---|
| 204 | self.mac) |
---|
| 205 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 206 | return |
---|
| 207 | |
---|
[11638] | 208 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[10765] | 209 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[13587] | 210 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 211 | """ |
---|
| 212 | grok.context(ICustomStudentOnlinePayment) |
---|
| 213 | product_id = PRODUCT_ID |
---|
| 214 | gateway_host = HOST |
---|
| 215 | gateway_url = URL |
---|
[15015] | 216 | mac = MAC |
---|
[10765] | 217 | |
---|
[13587] | 218 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 219 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
| 220 | """Payment verify view for the CollegePAY gateway |
---|
| 221 | """ |
---|
| 222 | grok.context(ICustomStudentOnlinePayment) |
---|
| 223 | product_id = PRODUCT_ID |
---|
| 224 | gateway_host = HOST |
---|
| 225 | gateway_url = URL |
---|
[15015] | 226 | mac = MAC |
---|
[13587] | 227 | |
---|
[11638] | 228 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[10765] | 229 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[13587] | 230 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 231 | """ |
---|
| 232 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 233 | product_id = PRODUCT_ID |
---|
| 234 | gateway_host = HOST |
---|
[12479] | 235 | gateway_url = URL |
---|
[15015] | 236 | mac = MAC |
---|
[13587] | 237 | |
---|
| 238 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 239 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 240 | """Payment verify view for the CollegePAY gateway |
---|
| 241 | """ |
---|
| 242 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 243 | product_id = PRODUCT_ID |
---|
| 244 | gateway_host = HOST |
---|
[15015] | 245 | gateway_url = URL |
---|
| 246 | mac = MAC |
---|