1 | ## $Id: browser.py 15346 2019-03-06 22:19:56Z 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 | from datetime import datetime |
---|
19 | import httplib |
---|
20 | import urllib |
---|
21 | import urllib2 |
---|
22 | import re |
---|
23 | from xml.dom.minidom import parseString |
---|
24 | import grok |
---|
25 | from zope.component import getUtility |
---|
26 | from zope.catalog.interfaces import ICatalog |
---|
27 | from waeup.kofa.interfaces import IUniversity, CLEARED |
---|
28 | from waeup.kofa.payments.interfaces import IPayer |
---|
29 | from waeup.kofa.webservices import PaymentDataWebservice |
---|
30 | from waeup.kofa.browser.layout import KofaPage, UtilityView |
---|
31 | from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent |
---|
32 | from waeup.kofa.applicants.viewlets import ApprovePaymentActionButton as APABApplicant |
---|
33 | from waeup.kofa.students.viewlets import PaymentReceiptActionButton as PRABStudent |
---|
34 | from waeup.kofa.applicants.viewlets import PaymentReceiptActionButton as PRABApplicant |
---|
35 | from kofacustom.nigeria.interswitch.browser import ( |
---|
36 | InterswitchActionButtonStudent, |
---|
37 | InterswitchRequestWebserviceActionButtonStudent, |
---|
38 | InterswitchActionButtonApplicant, |
---|
39 | InterswitchRequestWebserviceActionButtonApplicant) |
---|
40 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
41 | from kofacustom.nigeria.students.interfaces import INigeriaStudentOnlinePayment |
---|
42 | from kofacustom.nigeria.applicants.interfaces import INigeriaApplicantOnlinePayment |
---|
43 | from kofacustom.nigeria.etranzact.tests import HOST, TERMINAL_ID, HTTPS, GATEWAY_AMT |
---|
44 | from kofacustom.nigeria.etranzact.helpers import query_payoutlet |
---|
45 | |
---|
46 | grok.templatedir('browser_templates') |
---|
47 | |
---|
48 | def payoutlet_module_activated(session, payment): |
---|
49 | if payment.r_company and payment.r_company != 'etranzact': |
---|
50 | return False |
---|
51 | try: |
---|
52 | return getattr(grok.getSite()['configuration'][str(session)], |
---|
53 | 'etranzact_payoutlet_enabled', False) |
---|
54 | except KeyError: |
---|
55 | return False |
---|
56 | |
---|
57 | class EtranzactEnterPinActionButtonApplicant(APABApplicant): |
---|
58 | grok.context(INigeriaApplicantOnlinePayment) |
---|
59 | grok.require('waeup.payApplicant') |
---|
60 | grok.order(3) |
---|
61 | icon = 'actionicon_pay.png' |
---|
62 | text = _('Pay via Etranzact PayOutlet') |
---|
63 | target = 'enterpin' |
---|
64 | |
---|
65 | @property |
---|
66 | def target_url(self): |
---|
67 | if not payoutlet_module_activated( |
---|
68 | self.context.__parent__.__parent__.year, self.context): |
---|
69 | return '' |
---|
70 | if self.context.p_state in ('paid', 'waived', 'scholarship'): |
---|
71 | return '' |
---|
72 | return self.view.url(self.view.context, self.target) |
---|
73 | |
---|
74 | class EtranzactEnterPinActionButtonStudent(APABStudent): |
---|
75 | grok.context(INigeriaStudentOnlinePayment) |
---|
76 | grok.require('waeup.payStudent') |
---|
77 | grok.order(3) |
---|
78 | icon = 'actionicon_pay.png' |
---|
79 | text = _('Pay via Etranzact PayOutlet') |
---|
80 | target = 'enterpin' |
---|
81 | |
---|
82 | @property |
---|
83 | def target_url(self): |
---|
84 | if not payoutlet_module_activated( |
---|
85 | self.context.student.current_session, self.context): |
---|
86 | return '' |
---|
87 | if self.context.p_state in ('paid', 'waived', 'scholarship'): |
---|
88 | return '' |
---|
89 | return self.view.url(self.view.context, self.target) |
---|
90 | |
---|
91 | class EtranzactEnterPinPageStudent(KofaPage): |
---|
92 | """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageStudent` |
---|
93 | """ |
---|
94 | grok.context(INigeriaStudentOnlinePayment) |
---|
95 | grok.name('enterpin') |
---|
96 | grok.template('enterpin') |
---|
97 | grok.require('waeup.payStudent') |
---|
98 | |
---|
99 | buttonname = _('Submit to Etranzact') |
---|
100 | label = _('Requery Etranzact PayOutlet History') |
---|
101 | action = 'query_payoutlet_history' |
---|
102 | placeholder = _('Confirmation Number (PIN)') |
---|
103 | gateway_amt = GATEWAY_AMT |
---|
104 | |
---|
105 | def update(self): |
---|
106 | if not payoutlet_module_activated( |
---|
107 | self.context.student.current_session, self.context): |
---|
108 | return |
---|
109 | super(EtranzactEnterPinPageStudent, self).update() |
---|
110 | # Already now it becomes an Etranzact payment. We set the net amount |
---|
111 | # and add the gateway amount. |
---|
112 | if not self.context.r_company: |
---|
113 | self.context.net_amt = self.context.amount_auth |
---|
114 | self.context.amount_auth += self.gateway_amt |
---|
115 | self.context.gateway_amt = self.gateway_amt |
---|
116 | self.context.r_company = u'etranzact' |
---|
117 | return |
---|
118 | |
---|
119 | class EtranzactEnterPinPageApplicant(KofaPage): |
---|
120 | """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageApplicant` |
---|
121 | """ |
---|
122 | grok.require('waeup.payApplicant') |
---|
123 | grok.context(INigeriaApplicantOnlinePayment) |
---|
124 | grok.name('enterpin') |
---|
125 | grok.template('enterpin') |
---|
126 | |
---|
127 | buttonname = _('Submit to Etranzact') |
---|
128 | label = _('Requery Etranzact PayOutlet History') |
---|
129 | action = 'query_payoutlet_history' |
---|
130 | placeholder = _('Confirmation Number (PIN)') |
---|
131 | gateway_amt = GATEWAY_AMT |
---|
132 | |
---|
133 | def update(self): |
---|
134 | if not payoutlet_module_activated( |
---|
135 | self.context.__parent__.__parent__.year, self.context): |
---|
136 | return |
---|
137 | super(EtranzactEnterPinPageApplicant, self).update() |
---|
138 | # Already now it becomes an Etranzact payment. We set the net amount |
---|
139 | # and add the gateway amount. |
---|
140 | if not self.context.r_company: |
---|
141 | self.context.net_amt = self.context.amount_auth |
---|
142 | self.context.amount_auth += self.gateway_amt |
---|
143 | self.context.gateway_amt = self.gateway_amt |
---|
144 | self.context.r_company = u'etranzact' |
---|
145 | return |
---|
146 | |
---|
147 | class PayoutletPaymentReceiptActionButtonApplicant(PRABApplicant): |
---|
148 | |
---|
149 | grok.view(EtranzactEnterPinPageApplicant) |
---|
150 | |
---|
151 | @property |
---|
152 | def target_url(self): |
---|
153 | if not self.context.r_company: |
---|
154 | return '' |
---|
155 | return self.view.url(self.view.context, self.target) |
---|
156 | |
---|
157 | class PayoutletPaymentReceiptActionButtonStudent(PRABStudent): |
---|
158 | |
---|
159 | grok.view(EtranzactEnterPinPageStudent) |
---|
160 | |
---|
161 | @property |
---|
162 | def target_url(self): |
---|
163 | if not self.context.r_company: |
---|
164 | return '' |
---|
165 | return self.view.url(self.view.context, self.target) |
---|
166 | |
---|
167 | class EtranzactQueryHistoryPageStudent(UtilityView, grok.View): |
---|
168 | """ Query history of Etranzact payments |
---|
169 | """ |
---|
170 | grok.context(INigeriaStudentOnlinePayment) |
---|
171 | grok.name('query_payoutlet_history') |
---|
172 | grok.require('waeup.payStudent') |
---|
173 | terminal_id = TERMINAL_ID |
---|
174 | host = HOST |
---|
175 | https = HTTPS |
---|
176 | |
---|
177 | def update(self, confirmation_number=None): |
---|
178 | if not payoutlet_module_activated( |
---|
179 | self.context.student.current_session, self.context): |
---|
180 | return |
---|
181 | if self.context.p_state == 'paid': |
---|
182 | self.flash(_('This ticket has already been paid.')) |
---|
183 | return |
---|
184 | student = self.context.student |
---|
185 | success, msg, log = query_payoutlet( |
---|
186 | self.host, self.terminal_id, confirmation_number, |
---|
187 | self.context, self.https) |
---|
188 | student.writeLogMessage(self, log) |
---|
189 | if not success: |
---|
190 | self.flash(msg, type="danger") |
---|
191 | return |
---|
192 | flashtype, msg, log = self.context.doAfterStudentPayment() |
---|
193 | if log is not None: |
---|
194 | student.writeLogMessage(self, log) |
---|
195 | self.flash(msg, type=flashtype) |
---|
196 | return |
---|
197 | |
---|
198 | def render(self): |
---|
199 | self.redirect(self.url(self.context, '@@index')) |
---|
200 | return |
---|
201 | |
---|
202 | class EtranzactQueryHistoryPageApplicant(UtilityView, grok.View): |
---|
203 | """ Query history of Etranzact payments |
---|
204 | """ |
---|
205 | grok.context(INigeriaApplicantOnlinePayment) |
---|
206 | grok.name('query_payoutlet_history') |
---|
207 | grok.require('waeup.payApplicant') |
---|
208 | terminal_id = TERMINAL_ID |
---|
209 | host = HOST |
---|
210 | https = HTTPS |
---|
211 | |
---|
212 | def update(self, confirmation_number=None): |
---|
213 | if not payoutlet_module_activated( |
---|
214 | self.context.__parent__.__parent__.year, self.context): |
---|
215 | return |
---|
216 | if self.context.p_state == 'paid': |
---|
217 | self.flash(_('This ticket has already been paid.')) |
---|
218 | return |
---|
219 | applicant = self.context.__parent__ |
---|
220 | success, msg, log = query_payoutlet( |
---|
221 | self.host, self.terminal_id, confirmation_number, |
---|
222 | self.context, self.https) |
---|
223 | applicant.writeLogMessage(self, log) |
---|
224 | if not success: |
---|
225 | self.flash(msg) |
---|
226 | return |
---|
227 | flashtype, msg, log = self.context.doAfterApplicantPayment() |
---|
228 | if log is not None: |
---|
229 | applicant.writeLogMessage(self, log) |
---|
230 | self.flash(msg, type=flashtype) |
---|
231 | return |
---|
232 | |
---|
233 | def render(self): |
---|
234 | self.redirect(self.url(self.context, '@@index')) |
---|
235 | return |
---|