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

Last change on this file since 8431 was 8428, checked in by Henrik Bettermann, 13 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
RevLine 
[7191]1## $Id: payments.py 8428 2012-05-12 07:01:04Z henrik $
2##
[6635]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"""
[7599]19Student payment components.
[6635]20"""
21import grok
22from zope.component.interfaces import IFactory
[6875]23from zope.interface import implementedBy
[8420]24from waeup.kofa.interfaces import MessageFactory as _
[7811]25from waeup.kofa.students.interfaces import (
[6877]26    IStudentPaymentsContainer, IStudentNavigation, IStudentOnlinePayment)
[7811]27from waeup.kofa.payments import PaymentsContainer, OnlinePayment
28from waeup.kofa.utils.helpers import attrs_to_fields
[8420]29from waeup.kofa.accesscodes import create_accesscode
[6635]30
[6860]31class StudentPaymentsContainer(PaymentsContainer):
[6635]32    """This is a container for student payments.
33    """
[6860]34    grok.implements(IStudentPaymentsContainer, IStudentNavigation)
35    grok.provides(IStudentPaymentsContainer)
[6635]36
37    def __init__(self):
[6860]38        super(StudentPaymentsContainer, self).__init__()
[6635]39        return
40
[6642]41    def getStudent(self):
42        return self.__parent__
43
[6875]44StudentPaymentsContainer = attrs_to_fields(StudentPaymentsContainer)
45
46class StudentOnlinePayment(OnlinePayment):
47    """This is an online payment.
48    """
[6877]49    grok.implements(IStudentOnlinePayment, IStudentNavigation)
50    grok.provides(IStudentOnlinePayment)
[6875]51
52    def __init__(self):
53        super(StudentOnlinePayment, self).__init__()
54        return
55
56    def getStudent(self):
[8368]57        try:
58            return self.__parent__.__parent__
59        except AttributeError:
60            return None
[6875]61
[8422]62    def doAfterStudentPayment(self):
63        """Process student after payment was made.
[8420]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:
[8428]71                return False, error, error
[8420]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:
[8428]78                return False, error, error
[8420]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:
[8428]85                return False, error, error
[8420]86            self.ac = pin
[8428]87        log = 'successful payment: %s' % self.p_id
88        msg = _('Successful payment')
89        return True, msg, log
[8420]90
[8422]91    def approveStudentPayment(self):
92        """Approve payment and process student.
93        """
94        if self.p_state == 'paid':
[8428]95            return False, _('This ticket has already been paid.'), None
[8422]96        self.approve()
97        return self.doAfterStudentPayment()
98
99
[6875]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):
[7811]115        return implementedBy(StudentOnlinePayment)
Note: See TracBrowser for help on using the repository browser.