source: main/waeup.kofa/trunk/src/waeup/kofa/applicants/payment.py @ 8702

Last change on this file since 8702 was 8702, checked in by Henrik Bettermann, 12 years ago

Add getOwner method to payments which is needed for the webservice.

  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1## $Id: payment.py 8702 2012-06-13 05:44:31Z 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"""
19Application fee payment.
20"""
21import grok
22import sys
23from hurry.workflow.interfaces import (
24    IWorkflowInfo, InvalidTransitionError)
25from zope.component.interfaces import IFactory
26from zope.interface import implementedBy
27from waeup.kofa.interfaces import MessageFactory as _
28from waeup.kofa.payments import OnlinePayment
29from waeup.kofa.applicants.interfaces import IApplicantOnlinePayment
30from waeup.kofa.utils.helpers import attrs_to_fields
31
32class ApplicantOnlinePayment(OnlinePayment):
33    """This is an online payment.
34    """
35    grok.implements(IApplicantOnlinePayment)
36    grok.provides(IApplicantOnlinePayment)
37
38    def __init__(self):
39        super(ApplicantOnlinePayment, self).__init__()
40        return
41
42    def doAfterApplicantPaymentApproval(self):
43        """Process applicant after payment was approved.
44        """
45        wf_info = IWorkflowInfo(self.__parent__)
46        try:
47            wf_info.fireTransition('approve')
48        except InvalidTransitionError:
49            msg = log = 'Error: %s' % sys.exc_info()[1]
50            return False, msg, log
51        log = 'payment approved: %s' % self.p_id
52        msg = _('Payment approved')
53        return False, msg, log
54
55    def doAfterApplicantPayment(self):
56        """Process applicant after payment was made.
57        """
58        wf_info = IWorkflowInfo(self.__parent__)
59        try:
60            wf_info.fireTransition('pay')
61        except InvalidTransitionError:
62            msg = log = 'Error: %s' % sys.exc_info()[1]
63            return False, msg, log
64        log = 'successful payment: %s' % self.p_id
65        msg = _('Successful payment')
66        return False, msg, log
67
68    def approveApplicantPayment(self):
69        """Approve payment and process applicant.
70        """
71        if self.p_state == 'paid':
72            return False, _('This ticket has already been paid.'), None
73        self.approve()
74        return self.doAfterApplicantPaymentApproval()
75
76    def getOwner(self):
77        """Return applicant.
78        """
79        return self.__parent__
80
81ApplicantOnlinePayment = attrs_to_fields(ApplicantOnlinePayment)
82
83# Applicant online payments must be importable. So we might need a factory.
84class ApplicantOnlinePaymentFactory(grok.GlobalUtility):
85    """A factory for applicant online payments.
86    """
87    grok.implements(IFactory)
88    grok.name(u'waeup.ApplicantOnlinePayment')
89    title = u"Create a new online payment.",
90    description = u"This factory instantiates new online payment instances."
91
92    def __call__(self, *args, **kw):
93        return ApplicantOnlinePayment()
94
95    def getInterfaces(self):
96        return implementedBy(ApplicantOnlinePayment)
Note: See TracBrowser for help on using the repository browser.