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

Last change on this file since 13292 was 13042, checked in by Henrik Bettermann, 10 years ago

Rename method. Private methods are not found by Sphinx.

  • Property svn:keywords set to Id
File size: 7.7 KB
RevLine 
[7191]1## $Id: payments.py 13042 2015-06-12 06:54:59Z 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
[8735]49    def writeLogMessage(self, view, message):
50        return self.__parent__.writeLogMessage(view, message)
51
[6875]52StudentPaymentsContainer = attrs_to_fields(StudentPaymentsContainer)
53
54class StudentOnlinePayment(OnlinePayment):
55    """This is an online payment.
56    """
[6877]57    grok.implements(IStudentOnlinePayment, IStudentNavigation)
58    grok.provides(IStudentOnlinePayment)
[6875]59
60    def __init__(self):
61        super(StudentOnlinePayment, self).__init__()
62        return
63
[8736]64    @property
65    def student(self):
[8368]66        try:
67            return self.__parent__.__parent__
68        except AttributeError:
69            return None
[6875]70
[8735]71    def writeLogMessage(self, view, message):
72        return self.__parent__.__parent__.writeLogMessage(view, message)
73
[13042]74    def redeemTicket(self):
75        """Either create an appropriate access code or trigger an action
76        directly.
77        """
[8736]78        student = self.student
[8420]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:
[8732]84                return error
[8420]85            self.ac = pin
[8732]86        elif self.p_category in ('schoolfee', 'schoolfee_1'):
[12889]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
[8420]105            # Create SFE access code
106            pin, error = create_accesscode(
107                'SFE',0,self.amount_auth,student.student_id)
108            if error:
[8732]109                return error
[8420]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:
[8732]116                return error
[8420]117            self.ac = pin
[10449]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
[8732]125        return None
126
127    def doAfterStudentPayment(self):
128        """Process student after payment was made.
129        """
[9148]130        if self.p_current:
[13042]131            error = self.redeemTicket()
[9148]132            if error is not None:
[11580]133                return 'danger', error, error
[9438]134        log = 'successful %s payment: %s' % (self.p_category, self.p_id)
[8428]135        msg = _('Successful payment')
[11580]136        flashtype = 'success'
137        return flashtype, msg, log
[8420]138
[8453]139    def doAfterStudentPaymentApproval(self):
140        """Process student after payment was approved.
141        """
[9148]142        if self.p_current:
[13042]143            error = self.redeemTicket()
[9148]144            if error is not None:
[11580]145                return 'danger', error, error
[9438]146        log = '%s payment approved: %s' % (self.p_category, self.p_id)
[11583]147        msg = _('Payment approved.')
[11580]148        flashtype = 'success'
149        return flashtype, msg, log
[8453]150
[8422]151    def approveStudentPayment(self):
152        """Approve payment and process student.
153        """
154        if self.p_state == 'paid':
[11580]155            return 'warning', _('This ticket has already been paid.'), None
[8422]156        self.approve()
[8732]157        return self.doAfterStudentPaymentApproval()
[8422]158
159
[9984]160StudentOnlinePayment = attrs_to_fields(
161    StudentOnlinePayment, omit=['display_item'])
[6875]162
[10030]163class Payer(grok.Adapter):
164    """An adapter to publish student data through a simple webservice.
[8703]165    """
166    grok.context(IStudentOnlinePayment)
[10030]167    grok.implements(IPayer)
[8703]168
169    @property
[8708]170    def display_fullname(self):
[10030]171        "Name of  payer"
[8736]172        return self.context.student.display_fullname
[8703]173
[8708]174    @property
175    def id(self):
[10030]176        "Id of payer"
[8736]177        return self.context.student.student_id
[8708]178
179    @property
[9733]180    def matric_number(self):
[10030]181        "Matric number or reg number of payer"
[9506]182        return self.context.student.matric_number
183
184    @property
[9733]185    def reg_number(self):
[10030]186        "Reg number or reg number of payer"
[9733]187        return self.context.student.reg_number
188
189    @property
[8708]190    def faculty(self):
[10030]191        "Faculty of payer"
[8736]192        return self.context.student.faccode
[8708]193
194    @property
195    def department(self):
[10030]196        "Department of payer"
[8736]197        return self.context.student.depcode
[8708]198
[10906]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
[6875]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):
[7811]232        return implementedBy(StudentOnlinePayment)
Note: See TracBrowser for help on using the repository browser.