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

Last change on this file since 17208 was 16527, checked in by Henrik Bettermann, 3 years ago

Bugfix

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