1 | ## $Id: browser.py 10597 2013-09-09 06:00: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 zope.interface import Interface |
---|
22 | from zope.component import getUtility, queryAdapter |
---|
23 | from kofacustom.nigeria.interswitch.browser import ( |
---|
24 | InterswitchPaymentRequestWebservicePageStudent, |
---|
25 | InterswitchPaymentRequestWebservicePageApplicant |
---|
26 | ) |
---|
27 | from waeup.kofa.browser.layout import KofaPage, UtilityView |
---|
28 | from waeup.kofa.interfaces import IKofaUtils |
---|
29 | from waeup.kofa.utils.helpers import to_timezone |
---|
30 | from waeup.kwarapoly.students.interfaces import ICustomStudentOnlinePayment |
---|
31 | from waeup.kwarapoly.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
32 | from waeup.kwarapoly.interfaces import MessageFactory as _ |
---|
33 | |
---|
34 | PRODUCT_ID = '3930' |
---|
35 | SITE_NAME = 'kwarapoly.waeup.org' |
---|
36 | PROVIDER_ACCT = '1010764827' |
---|
37 | PROVIDER_BANK_ID = '117' |
---|
38 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
39 | INSTITUTION_NAME = 'KwaraPoly' |
---|
40 | CURRENCY = '566' |
---|
41 | GATEWAY_AMT = 300.0 |
---|
42 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
---|
43 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
---|
44 | |
---|
45 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
46 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
47 | |
---|
48 | HOST = 'webpay.interswitchng.com' |
---|
49 | #HOST = 'testwebpay.interswitchng.com' |
---|
50 | |
---|
51 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
52 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
53 | httplib.HTTPConnection.debuglevel = 0 |
---|
54 | |
---|
55 | def interswitch_img_url(view): |
---|
56 | static = view.static |
---|
57 | if static is None or static.get( |
---|
58 | 'interswitch_verve_mastercard.gif', None) is None: |
---|
59 | static = queryAdapter( |
---|
60 | view.request, Interface, name='waeup.kwarapoly.interswitch') |
---|
61 | return static['interswitch_verve_mastercard.gif']() |
---|
62 | |
---|
63 | class InterswitchPageStudent(KofaPage): |
---|
64 | """ View which sends a POST request to the Interswitch |
---|
65 | CollegePAY payment gateway. |
---|
66 | """ |
---|
67 | grok.context(ICustomStudentOnlinePayment) |
---|
68 | grok.name('goto_interswitch') |
---|
69 | grok.template('student_goto_interswitch') |
---|
70 | grok.require('waeup.payStudent') |
---|
71 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
72 | submit_button = _('Submit') |
---|
73 | action = POST_ACTION |
---|
74 | site_name = SITE_NAME |
---|
75 | currency = CURRENCY |
---|
76 | product_id = PRODUCT_ID |
---|
77 | mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D' |
---|
78 | |
---|
79 | def interswitch_img_url(self): |
---|
80 | return interswitch_img_url(self) |
---|
81 | |
---|
82 | def update(self): |
---|
83 | #if self.context.p_state != 'unpaid': |
---|
84 | if self.context.p_state == 'paid': |
---|
85 | self.flash(_("Payment ticket can't be re-send to CollegePAY.")) |
---|
86 | self.redirect(self.url(self.context, '@@index')) |
---|
87 | return |
---|
88 | |
---|
89 | student = self.student = self.context.student |
---|
90 | certificate = getattr(student['studycourse'],'certificate',None) |
---|
91 | self.amount_auth = 100 * self.context.amount_auth |
---|
92 | xmldict = {} |
---|
93 | if certificate is not None: |
---|
94 | xmldict['department'] = certificate.__parent__.__parent__.code |
---|
95 | xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code |
---|
96 | else: |
---|
97 | xmldict['department'] = None |
---|
98 | xmldict['faculty'] = None |
---|
99 | self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category] |
---|
100 | tz = getUtility(IKofaUtils).tzinfo |
---|
101 | self.local_date_time = to_timezone( |
---|
102 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
103 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
104 | # Provider data |
---|
105 | xmldict['detail_ref'] = self.context.p_id |
---|
106 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
107 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
108 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
109 | # Institution data |
---|
110 | xmldict['institution_acct'] = "0000000000000" |
---|
111 | xmldict['institution_bank_id'] = '0' |
---|
112 | xmldict['institution_item_name'] = self.category |
---|
113 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
114 | self.pay_item_id = '000' |
---|
115 | if self.context.p_category == 'schoolfee': |
---|
116 | provider_amt = 1200.0 |
---|
117 | xmldict['provider_amt'] = 100 * provider_amt |
---|
118 | self.pay_item_id = '101' |
---|
119 | dalash_amt = 1800.0 |
---|
120 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
121 | xmldict['institution_amt'] = 100 * ( |
---|
122 | self.context.amount_auth - provider_amt - |
---|
123 | GATEWAY_AMT - dalash_amt) |
---|
124 | if xmldict['faculty'] in ('CPGS',): |
---|
125 | xmldict['institution_acct'] = "1771180233" |
---|
126 | xmldict['institution_bank_id'] = '120' |
---|
127 | elif xmldict['faculty'] in ('IBAS',): |
---|
128 | xmldict['institution_acct'] = "0006772436" |
---|
129 | xmldict['institution_bank_id'] = '121' |
---|
130 | elif xmldict['faculty'] in ('IETS',): |
---|
131 | xmldict['institution_acct'] = "0106259811" |
---|
132 | xmldict['institution_bank_id'] = '10' |
---|
133 | elif xmldict['faculty'] in ('IFMS',): |
---|
134 | xmldict['institution_acct'] = "2013910271" |
---|
135 | xmldict['institution_bank_id'] = '8' |
---|
136 | elif xmldict['faculty'] in ('ITCH',): |
---|
137 | #acct. number changed from Zenith to FBN by gbenga Nov. 11, 2012 |
---|
138 | xmldict['institution_acct'] = "2013910271" |
---|
139 | xmldict['institution_bank_id'] = '8' |
---|
140 | |
---|
141 | elif 'maintenance' in self.context.p_category: |
---|
142 | self.pay_item_id = '102' |
---|
143 | xmldict['institution_acct'] = "0039050937" |
---|
144 | xmldict['institution_bank_id'] = '31' |
---|
145 | xmldict['institution_amt'] = 100 * ( |
---|
146 | self.context.amount_auth - GATEWAY_AMT) |
---|
147 | dalash_amt = 0.0 |
---|
148 | provider_amt = 0.0 |
---|
149 | |
---|
150 | hashargs = ( |
---|
151 | self.context.p_id + |
---|
152 | PRODUCT_ID + |
---|
153 | self.pay_item_id + |
---|
154 | str(int(self.amount_auth)) + |
---|
155 | self.site_redirect_url + |
---|
156 | self.mac) |
---|
157 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
158 | |
---|
159 | # Interswitch amount is not part of the xml data |
---|
160 | |
---|
161 | if self.context.p_category == 'schoolfee': |
---|
162 | xmltext = """<payment_item_detail> |
---|
163 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
164 | <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" /> |
---|
165 | <item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" /> |
---|
166 | <item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" /> |
---|
167 | </item_details> |
---|
168 | </payment_item_detail>""" % xmldict |
---|
169 | |
---|
170 | elif 'maintenance' in self.context.p_category: |
---|
171 | xmltext = """<payment_item_detail> |
---|
172 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
173 | <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" /> |
---|
174 | </item_details> |
---|
175 | </payment_item_detail>""" % xmldict |
---|
176 | |
---|
177 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
178 | self.context.provider_amt = provider_amt |
---|
179 | self.context.gateway_amt = GATEWAY_AMT |
---|
180 | self.context.thirdparty_amt = dalash_amt |
---|
181 | return |
---|
182 | |
---|
183 | class InterswitchPageApplicant(KofaPage): |
---|
184 | """ View which sends a POST request to the Interswitch |
---|
185 | CollegePAY payment gateway. |
---|
186 | """ |
---|
187 | grok.context(ICustomApplicantOnlinePayment) |
---|
188 | grok.require('waeup.payApplicant') |
---|
189 | grok.template('applicant_goto_interswitch') |
---|
190 | grok.name('goto_interswitch') |
---|
191 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
192 | submit_button = _('Submit') |
---|
193 | action = POST_ACTION |
---|
194 | site_name = SITE_NAME |
---|
195 | currency = CURRENCY |
---|
196 | pay_item_id = '103' |
---|
197 | product_id = PRODUCT_ID |
---|
198 | mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D' |
---|
199 | |
---|
200 | def interswitch_img_url(self): |
---|
201 | return interswitch_img_url(self) |
---|
202 | |
---|
203 | def update(self): |
---|
204 | if self.context.p_state != 'unpaid': |
---|
205 | self.flash(_("Payment ticket can't be re-send to CollegePAY.")) |
---|
206 | self.redirect(self.url(self.context, '@@index')) |
---|
207 | return |
---|
208 | if self.context.__parent__.__parent__.expired \ |
---|
209 | and self.context.__parent__.__parent__.strict_deadline: |
---|
210 | self.flash(_("Payment ticket can't be send to CollegePAY. " |
---|
211 | "Application period has expired.")) |
---|
212 | self.redirect(self.url(self.context, '@@index')) |
---|
213 | return |
---|
214 | self.applicant = self.context.__parent__ |
---|
215 | self.amount_auth = 100 * self.context.amount_auth |
---|
216 | xmldict = {} |
---|
217 | self.category = getUtility( |
---|
218 | IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category] |
---|
219 | tz = getUtility(IKofaUtils).tzinfo |
---|
220 | self.local_date_time = to_timezone( |
---|
221 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
222 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
223 | provider_amt = 300.0 |
---|
224 | dalash_amt = 200.0 |
---|
225 | if self.applicant.applicant_id.startswith('hnd'): |
---|
226 | xmldict['institution_acct'] = '7000016724' |
---|
227 | xmldict['institution_bank_id'] = '9' |
---|
228 | elif self.applicant.applicant_id.startswith('nd'): |
---|
229 | xmldict['institution_acct'] = '2014191363' |
---|
230 | xmldict['institution_bank_id'] = '8' |
---|
231 | elif self.applicant.applicant_id.startswith('prejambites'): |
---|
232 | xmldict['institution_acct'] = '0106259811' |
---|
233 | xmldict['institution_bank_id'] = '10' |
---|
234 | self.pay_item_id = '104' |
---|
235 | provider_amt = 0.0 |
---|
236 | dalash_amt = 0.0 |
---|
237 | elif self.applicant.applicant_id.startswith('pre'): |
---|
238 | xmldict['institution_acct'] = '2013910271' |
---|
239 | xmldict['institution_bank_id'] = '8' |
---|
240 | provider_amt = 0.0 |
---|
241 | dalash_amt = 0.0 |
---|
242 | else: |
---|
243 | xmldict['institution_acct'] = '00000000000' |
---|
244 | xmldict['institution_bank_id'] = '00' |
---|
245 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
246 | xmldict['detail_ref'] = self.context.p_id |
---|
247 | xmldict['provider_amt'] = 100 * provider_amt |
---|
248 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
249 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
250 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
251 | xmldict['institution_amt'] = 100 * ( |
---|
252 | self.context.amount_auth - provider_amt - GATEWAY_AMT - dalash_amt) |
---|
253 | xmldict['institution_item_name'] = self.context.p_category |
---|
254 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
255 | |
---|
256 | hashargs = ( |
---|
257 | self.context.p_id + |
---|
258 | PRODUCT_ID + |
---|
259 | self.pay_item_id + |
---|
260 | str(int(self.amount_auth)) + |
---|
261 | self.site_redirect_url + |
---|
262 | self.mac) |
---|
263 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
264 | |
---|
265 | # Interswitch amount is not part of the xml data |
---|
266 | |
---|
267 | if not self.applicant.applicant_id.startswith('pre'): |
---|
268 | xmltext = """<payment_item_detail> |
---|
269 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
270 | <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" /> |
---|
271 | <item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" /> |
---|
272 | <item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" /> |
---|
273 | </item_details> |
---|
274 | </payment_item_detail>""" % xmldict |
---|
275 | |
---|
276 | else: |
---|
277 | xmltext = """<payment_item_detail> |
---|
278 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
279 | <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" /> |
---|
280 | </item_details> |
---|
281 | </payment_item_detail>""" % xmldict |
---|
282 | |
---|
283 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
284 | self.context.provider_amt = provider_amt |
---|
285 | self.context.gateway_amt = GATEWAY_AMT |
---|
286 | self.context.thirdparty_amt = dalash_amt |
---|
287 | return |
---|
288 | |
---|
289 | class InterswitchPaymentRequestWebservicePageStudent( |
---|
290 | InterswitchPaymentRequestWebservicePageStudent): |
---|
291 | """ Request webservice view for the CollegePAY gateway |
---|
292 | """ |
---|
293 | grok.context(ICustomStudentOnlinePayment) |
---|
294 | product_id = PRODUCT_ID |
---|
295 | gateway_host = HOST |
---|
296 | gateway_url = URL |
---|
297 | |
---|
298 | class InterswitchPaymentRequestWebservicePageApplicant( |
---|
299 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
300 | """ Request webservice view for the CollegePAY gateway |
---|
301 | """ |
---|
302 | grok.context(ICustomApplicantOnlinePayment) |
---|
303 | product_id = PRODUCT_ID |
---|
304 | gateway_host = HOST |
---|
305 | gateway_url = URL |
---|