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

Last change on this file since 8638 was 8453, checked in by Henrik Bettermann, 13 years ago

Applicants must not trigger the the approve transition which lead to wrong history message.

Distinguish between payment approval and regular payment in log files too.

  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1## $Id: payments.py 8453 2012-05-15 20:29:34Z 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 doAfterStudentPaymentApproval(self):
92        """Process student after payment was approved.
93        """
94        student = self.getStudent()
95        if self.p_category == 'clearance':
96            # Create CLR access code
97            pin, error = create_accesscode(
98                'CLR',0,self.amount_auth,student.student_id)
99            if error:
100                return False, error, error
101            self.ac = pin
102        elif self.p_category == 'schoolfee':
103            # Create SFE access code
104            pin, error = create_accesscode(
105                'SFE',0,self.amount_auth,student.student_id)
106            if error:
107                return False, error, error
108            self.ac = pin
109        elif self.p_category == 'bed_allocation':
110            # Create HOS access code
111            pin, error = create_accesscode(
112                'HOS',0,self.amount_auth,student.student_id)
113            if error:
114                return False, error, error
115            self.ac = pin
116        log = 'payment approved: %s' % self.p_id
117        msg = _('Payment approved')
118        return True, msg, log
119
120    def approveStudentPayment(self):
121        """Approve payment and process student.
122        """
123        if self.p_state == 'paid':
124            return False, _('This ticket has already been paid.'), None
125        self.approve()
126        return self.doAfterStudentPayment()
127
128
129StudentOnlinePayment = attrs_to_fields(StudentOnlinePayment)
130
131# Student online payments must be importable. So we might need a factory.
132class StudentOnlinePaymentFactory(grok.GlobalUtility):
133    """A factory for student online payments.
134    """
135    grok.implements(IFactory)
136    grok.name(u'waeup.StudentOnlinePayment')
137    title = u"Create a new online payment.",
138    description = u"This factory instantiates new online payment instances."
139
140    def __call__(self, *args, **kw):
141        return StudentOnlinePayment()
142
143    def getInterfaces(self):
144        return implementedBy(StudentOnlinePayment)
Note: See TracBrowser for help on using the repository browser.