1 | ## $Id: browser.py 10011 2013-03-05 11:53:41Z 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.fceokene.students.interfaces import ICustomStudentOnlinePayment |
---|
29 | from waeup.fceokene.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
30 | from waeup.fceokene.interfaces import MessageFactory as _ |
---|
31 | |
---|
32 | PRODUCT_ID = '83' |
---|
33 | SITE_NAME = 'fceokene-kofa.waeup.org' |
---|
34 | PROVIDER_ACCT = '0026781725' |
---|
35 | PROVIDER_BANK_ID = '31' |
---|
36 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
37 | INSTITUTION_NAME = 'FCEOkene' |
---|
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 | pay_item_id = '' |
---|
65 | product_id = PRODUCT_ID |
---|
66 | |
---|
67 | def update(self): |
---|
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 | self.amount_auth = 100 * self.context.amount_auth |
---|
76 | xmldict = {} |
---|
77 | if certificate is not None: |
---|
78 | xmldict['department'] = certificate.__parent__.__parent__.code |
---|
79 | xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code |
---|
80 | else: |
---|
81 | xmldict['department'] = None |
---|
82 | xmldict['faculty'] = None |
---|
83 | self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category] |
---|
84 | tz = getUtility(IKofaUtils).tzinfo |
---|
85 | self.local_date_time = to_timezone( |
---|
86 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
87 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
88 | # Provider data |
---|
89 | provider_amt = 1600.0 |
---|
90 | xmldict['detail_ref'] = self.context.p_id |
---|
91 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
92 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
93 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
94 | xmldict['provider_amt'] = 100 * provider_amt |
---|
95 | # Institution data |
---|
96 | fceokene_split_amt = 1400.0 |
---|
97 | xmldict['fceokene_acct'] = "0000000000000" |
---|
98 | xmldict['institution_bank_id'] = '0' |
---|
99 | xmldict['institution_item_name'] = self.category |
---|
100 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
101 | if self.context.p_category == 'schoolfee': |
---|
102 | self.pay_item_id = '8302' |
---|
103 | if student.current_mode in ('nce_sw','prence',): |
---|
104 | xmldict['institution_acct'] = "1012044194" |
---|
105 | xmldict['institution_bank_id'] = '117' |
---|
106 | elif student.current_mode in ('nce_ft',) and \ |
---|
107 | student['studycourse'].current_verdict == 'O': |
---|
108 | xmldict['institution_acct'] = "1012044015" |
---|
109 | xmldict['institution_bank_id'] = '117' |
---|
110 | elif student.current_mode in ('nce_ft',): |
---|
111 | xmldict['institution_acct'] = "1012044015" |
---|
112 | xmldict['institution_bank_id'] = '117' |
---|
113 | elif student.current_mode in ('pd_ft',): |
---|
114 | xmldict['institution_acct'] = "1012415659" |
---|
115 | xmldict['institution_bank_id'] = '117' |
---|
116 | #undergraduate schoolfee added |
---|
117 | elif student.current_mode in ('ug_ft',): |
---|
118 | xmldict['institution_acct'] = "2003670143" |
---|
119 | xmldict['institution_bank_id'] = '8' |
---|
120 | xmldict['fceokene_split'] = 100 * fceokene_split_amt |
---|
121 | xmldict['institution_amt'] = 100 * ( |
---|
122 | self.context.amount_auth - provider_amt - |
---|
123 | GATEWAY_AMT - fceokene_split_amt) |
---|
124 | elif 'maintenance' in self.context.p_category: |
---|
125 | fceokene_split_amt = 0.0 |
---|
126 | provider_amt = 0.0 |
---|
127 | self.pay_item_id = '8300' |
---|
128 | xmldict['institution_amt'] = 100 * ( |
---|
129 | self.context.amount_auth - GATEWAY_AMT) |
---|
130 | xmldict['institution_acct'] = "1012044132" |
---|
131 | xmldict['institution_bank_id'] = '117' |
---|
132 | elif self.context.p_category == 'clearance': |
---|
133 | fceokene_split_amt = 0.0 |
---|
134 | provider_amt = 0.0 |
---|
135 | self.pay_item_id = '8304' |
---|
136 | xmldict['institution_amt'] = 100 * ( |
---|
137 | self.context.amount_auth - GATEWAY_AMT) |
---|
138 | xmldict['institution_acct'] = "2003670143" |
---|
139 | xmldict['institution_bank_id'] = '8' |
---|
140 | |
---|
141 | # Interswitch amount is not part of the xml data |
---|
142 | if self.context.p_category == 'schoolfee': |
---|
143 | xmltext = """<payment_item_detail> |
---|
144 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
145 | <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" /> |
---|
146 | <item_detail item_id="2" item_name="FCEOkene Split" item_amt="%(fceokene_split)d" bank_id="117" acct_num="1012044039" /> |
---|
147 | <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" /> |
---|
148 | </item_details> |
---|
149 | </payment_item_detail>""" % xmldict |
---|
150 | |
---|
151 | else: |
---|
152 | xmltext = """<payment_item_detail> |
---|
153 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
154 | <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" /> |
---|
155 | </item_details> |
---|
156 | </payment_item_detail>""" % xmldict |
---|
157 | |
---|
158 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
159 | self.context.provider_amt = provider_amt |
---|
160 | self.context.gateway_amt = GATEWAY_AMT |
---|
161 | self.context.thirdparty_amt = fceokene_split_amt |
---|
162 | return |
---|
163 | |
---|
164 | class InterswitchPageApplicant(KofaPage): |
---|
165 | """ View which sends a POST request to the Interswitch |
---|
166 | CollegePAY payment gateway. |
---|
167 | """ |
---|
168 | grok.context(ICustomApplicantOnlinePayment) |
---|
169 | grok.require('waeup.payApplicant') |
---|
170 | grok.template('applicant_goto_interswitch') |
---|
171 | grok.name('goto_interswitch') |
---|
172 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
173 | submit_button = _('Submit') |
---|
174 | action = POST_ACTION |
---|
175 | site_name = SITE_NAME |
---|
176 | currency = CURRENCY |
---|
177 | pay_item_id = '8303' |
---|
178 | product_id = PRODUCT_ID |
---|
179 | |
---|
180 | def update(self): |
---|
181 | if self.context.p_state != 'unpaid': |
---|
182 | self.flash(_("Payment ticket can't be re-send to CollegePAY.")) |
---|
183 | self.redirect(self.url(self.context, '@@index')) |
---|
184 | return |
---|
185 | if self.context.__parent__.__parent__.expired \ |
---|
186 | and self.context.__parent__.__parent__.strict_deadline: |
---|
187 | self.flash(_("Payment ticket can't be send to CollegePAY. " |
---|
188 | "Application period has expired.")) |
---|
189 | self.redirect(self.url(self.context, '@@index')) |
---|
190 | return |
---|
191 | self.applicant = self.context.__parent__ |
---|
192 | self.amount_auth = 100 * self.context.amount_auth |
---|
193 | xmldict = {} |
---|
194 | self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category] |
---|
195 | tz = getUtility(IKofaUtils).tzinfo |
---|
196 | self.local_date_time = to_timezone( |
---|
197 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
198 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
199 | xmldict['detail_ref'] = self.context.p_id |
---|
200 | # Provider data |
---|
201 | provider_amt = 500.0 |
---|
202 | xmldict['provider_amt'] = 100 * provider_amt |
---|
203 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
204 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
205 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
206 | # Institution data |
---|
207 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - |
---|
208 | provider_amt - GATEWAY_AMT) |
---|
209 | xmldict['institution_acct'] = '10120445289' |
---|
210 | xmldict['institution_bank_id'] = '117' |
---|
211 | xmldict['institution_item_name'] = self.context.p_category |
---|
212 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
213 | # Interswitch amount is not part of the xml data |
---|
214 | xmltext = """<payment_item_detail> |
---|
215 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
216 | <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" /> |
---|
217 | <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" /> |
---|
218 | </item_details> |
---|
219 | </payment_item_detail>""" % xmldict |
---|
220 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
221 | self.context.provider_amt = provider_amt |
---|
222 | self.context.gateway_amt = GATEWAY_AMT |
---|
223 | return |
---|
224 | |
---|
225 | |
---|
226 | class InterswitchPaymentRequestWebservicePageStudent( |
---|
227 | InterswitchPaymentRequestWebservicePageStudent): |
---|
228 | """ Request webservice view for the CollegePAY gateway |
---|
229 | """ |
---|
230 | grok.context(ICustomStudentOnlinePayment) |
---|
231 | product_id = PRODUCT_ID |
---|
232 | gateway_host = HOST |
---|
233 | gateway_url = URL |
---|
234 | |
---|
235 | class InterswitchPaymentRequestWebservicePageApplicant( |
---|
236 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
237 | """ Request webservice view for the CollegePAY gateway |
---|
238 | """ |
---|
239 | grok.context(ICustomApplicantOnlinePayment) |
---|
240 | product_id = PRODUCT_ID |
---|
241 | gateway_host = HOST |
---|
242 | gateway_url = URL |
---|