source: main/kofacustom.nigeria/branches/uli-paypal/src/kofacustom/nigeria/etranzact/payoutletbrowser.py @ 17929

Last change on this file since 17929 was 16484, checked in by Henrik Bettermann, 3 years ago

Implement PAYDirect Bank Branch payment.

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