source: main/waeup.kofa/trunk/src/waeup/kofa/payments/payment.py @ 8468

Last change on this file since 8468 was 8434, checked in by Henrik Bettermann, 13 years ago

Managers do not 'pay' fees for applicants and students, they approve payments made.

Add respective transitions.

  • Property svn:keywords set to Id
File size: 3.0 KB
RevLine 
[7195]1## $Id: payment.py 8434 2012-05-12 16:27:14Z henrik $
2##
[6864]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"""
19These are the payment tickets.
20"""
21import grok
[6869]22from datetime import datetime
[6864]23from grok import index
[8182]24from zope.component import getUtility
[8429]25from zope.i18n import translate
[8182]26from waeup.kofa.interfaces import IKofaUtils
[8420]27from waeup.kofa.interfaces import MessageFactory as _
[7811]28from waeup.kofa.payments.interfaces import (
[7627]29    IPayment, ISCPayment, IOnlinePayment,
30    payment_states, payment_categories)
[8420]31from waeup.kofa.utils.helpers import attrs_to_fields, get_current_principal
[6864]32
33class Payment(grok.Container):
34    """This is a payment.
35    """
36    grok.implements(IPayment)
37    grok.provides(IPayment)
38    grok.baseclass()
39
40    def __init__(self):
41        super(Payment, self).__init__()
[8194]42        self.creation_date = datetime.utcnow()
[6869]43        self.p_id = None
[6864]44        return
45
[6869]46    @property
47    def state(self):
48        return payment_states.getTermByToken(self.p_state).title
49
50    @property
51    def category(self):
52        return payment_categories.getTermByToken(self.p_category).title
53
[8420]54# not used
[6864]55class SCPayment(Payment):
56    """This is a scratch card payment.
57    """
58    grok.implements(ISCPayment)
59    grok.provides(ISCPayment)
60
61    def __init__(self):
62        super(SCPayment, self).__init__()
[6869]63        p_id = None
[6864]64        return
65
66SCPayment = attrs_to_fields(SCPayment)
67
68class OnlinePayment(Payment):
69    """This is an online payment.
70    """
71    grok.implements(IOnlinePayment)
72    grok.provides(IOnlinePayment)
73
74    def __init__(self):
75        super(OnlinePayment, self).__init__()
[6869]76        p_id = None
[6864]77        return
78
[8420]79    def approve(self):
80        "Approve online payment and set to paid."
81        self.r_amount_approved = self.amount_auth
82        self.r_code = u'AP'
83        self.p_state = 'paid'
[8429]84        user = get_current_principal()
[8434]85        user = get_current_principal()
86        if user is None:
87            # in tests
88            usertitle = 'system'
89        else:
90            usertitle = user.title
91        r_desc = _('Payment approved by ${a}', mapping = {'a': usertitle})
[8429]92        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
93        self.r_desc = translate(r_desc, 'waeup.kofa',
94            target_language=portal_language)
[8420]95        self.payment_date = datetime.utcnow()
96        return
97
[7811]98OnlinePayment = attrs_to_fields(OnlinePayment)
Note: See TracBrowser for help on using the repository browser.