1 | ## $Id: browser.py 14130 2016-08-25 15:27:24Z 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 |
---|
19 | import hashlib |
---|
20 | import grok |
---|
21 | from kofacustom.nigeria.interswitch.browser import ( |
---|
22 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
23 | InterswitchPaymentRequestWebservicePageStudent, |
---|
24 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
25 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
26 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
27 | ) |
---|
28 | from kofacustom.coewarri.students.interfaces import ICustomStudentOnlinePayment |
---|
29 | from kofacustom.coewarri.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
30 | from kofacustom.coewarri.interfaces import MessageFactory as _ |
---|
31 | |
---|
32 | PRODUCT_ID = '6667' |
---|
33 | SITE_NAME = 'coewarri-kofa.waeup.org' |
---|
34 | PROVIDER_ACCT = '0137712635' |
---|
35 | PROVIDER_BANK_ID = '10' |
---|
36 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
37 | INSTITUTION_NAME = 'COE Warri' |
---|
38 | CURRENCY = '566' |
---|
39 | GATEWAY_AMT = 300.0 |
---|
40 | |
---|
41 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay' |
---|
42 | #POST_ACTION = 'https://stageserv.interswitchng.com/test_paydirect/pay' |
---|
43 | HOST = 'webpay.interswitchng.com' |
---|
44 | #HOST = 'stageserv.interswitchng.com' |
---|
45 | URL = '/paydirect/api/v1/gettransaction.json' |
---|
46 | #URL = '/test_paydirect/api/v1/gettransaction.json' |
---|
47 | |
---|
48 | httplib.HTTPSConnection.debuglevel = 0 |
---|
49 | HTTPS = True |
---|
50 | |
---|
51 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
52 | """ View which sends a POST request to the Interswitch |
---|
53 | CollegePAY payment gateway. |
---|
54 | """ |
---|
55 | grok.context(ICustomStudentOnlinePayment) |
---|
56 | action = POST_ACTION |
---|
57 | site_name = SITE_NAME |
---|
58 | currency = CURRENCY |
---|
59 | product_id = PRODUCT_ID |
---|
60 | mac = '' |
---|
61 | |
---|
62 | def update(self): |
---|
63 | error = self.init_update() |
---|
64 | if error: |
---|
65 | self.flash(error, type='danger') |
---|
66 | self.redirect(self.url(self.context, '@@index')) |
---|
67 | return |
---|
68 | student = self.student |
---|
69 | xmldict = self.xmldict |
---|
70 | # Provider data |
---|
71 | xmldict['detail_ref'] = self.context.p_id |
---|
72 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
73 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
74 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
75 | # Institution data |
---|
76 | xmldict['institution_acct'] = '00000000' |
---|
77 | xmldict['institution_bank_id'] = '00' |
---|
78 | xmldict['institution_amt'] = '0.0' |
---|
79 | provider_amt = 0.0 |
---|
80 | self.pay_item_id = '0000' |
---|
81 | xmldict['provider_amt'] = 100 * provider_amt |
---|
82 | xmldict['institution_item_name'] = self.context.category |
---|
83 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
84 | xmldict['institution_amt'] = 100 * ( |
---|
85 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
86 | # Interswitch amount is not part of the xml data |
---|
87 | if provider_amt == 0: |
---|
88 | xmltext = """<payment_item_detail> |
---|
89 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
90 | <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" /> |
---|
91 | </item_details> |
---|
92 | </payment_item_detail>""" % xmldict |
---|
93 | else: |
---|
94 | xmltext = """<payment_item_detail> |
---|
95 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
96 | <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" /> |
---|
97 | <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" /> |
---|
98 | </item_details> |
---|
99 | </payment_item_detail>""" % xmldict |
---|
100 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
101 | self.context.provider_amt = provider_amt |
---|
102 | self.context.gateway_amt = GATEWAY_AMT |
---|
103 | |
---|
104 | hashargs = ( |
---|
105 | self.context.p_id + |
---|
106 | PRODUCT_ID + |
---|
107 | self.pay_item_id + |
---|
108 | str(int(self.amount_auth)) + |
---|
109 | self.site_redirect_url + |
---|
110 | self.mac) |
---|
111 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
112 | return |
---|
113 | |
---|
114 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
115 | """ View which sends a POST request to the Interswitch |
---|
116 | CollegePAY payment gateway. |
---|
117 | """ |
---|
118 | grok.context(ICustomApplicantOnlinePayment) |
---|
119 | action = POST_ACTION |
---|
120 | site_name = SITE_NAME |
---|
121 | currency = CURRENCY |
---|
122 | pay_item_id = '101' |
---|
123 | product_id = PRODUCT_ID |
---|
124 | mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94' |
---|
125 | |
---|
126 | def update(self): |
---|
127 | error = self.init_update() |
---|
128 | if error: |
---|
129 | self.flash(error, type='danger') |
---|
130 | self.redirect(self.url(self.context, '@@index')) |
---|
131 | return |
---|
132 | xmldict = {} |
---|
133 | provider_amt = 500.0 |
---|
134 | xmldict['institution_acct'] = '1005154149' |
---|
135 | xmldict['institution_bank_id'] = '7' |
---|
136 | xmldict['detail_ref'] = self.context.p_id |
---|
137 | xmldict['provider_amt'] = 100 * provider_amt |
---|
138 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
139 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
140 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
141 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
142 | xmldict['institution_item_name'] = self.context.category |
---|
143 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
144 | # Interswitch amount is not part of the xml data |
---|
145 | xmltext = """<payment_item_detail> |
---|
146 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
147 | <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" /> |
---|
148 | <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" /> |
---|
149 | </item_details> |
---|
150 | </payment_item_detail>""" % xmldict |
---|
151 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
152 | self.context.provider_amt = provider_amt |
---|
153 | self.context.gateway_amt = GATEWAY_AMT |
---|
154 | |
---|
155 | hashargs = ( |
---|
156 | self.context.p_id + |
---|
157 | PRODUCT_ID + |
---|
158 | self.pay_item_id + |
---|
159 | str(int(self.amount_auth)) + |
---|
160 | self.site_redirect_url + |
---|
161 | self.mac) |
---|
162 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
163 | return |
---|
164 | |
---|
165 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
166 | InterswitchPaymentRequestWebservicePageStudent): |
---|
167 | """Request webservice view for the CollegePAY gateway |
---|
168 | """ |
---|
169 | grok.context(ICustomStudentOnlinePayment) |
---|
170 | product_id = PRODUCT_ID |
---|
171 | gateway_host = HOST |
---|
172 | gateway_url = URL |
---|
173 | |
---|
174 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
175 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
176 | """Payment verify view for the CollegePAY gateway |
---|
177 | """ |
---|
178 | grok.context(ICustomStudentOnlinePayment) |
---|
179 | product_id = PRODUCT_ID |
---|
180 | gateway_host = HOST |
---|
181 | gateway_url = URL |
---|
182 | |
---|
183 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
184 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
185 | """Request webservice view for the CollegePAY gateway |
---|
186 | """ |
---|
187 | grok.context(ICustomApplicantOnlinePayment) |
---|
188 | product_id = PRODUCT_ID |
---|
189 | gateway_host = HOST |
---|
190 | gateway_url = URL |
---|
191 | mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94' |
---|
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 |
---|