1 | ## $Id: payments.py 14340 2016-12-14 08:38:01Z 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 | """ |
---|
19 | Student payment components. |
---|
20 | """ |
---|
21 | import grok |
---|
22 | from zope.component.interfaces import IFactory |
---|
23 | from zope.interface import implementedBy |
---|
24 | from waeup.kofa.students.interfaces import IStudentNavigation |
---|
25 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
26 | from kofacustom.nigeria.students.payments import ( |
---|
27 | NigeriaStudentOnlinePayment, NigeriaStudentOnlinePaymentFactory) |
---|
28 | from kofacustom.coewarri.students.interfaces import ICustomStudentOnlinePayment |
---|
29 | |
---|
30 | class CustomStudentOnlinePayment(NigeriaStudentOnlinePayment): |
---|
31 | """This is a custom online payment for students. |
---|
32 | |
---|
33 | Since this class inherits from StudentOnlinePayment, it automatically |
---|
34 | implements the interfaces of the parent class which means |
---|
35 | all viewlets and views meant for StudentOnlinePayment |
---|
36 | can also be accessed in the customized system. |
---|
37 | """ |
---|
38 | grok.implements(ICustomStudentOnlinePayment, IStudentNavigation) |
---|
39 | grok.provides(ICustomStudentOnlinePayment) |
---|
40 | |
---|
41 | def __init__(self): |
---|
42 | super(CustomStudentOnlinePayment, self).__init__() |
---|
43 | return |
---|
44 | |
---|
45 | @property |
---|
46 | def student(self): |
---|
47 | return self.__parent__.__parent__ |
---|
48 | |
---|
49 | def redeemTicket(self): |
---|
50 | """Either create an appropriate access code or trigger an action |
---|
51 | directly. |
---|
52 | """ |
---|
53 | student = self.student |
---|
54 | if self.p_category == 'clearance': |
---|
55 | # Create CLR access code |
---|
56 | pin, error = create_accesscode( |
---|
57 | 'CLR',0,self.amount_auth,student.student_id) |
---|
58 | if error: |
---|
59 | return error |
---|
60 | self.ac = pin |
---|
61 | elif self.p_category.startswith('schoolfee'): |
---|
62 | # Bypass activation code creation if next session |
---|
63 | # can be started directly. |
---|
64 | if student['studycourse'].next_session_allowed: |
---|
65 | try: |
---|
66 | if student.state == CLEARED: |
---|
67 | IWorkflowInfo(student).fireTransition( |
---|
68 | 'pay_first_school_fee') |
---|
69 | return None |
---|
70 | elif student.state == RETURNING: |
---|
71 | IWorkflowInfo(student).fireTransition( |
---|
72 | 'pay_school_fee') |
---|
73 | return None |
---|
74 | elif student.state == PAID: |
---|
75 | IWorkflowInfo(student).fireTransition( |
---|
76 | 'pay_pg_fee') |
---|
77 | return None |
---|
78 | except ConstraintNotSatisfied: |
---|
79 | pass |
---|
80 | # Create SFE access code |
---|
81 | pin, error = create_accesscode( |
---|
82 | 'SFE',0,self.amount_auth,student.student_id) |
---|
83 | if error: |
---|
84 | return error |
---|
85 | self.ac = pin |
---|
86 | elif self.p_category == 'bed_allocation': |
---|
87 | # Create HOS access code |
---|
88 | pin, error = create_accesscode( |
---|
89 | 'HOS',0,self.amount_auth,student.student_id) |
---|
90 | if error: |
---|
91 | return error |
---|
92 | self.ac = pin |
---|
93 | elif self.p_category == 'transcript': |
---|
94 | # Create TSC access code |
---|
95 | pin, error = create_accesscode( |
---|
96 | 'TSC',0,self.amount_auth,student.student_id) |
---|
97 | if error: |
---|
98 | return error |
---|
99 | self.ac = pin |
---|
100 | return None |
---|
101 | |
---|
102 | CustomStudentOnlinePayment = attrs_to_fields( |
---|
103 | CustomStudentOnlinePayment, omit=['display_item']) |
---|
104 | |
---|
105 | class CustomStudentOnlinePaymentFactory(NigeriaStudentOnlinePaymentFactory): |
---|
106 | """A factory for student online payments. |
---|
107 | """ |
---|
108 | |
---|
109 | def __call__(self, *args, **kw): |
---|
110 | return CustomStudentOnlinePayment() |
---|
111 | |
---|
112 | def getInterfaces(self): |
---|
113 | return implementedBy(CustomStudentOnlinePayment) |
---|