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