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

Last change on this file since 17958 was 17248, checked in by Henrik Bettermann, 23 months ago

Enable Paypal only for USD payments.
Enable all other gateway services only for NGN payments.

File size: 9.3 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):
[17248]49    if payment.p_currency != 'NGN':
50        return False
[15770]51    if payment.r_company and payment.r_company != 'etranzact':
52        return False
[15702]53    try:
54        return getattr(grok.getSite()['configuration'][str(session)],
55            'etranzact_payoutlet_enabled', False)
56    except KeyError:
[16246]57        session = datetime.now().year
58        try:
59            return getattr(grok.getSite()['configuration'][str(session)],
60                'etranzact_payoutlet_enabled', False)
61        except KeyError:
62            return False
[15702]63
64class EtranzactEnterPinActionButtonApplicant(APABApplicant):
65    grok.context(INigeriaApplicantOnlinePayment)
66    grok.require('waeup.payApplicant')
67    grok.order(3)
[15796]68    icon = 'actionicon_pay.png'
69    text = _('Pay via Etranzact PayOutlet')
[15702]70    target = 'enterpin'
71
72    @property
73    def target_url(self):
[15772]74        if not payoutlet_module_activated(
[15770]75            self.context.__parent__.__parent__.year, self.context):
[15702]76            return ''
[15796]77        if self.context.p_state in ('paid', 'waived', 'scholarship'):
[15702]78            return ''
79        return self.view.url(self.view.context, self.target)
80
81class EtranzactEnterPinActionButtonStudent(APABStudent):
82    grok.context(INigeriaStudentOnlinePayment)
83    grok.require('waeup.payStudent')
[16484]84    grok.order(10)
[15796]85    icon = 'actionicon_pay.png'
86    text = _('Pay via Etranzact PayOutlet')
[15702]87    target = 'enterpin'
88
89    @property
90    def target_url(self):
[15772]91        if not payoutlet_module_activated(
[15770]92            self.context.student.current_session, self.context):
[15702]93            return ''
[15796]94        if self.context.p_state in ('paid', 'waived', 'scholarship'):
[15702]95            return ''
96        return self.view.url(self.view.context, self.target)
97
98class EtranzactEnterPinPageStudent(KofaPage):
[15755]99    """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageStudent`
[15702]100    """
101    grok.context(INigeriaStudentOnlinePayment)
102    grok.name('enterpin')
103    grok.template('enterpin')
104    grok.require('waeup.payStudent')
105
[16484]106    buttonname = _('Requery now')
[15796]107    label = _('Requery Etranzact PayOutlet History')
[15702]108    action = 'query_payoutlet_history'
109    placeholder = _('Confirmation Number (PIN)')
[15755]110    gateway_amt = GATEWAY_AMT
[15702]111
112    def update(self):
[15772]113        if not payoutlet_module_activated(
[15770]114            self.context.student.current_session, self.context):
[15974]115            self.flash(_('Forbidden'), type='danger')
116            self.redirect(self.url(self.context, '@@index'))
[15702]117            return
[15755]118        # Already now it becomes an Etranzact payment. We set the net amount
119        # and add the gateway amount.
120        if not self.context.r_company:
121            self.context.net_amt = self.context.amount_auth
122            self.context.amount_auth += self.gateway_amt
123            self.context.gateway_amt = self.gateway_amt
124            self.context.r_company = u'etranzact'
[15702]125        return
126
[15771]127class EtranzactEnterPinPageApplicant(KofaPage):
[15755]128    """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageApplicant`
[15702]129    """
130    grok.require('waeup.payApplicant')
131    grok.context(INigeriaApplicantOnlinePayment)
[15771]132    grok.name('enterpin')
133    grok.template('enterpin')
[15702]134
[16484]135    buttonname = _('Requery now')
[15796]136    label = _('Requery Etranzact PayOutlet History')
137    action = 'query_payoutlet_history'
138    placeholder = _('Confirmation Number (PIN)')
139    gateway_amt = GATEWAY_AMT
140
[15771]141    def update(self):
[15772]142        if not payoutlet_module_activated(
[15771]143            self.context.__parent__.__parent__.year, self.context):
[15974]144            self.flash(_('Forbidden'), type='danger')
145            self.redirect(self.url(self.context, '@@index'))
[15771]146            return
147        # Already now it becomes an Etranzact payment. We set the net amount
148        # and add the gateway amount.
149        if not self.context.r_company:
150            self.context.net_amt = self.context.amount_auth
151            self.context.amount_auth += self.gateway_amt
152            self.context.gateway_amt = self.gateway_amt
153            self.context.r_company = u'etranzact'
154        return
155
[15796]156class PayoutletPaymentReceiptActionButtonApplicant(PRABApplicant):
157
158    grok.view(EtranzactEnterPinPageApplicant)
159
160    @property
161    def target_url(self):
162        if not self.context.r_company:
163            return ''
164        return self.view.url(self.view.context, self.target)
165
166class PayoutletPaymentReceiptActionButtonStudent(PRABStudent):
167
168    grok.view(EtranzactEnterPinPageStudent)
169
170    @property
171    def target_url(self):
172        if not self.context.r_company:
173            return ''
174        return self.view.url(self.view.context, self.target)
175
[15702]176class EtranzactQueryHistoryPageStudent(UtilityView, grok.View):
177    """ Query history of Etranzact payments
178    """
179    grok.context(INigeriaStudentOnlinePayment)
180    grok.name('query_payoutlet_history')
181    grok.require('waeup.payStudent')
182    terminal_id = TERMINAL_ID
[15730]183    host = HOST
184    https = HTTPS
[15702]185
186    def update(self, confirmation_number=None):
[15772]187        if not payoutlet_module_activated(
[15770]188            self.context.student.current_session, self.context):
[15974]189            self.flash(_('Forbidden'), type='danger')
190            self.redirect(self.url(self.context, '@@index'))
[15702]191            return
192        if self.context.p_state == 'paid':
193            self.flash(_('This ticket has already been paid.'))
194            return
195        student = self.context.student
196        success, msg, log = query_payoutlet(
[15730]197            self.host, self.terminal_id, confirmation_number,
198            self.context, self.https)
[15702]199        student.writeLogMessage(self, log)
200        if not success:
[15788]201            self.flash(msg, type="danger")
[15702]202            return
203        flashtype, msg, log = self.context.doAfterStudentPayment()
204        if log is not None:
205            student.writeLogMessage(self, log)
206        self.flash(msg, type=flashtype)
207        return
208
209    def render(self):
210        self.redirect(self.url(self.context, '@@index'))
211        return
212
213class EtranzactQueryHistoryPageApplicant(UtilityView, grok.View):
214    """ Query history of Etranzact payments
215    """
216    grok.context(INigeriaApplicantOnlinePayment)
217    grok.name('query_payoutlet_history')
218    grok.require('waeup.payApplicant')
219    terminal_id = TERMINAL_ID
[15730]220    host = HOST
221    https = HTTPS
[15702]222
223    def update(self, confirmation_number=None):
[15772]224        if not payoutlet_module_activated(
[15770]225            self.context.__parent__.__parent__.year, self.context):
[15974]226            self.flash(_('Forbidden'), type='danger')
227            self.redirect(self.url(self.context, '@@index'))
[15702]228            return
229        if self.context.p_state == 'paid':
230            self.flash(_('This ticket has already been paid.'))
231            return
232        applicant = self.context.__parent__
233        success, msg, log = query_payoutlet(
[15730]234            self.host, self.terminal_id, confirmation_number,
235            self.context, self.https)
[15702]236        applicant.writeLogMessage(self, log)
237        if not success:
238            self.flash(msg)
239            return
240        flashtype, msg, log = self.context.doAfterApplicantPayment()
241        if log is not None:
242            applicant.writeLogMessage(self, log)
243        self.flash(msg, type=flashtype)
244        return
245
246    def render(self):
247        self.redirect(self.url(self.context, '@@index'))
248        return
Note: See TracBrowser for help on using the repository browser.