source: main/waeup.kofa/trunk/src/waeup/kofa/students/payments.py @ 8428

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

Payment methods do now all return a success flag, a flash message string and a log string. All these adjustments are necessary for waeup.uniben.

  • Property svn:keywords set to Id
File size: 4.0 KB
Line 
1## $Id: payments.py 8428 2012-05-12 07:01:04Z henrik $
2##
3## Copyright (C) 2011 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##
18"""
19Student payment components.
20"""
21import grok
22from zope.component.interfaces import IFactory
23from zope.interface import implementedBy
24from waeup.kofa.interfaces import MessageFactory as _
25from waeup.kofa.students.interfaces import (
26    IStudentPaymentsContainer, IStudentNavigation, IStudentOnlinePayment)
27from waeup.kofa.payments import PaymentsContainer, OnlinePayment
28from waeup.kofa.utils.helpers import attrs_to_fields
29from waeup.kofa.accesscodes import create_accesscode
30
31class StudentPaymentsContainer(PaymentsContainer):
32    """This is a container for student payments.
33    """
34    grok.implements(IStudentPaymentsContainer, IStudentNavigation)
35    grok.provides(IStudentPaymentsContainer)
36
37    def __init__(self):
38        super(StudentPaymentsContainer, self).__init__()
39        return
40
41    def getStudent(self):
42        return self.__parent__
43
44StudentPaymentsContainer = attrs_to_fields(StudentPaymentsContainer)
45
46class StudentOnlinePayment(OnlinePayment):
47    """This is an online payment.
48    """
49    grok.implements(IStudentOnlinePayment, IStudentNavigation)
50    grok.provides(IStudentOnlinePayment)
51
52    def __init__(self):
53        super(StudentOnlinePayment, self).__init__()
54        return
55
56    def getStudent(self):
57        try:
58            return self.__parent__.__parent__
59        except AttributeError:
60            return None
61
62    def doAfterStudentPayment(self):
63        """Process student after payment was made.
64        """
65        student = self.getStudent()
66        if self.p_category == 'clearance':
67            # Create CLR access code
68            pin, error = create_accesscode(
69                'CLR',0,self.amount_auth,student.student_id)
70            if error:
71                return False, error, error
72            self.ac = pin
73        elif self.p_category == 'schoolfee':
74            # Create SFE access code
75            pin, error = create_accesscode(
76                'SFE',0,self.amount_auth,student.student_id)
77            if error:
78                return False, error, error
79            self.ac = pin
80        elif self.p_category == 'bed_allocation':
81            # Create HOS access code
82            pin, error = create_accesscode(
83                'HOS',0,self.amount_auth,student.student_id)
84            if error:
85                return False, error, error
86            self.ac = pin
87        log = 'successful payment: %s' % self.p_id
88        msg = _('Successful payment')
89        return True, msg, log
90
91    def approveStudentPayment(self):
92        """Approve payment and process student.
93        """
94        if self.p_state == 'paid':
95            return False, _('This ticket has already been paid.'), None
96        self.approve()
97        return self.doAfterStudentPayment()
98
99
100StudentOnlinePayment = attrs_to_fields(StudentOnlinePayment)
101
102# Student online payments must be importable. So we might need a factory.
103class StudentOnlinePaymentFactory(grok.GlobalUtility):
104    """A factory for student online payments.
105    """
106    grok.implements(IFactory)
107    grok.name(u'waeup.StudentOnlinePayment')
108    title = u"Create a new online payment.",
109    description = u"This factory instantiates new online payment instances."
110
111    def __call__(self, *args, **kw):
112        return StudentOnlinePayment()
113
114    def getInterfaces(self):
115        return implementedBy(StudentOnlinePayment)
Note: See TracBrowser for help on using the repository browser.