source: main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/payment.py @ 12157

Last change on this file since 12157 was 12157, checked in by uli, 10 years ago

Remove OnlinePayment?. All payments are online payments.

  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1## $Id: payment.py 12157 2014-12-05 23:16:13Z uli $
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"""
19These are the payment tickets.
20"""
21import decimal
22import grok
23import uuid
24from datetime import datetime
25from zope.event import notify
26from zope.component import getUtility
27from zope.i18n import translate
28from waeup.ikoba.interfaces import IIkobaUtils
29from waeup.ikoba.interfaces import MessageFactory as _
30from waeup.ikoba.payments.interfaces import (
31    IPayment, IOnlinePayment, STATE_UNPAID, STATE_FAILED, STATE_PAID,
32    )
33from waeup.ikoba.utils.helpers import attrs_to_fields, get_current_principal
34from waeup.ikoba.utils.logger import Logger
35
36
37class Payment(grok.Container, Logger):
38    """This is a payment.
39    """
40    grok.implements(IPayment)
41    grok.provides(IPayment)
42    grok.baseclass()
43
44    logger_name = 'waeup.ikoba.${sitename}.payments'
45    logger_filename = 'payments.log'
46    logger_format_str = '"%(asctime)s","%(user)s",%(message)s'
47
48    def __init__(self):
49        super(Payment, self).__init__()
50        self.creation_date = datetime.utcnow()
51        self.payment_date = None
52        self.payment_id = u'PAY_' + unicode(uuid.uuid4().hex)
53        self.amount = decimal.Decimal("0.00")
54        self.payed_item_id = None
55        self.payer_id = None
56        self.state = STATE_UNPAID
57        return
58
59    def approve(self, payment_date=None):
60        """A payment was approved.
61
62        Successful ending; the payment is marked as payed.
63
64        If `payment_date` is given, it must be a datetime object
65        giving a datetime in UTC timezone.
66
67        Raises ObjectModifiedEvent.
68        """
69        if payment_date is None:
70            payment_date = datetime.utcnow()
71        self.payment_date = payment_date
72        self.state = STATE_PAID
73        notify(grok.ObjectModifiedEvent(self))
74
75    def mark_failed(self, reason=None):
76        """Mark payment as failed.
77
78        Raises ObjectModifiedEvent.
79        """
80        self.state = STATE_FAILED
81        notify(grok.ObjectModifiedEvent(self))
Note: See TracBrowser for help on using the repository browser.