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

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

Show certificate-specific p_level value on payment pages.
Ensure that only allowed payment levels can be selected when
adding a balance payment.

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