source: main/waeup.ikoba/trunk/src/waeup/ikoba/payments/payment.py @ 12419

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

Merge changes from uli-paypal back into trunk.

  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1## $Id: payment.py 12311 2014-12-24 09:17:05Z 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.component import getUtilitiesFor
26from zope.event import notify
27from waeup.ikoba.payments.interfaces import (
28    IPayment, STATE_UNPAID, STATE_FAILED, STATE_PAID,
29    IPaymentGatewayService, IPayer,
30    )
31from waeup.ikoba.utils.logger import Logger
32
33
34def get_payment_providers():
35    """Get all services of payment gateways registered.
36    """
37    return dict(
38        getUtilitiesFor(IPaymentGatewayService)
39        )
40
41
42class PaymentProviderServiceBase(grok.GlobalUtility):
43
44    grok.baseclass()
45    grok.implements(IPaymentGatewayService)
46
47    title = u'Sample Credit Card Service'
48
49
50class Payment(grok.Model, Logger):
51    """This is a payment.
52    """
53    grok.implements(IPayment)
54    grok.provides(IPayment)
55
56    logger_name = 'waeup.ikoba.${sitename}.payments'
57    logger_filename = 'payments.log'
58    logger_format_str = '"%(asctime)s","%(user)s",%(message)s'
59
60    def __init__(self):
61        super(Payment, self).__init__()
62        self.creation_date = datetime.utcnow()
63        self.payment_date = None
64        self.payment_id = u'PAY_' + unicode(uuid.uuid4().hex)
65        self.gateway_service = None
66        self.amount = decimal.Decimal("0.00")
67        self.payed_item_id = None
68        self.payer_id = None
69        self.state = STATE_UNPAID
70        return
71
72    def approve(self, payment_date=None):
73        """A payment was approved.
74
75        Successful ending; the payment is marked as payed.
76
77        If `payment_date` is given, it must be a datetime object
78        giving a datetime in UTC timezone.
79
80        Raises ObjectModifiedEvent.
81        """
82        if payment_date is None:
83            payment_date = datetime.utcnow()
84        self.payment_date = payment_date
85        self.state = STATE_PAID
86        notify(grok.ObjectModifiedEvent(self))
87
88    def mark_failed(self, reason=None):
89        """Mark payment as failed.
90
91        Raises ObjectModifiedEvent.
92        """
93        self.state = STATE_FAILED
94        notify(grok.ObjectModifiedEvent(self))
Note: See TracBrowser for help on using the repository browser.