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

Last change on this file since 8431 was 8431, checked in by Henrik Bettermann, 13 years ago

Add missing imports.

  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1## $Id: payment.py 8431 2012-05-12 09:19:43Z 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 doAfterApplicantPayment(self):
43        """Process applicant after payment was made.
44        """
45        wf_info = IWorkflowInfo(self.__parent__)
46        try:
47            wf_info.fireTransition('pay')
48        except InvalidTransitionError:
49            msg = log = 'Error: %s' % sys.exc_info()[1]
50            return False, msg, log
51        log = 'successful payment: %s' % self.p_id
52        msg = _('Successful payment')
53        return False, msg, log
54
55    def approveApplicantPayment(self):
56        """Approve payment and process applicant.
57        """
58        if self.p_state == 'paid':
59            return False, _('This ticket has already been paid.'), None
60        self.approve()
61        return self.doAfterApplicantPayment()
62
63ApplicantOnlinePayment = attrs_to_fields(ApplicantOnlinePayment)
64
65# Applicant online payments must be importable. So we might need a factory.
66class ApplicantOnlinePaymentFactory(grok.GlobalUtility):
67    """A factory for applicant online payments.
68    """
69    grok.implements(IFactory)
70    grok.name(u'waeup.ApplicantOnlinePayment')
71    title = u"Create a new online payment.",
72    description = u"This factory instantiates new online payment instances."
73
74    def __call__(self, *args, **kw):
75        return ApplicantOnlinePayment()
76
77    def getInterfaces(self):
78        return implementedBy(ApplicantOnlinePayment)
Note: See TracBrowser for help on using the repository browser.