[10765] | 1 | ## $Id: browser.py 13587 2016-01-11 09:14:27Z 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 | ) |
---|
| 28 | from kofacustom.skeleton.students.interfaces import ICustomStudentOnlinePayment |
---|
| 29 | from kofacustom.skeleton.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
| 30 | from kofacustom.skeleton.interfaces import MessageFactory as _ |
---|
| 31 | |
---|
| 32 | PRODUCT_ID = '57' |
---|
| 33 | SITE_NAME = 'skeleton-kofa.waeup.org' |
---|
| 34 | PROVIDER_ACCT = '00000000' |
---|
| 35 | PROVIDER_BANK_ID = '00' |
---|
| 36 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
| 37 | INSTITUTION_NAME = 'Skeleton' |
---|
| 38 | CURRENCY = '566' |
---|
| 39 | GATEWAY_AMT = 150.0 |
---|
| 40 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
---|
| 41 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
---|
| 42 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
| 43 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
| 44 | |
---|
| 45 | HOST = 'webpay.interswitchng.com' |
---|
| 46 | #HOST = 'testwebpay.interswitchng.com' |
---|
| 47 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
| 48 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
[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 |
---|
[12479] | 61 | 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 |
---|
| 76 | # Institution data |
---|
| 77 | xmldict['institution_acct'] = '00000000' |
---|
| 78 | xmldict['institution_bank_id'] = '00' |
---|
| 79 | xmldict['institution_amt'] = '0.0' |
---|
| 80 | provider_amt = 0.0 |
---|
| 81 | self.pay_item_id = '0000' |
---|
| 82 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[12511] | 83 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 84 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 85 | xmldict['institution_amt'] = 100 * ( |
---|
| 86 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
| 87 | # Interswitch amount is not part of the xml data |
---|
| 88 | if provider_amt == 0: |
---|
| 89 | xmltext = """<payment_item_detail> |
---|
| 90 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 91 | <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" /> |
---|
| 92 | </item_details> |
---|
| 93 | </payment_item_detail>""" % xmldict |
---|
| 94 | else: |
---|
| 95 | xmltext = """<payment_item_detail> |
---|
| 96 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 97 | <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" /> |
---|
| 98 | <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" /> |
---|
| 99 | </item_details> |
---|
| 100 | </payment_item_detail>""" % xmldict |
---|
| 101 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 102 | self.context.provider_amt = provider_amt |
---|
| 103 | self.context.gateway_amt = GATEWAY_AMT |
---|
[12479] | 104 | |
---|
| 105 | hashargs = ( |
---|
| 106 | self.context.p_id + |
---|
| 107 | PRODUCT_ID + |
---|
| 108 | self.pay_item_id + |
---|
| 109 | str(int(self.amount_auth)) + |
---|
| 110 | self.site_redirect_url + |
---|
| 111 | self.mac) |
---|
| 112 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 113 | return |
---|
| 114 | |
---|
[11638] | 115 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[10765] | 116 | """ View which sends a POST request to the Interswitch |
---|
| 117 | CollegePAY payment gateway. |
---|
| 118 | """ |
---|
| 119 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 120 | action = POST_ACTION |
---|
| 121 | site_name = SITE_NAME |
---|
| 122 | currency = CURRENCY |
---|
| 123 | pay_item_id = '0000' |
---|
| 124 | product_id = PRODUCT_ID |
---|
[12479] | 125 | mac = '' |
---|
[10765] | 126 | |
---|
| 127 | def update(self): |
---|
[12979] | 128 | error = self.init_update() |
---|
| 129 | if error: |
---|
| 130 | self.flash(error, type='danger') |
---|
| 131 | self.redirect(self.url(self.context, '@@index')) |
---|
| 132 | return |
---|
[10765] | 133 | xmldict = {} |
---|
| 134 | provider_amt = 400.0 |
---|
| 135 | xmldict['institution_acct'] = '00000000000' |
---|
| 136 | xmldict['institution_bank_id'] = '00' |
---|
| 137 | xmldict['detail_ref'] = self.context.p_id |
---|
| 138 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 139 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 140 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 141 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 142 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[12511] | 143 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 144 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 145 | # Interswitch amount is not part of the xml data |
---|
| 146 | xmltext = """<payment_item_detail> |
---|
| 147 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 148 | <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" /> |
---|
| 149 | <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" /> |
---|
| 150 | </item_details> |
---|
| 151 | </payment_item_detail>""" % xmldict |
---|
| 152 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 153 | self.context.provider_amt = provider_amt |
---|
| 154 | self.context.gateway_amt = GATEWAY_AMT |
---|
[12479] | 155 | |
---|
| 156 | hashargs = ( |
---|
| 157 | self.context.p_id + |
---|
| 158 | PRODUCT_ID + |
---|
| 159 | self.pay_item_id + |
---|
| 160 | str(int(self.amount_auth)) + |
---|
| 161 | self.site_redirect_url + |
---|
| 162 | self.mac) |
---|
| 163 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 164 | return |
---|
| 165 | |
---|
[11638] | 166 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[10765] | 167 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[13587] | 168 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 169 | """ |
---|
| 170 | grok.context(ICustomStudentOnlinePayment) |
---|
| 171 | product_id = PRODUCT_ID |
---|
| 172 | gateway_host = HOST |
---|
| 173 | gateway_url = URL |
---|
| 174 | |
---|
[13587] | 175 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 176 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
| 177 | """Payment verify view for the CollegePAY gateway |
---|
| 178 | """ |
---|
| 179 | grok.context(ICustomStudentOnlinePayment) |
---|
| 180 | product_id = PRODUCT_ID |
---|
| 181 | gateway_host = HOST |
---|
| 182 | gateway_url = URL |
---|
| 183 | |
---|
[11638] | 184 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[10765] | 185 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[13587] | 186 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 187 | """ |
---|
| 188 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 189 | product_id = PRODUCT_ID |
---|
| 190 | gateway_host = HOST |
---|
[12479] | 191 | gateway_url = URL |
---|
[13587] | 192 | |
---|
| 193 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 194 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 195 | """Payment verify view for the CollegePAY gateway |
---|
| 196 | """ |
---|
| 197 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 198 | product_id = PRODUCT_ID |
---|
| 199 | gateway_host = HOST |
---|
| 200 | gateway_url = URL |
---|