[10765] | 1 | ## $Id: payment.py 15131 2018-09-07 09:01:25Z henrik $ |
---|
| 2 | ## |
---|
| 3 | ## Copyright (C) 2012 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 | Application fee payment. |
---|
| 20 | """ |
---|
| 21 | import grok |
---|
| 22 | from zope.component.interfaces import IFactory |
---|
| 23 | from zope.interface import implementedBy |
---|
| 24 | from waeup.kofa.applicants.payment import ApplicantOnlinePayment |
---|
| 25 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
[15000] | 26 | from kofacustom.edopoly.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
[15131] | 27 | from kofacustom.edopoly.interfaces import MessageFactory as _ |
---|
[10765] | 28 | |
---|
| 29 | class CustomApplicantOnlinePayment(ApplicantOnlinePayment): |
---|
| 30 | """This is a custom online payment for applicants. |
---|
| 31 | |
---|
| 32 | Since this class inherits from ApplicantOnlinePayment, it automatically |
---|
| 33 | implements the interfaces of the parent class which means |
---|
| 34 | all viewlets and views meant for StudentOnlinePayment |
---|
| 35 | can also be accessed in the customized system. |
---|
| 36 | """ |
---|
| 37 | grok.implements(ICustomApplicantOnlinePayment) |
---|
| 38 | grok.provides(ICustomApplicantOnlinePayment) |
---|
| 39 | |
---|
| 40 | def __init__(self): |
---|
| 41 | super(CustomApplicantOnlinePayment, self).__init__() |
---|
| 42 | return |
---|
| 43 | |
---|
[15131] | 44 | def doAfterApplicantPaymentApproval(self): |
---|
| 45 | """Process applicant after payment was approved. |
---|
| 46 | """ |
---|
| 47 | if not (self.__parent__.special and self.__parent__.state == PAID) \ |
---|
| 48 | and self.p_category != 'admission_checking': |
---|
| 49 | wf_info = IWorkflowInfo(self.__parent__) |
---|
| 50 | try: |
---|
| 51 | wf_info.fireTransition('approve') |
---|
| 52 | except InvalidTransitionError: |
---|
| 53 | msg = log = 'Error: %s' % sys.exc_info()[1] |
---|
| 54 | return 'danger', msg, log |
---|
| 55 | log = 'approved: %s' % self.p_id |
---|
| 56 | msg = _('Payment approved') |
---|
| 57 | flashtype = 'success' |
---|
| 58 | return flashtype, msg, log |
---|
| 59 | |
---|
| 60 | def doAfterApplicantPayment(self): |
---|
| 61 | """Process applicant after payment was made. |
---|
| 62 | """ |
---|
| 63 | if not (self.__parent__.special and self.__parent__.state == PAID) \ |
---|
| 64 | and self.p_category != 'admission_checking': |
---|
| 65 | wf_info = IWorkflowInfo(self.__parent__) |
---|
| 66 | try: |
---|
| 67 | wf_info.fireTransition('pay') |
---|
| 68 | except InvalidTransitionError: |
---|
| 69 | msg = log = 'Error: %s' % sys.exc_info()[1] |
---|
| 70 | return 'danger', msg, log |
---|
| 71 | log = 'successful payment: %s' % self.p_id |
---|
| 72 | msg = _('Successful payment') |
---|
| 73 | flashtype = 'success' |
---|
| 74 | return flashtype, msg, log |
---|
| 75 | |
---|
[10765] | 76 | CustomApplicantOnlinePayment = attrs_to_fields( |
---|
| 77 | CustomApplicantOnlinePayment, omit=['display_item']) |
---|
| 78 | |
---|
| 79 | # Applicant online payments must be importable. So we might need a factory. |
---|
| 80 | class CustomApplicantOnlinePaymentFactory(grok.GlobalUtility): |
---|
| 81 | """A factory for applicant online payments. |
---|
| 82 | """ |
---|
| 83 | grok.implements(IFactory) |
---|
| 84 | grok.name(u'waeup.ApplicantOnlinePayment') |
---|
| 85 | title = u"Create a new online payment.", |
---|
| 86 | description = u"This factory instantiates new online payment instances." |
---|
| 87 | |
---|
| 88 | def __call__(self, *args, **kw): |
---|
| 89 | return CustomApplicantOnlinePayment() |
---|
| 90 | |
---|
| 91 | def getInterfaces(self): |
---|
| 92 | return implementedBy(CustomApplicantOnlinePayment) |
---|