[7191] | 1 | ## $Id: payments.py 10906 2014-01-14 06:52:21Z 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] | 19 | Student payment components. |
---|
[6635] | 20 | """ |
---|
| 21 | import grok |
---|
| 22 | from zope.component.interfaces import IFactory |
---|
[6875] | 23 | from zope.interface import implementedBy |
---|
[8420] | 24 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
[7811] | 25 | from waeup.kofa.students.interfaces import ( |
---|
[6877] | 26 | IStudentPaymentsContainer, IStudentNavigation, IStudentOnlinePayment) |
---|
[7811] | 27 | from waeup.kofa.payments import PaymentsContainer, OnlinePayment |
---|
[10030] | 28 | from waeup.kofa.payments.interfaces import IPayer |
---|
[7811] | 29 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
[8420] | 30 | from waeup.kofa.accesscodes import create_accesscode |
---|
[6635] | 31 | |
---|
[6860] | 32 | class StudentPaymentsContainer(PaymentsContainer): |
---|
[6635] | 33 | """This is a container for student payments. |
---|
| 34 | """ |
---|
[6860] | 35 | grok.implements(IStudentPaymentsContainer, IStudentNavigation) |
---|
| 36 | grok.provides(IStudentPaymentsContainer) |
---|
[6635] | 37 | |
---|
| 38 | def __init__(self): |
---|
[6860] | 39 | super(StudentPaymentsContainer, self).__init__() |
---|
[6635] | 40 | return |
---|
| 41 | |
---|
[8736] | 42 | @property |
---|
| 43 | def student(self): |
---|
[6642] | 44 | return self.__parent__ |
---|
| 45 | |
---|
[8735] | 46 | def writeLogMessage(self, view, message): |
---|
| 47 | return self.__parent__.writeLogMessage(view, message) |
---|
| 48 | |
---|
[6875] | 49 | StudentPaymentsContainer = attrs_to_fields(StudentPaymentsContainer) |
---|
| 50 | |
---|
| 51 | class StudentOnlinePayment(OnlinePayment): |
---|
| 52 | """This is an online payment. |
---|
| 53 | """ |
---|
[6877] | 54 | grok.implements(IStudentOnlinePayment, IStudentNavigation) |
---|
| 55 | grok.provides(IStudentOnlinePayment) |
---|
[6875] | 56 | |
---|
| 57 | def __init__(self): |
---|
| 58 | super(StudentOnlinePayment, self).__init__() |
---|
| 59 | return |
---|
| 60 | |
---|
[8736] | 61 | @property |
---|
| 62 | def student(self): |
---|
[8368] | 63 | try: |
---|
| 64 | return self.__parent__.__parent__ |
---|
| 65 | except AttributeError: |
---|
| 66 | return None |
---|
[6875] | 67 | |
---|
[8735] | 68 | def writeLogMessage(self, view, message): |
---|
| 69 | return self.__parent__.__parent__.writeLogMessage(view, message) |
---|
| 70 | |
---|
[8732] | 71 | def _createActivationCodes(self): |
---|
[8736] | 72 | student = self.student |
---|
[8420] | 73 | if self.p_category == 'clearance': |
---|
| 74 | # Create CLR access code |
---|
| 75 | pin, error = create_accesscode( |
---|
| 76 | 'CLR',0,self.amount_auth,student.student_id) |
---|
| 77 | if error: |
---|
[8732] | 78 | return error |
---|
[8420] | 79 | self.ac = pin |
---|
[8732] | 80 | elif self.p_category in ('schoolfee', 'schoolfee_1'): |
---|
[8420] | 81 | # Create SFE access code |
---|
| 82 | pin, error = create_accesscode( |
---|
| 83 | 'SFE',0,self.amount_auth,student.student_id) |
---|
| 84 | if error: |
---|
[8732] | 85 | return error |
---|
[8420] | 86 | self.ac = pin |
---|
| 87 | elif self.p_category == 'bed_allocation': |
---|
| 88 | # Create HOS access code |
---|
| 89 | pin, error = create_accesscode( |
---|
| 90 | 'HOS',0,self.amount_auth,student.student_id) |
---|
| 91 | if error: |
---|
[8732] | 92 | return error |
---|
[8420] | 93 | self.ac = pin |
---|
[10449] | 94 | elif self.p_category == 'transcript': |
---|
| 95 | # Create TSC access code |
---|
| 96 | pin, error = create_accesscode( |
---|
| 97 | 'TSC',0,self.amount_auth,student.student_id) |
---|
| 98 | if error: |
---|
| 99 | return error |
---|
| 100 | self.ac = pin |
---|
[8732] | 101 | return None |
---|
| 102 | |
---|
| 103 | def doAfterStudentPayment(self): |
---|
| 104 | """Process student after payment was made. |
---|
| 105 | """ |
---|
[9148] | 106 | if self.p_current: |
---|
| 107 | error = self._createActivationCodes() |
---|
| 108 | if error is not None: |
---|
| 109 | return False, error, error |
---|
[9438] | 110 | log = 'successful %s payment: %s' % (self.p_category, self.p_id) |
---|
[8428] | 111 | msg = _('Successful payment') |
---|
| 112 | return True, msg, log |
---|
[8420] | 113 | |
---|
[8453] | 114 | def doAfterStudentPaymentApproval(self): |
---|
| 115 | """Process student after payment was approved. |
---|
| 116 | """ |
---|
[9148] | 117 | if self.p_current: |
---|
| 118 | error = self._createActivationCodes() |
---|
| 119 | if error is not None: |
---|
| 120 | return False, error, error |
---|
[9438] | 121 | log = '%s payment approved: %s' % (self.p_category, self.p_id) |
---|
[8453] | 122 | msg = _('Payment approved') |
---|
| 123 | return True, msg, log |
---|
| 124 | |
---|
[8422] | 125 | def approveStudentPayment(self): |
---|
| 126 | """Approve payment and process student. |
---|
| 127 | """ |
---|
| 128 | if self.p_state == 'paid': |
---|
[8428] | 129 | return False, _('This ticket has already been paid.'), None |
---|
[8422] | 130 | self.approve() |
---|
[8732] | 131 | return self.doAfterStudentPaymentApproval() |
---|
[8422] | 132 | |
---|
| 133 | |
---|
[9984] | 134 | StudentOnlinePayment = attrs_to_fields( |
---|
| 135 | StudentOnlinePayment, omit=['display_item']) |
---|
[6875] | 136 | |
---|
[10030] | 137 | class Payer(grok.Adapter): |
---|
| 138 | """An adapter to publish student data through a simple webservice. |
---|
[8703] | 139 | """ |
---|
| 140 | grok.context(IStudentOnlinePayment) |
---|
[10030] | 141 | grok.implements(IPayer) |
---|
[8703] | 142 | |
---|
| 143 | @property |
---|
[8708] | 144 | def display_fullname(self): |
---|
[10030] | 145 | "Name of payer" |
---|
[8736] | 146 | return self.context.student.display_fullname |
---|
[8703] | 147 | |
---|
[8708] | 148 | @property |
---|
| 149 | def id(self): |
---|
[10030] | 150 | "Id of payer" |
---|
[8736] | 151 | return self.context.student.student_id |
---|
[8708] | 152 | |
---|
| 153 | @property |
---|
[9733] | 154 | def matric_number(self): |
---|
[10030] | 155 | "Matric number or reg number of payer" |
---|
[9506] | 156 | return self.context.student.matric_number |
---|
| 157 | |
---|
| 158 | @property |
---|
[9733] | 159 | def reg_number(self): |
---|
[10030] | 160 | "Reg number or reg number of payer" |
---|
[9733] | 161 | return self.context.student.reg_number |
---|
| 162 | |
---|
| 163 | @property |
---|
[8708] | 164 | def faculty(self): |
---|
[10030] | 165 | "Faculty of payer" |
---|
[8736] | 166 | return self.context.student.faccode |
---|
[8708] | 167 | |
---|
| 168 | @property |
---|
| 169 | def department(self): |
---|
[10030] | 170 | "Department of payer" |
---|
[8736] | 171 | return self.context.student.depcode |
---|
[8708] | 172 | |
---|
[10906] | 173 | @property |
---|
| 174 | def email(self): |
---|
| 175 | "Email of payer" |
---|
| 176 | return self.context.student.email |
---|
| 177 | |
---|
| 178 | @property |
---|
| 179 | def phone(self): |
---|
| 180 | "Phone number of payer" |
---|
| 181 | return self.context.student.phone |
---|
| 182 | |
---|
| 183 | @property |
---|
| 184 | def current_mode(self): |
---|
| 185 | "Current study mode of payer" |
---|
| 186 | return self.context.student.current_mode |
---|
| 187 | |
---|
| 188 | @property |
---|
| 189 | def current_level(self): |
---|
| 190 | "Current level of payer" |
---|
| 191 | return self.context.student.current_level |
---|
| 192 | |
---|
[6875] | 193 | # Student online payments must be importable. So we might need a factory. |
---|
| 194 | class StudentOnlinePaymentFactory(grok.GlobalUtility): |
---|
| 195 | """A factory for student online payments. |
---|
| 196 | """ |
---|
| 197 | grok.implements(IFactory) |
---|
| 198 | grok.name(u'waeup.StudentOnlinePayment') |
---|
| 199 | title = u"Create a new online payment.", |
---|
| 200 | description = u"This factory instantiates new online payment instances." |
---|
| 201 | |
---|
| 202 | def __call__(self, *args, **kw): |
---|
| 203 | return StudentOnlinePayment() |
---|
| 204 | |
---|
| 205 | def getInterfaces(self): |
---|
[7811] | 206 | return implementedBy(StudentOnlinePayment) |
---|