1 | ## $Id: payment.py 11580 2014-04-04 08:37:59Z 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 IPayer |
---|
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 | if not self.__parent__.special: |
---|
47 | wf_info = IWorkflowInfo(self.__parent__) |
---|
48 | try: |
---|
49 | wf_info.fireTransition('approve') |
---|
50 | except InvalidTransitionError: |
---|
51 | msg = log = 'Error: %s' % sys.exc_info()[1] |
---|
52 | return 'danger', msg, log |
---|
53 | log = 'payment approved: %s' % self.p_id |
---|
54 | msg = _('Payment approved') |
---|
55 | flashtype = 'success' |
---|
56 | return flashtype, msg, log |
---|
57 | |
---|
58 | def doAfterApplicantPayment(self): |
---|
59 | """Process applicant after payment was made. |
---|
60 | """ |
---|
61 | if not self.__parent__.special: |
---|
62 | wf_info = IWorkflowInfo(self.__parent__) |
---|
63 | try: |
---|
64 | wf_info.fireTransition('pay') |
---|
65 | except InvalidTransitionError: |
---|
66 | msg = log = 'Error: %s' % sys.exc_info()[1] |
---|
67 | return 'danger', msg, log |
---|
68 | log = 'successful payment: %s' % self.p_id |
---|
69 | msg = _('Successful payment') |
---|
70 | flashtype = 'success' |
---|
71 | return flashtype, msg, log |
---|
72 | |
---|
73 | def approveApplicantPayment(self): |
---|
74 | """Approve payment and process applicant. |
---|
75 | """ |
---|
76 | if self.p_state == 'paid': |
---|
77 | return 'warning', _('This ticket has already been paid.'), None |
---|
78 | self.approve() |
---|
79 | return self.doAfterApplicantPaymentApproval() |
---|
80 | |
---|
81 | ApplicantOnlinePayment = attrs_to_fields( |
---|
82 | ApplicantOnlinePayment, omit=['display_item']) |
---|
83 | |
---|
84 | class Payer(grok.Adapter): |
---|
85 | """An adapter to publish applicant data through a simple webservice. |
---|
86 | """ |
---|
87 | grok.context(IApplicantOnlinePayment) |
---|
88 | grok.implements(IPayer) |
---|
89 | |
---|
90 | @property |
---|
91 | def display_fullname(self): |
---|
92 | "Name of payer" |
---|
93 | return self.context.__parent__.display_fullname |
---|
94 | |
---|
95 | @property |
---|
96 | def id(self): |
---|
97 | "Id of payer" |
---|
98 | return self.context.__parent__.applicant_id |
---|
99 | |
---|
100 | @property |
---|
101 | def reg_number(self): |
---|
102 | "Reg number of payer" |
---|
103 | return self.context.__parent__.reg_number |
---|
104 | |
---|
105 | @property |
---|
106 | def matric_number(self): |
---|
107 | return 'N/A' |
---|
108 | |
---|
109 | @property |
---|
110 | def faculty(self): |
---|
111 | return 'N/A' |
---|
112 | |
---|
113 | @property |
---|
114 | def department(self): |
---|
115 | return 'N/A' |
---|
116 | |
---|
117 | @property |
---|
118 | def email(self): |
---|
119 | "Email of payer" |
---|
120 | return self.context.__parent__.email |
---|
121 | |
---|
122 | @property |
---|
123 | def phone(self): |
---|
124 | "Phone number of payer" |
---|
125 | return self.context.__parent__.phone |
---|
126 | |
---|
127 | @property |
---|
128 | def current_mode(self): |
---|
129 | "Current study mode of payer" |
---|
130 | return 'N/A' |
---|
131 | |
---|
132 | @property |
---|
133 | def current_level(self): |
---|
134 | "Current level of payer" |
---|
135 | return 'N/A' |
---|
136 | |
---|
137 | # Applicant online payments must be importable. So we might need a factory. |
---|
138 | class ApplicantOnlinePaymentFactory(grok.GlobalUtility): |
---|
139 | """A factory for applicant online payments. |
---|
140 | """ |
---|
141 | grok.implements(IFactory) |
---|
142 | grok.name(u'waeup.ApplicantOnlinePayment') |
---|
143 | title = u"Create a new online payment.", |
---|
144 | description = u"This factory instantiates new online payment instances." |
---|
145 | |
---|
146 | def __call__(self, *args, **kw): |
---|
147 | return ApplicantOnlinePayment() |
---|
148 | |
---|
149 | def getInterfaces(self): |
---|
150 | return implementedBy(ApplicantOnlinePayment) |
---|