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

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

Make Payment a full citizen.

  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1## $Id: payment.py 12158 2014-12-05 23:27:58Z 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
43    logger_name = 'waeup.ikoba.${sitename}.payments'
44    logger_filename = 'payments.log'
45    logger_format_str = '"%(asctime)s","%(user)s",%(message)s'
46
47    def __init__(self):
48        super(Payment, self).__init__()
49        self.creation_date = datetime.utcnow()
50        self.payment_date = None
51        self.payment_id = u'PAY_' + unicode(uuid.uuid4().hex)
52        self.amount = decimal.Decimal("0.00")
53        self.payed_item_id = None
54        self.payer_id = None
55        self.state = STATE_UNPAID
56        return
57
58    def approve(self, payment_date=None):
59        """A payment was approved.
60
61        Successful ending; the payment is marked as payed.
62
63        If `payment_date` is given, it must be a datetime object
64        giving a datetime in UTC timezone.
65
66        Raises ObjectModifiedEvent.
67        """
68        if payment_date is None:
69            payment_date = datetime.utcnow()
70        self.payment_date = payment_date
71        self.state = STATE_PAID
72        notify(grok.ObjectModifiedEvent(self))
73
74    def mark_failed(self, reason=None):
75        """Mark payment as failed.
76
77        Raises ObjectModifiedEvent.
78        """
79        self.state = STATE_FAILED
80        notify(grok.ObjectModifiedEvent(self))
Note: See TracBrowser for help on using the repository browser.