1 | ## $Id: payment.py 8420 2012-05-11 14:18:47Z henrik $ |
---|
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 | """ |
---|
19 | These are the payment tickets. |
---|
20 | """ |
---|
21 | import grok |
---|
22 | from datetime import datetime |
---|
23 | from grok import index |
---|
24 | from zope.component import getUtility |
---|
25 | from waeup.kofa.interfaces import IKofaUtils |
---|
26 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
27 | from waeup.kofa.payments.interfaces import ( |
---|
28 | IPayment, ISCPayment, IOnlinePayment, |
---|
29 | payment_states, payment_categories) |
---|
30 | from waeup.kofa.utils.helpers import attrs_to_fields, get_current_principal |
---|
31 | |
---|
32 | class Payment(grok.Container): |
---|
33 | """This is a payment. |
---|
34 | """ |
---|
35 | grok.implements(IPayment) |
---|
36 | grok.provides(IPayment) |
---|
37 | grok.baseclass() |
---|
38 | |
---|
39 | def __init__(self): |
---|
40 | super(Payment, self).__init__() |
---|
41 | self.creation_date = datetime.utcnow() |
---|
42 | self.p_id = None |
---|
43 | return |
---|
44 | |
---|
45 | @property |
---|
46 | def state(self): |
---|
47 | return payment_states.getTermByToken(self.p_state).title |
---|
48 | |
---|
49 | @property |
---|
50 | def category(self): |
---|
51 | return payment_categories.getTermByToken(self.p_category).title |
---|
52 | |
---|
53 | # not used |
---|
54 | class SCPayment(Payment): |
---|
55 | """This is a scratch card payment. |
---|
56 | """ |
---|
57 | grok.implements(ISCPayment) |
---|
58 | grok.provides(ISCPayment) |
---|
59 | |
---|
60 | def __init__(self): |
---|
61 | super(SCPayment, self).__init__() |
---|
62 | p_id = None |
---|
63 | return |
---|
64 | |
---|
65 | SCPayment = attrs_to_fields(SCPayment) |
---|
66 | |
---|
67 | class OnlinePayment(Payment): |
---|
68 | """This is an online payment. |
---|
69 | """ |
---|
70 | grok.implements(IOnlinePayment) |
---|
71 | grok.provides(IOnlinePayment) |
---|
72 | |
---|
73 | def __init__(self): |
---|
74 | super(OnlinePayment, self).__init__() |
---|
75 | p_id = None |
---|
76 | return |
---|
77 | |
---|
78 | def approve(self): |
---|
79 | "Approve online payment and set to paid." |
---|
80 | self.r_amount_approved = self.amount_auth |
---|
81 | self.r_code = u'AP' |
---|
82 | self.p_state = 'paid' |
---|
83 | #user = get_current_principal() |
---|
84 | self.payment_date = datetime.utcnow() |
---|
85 | return |
---|
86 | |
---|
87 | OnlinePayment = attrs_to_fields(OnlinePayment) |
---|