source: main/waeup.aaue/trunk/src/waeup/aaue/students/payments.py @ 13402

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

Reconfigure payments according to ticket #129. Some tests are still missing. Do not upgrade!

  • Property svn:keywords set to Id
File size: 4.0 KB
RevLine 
[8247]1## $Id: payments.py 13400 2015-11-06 18:29:20Z 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
[13043]24from zope.schema.interfaces import ConstraintNotSatisfied
25from hurry.workflow.interfaces import IWorkflowInfo
[8247]26from waeup.kofa.students.interfaces import IStudentNavigation
[8712]27from waeup.kofa.students.payments import (
28    StudentOnlinePayment, StudentOnlinePaymentFactory)
[13049]29from waeup.kofa.students.workflow import CLEARED, RETURNING, PAID
[8247]30from waeup.kofa.utils.helpers import attrs_to_fields
[11622]31from waeup.kofa.accesscodes import create_accesscode
[8444]32from waeup.aaue.students.interfaces import ICustomStudentOnlinePayment
[8247]33
[8421]34class CustomStudentOnlinePayment(StudentOnlinePayment):
35    """This is a custom online payment for students.
36
37    Since this class inherits from StudentOnlinePayment, it automatically
38    implements the interfaces of the parent class which means
39    all viewlets and views meant for StudentOnlinePayment
40    can also be accessed in the customized system.
[8247]41    """
42    grok.implements(ICustomStudentOnlinePayment, IStudentNavigation)
43    grok.provides(ICustomStudentOnlinePayment)
44
45    def __init__(self):
46        super(CustomStudentOnlinePayment, self).__init__()
47        return
48
[13043]49    def redeemTicket(self):
[11622]50        student = self.student
[13400]51        if self.p_category.startswith('schoolfee'):
[13043]52            # Bypass activation code creation if next session
53            # can be started directly.
54            if student['studycourse'].next_session_allowed:
55                try:
56                    if student.state == CLEARED:
57                        IWorkflowInfo(student).fireTransition(
58                            'pay_first_school_fee')
59                        return None
60                    elif student.state == RETURNING:
61                        IWorkflowInfo(student).fireTransition(
62                            'pay_school_fee')
63                        return None
64                    elif student.state == PAID:
65                        IWorkflowInfo(student).fireTransition(
66                            'pay_pg_fee')
67                        return None
68                except ConstraintNotSatisfied:
69                    pass
[11622]70            # Create SFE access code
71            pin, error = create_accesscode(
72                'SFE',0,self.amount_auth,student.student_id)
73            if error:
74                return error
75            self.ac = pin
76        elif self.p_category == 'bed_allocation':
77            # Create HOS access code
78            pin, error = create_accesscode(
79                'HOS',0,self.amount_auth,student.student_id)
80            if error:
81                return error
82            self.ac = pin
83        elif self.p_category == 'transcript':
84            # Create TSC access code
85            pin, error = create_accesscode(
86                'TSC',0,self.amount_auth,student.student_id)
87            if error:
88                return error
89            self.ac = pin
90        return None
[8247]91
[9990]92CustomStudentOnlinePayment = attrs_to_fields(
93    CustomStudentOnlinePayment, omit=['display_item'])
[8247]94
[8712]95class CustomStudentOnlinePaymentFactory(StudentOnlinePaymentFactory):
[8247]96    """A factory for student online payments.
97    """
98
99    def __call__(self, *args, **kw):
100        return CustomStudentOnlinePayment()
101
102    def getInterfaces(self):
103        return implementedBy(CustomStudentOnlinePayment)
Note: See TracBrowser for help on using the repository browser.