1 | ## $Id: payment.py 9505 2012-11-02 08:40:37Z 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.event import notify |
---|
25 | from zope.component import getUtility |
---|
26 | from zope.i18n import translate |
---|
27 | from waeup.kofa.interfaces import IKofaUtils |
---|
28 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
29 | from waeup.kofa.payments.interfaces import ( |
---|
30 | IPayment, IOnlinePayment, |
---|
31 | payment_states) |
---|
32 | from waeup.kofa.utils.helpers import attrs_to_fields, get_current_principal |
---|
33 | |
---|
34 | class Payment(grok.Container): |
---|
35 | """This is a payment. |
---|
36 | """ |
---|
37 | grok.implements(IPayment) |
---|
38 | grok.provides(IPayment) |
---|
39 | grok.baseclass() |
---|
40 | |
---|
41 | def __init__(self): |
---|
42 | super(Payment, self).__init__() |
---|
43 | self.creation_date = datetime.utcnow() |
---|
44 | self.p_id = None |
---|
45 | return |
---|
46 | |
---|
47 | @property |
---|
48 | def state(self): |
---|
49 | return payment_states.getTermByToken(self.p_state).title |
---|
50 | |
---|
51 | @property |
---|
52 | def category(self): |
---|
53 | utils = getUtility(IKofaUtils) |
---|
54 | return utils.PAYMENT_CATEGORIES[self.p_category] |
---|
55 | |
---|
56 | class OnlinePayment(Payment): |
---|
57 | """This is an online payment. |
---|
58 | """ |
---|
59 | grok.implements(IOnlinePayment) |
---|
60 | grok.provides(IOnlinePayment) |
---|
61 | |
---|
62 | def __init__(self): |
---|
63 | super(OnlinePayment, self).__init__() |
---|
64 | p_id = None |
---|
65 | return |
---|
66 | |
---|
67 | def approve(self): |
---|
68 | "Approve online payment and set to paid." |
---|
69 | self.r_amount_approved = self.amount_auth |
---|
70 | self.r_code = u'AP' |
---|
71 | self.p_state = 'paid' |
---|
72 | user = get_current_principal() |
---|
73 | if user is None: |
---|
74 | # in tests |
---|
75 | usertitle = 'system' |
---|
76 | else: |
---|
77 | usertitle = getattr(user, 'public_name', None) |
---|
78 | if not usertitle: |
---|
79 | usertitle = user.title |
---|
80 | r_desc = _('Payment approved by ${a}', mapping = {'a': usertitle}) |
---|
81 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
82 | self.r_desc = translate(r_desc, 'waeup.kofa', |
---|
83 | target_language=portal_language) |
---|
84 | self.payment_date = datetime.utcnow() |
---|
85 | # Update catalog |
---|
86 | notify(grok.ObjectModifiedEvent(self)) |
---|
87 | return |
---|
88 | |
---|
89 | OnlinePayment = attrs_to_fields(OnlinePayment) |
---|