[7191] | 1 | ## $Id: payments.py 8453 2012-05-15 20:29:34Z 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 |
---|
| 28 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
[8420] | 29 | from waeup.kofa.accesscodes import create_accesscode |
---|
[6635] | 30 | |
---|
[6860] | 31 | class StudentPaymentsContainer(PaymentsContainer): |
---|
[6635] | 32 | """This is a container for student payments. |
---|
| 33 | """ |
---|
[6860] | 34 | grok.implements(IStudentPaymentsContainer, IStudentNavigation) |
---|
| 35 | grok.provides(IStudentPaymentsContainer) |
---|
[6635] | 36 | |
---|
| 37 | def __init__(self): |
---|
[6860] | 38 | super(StudentPaymentsContainer, self).__init__() |
---|
[6635] | 39 | return |
---|
| 40 | |
---|
[6642] | 41 | def getStudent(self): |
---|
| 42 | return self.__parent__ |
---|
| 43 | |
---|
[6875] | 44 | StudentPaymentsContainer = attrs_to_fields(StudentPaymentsContainer) |
---|
| 45 | |
---|
| 46 | class StudentOnlinePayment(OnlinePayment): |
---|
| 47 | """This is an online payment. |
---|
| 48 | """ |
---|
[6877] | 49 | grok.implements(IStudentOnlinePayment, IStudentNavigation) |
---|
| 50 | grok.provides(IStudentOnlinePayment) |
---|
[6875] | 51 | |
---|
| 52 | def __init__(self): |
---|
| 53 | super(StudentOnlinePayment, self).__init__() |
---|
| 54 | return |
---|
| 55 | |
---|
| 56 | def getStudent(self): |
---|
[8368] | 57 | try: |
---|
| 58 | return self.__parent__.__parent__ |
---|
| 59 | except AttributeError: |
---|
| 60 | return None |
---|
[6875] | 61 | |
---|
[8422] | 62 | def doAfterStudentPayment(self): |
---|
| 63 | """Process student after payment was made. |
---|
[8420] | 64 | """ |
---|
| 65 | student = self.getStudent() |
---|
| 66 | if self.p_category == 'clearance': |
---|
| 67 | # Create CLR access code |
---|
| 68 | pin, error = create_accesscode( |
---|
| 69 | 'CLR',0,self.amount_auth,student.student_id) |
---|
| 70 | if error: |
---|
[8428] | 71 | return False, error, error |
---|
[8420] | 72 | self.ac = pin |
---|
| 73 | elif self.p_category == 'schoolfee': |
---|
| 74 | # Create SFE access code |
---|
| 75 | pin, error = create_accesscode( |
---|
| 76 | 'SFE',0,self.amount_auth,student.student_id) |
---|
| 77 | if error: |
---|
[8428] | 78 | return False, error, error |
---|
[8420] | 79 | self.ac = pin |
---|
| 80 | elif self.p_category == 'bed_allocation': |
---|
| 81 | # Create HOS access code |
---|
| 82 | pin, error = create_accesscode( |
---|
| 83 | 'HOS',0,self.amount_auth,student.student_id) |
---|
| 84 | if error: |
---|
[8428] | 85 | return False, error, error |
---|
[8420] | 86 | self.ac = pin |
---|
[8428] | 87 | log = 'successful payment: %s' % self.p_id |
---|
| 88 | msg = _('Successful payment') |
---|
| 89 | return True, msg, log |
---|
[8420] | 90 | |
---|
[8453] | 91 | def doAfterStudentPaymentApproval(self): |
---|
| 92 | """Process student after payment was approved. |
---|
| 93 | """ |
---|
| 94 | student = self.getStudent() |
---|
| 95 | if self.p_category == 'clearance': |
---|
| 96 | # Create CLR access code |
---|
| 97 | pin, error = create_accesscode( |
---|
| 98 | 'CLR',0,self.amount_auth,student.student_id) |
---|
| 99 | if error: |
---|
| 100 | return False, error, error |
---|
| 101 | self.ac = pin |
---|
| 102 | elif self.p_category == 'schoolfee': |
---|
| 103 | # Create SFE access code |
---|
| 104 | pin, error = create_accesscode( |
---|
| 105 | 'SFE',0,self.amount_auth,student.student_id) |
---|
| 106 | if error: |
---|
| 107 | return False, error, error |
---|
| 108 | self.ac = pin |
---|
| 109 | elif self.p_category == 'bed_allocation': |
---|
| 110 | # Create HOS access code |
---|
| 111 | pin, error = create_accesscode( |
---|
| 112 | 'HOS',0,self.amount_auth,student.student_id) |
---|
| 113 | if error: |
---|
| 114 | return False, error, error |
---|
| 115 | self.ac = pin |
---|
| 116 | log = 'payment approved: %s' % self.p_id |
---|
| 117 | msg = _('Payment approved') |
---|
| 118 | return True, msg, log |
---|
| 119 | |
---|
[8422] | 120 | def approveStudentPayment(self): |
---|
| 121 | """Approve payment and process student. |
---|
| 122 | """ |
---|
| 123 | if self.p_state == 'paid': |
---|
[8428] | 124 | return False, _('This ticket has already been paid.'), None |
---|
[8422] | 125 | self.approve() |
---|
| 126 | return self.doAfterStudentPayment() |
---|
| 127 | |
---|
| 128 | |
---|
[6875] | 129 | StudentOnlinePayment = attrs_to_fields(StudentOnlinePayment) |
---|
| 130 | |
---|
| 131 | # Student online payments must be importable. So we might need a factory. |
---|
| 132 | class StudentOnlinePaymentFactory(grok.GlobalUtility): |
---|
| 133 | """A factory for student online payments. |
---|
| 134 | """ |
---|
| 135 | grok.implements(IFactory) |
---|
| 136 | grok.name(u'waeup.StudentOnlinePayment') |
---|
| 137 | title = u"Create a new online payment.", |
---|
| 138 | description = u"This factory instantiates new online payment instances." |
---|
| 139 | |
---|
| 140 | def __call__(self, *args, **kw): |
---|
| 141 | return StudentOnlinePayment() |
---|
| 142 | |
---|
| 143 | def getInterfaces(self): |
---|
[7811] | 144 | return implementedBy(StudentOnlinePayment) |
---|