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

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

We won't store things in payments, will we?

  • Property svn:keywords set to Id
File size: 2.4 KB
RevLine 
[7195]1## $Id: payment.py 12163 2014-12-07 18:29:12Z uli $
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"""
[12134]21import decimal
[6864]22import grok
[12134]23import uuid
[6869]24from datetime import datetime
[9505]25from zope.event import notify
[11949]26from waeup.ikoba.payments.interfaces import (
[12159]27    IPayment, STATE_UNPAID, STATE_FAILED, STATE_PAID,
[12140]28    )
[11949]29from waeup.ikoba.utils.logger import Logger
[6864]30
[12135]31
[12163]32class Payment(grok.Model, Logger):
[6864]33    """This is a payment.
34    """
35    grok.implements(IPayment)
36    grok.provides(IPayment)
37
[11949]38    logger_name = 'waeup.ikoba.${sitename}.payments'
[9769]39    logger_filename = 'payments.log'
40    logger_format_str = '"%(asctime)s","%(user)s",%(message)s'
41
[6864]42    def __init__(self):
43        super(Payment, self).__init__()
[8194]44        self.creation_date = datetime.utcnow()
[12134]45        self.payment_date = None
46        self.payment_id = u'PAY_' + unicode(uuid.uuid4().hex)
47        self.amount = decimal.Decimal("0.00")
48        self.payed_item_id = None
49        self.payer_id = None
50        self.state = STATE_UNPAID
[6864]51        return
52
[12139]53    def approve(self, payment_date=None):
54        """A payment was approved.
[6869]55
[12139]56        Successful ending; the payment is marked as payed.
57
58        If `payment_date` is given, it must be a datetime object
59        giving a datetime in UTC timezone.
60
61        Raises ObjectModifiedEvent.
62        """
63        if payment_date is None:
64            payment_date = datetime.utcnow()
65        self.payment_date = payment_date
[12152]66        self.state = STATE_PAID
[12139]67        notify(grok.ObjectModifiedEvent(self))
68
69    def mark_failed(self, reason=None):
70        """Mark payment as failed.
71
72        Raises ObjectModifiedEvent.
73        """
[12152]74        self.state = STATE_FAILED
[12139]75        notify(grok.ObjectModifiedEvent(self))
Note: See TracBrowser for help on using the repository browser.