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