1 | ## $Id: browser.py 10111 2013-04-29 10:09:06Z 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 grok |
---|
20 | from zope.component import getUtility |
---|
21 | from kofacustom.nigeria.interswitch.browser import ( |
---|
22 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
23 | InterswitchPaymentRequestWebservicePageStudent |
---|
24 | ) |
---|
25 | from waeup.kofa.browser.layout import KofaPage |
---|
26 | from waeup.kofa.interfaces import IKofaUtils |
---|
27 | from waeup.kofa.utils.helpers import to_timezone |
---|
28 | from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment |
---|
29 | from waeup.uniben.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
30 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
31 | |
---|
32 | PRODUCT_ID = '57' |
---|
33 | SITE_NAME = 'uniben-kofa.waeup.org' |
---|
34 | PROVIDER_ACCT = '1010764827' |
---|
35 | PROVIDER_BANK_ID = '117' |
---|
36 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
37 | INSTITUTION_NAME = 'Uniben' |
---|
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' |
---|
49 | httplib.HTTPConnection.debuglevel = 0 |
---|
50 | |
---|
51 | class InterswitchPageStudent(KofaPage): |
---|
52 | """ View which sends a POST request to the Interswitch |
---|
53 | CollegePAY payment gateway. |
---|
54 | """ |
---|
55 | grok.context(ICustomStudentOnlinePayment) |
---|
56 | grok.name('goto_interswitch') |
---|
57 | grok.template('student_goto_interswitch') |
---|
58 | grok.require('waeup.payStudent') |
---|
59 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
60 | submit_button = _('Submit') |
---|
61 | action = POST_ACTION |
---|
62 | site_name = SITE_NAME |
---|
63 | currency = CURRENCY |
---|
64 | product_id = PRODUCT_ID |
---|
65 | |
---|
66 | def update(self): |
---|
67 | #if self.context.p_state != 'unpaid': |
---|
68 | if self.context.p_state == 'paid': |
---|
69 | self.flash(_("Payment ticket can't be re-send to CollegePAY.")) |
---|
70 | self.redirect(self.url(self.context, '@@index')) |
---|
71 | return |
---|
72 | |
---|
73 | student = self.student = self.context.student |
---|
74 | certificate = getattr(student['studycourse'],'certificate',None) |
---|
75 | if certificate is None: |
---|
76 | self.flash(_("Study course data are incomplete.")) |
---|
77 | self.redirect(self.url(self.context, '@@index')) |
---|
78 | return |
---|
79 | self.amount_auth = 100 * self.context.amount_auth |
---|
80 | xmldict = {} |
---|
81 | if certificate is not None: |
---|
82 | xmldict['department'] = certificate.__parent__.__parent__.code |
---|
83 | xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code |
---|
84 | else: |
---|
85 | xmldict['department'] = None |
---|
86 | xmldict['faculty'] = None |
---|
87 | self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category] |
---|
88 | tz = getUtility(IKofaUtils).tzinfo |
---|
89 | self.local_date_time = to_timezone( |
---|
90 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
91 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
92 | # Provider data |
---|
93 | xmldict['detail_ref'] = self.context.p_id |
---|
94 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
95 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
96 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
97 | # Institution data |
---|
98 | xmldict['institution_acct'] = '000000000000' |
---|
99 | xmldict['institution_bank_id'] = '00' |
---|
100 | xmldict['institution_amt'] = '0.0' |
---|
101 | provider_amt = 0.0 |
---|
102 | self.pay_item_id = '0000' |
---|
103 | if self.context.p_category == 'schoolfee': |
---|
104 | if not self.context.p_item == 'Balance': |
---|
105 | provider_amt = 1500.0 |
---|
106 | if student.current_mode.endswith('_ft'): |
---|
107 | self.pay_item_id = '5700' |
---|
108 | if student.current_mode in ('ug_ft','de_ft','ct_ft','ume_ft'): |
---|
109 | xmldict['institution_acct'] = '2017506430' |
---|
110 | xmldict['institution_bank_id'] = '8' |
---|
111 | elif student.current_mode in ('dp_ft'): |
---|
112 | xmldict['institution_acct'] = '9201805071' |
---|
113 | xmldict['institution_bank_id'] = '17' |
---|
114 | elif student.current_mode in ('pg_ft'): |
---|
115 | xmldict['institution_acct'] = '5330832799' |
---|
116 | xmldict['institution_bank_id'] = '51' |
---|
117 | elif student.current_mode.endswith('_pt'): |
---|
118 | self.pay_item_id = '5701' |
---|
119 | if student.current_mode in ('ug_pt','de_pt','ct_pt'): |
---|
120 | xmldict['institution_acct'] = '0122009929' |
---|
121 | xmldict['institution_bank_id'] = '16' |
---|
122 | elif student.current_mode in ('dp_pt'): |
---|
123 | xmldict['institution_acct'] = '9201805071' |
---|
124 | xmldict['institution_bank_id'] = '17' |
---|
125 | elif student.current_mode in ('pg_pt'): |
---|
126 | xmldict['institution_acct'] = '0031716047' |
---|
127 | xmldict['institution_bank_id'] = '10' |
---|
128 | elif self.context.p_category == 'clearance': |
---|
129 | self.pay_item_id = '5702' |
---|
130 | provider_amt = 1500.0 |
---|
131 | if student.faccode == 'FCETA': |
---|
132 | xmldict['institution_acct'] = '5210007943' |
---|
133 | xmldict['institution_bank_id'] = '51' |
---|
134 | elif student.current_mode == 'pg_ft': |
---|
135 | xmldict['institution_acct'] = '5330832799' |
---|
136 | xmldict['institution_bank_id'] = '51' |
---|
137 | elif student.current_mode == 'pg_pt': |
---|
138 | xmldict['institution_acct'] = '0031716047' |
---|
139 | xmldict['institution_bank_id'] = '10' |
---|
140 | elif student.current_mode == 'dp_pt': |
---|
141 | xmldict['institution_acct'] = '9201805071' |
---|
142 | xmldict['institution_bank_id'] = '17' |
---|
143 | else: |
---|
144 | xmldict['institution_bank_id'] = '7' |
---|
145 | xmldict['institution_acct'] = '1003475516' |
---|
146 | elif self.context.p_category == 'gown': |
---|
147 | self.pay_item_id = '5704' |
---|
148 | xmldict['institution_bank_id'] = '7' |
---|
149 | xmldict['institution_acct'] = '1016232382' |
---|
150 | elif self.context.p_category.startswith('hostel_maintenance'): |
---|
151 | self.pay_item_id = '5705' |
---|
152 | xmldict['institution_bank_id'] = '129' |
---|
153 | xmldict['institution_acct'] = '0014414547' |
---|
154 | |
---|
155 | xmldict['provider_amt'] = 100 * provider_amt |
---|
156 | xmldict['institution_item_name'] = self.category |
---|
157 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
158 | xmldict['institution_amt'] = 100 * ( |
---|
159 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
160 | # Interswitch amount is not part of the xml data |
---|
161 | if provider_amt == 0: |
---|
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_details> |
---|
166 | </payment_item_detail>""" % xmldict |
---|
167 | else: |
---|
168 | xmltext = """<payment_item_detail> |
---|
169 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
170 | <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" /> |
---|
171 | <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" /> |
---|
172 | </item_details> |
---|
173 | </payment_item_detail>""" % xmldict |
---|
174 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
175 | self.context.provider_amt = provider_amt |
---|
176 | self.context.gateway_amt = GATEWAY_AMT |
---|
177 | return |
---|
178 | |
---|
179 | class InterswitchPageApplicant(KofaPage): |
---|
180 | """ View which sends a POST request to the Interswitch |
---|
181 | CollegePAY payment gateway. |
---|
182 | """ |
---|
183 | grok.context(ICustomApplicantOnlinePayment) |
---|
184 | grok.require('waeup.payApplicant') |
---|
185 | grok.template('applicant_goto_interswitch') |
---|
186 | grok.name('goto_interswitch') |
---|
187 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
188 | submit_button = _('Submit') |
---|
189 | action = POST_ACTION |
---|
190 | site_name = SITE_NAME |
---|
191 | currency = CURRENCY |
---|
192 | pay_item_id = '5703' |
---|
193 | product_id = PRODUCT_ID |
---|
194 | |
---|
195 | def update(self): |
---|
196 | if self.context.p_state != 'unpaid': |
---|
197 | self.flash(_("Payment ticket can't be re-send to CollegePAY.")) |
---|
198 | self.redirect(self.url(self.context, '@@index')) |
---|
199 | return |
---|
200 | if self.context.__parent__.__parent__.expired \ |
---|
201 | and self.context.__parent__.__parent__.strict_deadline: |
---|
202 | self.flash(_("Payment ticket can't be send to CollegePAY. " |
---|
203 | "Application period has expired.")) |
---|
204 | self.redirect(self.url(self.context, '@@index')) |
---|
205 | return |
---|
206 | self.applicant = self.context.__parent__ |
---|
207 | self.amount_auth = 100 * self.context.amount_auth |
---|
208 | xmldict = {} |
---|
209 | self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category] |
---|
210 | tz = getUtility(IKofaUtils).tzinfo |
---|
211 | self.local_date_time = to_timezone( |
---|
212 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
213 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
214 | provider_amt = 400.0 |
---|
215 | if self.applicant.applicant_id.startswith('pg'): |
---|
216 | xmldict['institution_acct'] = '0031716030' |
---|
217 | xmldict['institution_bank_id'] = '10' |
---|
218 | elif self.applicant.applicant_id.startswith('dp'): |
---|
219 | xmldict['institution_acct'] = '9201805071' |
---|
220 | xmldict['institution_bank_id'] = '17' |
---|
221 | else: |
---|
222 | xmldict['institution_acct'] = '6220032503' |
---|
223 | xmldict['institution_bank_id'] = '51' |
---|
224 | xmldict['detail_ref'] = self.context.p_id |
---|
225 | xmldict['provider_amt'] = 100 * provider_amt |
---|
226 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
227 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
228 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
229 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
230 | xmldict['institution_item_name'] = self.context.p_category |
---|
231 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
232 | # Interswitch amount is not part of the xml data |
---|
233 | xmltext = """<payment_item_detail> |
---|
234 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
235 | <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" /> |
---|
236 | <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" /> |
---|
237 | </item_details> |
---|
238 | </payment_item_detail>""" % xmldict |
---|
239 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
240 | self.context.provider_amt = provider_amt |
---|
241 | self.context.gateway_amt = GATEWAY_AMT |
---|
242 | return |
---|
243 | |
---|
244 | class InterswitchPaymentRequestWebservicePageStudent( |
---|
245 | InterswitchPaymentRequestWebservicePageStudent): |
---|
246 | """ Request webservice view for the CollegePAY gateway |
---|
247 | """ |
---|
248 | grok.context(ICustomStudentOnlinePayment) |
---|
249 | product_id = PRODUCT_ID |
---|
250 | gateway_host = HOST |
---|
251 | gateway_url = URL |
---|
252 | |
---|
253 | class InterswitchPaymentRequestWebservicePageApplicant( |
---|
254 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
255 | """ Request webservice view for the CollegePAY gateway |
---|
256 | """ |
---|
257 | grok.context(ICustomApplicantOnlinePayment) |
---|
258 | product_id = PRODUCT_ID |
---|
259 | gateway_host = HOST |
---|
260 | gateway_url = URL |
---|