source: main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/payoutletbrowser.py @ 15974

Last change on this file since 15974 was 15974, checked in by Henrik Bettermann, 5 years ago

Do not allow to submit forms to other companies than payment.r_company.

File size: 9.0 KB
Line 
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##
18from datetime import datetime
19import httplib
20import urllib
21import urllib2
22import re
23from xml.dom.minidom import parseString
24import grok
25from zope.component import getUtility
26from zope.catalog.interfaces import ICatalog
27from waeup.kofa.interfaces import IUniversity, CLEARED
28from waeup.kofa.payments.interfaces import IPayer
29from waeup.kofa.webservices import PaymentDataWebservice
30from waeup.kofa.browser.layout import KofaPage, UtilityView
31from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent
32from waeup.kofa.applicants.viewlets import ApprovePaymentActionButton as APABApplicant
33from waeup.kofa.students.viewlets import PaymentReceiptActionButton as PRABStudent
34from waeup.kofa.applicants.viewlets import PaymentReceiptActionButton as PRABApplicant
35from kofacustom.nigeria.interswitch.browser import (
36    InterswitchActionButtonStudent,
37    InterswitchRequestWebserviceActionButtonStudent,
38    InterswitchActionButtonApplicant,
39    InterswitchRequestWebserviceActionButtonApplicant)
40from kofacustom.nigeria.interfaces import MessageFactory as _
41from kofacustom.nigeria.students.interfaces import INigeriaStudentOnlinePayment
42from kofacustom.nigeria.applicants.interfaces import INigeriaApplicantOnlinePayment
43from kofacustom.nigeria.etranzact.tests import HOST, TERMINAL_ID, HTTPS, GATEWAY_AMT
44from kofacustom.nigeria.etranzact.helpers import query_payoutlet
45
46grok.templatedir('browser_templates')
47
48def 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
57class 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
74class 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
91class 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            self.flash(_('Forbidden'), type='danger')
109            self.redirect(self.url(self.context, '@@index'))
110            return
111        # Already now it becomes an Etranzact payment. We set the net amount
112        # and add the gateway amount.
113        if not self.context.r_company:
114            self.context.net_amt = self.context.amount_auth
115            self.context.amount_auth += self.gateway_amt
116            self.context.gateway_amt = self.gateway_amt
117            self.context.r_company = u'etranzact'
118        return
119
120class EtranzactEnterPinPageApplicant(KofaPage):
121    """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageApplicant`
122    """
123    grok.require('waeup.payApplicant')
124    grok.context(INigeriaApplicantOnlinePayment)
125    grok.name('enterpin')
126    grok.template('enterpin')
127
128    buttonname = _('Submit to Etranzact')
129    label = _('Requery Etranzact PayOutlet History')
130    action = 'query_payoutlet_history'
131    placeholder = _('Confirmation Number (PIN)')
132    gateway_amt = GATEWAY_AMT
133
134    def update(self):
135        if not payoutlet_module_activated(
136            self.context.__parent__.__parent__.year, self.context):
137            self.flash(_('Forbidden'), type='danger')
138            self.redirect(self.url(self.context, '@@index'))
139            return
140        # Already now it becomes an Etranzact payment. We set the net amount
141        # and add the gateway amount.
142        if not self.context.r_company:
143            self.context.net_amt = self.context.amount_auth
144            self.context.amount_auth += self.gateway_amt
145            self.context.gateway_amt = self.gateway_amt
146            self.context.r_company = u'etranzact'
147        return
148
149class PayoutletPaymentReceiptActionButtonApplicant(PRABApplicant):
150
151    grok.view(EtranzactEnterPinPageApplicant)
152
153    @property
154    def target_url(self):
155        if not self.context.r_company:
156            return ''
157        return self.view.url(self.view.context, self.target)
158
159class PayoutletPaymentReceiptActionButtonStudent(PRABStudent):
160
161    grok.view(EtranzactEnterPinPageStudent)
162
163    @property
164    def target_url(self):
165        if not self.context.r_company:
166            return ''
167        return self.view.url(self.view.context, self.target)
168
169class EtranzactQueryHistoryPageStudent(UtilityView, grok.View):
170    """ Query history of Etranzact payments
171    """
172    grok.context(INigeriaStudentOnlinePayment)
173    grok.name('query_payoutlet_history')
174    grok.require('waeup.payStudent')
175    terminal_id = TERMINAL_ID
176    host = HOST
177    https = HTTPS
178
179    def update(self, confirmation_number=None):
180        if not payoutlet_module_activated(
181            self.context.student.current_session, self.context):
182            self.flash(_('Forbidden'), type='danger')
183            self.redirect(self.url(self.context, '@@index'))
184            return
185        if self.context.p_state == 'paid':
186            self.flash(_('This ticket has already been paid.'))
187            return
188        student = self.context.student
189        success, msg, log = query_payoutlet(
190            self.host, self.terminal_id, confirmation_number,
191            self.context, self.https)
192        student.writeLogMessage(self, log)
193        if not success:
194            self.flash(msg, type="danger")
195            return
196        flashtype, msg, log = self.context.doAfterStudentPayment()
197        if log is not None:
198            student.writeLogMessage(self, log)
199        self.flash(msg, type=flashtype)
200        return
201
202    def render(self):
203        self.redirect(self.url(self.context, '@@index'))
204        return
205
206class EtranzactQueryHistoryPageApplicant(UtilityView, grok.View):
207    """ Query history of Etranzact payments
208    """
209    grok.context(INigeriaApplicantOnlinePayment)
210    grok.name('query_payoutlet_history')
211    grok.require('waeup.payApplicant')
212    terminal_id = TERMINAL_ID
213    host = HOST
214    https = HTTPS
215
216    def update(self, confirmation_number=None):
217        if not payoutlet_module_activated(
218            self.context.__parent__.__parent__.year, self.context):
219            self.flash(_('Forbidden'), type='danger')
220            self.redirect(self.url(self.context, '@@index'))
221            return
222        if self.context.p_state == 'paid':
223            self.flash(_('This ticket has already been paid.'))
224            return
225        applicant = self.context.__parent__
226        success, msg, log = query_payoutlet(
227            self.host, self.terminal_id, confirmation_number,
228            self.context, self.https)
229        applicant.writeLogMessage(self, log)
230        if not success:
231            self.flash(msg)
232            return
233        flashtype, msg, log = self.context.doAfterApplicantPayment()
234        if log is not None:
235            applicant.writeLogMessage(self, log)
236        self.flash(msg, type=flashtype)
237        return
238
239    def render(self):
240        self.redirect(self.url(self.context, '@@index'))
241        return
Note: See TracBrowser for help on using the repository browser.