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

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

Add getOwner method to payments which is needed for the webservice.

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