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

Last change on this file since 13005 was 13005, checked in by Henrik Bettermann, 10 years ago

Add Payment class attribute created_online to mark payment tickets
which are added online and not by import. This attribute is needed in
custom packages when sending data to payment gateways.

  • Property svn:keywords set to Id
File size: 3.2 KB
RevLine 
[7195]1## $Id: payment.py 13005 2015-05-27 15:26:26Z 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
[9505]24from zope.event import notify
[8182]25from zope.component import getUtility
[8429]26from zope.i18n import translate
[8182]27from waeup.kofa.interfaces import IKofaUtils
[8420]28from waeup.kofa.interfaces import MessageFactory as _
[7811]29from waeup.kofa.payments.interfaces import (
[9469]30    IPayment, IOnlinePayment,
[9405]31    payment_states)
[8420]32from waeup.kofa.utils.helpers import attrs_to_fields, get_current_principal
[9769]33from waeup.kofa.utils.logger import Logger
[6864]34
[9769]35class Payment(grok.Container, Logger):
[6864]36    """This is a payment.
37    """
38    grok.implements(IPayment)
39    grok.provides(IPayment)
40    grok.baseclass()
41
[9769]42    logger_name = 'waeup.kofa.${sitename}.payments'
43    logger_filename = 'payments.log'
44    logger_format_str = '"%(asctime)s","%(user)s",%(message)s'
45
[13005]46    created_online = False
[9769]47
[6864]48    def __init__(self):
49        super(Payment, self).__init__()
[8194]50        self.creation_date = datetime.utcnow()
[6869]51        self.p_id = None
[6864]52        return
53
[6869]54    @property
[10232]55    def p_state_title(self):
[6869]56        return payment_states.getTermByToken(self.p_state).title
57
58    @property
59    def category(self):
[9405]60        utils = getUtility(IKofaUtils)
[10842]61        return utils.PAYMENT_CATEGORIES.get(self.p_category, None)
[6869]62
[9984]63    @property
64    def display_item(self):
[9987]65        kofa_utils = getUtility(IKofaUtils)
66        return kofa_utils.getPaymentItem(self)
[9984]67
[6864]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        if user is None:
86            # in tests
87            usertitle = 'system'
88        else:
[8758]89            usertitle = getattr(user, 'public_name', None)
90            if not usertitle:
91                usertitle = user.title
[8434]92        r_desc = _('Payment approved by ${a}', mapping = {'a': usertitle})
[8429]93        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
94        self.r_desc = translate(r_desc, 'waeup.kofa',
95            target_language=portal_language)
[8420]96        self.payment_date = datetime.utcnow()
[9505]97        # Update catalog
98        notify(grok.ObjectModifiedEvent(self))
[8420]99        return
100
[9984]101OnlinePayment = attrs_to_fields(OnlinePayment, omit=['display_item'])
Note: See TracBrowser for help on using the repository browser.