1 | ## $Id: browser.py 14237 2016-10-27 21:07:05Z 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 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
26 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
27 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
28 | ) |
---|
29 | from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment |
---|
30 | from waeup.uniben.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
31 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
32 | |
---|
33 | PRODUCT_ID = '57' |
---|
34 | SITE_NAME = 'uniben-kofa.waeup.org' |
---|
35 | PROVIDER_ACCT = '1014261520' |
---|
36 | PROVIDER_BANK_ID = '117' |
---|
37 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
38 | INSTITUTION_NAME = 'Uniben' |
---|
39 | INSTITUTION_ACCT = '2017506430' |
---|
40 | INSTITUTION_BANK_ID = '8' |
---|
41 | CURRENCY = '566' |
---|
42 | GATEWAY_AMT = 150.0 |
---|
43 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
---|
44 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
---|
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 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
51 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
52 | httplib.HTTPConnection.debuglevel = 0 |
---|
53 | |
---|
54 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
55 | """ View which sends a POST request to the Interswitch |
---|
56 | CollegePAY payment gateway. |
---|
57 | """ |
---|
58 | grok.context(ICustomStudentOnlinePayment) |
---|
59 | action = POST_ACTION |
---|
60 | site_name = SITE_NAME |
---|
61 | currency = CURRENCY |
---|
62 | product_id = PRODUCT_ID |
---|
63 | |
---|
64 | def dynamic_provider_amt(self, student): |
---|
65 | if student.entry_session >= 2016: |
---|
66 | return 2500.0 |
---|
67 | return 1500.0 |
---|
68 | |
---|
69 | def update(self): |
---|
70 | error = self.init_update() |
---|
71 | if error: |
---|
72 | self.flash(error, type='danger') |
---|
73 | self.redirect(self.url(self.context, '@@index')) |
---|
74 | return |
---|
75 | student = self.student |
---|
76 | xmldict = self.xmldict |
---|
77 | # Provider data |
---|
78 | xmldict['detail_ref'] = self.context.p_id |
---|
79 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
80 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
81 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
82 | # Institution data |
---|
83 | xmldict['institution_acct'] = INSTITUTION_ACCT |
---|
84 | xmldict['institution_bank_id'] = INSTITUTION_BANK_ID |
---|
85 | xmldict['institution_amt'] = '0.0' |
---|
86 | provider_amt = 0.0 |
---|
87 | self.pay_item_id = '0000' |
---|
88 | if self.context.p_category == 'schoolfee': |
---|
89 | if not self.context.p_item == 'Balance': |
---|
90 | provider_amt = self.dynamic_provider_amt(student) |
---|
91 | if student.current_mode.endswith('_ft'): |
---|
92 | self.pay_item_id = '5700' |
---|
93 | elif student.current_mode[-3:] in ('_pt', '_sw'): |
---|
94 | self.pay_item_id = '5701' |
---|
95 | elif student.faccode == 'JUPEB': |
---|
96 | self.pay_item_id = '5718' |
---|
97 | elif self.context.p_category == 'clearance': |
---|
98 | self.pay_item_id = '5702' |
---|
99 | provider_amt = self.dynamic_provider_amt(student) |
---|
100 | elif self.context.p_category == 'gown': |
---|
101 | self.pay_item_id = '5704' |
---|
102 | elif self.context.p_category.startswith('hostel_maintenance'): |
---|
103 | self.pay_item_id = '5705' |
---|
104 | elif self.context.p_category.startswith('bed_allocation'): |
---|
105 | self.pay_item_id = '5716' |
---|
106 | elif self.context.p_category == 'jupeb': |
---|
107 | self.pay_item_id = '5717' |
---|
108 | |
---|
109 | xmldict['provider_amt'] = 100 * provider_amt |
---|
110 | xmldict['institution_item_name'] = self.category |
---|
111 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
112 | xmldict['institution_amt'] = 100 * ( |
---|
113 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
114 | |
---|
115 | if provider_amt == 0: |
---|
116 | xmltext = """<payment_item_detail> |
---|
117 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
118 | <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" /> |
---|
119 | </item_details> |
---|
120 | </payment_item_detail>""" % xmldict |
---|
121 | else: |
---|
122 | xmltext = """<payment_item_detail> |
---|
123 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
124 | <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" /> |
---|
125 | <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" /> |
---|
126 | </item_details> |
---|
127 | </payment_item_detail>""" % xmldict |
---|
128 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
129 | self.context.provider_amt = provider_amt |
---|
130 | self.context.gateway_amt = GATEWAY_AMT |
---|
131 | return |
---|
132 | |
---|
133 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
134 | """ View which sends a POST request to the Interswitch |
---|
135 | CollegePAY payment gateway. |
---|
136 | """ |
---|
137 | grok.context(ICustomApplicantOnlinePayment) |
---|
138 | action = POST_ACTION |
---|
139 | site_name = SITE_NAME |
---|
140 | currency = CURRENCY |
---|
141 | pay_item_id = '5703' |
---|
142 | product_id = PRODUCT_ID |
---|
143 | |
---|
144 | def update(self): |
---|
145 | error = self.init_update() |
---|
146 | if error: |
---|
147 | self.flash(error, type='danger') |
---|
148 | self.redirect(self.url(self.context, '@@index')) |
---|
149 | return |
---|
150 | xmldict = {} |
---|
151 | provider_amt = 400.0 |
---|
152 | if self.applicant.applicant_id.startswith('cbt'): |
---|
153 | provider_amt = 200.0 |
---|
154 | xmldict['institution_acct'] = INSTITUTION_ACCT |
---|
155 | xmldict['institution_bank_id'] = INSTITUTION_BANK_ID |
---|
156 | if self.applicant.applicant_id.startswith('ak'): |
---|
157 | xmldict['institution_acct'] = 1014774176 |
---|
158 | xmldict['institution_bank_id'] = 117 |
---|
159 | xmldict['detail_ref'] = self.context.p_id |
---|
160 | xmldict['provider_amt'] = 100 * provider_amt |
---|
161 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
162 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
163 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
164 | xmldict['institution_amt'] = 100 * ( |
---|
165 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
166 | xmldict['institution_item_name'] = self.category |
---|
167 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
168 | # Interswitch amount is not part of the xml data |
---|
169 | xmltext = """<payment_item_detail> |
---|
170 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)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 CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
181 | InterswitchPaymentRequestWebservicePageStudent): |
---|
182 | """Request webservice view for the CollegePAY gateway |
---|
183 | """ |
---|
184 | grok.context(ICustomStudentOnlinePayment) |
---|
185 | product_id = PRODUCT_ID |
---|
186 | gateway_host = HOST |
---|
187 | gateway_url = URL |
---|
188 | |
---|
189 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
190 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
191 | """Payment verify view for the CollegePAY gateway |
---|
192 | """ |
---|
193 | grok.context(ICustomStudentOnlinePayment) |
---|
194 | product_id = PRODUCT_ID |
---|
195 | gateway_host = HOST |
---|
196 | gateway_url = URL |
---|
197 | |
---|
198 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
199 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
200 | """Request webservice view for the CollegePAY gateway |
---|
201 | """ |
---|
202 | grok.context(ICustomApplicantOnlinePayment) |
---|
203 | product_id = PRODUCT_ID |
---|
204 | gateway_host = HOST |
---|
205 | gateway_url = URL |
---|
206 | |
---|
207 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
208 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
209 | """Payment verify view for the CollegePAY gateway |
---|
210 | """ |
---|
211 | grok.context(ICustomApplicantOnlinePayment) |
---|
212 | product_id = PRODUCT_ID |
---|
213 | gateway_host = HOST |
---|
214 | gateway_url = URL |
---|