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 | """ |
---|
19 | Application fee payment. |
---|
20 | """ |
---|
21 | import grok |
---|
22 | import sys |
---|
23 | from hurry.workflow.interfaces import ( |
---|
24 | IWorkflowInfo, InvalidTransitionError) |
---|
25 | from zope.component.interfaces import IFactory |
---|
26 | from zope.interface import implementedBy |
---|
27 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
28 | from waeup.kofa.payments import OnlinePayment |
---|
29 | from waeup.kofa.applicants.interfaces import IApplicantOnlinePayment |
---|
30 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
31 | |
---|
32 | class 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 | |
---|
63 | ApplicantOnlinePayment = attrs_to_fields(ApplicantOnlinePayment) |
---|
64 | |
---|
65 | # Applicant online payments must be importable. So we might need a factory. |
---|
66 | class 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) |
---|