source: main/kofacustom.nigeria/branches/0.1/src/kofacustom/nigeria/interswitch/browser.py @ 17952

Last change on this file since 17952 was 9781, checked in by Henrik Bettermann, 12 years ago

Define buttons and pages in kofacustom. These views are the same for all portals.

  • Property svn:keywords set to Id
File size: 4.8 KB
Line 
1## $Id: browser.py 9781 2012-12-07 08:21:24Z 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##
18import grok
19from waeup.kofa.browser.layout import UtilityView
20from waeup.kofa.browser.viewlets import ManageActionButton
21from waeup.kofa.students.browser import OnlinePaymentDisplayFormPage as OPDPStudent
22from waeup.kofa.applicants.browser import OnlinePaymentDisplayFormPage as OPDPApplicant
23from kofacustom.nigeria.interswitch.helpers import (
24    query_interswitch, write_payments_log)
25from kofacustom.nigeria.payments.interfaces import INigeriaOnlinePayment
26from kofacustom.nigeria.students.interfaces import INigeriaStudentOnlinePayment
27from kofacustom.nigeria.applicants.interfaces import INigeriaApplicantOnlinePayment
28from kofacustom.nigeria.interfaces import MessageFactory as _
29
30class InterswitchActionButtonStudent(ManageActionButton):
31    grok.order(1)
32    grok.context(INigeriaOnlinePayment)
33    grok.view(OPDPStudent)
34    grok.require('waeup.payStudent')
35    icon = 'actionicon_pay.png'
36    text = _('CollegePAY')
37    target = 'goto_interswitch'
38
39    @property
40    def target_url(self):
41        if self.context.p_state != 'unpaid':
42            return ''
43        return self.view.url(self.view.context, self.target)
44
45class InterswitchActionButtonApplicant(InterswitchActionButtonStudent):
46    grok.view(OPDPApplicant)
47    grok.require('waeup.payApplicant')
48
49class InterswitchRequestWebserviceActionButtonStudent(ManageActionButton):
50    grok.order(2)
51    grok.context(INigeriaOnlinePayment)
52    grok.view(OPDPStudent)
53    grok.require('waeup.payStudent')
54    icon = 'actionicon_call.png'
55    text = _('Requery CollegePAY')
56    target = 'request_webservice'
57
58    @property
59    def target_url(self):
60        if self.context.p_state == 'paid':
61            return ''
62        return self.view.url(self.view.context, self.target)
63
64class InterswitchRequestWebserviceActionButtonApplicant(
65    InterswitchRequestWebserviceActionButtonStudent):
66    grok.view(OPDPApplicant)
67    grok.require('waeup.payApplicant')
68
69class InterswitchPaymentRequestWebservicePageStudent(UtilityView, grok.View):
70    """ Request webservice view for the CollegePAY gateway
71    """
72    grok.context(INigeriaStudentOnlinePayment)
73    grok.name('request_webservice')
74    grok.require('waeup.payStudent')
75
76    product_id = None
77    gateway_host = None
78    gateway_url = None
79
80    def update(self):
81        if self.context.p_state == 'paid':
82            self.flash(_('This ticket has already been paid.'))
83            return
84        student = self.context.student
85        success, msg, log = query_interswitch(
86            self.context, self.product_id, self.gateway_host, self.gateway_url)
87        student.writeLogMessage(self, log)
88        if not success:
89            self.flash(msg)
90            return
91        write_payments_log(student.student_id, self.context)
92        success, msg, log = self.context.doAfterStudentPayment()
93        if log is not None:
94            student.writeLogMessage(self, log)
95        self.flash(msg)
96        return
97
98    def render(self):
99        self.redirect(self.url(self.context, '@@index'))
100        return
101
102class InterswitchPaymentRequestWebservicePageApplicant(UtilityView, grok.View):
103    """ Request webservice view for the CollegePAY gateway
104    """
105    grok.context(INigeriaApplicantOnlinePayment)
106    grok.name('request_webservice')
107    grok.require('waeup.payApplicant')
108
109    product_id = None
110    gateway_host = None
111    gateway_url = None
112
113    def update(self):
114        if self.context.p_state == 'paid':
115            self.flash(_('This ticket has already been paid.'))
116            return
117        applicant = self.context.__parent__
118        success, msg, log = query_interswitch(
119            self.context, self.product_id, self.gateway_host, self.gateway_url)
120        applicant.writeLogMessage(self, log)
121        if not success:
122            self.flash(msg)
123            return
124        write_payments_log(applicant.applicant_id, self.context)
125        success, msg, log = self.context.doAfterApplicantPayment()
126        if log is not None:
127            applicant.writeLogMessage(self, log)
128        self.flash(msg)
129        return
130
131    def render(self):
132        self.redirect(self.url(self.context, '@@index'))
133        return
Note: See TracBrowser for help on using the repository browser.