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

Last change on this file since 11575 was 11575, checked in by Henrik Bettermann, 11 years ago

Multiple payments in special application containers enabled.
Special payment applicants remain in state started after payment.

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