1 | ## $Id: payment.py 9733 2012-11-27 18:56:08Z 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.payments.interfaces import IPaymentWebservice |
---|
30 | from waeup.kofa.applicants.interfaces import IApplicantOnlinePayment |
---|
31 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
32 | |
---|
33 | class ApplicantOnlinePayment(OnlinePayment): |
---|
34 | """This is an online payment. |
---|
35 | """ |
---|
36 | grok.implements(IApplicantOnlinePayment) |
---|
37 | grok.provides(IApplicantOnlinePayment) |
---|
38 | |
---|
39 | def __init__(self): |
---|
40 | super(ApplicantOnlinePayment, self).__init__() |
---|
41 | return |
---|
42 | |
---|
43 | def doAfterApplicantPaymentApproval(self): |
---|
44 | """Process applicant after payment was approved. |
---|
45 | """ |
---|
46 | wf_info = IWorkflowInfo(self.__parent__) |
---|
47 | try: |
---|
48 | wf_info.fireTransition('approve') |
---|
49 | except InvalidTransitionError: |
---|
50 | msg = log = 'Error: %s' % sys.exc_info()[1] |
---|
51 | return False, msg, log |
---|
52 | log = 'payment approved: %s' % self.p_id |
---|
53 | msg = _('Payment approved') |
---|
54 | return False, msg, log |
---|
55 | |
---|
56 | def doAfterApplicantPayment(self): |
---|
57 | """Process applicant after payment was made. |
---|
58 | """ |
---|
59 | wf_info = IWorkflowInfo(self.__parent__) |
---|
60 | try: |
---|
61 | wf_info.fireTransition('pay') |
---|
62 | except InvalidTransitionError: |
---|
63 | msg = log = 'Error: %s' % sys.exc_info()[1] |
---|
64 | return False, msg, log |
---|
65 | log = 'successful payment: %s' % self.p_id |
---|
66 | msg = _('Successful payment') |
---|
67 | return False, msg, log |
---|
68 | |
---|
69 | def approveApplicantPayment(self): |
---|
70 | """Approve payment and process applicant. |
---|
71 | """ |
---|
72 | if self.p_state == 'paid': |
---|
73 | return False, _('This ticket has already been paid.'), None |
---|
74 | self.approve() |
---|
75 | return self.doAfterApplicantPaymentApproval() |
---|
76 | |
---|
77 | ApplicantOnlinePayment = attrs_to_fields(ApplicantOnlinePayment) |
---|
78 | |
---|
79 | class PaymentWebservice(grok.Adapter): |
---|
80 | """An adapter to publish applicant data through a webservice. |
---|
81 | """ |
---|
82 | grok.context(IApplicantOnlinePayment) |
---|
83 | grok.implements(IPaymentWebservice) |
---|
84 | |
---|
85 | @property |
---|
86 | def display_fullname(self): |
---|
87 | "Name of payee" |
---|
88 | return self.context.__parent__.display_fullname |
---|
89 | |
---|
90 | @property |
---|
91 | def id(self): |
---|
92 | "Id of payee" |
---|
93 | return self.context.__parent__.applicant_id |
---|
94 | |
---|
95 | @property |
---|
96 | def reg_number(self): |
---|
97 | "Reg number of payee" |
---|
98 | return self.context.__parent__.reg_number |
---|
99 | |
---|
100 | @property |
---|
101 | def matric_number(self): |
---|
102 | return '' |
---|
103 | |
---|
104 | @property |
---|
105 | def faculty(self): |
---|
106 | return '' |
---|
107 | |
---|
108 | @property |
---|
109 | def department(self): |
---|
110 | return '' |
---|
111 | |
---|
112 | # Applicant online payments must be importable. So we might need a factory. |
---|
113 | class ApplicantOnlinePaymentFactory(grok.GlobalUtility): |
---|
114 | """A factory for applicant online payments. |
---|
115 | """ |
---|
116 | grok.implements(IFactory) |
---|
117 | grok.name(u'waeup.ApplicantOnlinePayment') |
---|
118 | title = u"Create a new online payment.", |
---|
119 | description = u"This factory instantiates new online payment instances." |
---|
120 | |
---|
121 | def __call__(self, *args, **kw): |
---|
122 | return ApplicantOnlinePayment() |
---|
123 | |
---|
124 | def getInterfaces(self): |
---|
125 | return implementedBy(ApplicantOnlinePayment) |
---|