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

Last change on this file since 13434 was 13398, checked in by Henrik Bettermann, 9 years ago

All kind of school fee payments trigger the same actions. AAUE installment payment is deprecated.

  • Property svn:keywords set to Id
File size: 7.7 KB
Line 
1## $Id: payments.py 13398 2015-11-06 10:59:22Z 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 zope.schema.interfaces import ConstraintNotSatisfied
25from hurry.workflow.interfaces import IWorkflowInfo
26from waeup.kofa.interfaces import MessageFactory as _
27from waeup.kofa.students.interfaces import (
28    IStudentPaymentsContainer, IStudentNavigation, IStudentOnlinePayment)
29from waeup.kofa.students.workflow import CLEARED, RETURNING, PAID
30from waeup.kofa.payments import PaymentsContainer, OnlinePayment
31from waeup.kofa.payments.interfaces import IPayer
32from waeup.kofa.utils.helpers import attrs_to_fields
33from waeup.kofa.accesscodes import create_accesscode
34
35class StudentPaymentsContainer(PaymentsContainer):
36    """This is a container for student payments.
37    """
38    grok.implements(IStudentPaymentsContainer, IStudentNavigation)
39    grok.provides(IStudentPaymentsContainer)
40
41    def __init__(self):
42        super(StudentPaymentsContainer, self).__init__()
43        return
44
45    @property
46    def student(self):
47        return self.__parent__
48
49    def writeLogMessage(self, view, message):
50        return self.__parent__.writeLogMessage(view, message)
51
52StudentPaymentsContainer = attrs_to_fields(StudentPaymentsContainer)
53
54class StudentOnlinePayment(OnlinePayment):
55    """This is an online payment.
56    """
57    grok.implements(IStudentOnlinePayment, IStudentNavigation)
58    grok.provides(IStudentOnlinePayment)
59
60    def __init__(self):
61        super(StudentOnlinePayment, self).__init__()
62        return
63
64    @property
65    def student(self):
66        try:
67            return self.__parent__.__parent__
68        except AttributeError:
69            return None
70
71    def writeLogMessage(self, view, message):
72        return self.__parent__.__parent__.writeLogMessage(view, message)
73
74    def redeemTicket(self):
75        """Either create an appropriate access code or trigger an action
76        directly.
77        """
78        student = self.student
79        if self.p_category == 'clearance':
80            # Create CLR access code
81            pin, error = create_accesscode(
82                'CLR',0,self.amount_auth,student.student_id)
83            if error:
84                return error
85            self.ac = pin
86        elif self.p_category.startswith('schoolfee'):
87            # Bypass activation code creation if next session
88            # can be started directly.
89            if student['studycourse'].next_session_allowed:
90                try:
91                    if student.state == CLEARED:
92                        IWorkflowInfo(student).fireTransition(
93                            'pay_first_school_fee')
94                        return None
95                    elif student.state == RETURNING:
96                        IWorkflowInfo(student).fireTransition(
97                            'pay_school_fee')
98                        return None
99                    elif student.state == PAID:
100                        IWorkflowInfo(student).fireTransition(
101                            'pay_pg_fee')
102                        return None
103                except ConstraintNotSatisfied:
104                    pass
105            # Create SFE access code
106            pin, error = create_accesscode(
107                'SFE',0,self.amount_auth,student.student_id)
108            if error:
109                return error
110            self.ac = pin
111        elif self.p_category == 'bed_allocation':
112            # Create HOS access code
113            pin, error = create_accesscode(
114                'HOS',0,self.amount_auth,student.student_id)
115            if error:
116                return error
117            self.ac = pin
118        elif self.p_category == 'transcript':
119            # Create TSC access code
120            pin, error = create_accesscode(
121                'TSC',0,self.amount_auth,student.student_id)
122            if error:
123                return error
124            self.ac = pin
125        return None
126
127    def doAfterStudentPayment(self):
128        """Process student after payment was made.
129        """
130        if self.p_current:
131            error = self.redeemTicket()
132            if error is not None:
133                return 'danger', error, error
134        log = 'successful %s payment: %s' % (self.p_category, self.p_id)
135        msg = _('Successful payment')
136        flashtype = 'success'
137        return flashtype, msg, log
138
139    def doAfterStudentPaymentApproval(self):
140        """Process student after payment was approved.
141        """
142        if self.p_current:
143            error = self.redeemTicket()
144            if error is not None:
145                return 'danger', error, error
146        log = '%s payment approved: %s' % (self.p_category, self.p_id)
147        msg = _('Payment approved.')
148        flashtype = 'success'
149        return flashtype, msg, log
150
151    def approveStudentPayment(self):
152        """Approve payment and process student.
153        """
154        if self.p_state == 'paid':
155            return 'warning', _('This ticket has already been paid.'), None
156        self.approve()
157        return self.doAfterStudentPaymentApproval()
158
159
160StudentOnlinePayment = attrs_to_fields(
161    StudentOnlinePayment, omit=['display_item'])
162
163class Payer(grok.Adapter):
164    """An adapter to publish student data through a simple webservice.
165    """
166    grok.context(IStudentOnlinePayment)
167    grok.implements(IPayer)
168
169    @property
170    def display_fullname(self):
171        "Name of  payer"
172        return self.context.student.display_fullname
173
174    @property
175    def id(self):
176        "Id of payer"
177        return self.context.student.student_id
178
179    @property
180    def matric_number(self):
181        "Matric number or reg number of payer"
182        return self.context.student.matric_number
183
184    @property
185    def reg_number(self):
186        "Reg number or reg number of payer"
187        return self.context.student.reg_number
188
189    @property
190    def faculty(self):
191        "Faculty of payer"
192        return self.context.student.faccode
193
194    @property
195    def department(self):
196        "Department of payer"
197        return self.context.student.depcode
198
199    @property
200    def email(self):
201        "Email of payer"
202        return self.context.student.email
203
204    @property
205    def phone(self):
206        "Phone number of payer"
207        return self.context.student.phone
208
209    @property
210    def current_mode(self):
211        "Current study mode of payer"
212        return self.context.student.current_mode
213
214    @property
215    def current_level(self):
216        "Current level of payer"
217        return self.context.student.current_level
218
219# Student online payments must be importable. So we might need a factory.
220class StudentOnlinePaymentFactory(grok.GlobalUtility):
221    """A factory for student online payments.
222    """
223    grok.implements(IFactory)
224    grok.name(u'waeup.StudentOnlinePayment')
225    title = u"Create a new online payment.",
226    description = u"This factory instantiates new online payment instances."
227
228    def __call__(self, *args, **kw):
229        return StudentOnlinePayment()
230
231    def getInterfaces(self):
232        return implementedBy(StudentOnlinePayment)
Note: See TracBrowser for help on using the repository browser.