1 | ## $Id: payments.py 14345 2016-12-14 17:04:27Z 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.schema.interfaces import ConstraintNotSatisfied |
---|
24 | from zope.interface import implementedBy |
---|
25 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
26 | from waeup.kofa.students.interfaces import IStudentNavigation |
---|
27 | from waeup.kofa.students.workflow import CLEARED, RETURNING, PAID |
---|
28 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
29 | from waeup.kofa.accesscodes import create_accesscode |
---|
30 | from kofacustom.nigeria.students.payments import ( |
---|
31 | NigeriaStudentOnlinePayment, NigeriaStudentOnlinePaymentFactory) |
---|
32 | from kofacustom.coewarri.students.interfaces import ICustomStudentOnlinePayment |
---|
33 | |
---|
34 | class CustomStudentOnlinePayment(NigeriaStudentOnlinePayment): |
---|
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. |
---|
41 | """ |
---|
42 | grok.implements(ICustomStudentOnlinePayment, IStudentNavigation) |
---|
43 | grok.provides(ICustomStudentOnlinePayment) |
---|
44 | |
---|
45 | def __init__(self): |
---|
46 | super(CustomStudentOnlinePayment, self).__init__() |
---|
47 | return |
---|
48 | |
---|
49 | @property |
---|
50 | def student(self): |
---|
51 | return self.__parent__.__parent__ |
---|
52 | |
---|
53 | def redeemTicket(self): |
---|
54 | """Either create an appropriate access code or trigger an action |
---|
55 | directly. |
---|
56 | """ |
---|
57 | student = self.student |
---|
58 | if self.p_category == 'clearance': |
---|
59 | # Create CLR access code |
---|
60 | pin, error = create_accesscode( |
---|
61 | 'CLR',0,self.amount_auth,student.student_id) |
---|
62 | if error: |
---|
63 | return error |
---|
64 | self.ac = pin |
---|
65 | elif self.p_category in ('schoolfee', 'schoolfee_1') : |
---|
66 | # Bypass activation code creation if next session |
---|
67 | # can be started directly. |
---|
68 | if student['studycourse'].next_session_allowed: |
---|
69 | try: |
---|
70 | if student.state == CLEARED: |
---|
71 | IWorkflowInfo(student).fireTransition( |
---|
72 | 'pay_first_school_fee') |
---|
73 | return None |
---|
74 | elif student.state == RETURNING: |
---|
75 | IWorkflowInfo(student).fireTransition( |
---|
76 | 'pay_school_fee') |
---|
77 | return None |
---|
78 | elif student.state == PAID: |
---|
79 | IWorkflowInfo(student).fireTransition( |
---|
80 | 'pay_pg_fee') |
---|
81 | return None |
---|
82 | except ConstraintNotSatisfied: |
---|
83 | pass |
---|
84 | # Create SFE access code |
---|
85 | pin, error = create_accesscode( |
---|
86 | 'SFE',0,self.amount_auth,student.student_id) |
---|
87 | if error: |
---|
88 | return error |
---|
89 | self.ac = pin |
---|
90 | elif self.p_category == 'bed_allocation': |
---|
91 | # Create HOS access code |
---|
92 | pin, error = create_accesscode( |
---|
93 | 'HOS',0,self.amount_auth,student.student_id) |
---|
94 | if error: |
---|
95 | return error |
---|
96 | self.ac = pin |
---|
97 | elif self.p_category == 'transcript': |
---|
98 | # Create TSC access code |
---|
99 | pin, error = create_accesscode( |
---|
100 | 'TSC',0,self.amount_auth,student.student_id) |
---|
101 | if error: |
---|
102 | return error |
---|
103 | self.ac = pin |
---|
104 | return None |
---|
105 | |
---|
106 | CustomStudentOnlinePayment = attrs_to_fields( |
---|
107 | CustomStudentOnlinePayment, omit=['display_item']) |
---|
108 | |
---|
109 | class CustomStudentOnlinePaymentFactory(NigeriaStudentOnlinePaymentFactory): |
---|
110 | """A factory for student online payments. |
---|
111 | """ |
---|
112 | |
---|
113 | def __call__(self, *args, **kw): |
---|
114 | return CustomStudentOnlinePayment() |
---|
115 | |
---|
116 | def getInterfaces(self): |
---|
117 | return implementedBy(CustomStudentOnlinePayment) |
---|