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

Last change on this file since 16153 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
RevLine 
[15702]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
[15796]33from waeup.kofa.students.viewlets import PaymentReceiptActionButton as PRABStudent
34from waeup.kofa.applicants.viewlets import PaymentReceiptActionButton as PRABApplicant
[15702]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
[15755]43from kofacustom.nigeria.etranzact.tests import HOST, TERMINAL_ID, HTTPS, GATEWAY_AMT
[15730]44from kofacustom.nigeria.etranzact.helpers import query_payoutlet
[15702]45
46grok.templatedir('browser_templates')
47
[15772]48def payoutlet_module_activated(session, payment):
[15770]49    if payment.r_company and payment.r_company != 'etranzact':
50        return False
[15702]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)
[15796]61    icon = 'actionicon_pay.png'
62    text = _('Pay via Etranzact PayOutlet')
[15702]63    target = 'enterpin'
64
65    @property
66    def target_url(self):
[15772]67        if not payoutlet_module_activated(
[15770]68            self.context.__parent__.__parent__.year, self.context):
[15702]69            return ''
[15796]70        if self.context.p_state in ('paid', 'waived', 'scholarship'):
[15702]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)
[15796]78    icon = 'actionicon_pay.png'
79    text = _('Pay via Etranzact PayOutlet')
[15702]80    target = 'enterpin'
81
82    @property
83    def target_url(self):
[15772]84        if not payoutlet_module_activated(
[15770]85            self.context.student.current_session, self.context):
[15702]86            return ''
[15796]87        if self.context.p_state in ('paid', 'waived', 'scholarship'):
[15702]88            return ''
89        return self.view.url(self.view.context, self.target)
90
91class EtranzactEnterPinPageStudent(KofaPage):
[15755]92    """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageStudent`
[15702]93    """
94    grok.context(INigeriaStudentOnlinePayment)
95    grok.name('enterpin')
96    grok.template('enterpin')
97    grok.require('waeup.payStudent')
98
99    buttonname = _('Submit to Etranzact')
[15796]100    label = _('Requery Etranzact PayOutlet History')
[15702]101    action = 'query_payoutlet_history'
102    placeholder = _('Confirmation Number (PIN)')
[15755]103    gateway_amt = GATEWAY_AMT
[15702]104
105    def update(self):
[15772]106        if not payoutlet_module_activated(
[15770]107            self.context.student.current_session, self.context):
[15974]108            self.flash(_('Forbidden'), type='danger')
109            self.redirect(self.url(self.context, '@@index'))
[15702]110            return
[15755]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'
[15702]118        return
119
[15771]120class EtranzactEnterPinPageApplicant(KofaPage):
[15755]121    """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageApplicant`
[15702]122    """
123    grok.require('waeup.payApplicant')
124    grok.context(INigeriaApplicantOnlinePayment)
[15771]125    grok.name('enterpin')
126    grok.template('enterpin')
[15702]127
[15796]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
[15771]134    def update(self):
[15772]135        if not payoutlet_module_activated(
[15771]136            self.context.__parent__.__parent__.year, self.context):
[15974]137            self.flash(_('Forbidden'), type='danger')
138            self.redirect(self.url(self.context, '@@index'))
[15771]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
[15796]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
[15702]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
[15730]176    host = HOST
177    https = HTTPS
[15702]178
179    def update(self, confirmation_number=None):
[15772]180        if not payoutlet_module_activated(
[15770]181            self.context.student.current_session, self.context):
[15974]182            self.flash(_('Forbidden'), type='danger')
183            self.redirect(self.url(self.context, '@@index'))
[15702]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(
[15730]190            self.host, self.terminal_id, confirmation_number,
191            self.context, self.https)
[15702]192        student.writeLogMessage(self, log)
193        if not success:
[15788]194            self.flash(msg, type="danger")
[15702]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
[15730]213    host = HOST
214    https = HTTPS
[15702]215
216    def update(self, confirmation_number=None):
[15772]217        if not payoutlet_module_activated(
[15770]218            self.context.__parent__.__parent__.year, self.context):
[15974]219            self.flash(_('Forbidden'), type='danger')
220            self.redirect(self.url(self.context, '@@index'))
[15702]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(
[15730]227            self.host, self.terminal_id, confirmation_number,
228            self.context, self.https)
[15702]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.