[10765] | 1 | ## $Id: browser.py 15031 2018-05-28 07:36:19Z 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 | |
---|
[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 |
---|
[15015] | 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 |
---|
[10765] | 71 | # Provider data |
---|
| 72 | xmldict['detail_ref'] = self.context.p_id |
---|
| 73 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 74 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 75 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[15015] | 76 | provider_amt = 0.0 |
---|
[15031] | 77 | if not self.context.p_item == 'Balance': |
---|
| 78 | if self.context.p_category == 'ict_entre': |
---|
| 79 | provider_amt = 3000.0 |
---|
| 80 | if self.context.p_category == 'clearance': |
---|
| 81 | provider_amt = 1500.0 |
---|
| 82 | if self.context.p_category in ('transcript', 'certificate'): |
---|
| 83 | provider_amt = 2000.0 |
---|
[10765] | 84 | # Institution data |
---|
[15026] | 85 | xmldict['institution_acct'] = '0068241848' |
---|
[15009] | 86 | xmldict['institution_bank_id'] = '121' |
---|
[10765] | 87 | xmldict['institution_amt'] = '0.0' |
---|
[15009] | 88 | self.pay_item_id = '101' # must be provided by Interswitch |
---|
[10765] | 89 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[12511] | 90 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 91 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 92 | xmldict['institution_amt'] = 100 * ( |
---|
| 93 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
| 94 | # Interswitch amount is not part of the xml data |
---|
| 95 | if provider_amt == 0: |
---|
| 96 | xmltext = """<payment_item_detail> |
---|
| 97 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 98 | <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" /> |
---|
| 99 | </item_details> |
---|
| 100 | </payment_item_detail>""" % xmldict |
---|
| 101 | else: |
---|
| 102 | xmltext = """<payment_item_detail> |
---|
| 103 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 104 | <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" /> |
---|
| 105 | <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" /> |
---|
| 106 | </item_details> |
---|
| 107 | </payment_item_detail>""" % xmldict |
---|
| 108 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 109 | self.context.provider_amt = provider_amt |
---|
| 110 | self.context.gateway_amt = GATEWAY_AMT |
---|
[12479] | 111 | |
---|
| 112 | hashargs = ( |
---|
| 113 | self.context.p_id + |
---|
| 114 | PRODUCT_ID + |
---|
| 115 | self.pay_item_id + |
---|
| 116 | str(int(self.amount_auth)) + |
---|
| 117 | self.site_redirect_url + |
---|
| 118 | self.mac) |
---|
| 119 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 120 | return |
---|
| 121 | |
---|
[11638] | 122 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[10765] | 123 | """ View which sends a POST request to the Interswitch |
---|
| 124 | CollegePAY payment gateway. |
---|
| 125 | """ |
---|
| 126 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 127 | action = POST_ACTION |
---|
| 128 | site_name = SITE_NAME |
---|
| 129 | currency = CURRENCY |
---|
[15015] | 130 | pay_item_id = '101' # must be provided by Interswitch |
---|
[10765] | 131 | product_id = PRODUCT_ID |
---|
[15015] | 132 | mac = MAC |
---|
[10765] | 133 | |
---|
| 134 | def update(self): |
---|
[12979] | 135 | error = self.init_update() |
---|
| 136 | if error: |
---|
| 137 | self.flash(error, type='danger') |
---|
| 138 | self.redirect(self.url(self.context, '@@index')) |
---|
| 139 | return |
---|
[10765] | 140 | xmldict = {} |
---|
[15015] | 141 | provider_amt = 1000.0 |
---|
| 142 | xmldict['institution_acct'] = '1015666713' |
---|
| 143 | xmldict['institution_bank_id'] = '121' |
---|
[10765] | 144 | xmldict['detail_ref'] = self.context.p_id |
---|
| 145 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 146 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 147 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 148 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 149 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[12511] | 150 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 151 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 152 | # Interswitch amount is not part of the xml data |
---|
| 153 | xmltext = """<payment_item_detail> |
---|
| 154 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 155 | <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" /> |
---|
| 156 | <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" /> |
---|
| 157 | </item_details> |
---|
| 158 | </payment_item_detail>""" % xmldict |
---|
| 159 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 160 | self.context.provider_amt = provider_amt |
---|
| 161 | self.context.gateway_amt = GATEWAY_AMT |
---|
[12479] | 162 | |
---|
| 163 | hashargs = ( |
---|
| 164 | self.context.p_id + |
---|
| 165 | PRODUCT_ID + |
---|
| 166 | self.pay_item_id + |
---|
| 167 | str(int(self.amount_auth)) + |
---|
| 168 | self.site_redirect_url + |
---|
| 169 | self.mac) |
---|
| 170 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 171 | return |
---|
| 172 | |
---|
[11638] | 173 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[10765] | 174 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[13587] | 175 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 176 | """ |
---|
| 177 | grok.context(ICustomStudentOnlinePayment) |
---|
| 178 | product_id = PRODUCT_ID |
---|
| 179 | gateway_host = HOST |
---|
| 180 | gateway_url = URL |
---|
[15015] | 181 | mac = MAC |
---|
[10765] | 182 | |
---|
[13587] | 183 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 184 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
| 185 | """Payment verify view for the CollegePAY gateway |
---|
| 186 | """ |
---|
| 187 | grok.context(ICustomStudentOnlinePayment) |
---|
| 188 | product_id = PRODUCT_ID |
---|
| 189 | gateway_host = HOST |
---|
| 190 | gateway_url = URL |
---|
[15015] | 191 | mac = MAC |
---|
[13587] | 192 | |
---|
[11638] | 193 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[10765] | 194 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[13587] | 195 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 196 | """ |
---|
| 197 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 198 | product_id = PRODUCT_ID |
---|
| 199 | gateway_host = HOST |
---|
[12479] | 200 | gateway_url = URL |
---|
[15015] | 201 | mac = MAC |
---|
[13587] | 202 | |
---|
| 203 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 204 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 205 | """Payment verify view for the CollegePAY gateway |
---|
| 206 | """ |
---|
| 207 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 208 | product_id = PRODUCT_ID |
---|
| 209 | gateway_host = HOST |
---|
[15015] | 210 | gateway_url = URL |
---|
| 211 | mac = MAC |
---|