1 | ## $Id: payments.py 8708 2012-06-13 13:29:35Z 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.interfaces import MessageFactory as _ |
---|
25 | from waeup.kofa.students.interfaces import ( |
---|
26 | IStudentPaymentsContainer, IStudentNavigation, IStudentOnlinePayment) |
---|
27 | from waeup.kofa.payments import PaymentsContainer, OnlinePayment |
---|
28 | from waeup.kofa.payments.interfaces import IPaymentWebservice |
---|
29 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
30 | from waeup.kofa.accesscodes import create_accesscode |
---|
31 | |
---|
32 | class StudentPaymentsContainer(PaymentsContainer): |
---|
33 | """This is a container for student payments. |
---|
34 | """ |
---|
35 | grok.implements(IStudentPaymentsContainer, IStudentNavigation) |
---|
36 | grok.provides(IStudentPaymentsContainer) |
---|
37 | |
---|
38 | def __init__(self): |
---|
39 | super(StudentPaymentsContainer, self).__init__() |
---|
40 | return |
---|
41 | |
---|
42 | def getStudent(self): |
---|
43 | return self.__parent__ |
---|
44 | |
---|
45 | StudentPaymentsContainer = attrs_to_fields(StudentPaymentsContainer) |
---|
46 | |
---|
47 | class StudentOnlinePayment(OnlinePayment): |
---|
48 | """This is an online payment. |
---|
49 | """ |
---|
50 | grok.implements(IStudentOnlinePayment, IStudentNavigation) |
---|
51 | grok.provides(IStudentOnlinePayment) |
---|
52 | |
---|
53 | def __init__(self): |
---|
54 | super(StudentOnlinePayment, self).__init__() |
---|
55 | return |
---|
56 | |
---|
57 | def getStudent(self): |
---|
58 | try: |
---|
59 | return self.__parent__.__parent__ |
---|
60 | except AttributeError: |
---|
61 | return None |
---|
62 | |
---|
63 | def doAfterStudentPayment(self): |
---|
64 | """Process student after payment was made. |
---|
65 | """ |
---|
66 | student = self.getStudent() |
---|
67 | if self.p_category == 'clearance': |
---|
68 | # Create CLR access code |
---|
69 | pin, error = create_accesscode( |
---|
70 | 'CLR',0,self.amount_auth,student.student_id) |
---|
71 | if error: |
---|
72 | return False, error, error |
---|
73 | self.ac = pin |
---|
74 | elif self.p_category == 'schoolfee': |
---|
75 | # Create SFE access code |
---|
76 | pin, error = create_accesscode( |
---|
77 | 'SFE',0,self.amount_auth,student.student_id) |
---|
78 | if error: |
---|
79 | return False, error, error |
---|
80 | self.ac = pin |
---|
81 | elif self.p_category == 'bed_allocation': |
---|
82 | # Create HOS access code |
---|
83 | pin, error = create_accesscode( |
---|
84 | 'HOS',0,self.amount_auth,student.student_id) |
---|
85 | if error: |
---|
86 | return False, error, error |
---|
87 | self.ac = pin |
---|
88 | log = 'successful payment: %s' % self.p_id |
---|
89 | msg = _('Successful payment') |
---|
90 | return True, msg, log |
---|
91 | |
---|
92 | def doAfterStudentPaymentApproval(self): |
---|
93 | """Process student after payment was approved. |
---|
94 | """ |
---|
95 | student = self.getStudent() |
---|
96 | if self.p_category == 'clearance': |
---|
97 | # Create CLR access code |
---|
98 | pin, error = create_accesscode( |
---|
99 | 'CLR',0,self.amount_auth,student.student_id) |
---|
100 | if error: |
---|
101 | return False, error, error |
---|
102 | self.ac = pin |
---|
103 | elif self.p_category == 'schoolfee': |
---|
104 | # Create SFE access code |
---|
105 | pin, error = create_accesscode( |
---|
106 | 'SFE',0,self.amount_auth,student.student_id) |
---|
107 | if error: |
---|
108 | return False, error, error |
---|
109 | self.ac = pin |
---|
110 | elif self.p_category == 'bed_allocation': |
---|
111 | # Create HOS access code |
---|
112 | pin, error = create_accesscode( |
---|
113 | 'HOS',0,self.amount_auth,student.student_id) |
---|
114 | if error: |
---|
115 | return False, error, error |
---|
116 | self.ac = pin |
---|
117 | log = 'payment approved: %s' % self.p_id |
---|
118 | msg = _('Payment approved') |
---|
119 | return True, msg, log |
---|
120 | |
---|
121 | def approveStudentPayment(self): |
---|
122 | """Approve payment and process student. |
---|
123 | """ |
---|
124 | if self.p_state == 'paid': |
---|
125 | return False, _('This ticket has already been paid.'), None |
---|
126 | self.approve() |
---|
127 | return self.doAfterStudentPayment() |
---|
128 | |
---|
129 | |
---|
130 | StudentOnlinePayment = attrs_to_fields(StudentOnlinePayment) |
---|
131 | |
---|
132 | class PaymentWebservice(grok.Adapter): |
---|
133 | """An adapter to publish student data through a webservice. |
---|
134 | """ |
---|
135 | grok.context(IStudentOnlinePayment) |
---|
136 | grok.implements(IPaymentWebservice) |
---|
137 | |
---|
138 | @property |
---|
139 | def display_fullname(self): |
---|
140 | "Name of payee." |
---|
141 | return self.context.getStudent().display_fullname |
---|
142 | |
---|
143 | @property |
---|
144 | def id(self): |
---|
145 | "Id of payee" |
---|
146 | return self.context.getStudent().student_id |
---|
147 | |
---|
148 | @property |
---|
149 | def faculty(self): |
---|
150 | "Faculty of payee" |
---|
151 | return self.context.getStudent().faccode |
---|
152 | |
---|
153 | @property |
---|
154 | def department(self): |
---|
155 | "Department of payee" |
---|
156 | return self.context.getStudent().depcode |
---|
157 | |
---|
158 | # Student online payments must be importable. So we might need a factory. |
---|
159 | class StudentOnlinePaymentFactory(grok.GlobalUtility): |
---|
160 | """A factory for student online payments. |
---|
161 | """ |
---|
162 | grok.implements(IFactory) |
---|
163 | grok.name(u'waeup.StudentOnlinePayment') |
---|
164 | title = u"Create a new online payment.", |
---|
165 | description = u"This factory instantiates new online payment instances." |
---|
166 | |
---|
167 | def __call__(self, *args, **kw): |
---|
168 | return StudentOnlinePayment() |
---|
169 | |
---|
170 | def getInterfaces(self): |
---|
171 | return implementedBy(StudentOnlinePayment) |
---|