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 |
---|
42 | from kofacustom.nigeria.etranzact.helpers import query_payoutlet |
---|
43 | |
---|
44 | grok.templatedir('browser_templates') |
---|
45 | |
---|
46 | def module_activated(session): |
---|
47 | try: |
---|
48 | return getattr(grok.getSite()['configuration'][str(session)], |
---|
49 | 'etranzact_payoutlet_enabled', False) |
---|
50 | except KeyError: |
---|
51 | return False |
---|
52 | |
---|
53 | class EtranzactEnterPinActionButtonApplicant(APABApplicant): |
---|
54 | grok.context(INigeriaApplicantOnlinePayment) |
---|
55 | grok.require('waeup.payApplicant') |
---|
56 | grok.order(3) |
---|
57 | icon = 'actionicon_call.png' |
---|
58 | text = _('Enter Etranzact PIN') |
---|
59 | target = 'enterpin' |
---|
60 | |
---|
61 | @property |
---|
62 | def target_url(self): |
---|
63 | if not module_activated(self.context.__parent__.__parent__.year): |
---|
64 | return '' |
---|
65 | if self.context.p_state in ('paid', 'waived'): |
---|
66 | return '' |
---|
67 | return self.view.url(self.view.context, self.target) |
---|
68 | |
---|
69 | class EtranzactEnterPinActionButtonStudent(APABStudent): |
---|
70 | grok.context(INigeriaStudentOnlinePayment) |
---|
71 | grok.require('waeup.payStudent') |
---|
72 | grok.order(3) |
---|
73 | icon = 'actionicon_call.png' |
---|
74 | text = _('Enter Etranzact PIN') |
---|
75 | target = 'enterpin' |
---|
76 | |
---|
77 | @property |
---|
78 | def target_url(self): |
---|
79 | if not module_activated(self.context.student.current_session): |
---|
80 | return '' |
---|
81 | if self.context.p_state in ('paid', 'waived'): |
---|
82 | return '' |
---|
83 | return self.view.url(self.view.context, self.target) |
---|
84 | |
---|
85 | class EtranzactEnterPinPageStudent(KofaPage): |
---|
86 | """ |
---|
87 | """ |
---|
88 | grok.context(INigeriaStudentOnlinePayment) |
---|
89 | grok.name('enterpin') |
---|
90 | grok.template('enterpin') |
---|
91 | grok.require('waeup.payStudent') |
---|
92 | |
---|
93 | buttonname = _('Submit to Etranzact') |
---|
94 | label = _('Requery Etranzact History') |
---|
95 | action = 'query_payoutlet_history' |
---|
96 | placeholder = _('Confirmation Number (PIN)') |
---|
97 | |
---|
98 | def update(self): |
---|
99 | if not module_activated(self.context.student.current_session): |
---|
100 | return |
---|
101 | super(EtranzactEnterPinPageStudent, self).update() |
---|
102 | return |
---|
103 | |
---|
104 | class EtranzactEnterPinPageApplicant(EtranzactEnterPinPageStudent): |
---|
105 | """ |
---|
106 | """ |
---|
107 | grok.require('waeup.payApplicant') |
---|
108 | grok.context(INigeriaApplicantOnlinePayment) |
---|
109 | |
---|
110 | class EtranzactQueryHistoryPageStudent(UtilityView, grok.View): |
---|
111 | """ Query history of Etranzact payments |
---|
112 | """ |
---|
113 | grok.context(INigeriaStudentOnlinePayment) |
---|
114 | grok.name('query_payoutlet_history') |
---|
115 | grok.require('waeup.payStudent') |
---|
116 | terminal_id = TERMINAL_ID |
---|
117 | host = HOST |
---|
118 | https = HTTPS |
---|
119 | |
---|
120 | def update(self, confirmation_number=None): |
---|
121 | if not module_activated(self.context.student.current_session): |
---|
122 | return |
---|
123 | if self.context.p_state == 'paid': |
---|
124 | self.flash(_('This ticket has already been paid.')) |
---|
125 | return |
---|
126 | student = self.context.student |
---|
127 | success, msg, log = query_payoutlet( |
---|
128 | self.host, self.terminal_id, confirmation_number, |
---|
129 | self.context, self.https) |
---|
130 | student.writeLogMessage(self, log) |
---|
131 | if not success: |
---|
132 | self.flash(msg) |
---|
133 | return |
---|
134 | flashtype, msg, log = self.context.doAfterStudentPayment() |
---|
135 | if log is not None: |
---|
136 | student.writeLogMessage(self, log) |
---|
137 | self.flash(msg, type=flashtype) |
---|
138 | return |
---|
139 | |
---|
140 | def render(self): |
---|
141 | self.redirect(self.url(self.context, '@@index')) |
---|
142 | return |
---|
143 | |
---|
144 | class EtranzactQueryHistoryPageApplicant(UtilityView, grok.View): |
---|
145 | """ Query history of Etranzact payments |
---|
146 | """ |
---|
147 | grok.context(INigeriaApplicantOnlinePayment) |
---|
148 | grok.name('query_payoutlet_history') |
---|
149 | grok.require('waeup.payApplicant') |
---|
150 | terminal_id = TERMINAL_ID |
---|
151 | host = HOST |
---|
152 | https = HTTPS |
---|
153 | |
---|
154 | def update(self, confirmation_number=None): |
---|
155 | if not module_activated(self.context.__parent__.__parent__.year): |
---|
156 | return |
---|
157 | ob_class = self.__implemented__.__name__ |
---|
158 | if self.context.p_state == 'paid': |
---|
159 | self.flash(_('This ticket has already been paid.')) |
---|
160 | return |
---|
161 | applicant = self.context.__parent__ |
---|
162 | success, msg, log = query_payoutlet( |
---|
163 | self.host, self.terminal_id, confirmation_number, |
---|
164 | self.context, self.https) |
---|
165 | applicant.writeLogMessage(self, log) |
---|
166 | if not success: |
---|
167 | self.flash(msg) |
---|
168 | return |
---|
169 | flashtype, msg, log = self.context.doAfterApplicantPayment() |
---|
170 | if log is not None: |
---|
171 | applicant.writeLogMessage(self, log) |
---|
172 | self.flash(msg, type=flashtype) |
---|
173 | return |
---|
174 | |
---|
175 | def render(self): |
---|
176 | self.redirect(self.url(self.context, '@@index')) |
---|
177 | return |
---|