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

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

Prepare all payment gateway modules for net amount fee configuration. In the future, provider and gateway surcharges will be determined and added just before the data are being send to the gateways for the first time.

File size: 7.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
33from kofacustom.nigeria.interswitch.browser import (
34    InterswitchActionButtonStudent,
35    InterswitchRequestWebserviceActionButtonStudent,
36    InterswitchActionButtonApplicant,
37    InterswitchRequestWebserviceActionButtonApplicant)
38from kofacustom.nigeria.interfaces import MessageFactory as _
39from kofacustom.nigeria.students.interfaces import INigeriaStudentOnlinePayment
40from kofacustom.nigeria.applicants.interfaces import INigeriaApplicantOnlinePayment
[15755]41from kofacustom.nigeria.etranzact.tests import HOST, TERMINAL_ID, HTTPS, GATEWAY_AMT
[15730]42from kofacustom.nigeria.etranzact.helpers import query_payoutlet
[15702]43
44grok.templatedir('browser_templates')
45
46def 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
53class 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 ''
[15730]65        if self.context.p_state in ('paid', 'waived'):
[15702]66            return ''
67        return self.view.url(self.view.context, self.target)
68
69class 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 ''
[15730]81        if self.context.p_state in ('paid', 'waived'):
[15702]82            return ''
83        return self.view.url(self.view.context, self.target)
84
85class EtranzactEnterPinPageStudent(KofaPage):
[15755]86    """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageStudent`
[15702]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)')
[15755]97    gateway_amt = GATEWAY_AMT
[15702]98
99    def update(self):
100        if not module_activated(self.context.student.current_session):
101            return
[15755]102        if self.context.r_company and self.context.r_company != 'etranzact':
103            return _("Payment ticket has been used for another payment gateway.")
[15702]104        super(EtranzactEnterPinPageStudent, self).update()
[15755]105        # Already now it becomes an Etranzact payment. We set the net amount
106        # and add the gateway amount.
107        if not self.context.r_company:
108            self.context.net_amt = self.context.amount_auth
109            self.context.amount_auth += self.gateway_amt
110            self.context.gateway_amt = self.gateway_amt
111            self.context.r_company = u'etranzact'
[15702]112        return
113
114class EtranzactEnterPinPageApplicant(EtranzactEnterPinPageStudent):
[15755]115    """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageApplicant`
[15702]116    """
117    grok.require('waeup.payApplicant')
118    grok.context(INigeriaApplicantOnlinePayment)
119
120class EtranzactQueryHistoryPageStudent(UtilityView, grok.View):
121    """ Query history of Etranzact payments
122    """
123    grok.context(INigeriaStudentOnlinePayment)
124    grok.name('query_payoutlet_history')
125    grok.require('waeup.payStudent')
126    terminal_id = TERMINAL_ID
[15730]127    host = HOST
128    https = HTTPS
[15702]129
130    def update(self, confirmation_number=None):
131        if not module_activated(self.context.student.current_session):
132            return
133        if self.context.p_state == 'paid':
134            self.flash(_('This ticket has already been paid.'))
135            return
136        student = self.context.student
137        success, msg, log = query_payoutlet(
[15730]138            self.host, self.terminal_id, confirmation_number,
139            self.context, self.https)
[15702]140        student.writeLogMessage(self, log)
141        if not success:
142            self.flash(msg)
143            return
144        flashtype, msg, log = self.context.doAfterStudentPayment()
145        if log is not None:
146            student.writeLogMessage(self, log)
147        self.flash(msg, type=flashtype)
148        return
149
150    def render(self):
151        self.redirect(self.url(self.context, '@@index'))
152        return
153
154class EtranzactQueryHistoryPageApplicant(UtilityView, grok.View):
155    """ Query history of Etranzact payments
156    """
157    grok.context(INigeriaApplicantOnlinePayment)
158    grok.name('query_payoutlet_history')
159    grok.require('waeup.payApplicant')
160    terminal_id = TERMINAL_ID
[15730]161    host = HOST
162    https = HTTPS
[15702]163
164    def update(self, confirmation_number=None):
165        if not module_activated(self.context.__parent__.__parent__.year):
166            return
167        if self.context.p_state == 'paid':
168            self.flash(_('This ticket has already been paid.'))
169            return
170        applicant = self.context.__parent__
171        success, msg, log = query_payoutlet(
[15730]172            self.host, self.terminal_id, confirmation_number,
173            self.context, self.https)
[15702]174        applicant.writeLogMessage(self, log)
175        if not success:
176            self.flash(msg)
177            return
178        flashtype, msg, log = self.context.doAfterApplicantPayment()
179        if log is not None:
180            applicant.writeLogMessage(self, log)
181        self.flash(msg, type=flashtype)
182        return
183
184    def render(self):
185        self.redirect(self.url(self.context, '@@index'))
186        return
Note: See TracBrowser for help on using the repository browser.