1 | ## $Id: browser.py 13336 2015-10-17 04:51:14Z 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 waeup.kofa.students.interfaces import IStudentsUtils |
---|
22 | from kofacustom.nigeria.interswitch.browser import ( |
---|
23 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
24 | InterswitchPaymentRequestWebservicePageStudent, |
---|
25 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
26 | ) |
---|
27 | from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment |
---|
28 | from waeup.uniben.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
29 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
30 | |
---|
31 | PRODUCT_ID = '57' |
---|
32 | SITE_NAME = 'uniben-kofa.waeup.org' |
---|
33 | PROVIDER_ACCT = '1010764827' |
---|
34 | PROVIDER_BANK_ID = '117' |
---|
35 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
36 | INSTITUTION_NAME = 'Uniben' |
---|
37 | CURRENCY = '566' |
---|
38 | GATEWAY_AMT = 150.0 |
---|
39 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
---|
40 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
---|
41 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
42 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
43 | |
---|
44 | HOST = 'webpay.interswitchng.com' |
---|
45 | #HOST = 'testwebpay.interswitchng.com' |
---|
46 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
47 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
48 | httplib.HTTPConnection.debuglevel = 0 |
---|
49 | |
---|
50 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
51 | """ View which sends a POST request to the Interswitch |
---|
52 | CollegePAY payment gateway. |
---|
53 | """ |
---|
54 | grok.context(ICustomStudentOnlinePayment) |
---|
55 | action = POST_ACTION |
---|
56 | site_name = SITE_NAME |
---|
57 | currency = CURRENCY |
---|
58 | product_id = PRODUCT_ID |
---|
59 | |
---|
60 | def update(self): |
---|
61 | error = self.init_update() |
---|
62 | if error: |
---|
63 | self.flash(error, type='danger') |
---|
64 | self.redirect(self.url(self.context, '@@index')) |
---|
65 | return |
---|
66 | student = self.student |
---|
67 | xmldict = self.xmldict |
---|
68 | # Provider data |
---|
69 | xmldict['detail_ref'] = self.context.p_id |
---|
70 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
71 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
72 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
73 | # Institution data |
---|
74 | xmldict['institution_acct'] = '000000000000' |
---|
75 | xmldict['institution_bank_id'] = '00' |
---|
76 | xmldict['institution_amt'] = '0.0' |
---|
77 | provider_amt = 0.0 |
---|
78 | self.pay_item_id = '0000' |
---|
79 | if self.context.p_category == 'schoolfee': |
---|
80 | if not self.context.p_item == 'Balance': |
---|
81 | provider_amt = 1500.0 |
---|
82 | if student.current_mode.endswith('_ft'): |
---|
83 | self.pay_item_id = '5700' |
---|
84 | if student.current_mode in ('ug_ft','de_ft','ume_ft'): |
---|
85 | xmldict['institution_acct'] = '2017506430' |
---|
86 | xmldict['institution_bank_id'] = '8' |
---|
87 | elif student.current_mode in ('dp_ft','dp_pt','ct_pt','ct_ft'): |
---|
88 | xmldict['institution_acct'] = '0058653774' |
---|
89 | xmldict['institution_bank_id'] = '72' |
---|
90 | elif student.current_mode in ('pg_ft'): |
---|
91 | xmldict['institution_acct'] = '6230033428' |
---|
92 | xmldict['institution_bank_id'] = '51' |
---|
93 | elif student.current_mode.endswith('_pt'): |
---|
94 | self.pay_item_id = '5701' |
---|
95 | if student.current_mode in ('ug_pt','de_pt'): |
---|
96 | xmldict['institution_acct'] = '0122009929' |
---|
97 | xmldict['institution_bank_id'] = '16' |
---|
98 | elif student.current_mode in ('pg_pt', 'special_pg_pt'): |
---|
99 | xmldict['institution_acct'] = '4150033274' |
---|
100 | xmldict['institution_bank_id'] = '51' |
---|
101 | elif student.faccode == 'JUPEB': |
---|
102 | self.pay_item_id = '5718' |
---|
103 | xmldict['institution_acct'] = '1014433907' |
---|
104 | xmldict['institution_bank_id'] = '117' |
---|
105 | elif self.context.p_category == 'clearance': |
---|
106 | self.pay_item_id = '5702' |
---|
107 | provider_amt = 1500.0 |
---|
108 | if student.faccode == 'FCETA': |
---|
109 | xmldict['institution_acct'] = '5210007943' |
---|
110 | xmldict['institution_bank_id'] = '51' |
---|
111 | else: |
---|
112 | xmldict['institution_bank_id'] = '10' |
---|
113 | xmldict['institution_acct'] = '0031716047' |
---|
114 | elif self.context.p_category == 'gown': |
---|
115 | self.pay_item_id = '5704' |
---|
116 | xmldict['institution_bank_id'] = '16' |
---|
117 | xmldict['institution_acct'] = '0122011401' |
---|
118 | elif self.context.p_category.startswith('bed_allocation'): |
---|
119 | self.pay_item_id = '5716' |
---|
120 | students_utils = getUtility(IStudentsUtils) |
---|
121 | stage = students_utils.getAccommodationDetails(student)['bt'] |
---|
122 | stage = stage.split('_')[2] |
---|
123 | if stage == 'fr': |
---|
124 | union_dues = 500.0 |
---|
125 | else: |
---|
126 | union_dues = 300.0 |
---|
127 | xmldict['institution_bank_id'] = '129' |
---|
128 | xmldict['institution_acct'] = '0014419432' |
---|
129 | xmldict['union_dues'] = 100 * union_dues |
---|
130 | elif self.context.p_category.startswith('hostel_maintenance'): |
---|
131 | self.pay_item_id = '5705' |
---|
132 | xmldict['institution_bank_id'] = '129' |
---|
133 | xmldict['institution_acct'] = '0014419432' |
---|
134 | |
---|
135 | xmldict['provider_amt'] = 100 * provider_amt |
---|
136 | xmldict['institution_item_name'] = self.category |
---|
137 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
138 | xmldict['institution_amt'] = 100 * ( |
---|
139 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
140 | |
---|
141 | if self.context.p_category == 'bed_allocation': |
---|
142 | xmldict['institution_amt'] = 100 * ( |
---|
143 | self.context.amount_auth - GATEWAY_AMT - union_dues) |
---|
144 | xmltext = """<payment_item_detail> |
---|
145 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
146 | <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" /> |
---|
147 | <item_detail item_id="2" item_name="UNION DUES" item_amt="%(union_dues)d" bank_id="31" acct_num="0005986952" /> |
---|
148 | </item_details> |
---|
149 | </payment_item_detail>""" % xmldict |
---|
150 | elif provider_amt == 0: |
---|
151 | xmltext = """<payment_item_detail> |
---|
152 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
153 | <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" /> |
---|
154 | </item_details> |
---|
155 | </payment_item_detail>""" % xmldict |
---|
156 | elif self.context.p_category == 'schoolfee' and \ |
---|
157 | student.current_mode == 'ug_ft': |
---|
158 | xmldict['institution_amt'] = 100 * ( |
---|
159 | self.context.amount_auth - provider_amt - GATEWAY_AMT - 3000) |
---|
160 | xmltext = """<payment_item_detail> |
---|
161 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
162 | <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" /> |
---|
163 | <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" /> |
---|
164 | <item_detail item_id="3" item_name="T-SHIP" item_amt="200000" bank_id="72" acct_num="0061647254" /> |
---|
165 | <item_detail item_id="4" item_name="MTN-NET LIBRARY" item_amt="100000" bank_id="8" acct_num="20177722298" /> |
---|
166 | </item_details> |
---|
167 | </payment_item_detail>""" % xmldict |
---|
168 | else: |
---|
169 | xmltext = """<payment_item_detail> |
---|
170 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
171 | <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" /> |
---|
172 | <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" /> |
---|
173 | </item_details> |
---|
174 | </payment_item_detail>""" % xmldict |
---|
175 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
176 | self.context.provider_amt = provider_amt |
---|
177 | self.context.gateway_amt = GATEWAY_AMT |
---|
178 | return |
---|
179 | |
---|
180 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
181 | """ View which sends a POST request to the Interswitch |
---|
182 | CollegePAY payment gateway. |
---|
183 | """ |
---|
184 | grok.context(ICustomApplicantOnlinePayment) |
---|
185 | action = POST_ACTION |
---|
186 | site_name = SITE_NAME |
---|
187 | currency = CURRENCY |
---|
188 | pay_item_id = '5703' |
---|
189 | product_id = PRODUCT_ID |
---|
190 | |
---|
191 | def update(self): |
---|
192 | error = self.init_update() |
---|
193 | if error: |
---|
194 | self.flash(error, type='danger') |
---|
195 | self.redirect(self.url(self.context, '@@index')) |
---|
196 | return |
---|
197 | xmldict = {} |
---|
198 | provider_amt = 400.0 |
---|
199 | if self.applicant.applicant_id[:3] in ('pga', 'pgd'): # CERHI |
---|
200 | xmldict['institution_acct'] = '1014312532' |
---|
201 | xmldict['institution_bank_id'] = '117' |
---|
202 | elif self.applicant.applicant_id.startswith('pg'): |
---|
203 | xmldict['institution_acct'] = '0031716030' |
---|
204 | xmldict['institution_bank_id'] = '10' |
---|
205 | elif self.applicant.applicant_id.startswith('dp'): |
---|
206 | xmldict['institution_acct'] = '9201805071' |
---|
207 | xmldict['institution_bank_id'] = '17' |
---|
208 | elif self.applicant.applicant_id.startswith('pt'): |
---|
209 | xmldict['institution_acct'] = '9201805071' |
---|
210 | xmldict['institution_bank_id'] = '17' |
---|
211 | elif self.applicant.applicant_id.startswith('pre'): |
---|
212 | xmldict['institution_acct'] = '1014315131' |
---|
213 | xmldict['institution_bank_id'] = '117' |
---|
214 | elif self.applicant.applicant_id.startswith('cbt'): |
---|
215 | xmldict['institution_acct'] = '5030058259' |
---|
216 | xmldict['institution_bank_id'] = '51' |
---|
217 | provider_amt = 200.0 |
---|
218 | else: |
---|
219 | xmldict['institution_acct'] = '1014326805' |
---|
220 | xmldict['institution_bank_id'] = '117' |
---|
221 | xmldict['detail_ref'] = self.context.p_id |
---|
222 | xmldict['provider_amt'] = 100 * provider_amt |
---|
223 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
224 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
225 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
226 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
227 | xmldict['institution_item_name'] = self.context.p_category |
---|
228 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
229 | # Interswitch amount is not part of the xml data |
---|
230 | xmltext = """<payment_item_detail> |
---|
231 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
232 | <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" /> |
---|
233 | <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" /> |
---|
234 | </item_details> |
---|
235 | </payment_item_detail>""" % xmldict |
---|
236 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
237 | self.context.provider_amt = provider_amt |
---|
238 | self.context.gateway_amt = GATEWAY_AMT |
---|
239 | return |
---|
240 | |
---|
241 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
242 | InterswitchPaymentRequestWebservicePageStudent): |
---|
243 | """ Request webservice view for the CollegePAY gateway |
---|
244 | """ |
---|
245 | grok.context(ICustomStudentOnlinePayment) |
---|
246 | product_id = PRODUCT_ID |
---|
247 | gateway_host = HOST |
---|
248 | gateway_url = URL |
---|
249 | |
---|
250 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
251 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
252 | """ Request webservice view for the CollegePAY gateway |
---|
253 | """ |
---|
254 | grok.context(ICustomApplicantOnlinePayment) |
---|
255 | product_id = PRODUCT_ID |
---|
256 | gateway_host = HOST |
---|
257 | gateway_url = URL |
---|