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