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

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

Try to make IPayment more consistent.

  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1## $Id: interfaces.py 12138 2014-12-04 04:01:07Z 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##
18import decimal
19from zope import schema
20from waeup.ikoba.interfaces import (
21    IIkobaObject, SimpleIkobaVocabulary, ContextualDictSourceFactoryBase)
22from waeup.ikoba.interfaces import MessageFactory as _
23
24
25#: Possible states of payments
26STATE_UNPAID = 1
27STATE_PAID = 2
28STATE_FAILED = 4
29
30payment_states = SimpleIkobaVocabulary(
31    (_('Not yet paid'), STATE_UNPAID),
32    (_('Paid'), STATE_PAID),
33    (_('Failed'), STATE_FAILED),
34    )
35
36
37class PaymentCategorySource(ContextualDictSourceFactoryBase):
38    """A payment category source delivers all categories of payments.
39
40    """
41    #: name of dict to deliver from ikoba utils.
42    DICT_NAME = 'PAYMENT_CATEGORIES'
43
44
45class IPaymentsContainer(IIkobaObject):
46    """A container for all kind of payment objects.
47
48    """
49
50
51class IPayment(IIkobaObject):
52    """A base representation of payments.
53
54    A payment can be approve()d, which means the act of paying was
55    really performed. It can also fail for any reason.
56
57    """
58    payment_id = schema.TextLine(
59        title=u'Payment Identifier',
60        default=None,
61        required=True,
62        )
63
64    payer_id = schema.TextLine(
65        title=u'Payer',
66        default=None,
67        required=True,
68        )
69
70    payed_item_id = schema.TextLine(
71        title=u'Payed Item',
72        default=None,
73        required=True,
74        )
75
76    state = schema.Choice(
77        title=_(u'Payment State'),
78        default=STATE_UNPAID,
79        vocabulary=payment_states,
80        required=True,
81        )
82
83    creation_date = schema.Datetime(
84        title=_(u'Creation Datetime'),
85        readonly=False,
86        required=False,
87        )
88
89    payment_date = schema.Datetime(
90        title=_(u'Payment Datetime'),
91        required=False,
92        readonly=False,
93        )
94
95    amount = schema.Decimal(
96        title=_(u'Amount'),
97        description=_(
98            'The overall sum payed, including all taxes fees, etc.'),
99        default=decimal.Decimal("0.00"),
100        required=True,
101        readonly=False,
102        )
103
104    def approve():
105        """Approve a payment.
106
107        The payment was approved and can now be considered payed. This
108        kind of approvement means the final one (in case there are
109        several instances to ask).
110        """
111
112    def mark_failed(reason=None):
113        """Mark the payment as failed.
114
115        A failed payment was canceled due to technical problems,
116        insufficient funds, etc.
117        """
118
119
120class IOnlinePayment(IPayment):
121    """A payment via payment gateways.
122
123    """
124
125    ac = schema.TextLine(
126        title=_(u'Activation Code'),
127        default=None,
128        required=False,
129        readonly=False,
130        )
131
132    r_amount_approved = schema.Float(
133        title=_(u'Response Amount Approved'),
134        default=0.0,
135        required=False,
136        readonly=False,
137        )
138
139    r_code = schema.TextLine(
140        title=_(u'Response Code'),
141        default=None,
142        required=False,
143        readonly=False,
144        )
145
146    r_desc = schema.TextLine(
147        title=_(u'Response Description'),
148        default=None,
149        required=False,
150        readonly=False,
151        )
152
153    def approve():
154        "Approve an online payment and set to paid."
Note: See TracBrowser for help on using the repository browser.