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

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

Add more attributes to webservice adapter.

  • Property svn:keywords set to Id
File size: 5.8 KB
RevLine 
[7191]1## $Id: payments.py 8708 2012-06-13 13:29:35Z 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
[8703]28from waeup.kofa.payments.interfaces import IPaymentWebservice
[7811]29from waeup.kofa.utils.helpers import attrs_to_fields
[8420]30from waeup.kofa.accesscodes import create_accesscode
[6635]31
[6860]32class StudentPaymentsContainer(PaymentsContainer):
[6635]33    """This is a container for student payments.
34    """
[6860]35    grok.implements(IStudentPaymentsContainer, IStudentNavigation)
36    grok.provides(IStudentPaymentsContainer)
[6635]37
38    def __init__(self):
[6860]39        super(StudentPaymentsContainer, self).__init__()
[6635]40        return
41
[6642]42    def getStudent(self):
43        return self.__parent__
44
[6875]45StudentPaymentsContainer = attrs_to_fields(StudentPaymentsContainer)
46
47class StudentOnlinePayment(OnlinePayment):
48    """This is an online payment.
49    """
[6877]50    grok.implements(IStudentOnlinePayment, IStudentNavigation)
51    grok.provides(IStudentOnlinePayment)
[6875]52
53    def __init__(self):
54        super(StudentOnlinePayment, self).__init__()
55        return
56
57    def getStudent(self):
[8368]58        try:
59            return self.__parent__.__parent__
60        except AttributeError:
61            return None
[6875]62
[8422]63    def doAfterStudentPayment(self):
64        """Process student after payment was made.
[8420]65        """
66        student = self.getStudent()
67        if self.p_category == 'clearance':
68            # Create CLR access code
69            pin, error = create_accesscode(
70                'CLR',0,self.amount_auth,student.student_id)
71            if error:
[8428]72                return False, error, error
[8420]73            self.ac = pin
74        elif self.p_category == 'schoolfee':
75            # Create SFE access code
76            pin, error = create_accesscode(
77                'SFE',0,self.amount_auth,student.student_id)
78            if error:
[8428]79                return False, error, error
[8420]80            self.ac = pin
81        elif self.p_category == 'bed_allocation':
82            # Create HOS access code
83            pin, error = create_accesscode(
84                'HOS',0,self.amount_auth,student.student_id)
85            if error:
[8428]86                return False, error, error
[8420]87            self.ac = pin
[8428]88        log = 'successful payment: %s' % self.p_id
89        msg = _('Successful payment')
90        return True, msg, log
[8420]91
[8453]92    def doAfterStudentPaymentApproval(self):
93        """Process student after payment was approved.
94        """
95        student = self.getStudent()
96        if self.p_category == 'clearance':
97            # Create CLR access code
98            pin, error = create_accesscode(
99                'CLR',0,self.amount_auth,student.student_id)
100            if error:
101                return False, error, error
102            self.ac = pin
103        elif self.p_category == 'schoolfee':
104            # Create SFE access code
105            pin, error = create_accesscode(
106                'SFE',0,self.amount_auth,student.student_id)
107            if error:
108                return False, error, error
109            self.ac = pin
110        elif self.p_category == 'bed_allocation':
111            # Create HOS access code
112            pin, error = create_accesscode(
113                'HOS',0,self.amount_auth,student.student_id)
114            if error:
115                return False, error, error
116            self.ac = pin
117        log = 'payment approved: %s' % self.p_id
118        msg = _('Payment approved')
119        return True, msg, log
120
[8422]121    def approveStudentPayment(self):
122        """Approve payment and process student.
123        """
124        if self.p_state == 'paid':
[8428]125            return False, _('This ticket has already been paid.'), None
[8422]126        self.approve()
127        return self.doAfterStudentPayment()
128
129
[6875]130StudentOnlinePayment = attrs_to_fields(StudentOnlinePayment)
131
[8703]132class PaymentWebservice(grok.Adapter):
133    """An adapter to publish student data through a webservice.
134    """
135    grok.context(IStudentOnlinePayment)
136    grok.implements(IPaymentWebservice)
137
138    @property
[8708]139    def display_fullname(self):
140        "Name of  payee."
[8703]141        return self.context.getStudent().display_fullname
142
[8708]143    @property
144    def id(self):
145        "Id of payee"
146        return self.context.getStudent().student_id
147
148    @property
149    def faculty(self):
150        "Faculty of payee"
151        return self.context.getStudent().faccode
152
153    @property
154    def department(self):
155        "Department of payee"
156        return self.context.getStudent().depcode
157
[6875]158# Student online payments must be importable. So we might need a factory.
159class StudentOnlinePaymentFactory(grok.GlobalUtility):
160    """A factory for student online payments.
161    """
162    grok.implements(IFactory)
163    grok.name(u'waeup.StudentOnlinePayment')
164    title = u"Create a new online payment.",
165    description = u"This factory instantiates new online payment instances."
166
167    def __call__(self, *args, **kw):
168        return StudentOnlinePayment()
169
170    def getInterfaces(self):
[7811]171        return implementedBy(StudentOnlinePayment)
Note: See TracBrowser for help on using the repository browser.