1 | ## $Id: interfaces.py 12276 2014-12-21 08:41:49Z 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 | import decimal |
---|
19 | from zope import schema |
---|
20 | from zope.interface import Interface |
---|
21 | from waeup.ikoba.interfaces import ( |
---|
22 | IIkobaObject, SimpleIkobaVocabulary, ContextualDictSourceFactoryBase) |
---|
23 | from waeup.ikoba.interfaces import MessageFactory as _ |
---|
24 | |
---|
25 | |
---|
26 | #: Possible states of payments |
---|
27 | STATE_UNPAID = 1 |
---|
28 | STATE_PAID = 2 |
---|
29 | STATE_FAILED = 4 |
---|
30 | |
---|
31 | payment_states = SimpleIkobaVocabulary( |
---|
32 | (_('Not yet paid'), STATE_UNPAID), |
---|
33 | (_('Paid'), STATE_PAID), |
---|
34 | (_('Failed'), STATE_FAILED), |
---|
35 | ) |
---|
36 | |
---|
37 | |
---|
38 | class IPaymentGatewayService(Interface): |
---|
39 | """A financial gateway service. |
---|
40 | |
---|
41 | Any gateway provider might provide several services. For instance |
---|
42 | payments by credit card, scratch card, bank transfer, etc. An |
---|
43 | `IPaymentGatewayService` represents one of those services. |
---|
44 | |
---|
45 | Payment services are normally registered as a named global |
---|
46 | utility. |
---|
47 | """ |
---|
48 | title = schema.TextLine( |
---|
49 | title=u'Title', |
---|
50 | description=u'Human readable name of gateway service.', |
---|
51 | required=True, |
---|
52 | ) |
---|
53 | |
---|
54 | |
---|
55 | class PaymentCategorySource(ContextualDictSourceFactoryBase): |
---|
56 | """A payment category source delivers all categories of payments. |
---|
57 | |
---|
58 | """ |
---|
59 | #: name of dict to deliver from ikoba utils. |
---|
60 | DICT_NAME = 'PAYMENT_CATEGORIES' |
---|
61 | |
---|
62 | |
---|
63 | class IPaymentsContainer(IIkobaObject): |
---|
64 | """A container for all kind of payment objects. |
---|
65 | |
---|
66 | """ |
---|
67 | |
---|
68 | |
---|
69 | class IPayment(IIkobaObject): |
---|
70 | """A base representation of payments. |
---|
71 | |
---|
72 | In a payment, a payer payes someone (the payee) for something, the |
---|
73 | item to pay. |
---|
74 | |
---|
75 | We currently support only the case where one payer pays one payee |
---|
76 | for one item. The item might include taxes, handling, |
---|
77 | shipping, etc. |
---|
78 | |
---|
79 | As in RL any payment is actually performed by some financial |
---|
80 | service provider (like paypal, interswitch, etc.), each of which |
---|
81 | might provide several types of payments (credit card, scratch |
---|
82 | card, you name it). |
---|
83 | |
---|
84 | In Ikoba we call financial service providers 'gateway' and their |
---|
85 | types of services are handled as gateway types. Therefore PayPal |
---|
86 | handling a credit card payment is different from PayPal handling a |
---|
87 | regular PayPal account transaction. |
---|
88 | |
---|
89 | A payment can be approve()d, which means the act of paying was |
---|
90 | really performed. It can also fail for any reason, in which case |
---|
91 | we mark the payment 'failed'. |
---|
92 | """ |
---|
93 | payment_id = schema.TextLine( |
---|
94 | title=u'Payment Identifier', |
---|
95 | default=None, |
---|
96 | required=True, |
---|
97 | ) |
---|
98 | |
---|
99 | payer_id = schema.TextLine( |
---|
100 | title=u'Payer', |
---|
101 | default=None, |
---|
102 | required=True, |
---|
103 | ) |
---|
104 | |
---|
105 | payed_item_id = schema.TextLine( |
---|
106 | title=u'Payed Item ID', |
---|
107 | default=None, |
---|
108 | required=True, |
---|
109 | ) |
---|
110 | |
---|
111 | state = schema.Choice( |
---|
112 | title=_(u'Payment State'), |
---|
113 | default=STATE_UNPAID, |
---|
114 | vocabulary=payment_states, |
---|
115 | required=True, |
---|
116 | ) |
---|
117 | |
---|
118 | creation_date = schema.Datetime( |
---|
119 | title=_(u'Creation Datetime'), |
---|
120 | readonly=False, |
---|
121 | required=False, |
---|
122 | ) |
---|
123 | |
---|
124 | payment_date = schema.Datetime( |
---|
125 | title=_(u'Payment Datetime'), |
---|
126 | required=False, |
---|
127 | readonly=False, |
---|
128 | ) |
---|
129 | |
---|
130 | amount = schema.Decimal( |
---|
131 | title=_(u'Amount'), |
---|
132 | description=_( |
---|
133 | 'The overall sum payed, including all taxes fees, etc.'), |
---|
134 | default=decimal.Decimal("0.00"), |
---|
135 | required=True, |
---|
136 | readonly=False, |
---|
137 | ) |
---|
138 | |
---|
139 | def approve(): |
---|
140 | """Approve a payment. |
---|
141 | |
---|
142 | The payment was approved and can now be considered payed. This |
---|
143 | kind of approvement means the final one (in case there are |
---|
144 | several instances to ask). |
---|
145 | """ |
---|
146 | |
---|
147 | def mark_failed(reason=None): |
---|
148 | """Mark the payment as failed. |
---|
149 | |
---|
150 | A failed payment was canceled due to technical problems, |
---|
151 | insufficient funds, etc. |
---|
152 | """ |
---|
153 | |
---|
154 | |
---|
155 | class IOnlinePayment(IPayment): |
---|
156 | """A payment via payment gateways. |
---|
157 | |
---|
158 | """ |
---|
159 | |
---|
160 | ac = schema.TextLine( |
---|
161 | title=_(u'Activation Code'), |
---|
162 | default=None, |
---|
163 | required=False, |
---|
164 | readonly=False, |
---|
165 | ) |
---|
166 | |
---|
167 | r_amount_approved = schema.Float( |
---|
168 | title=_(u'Response Amount Approved'), |
---|
169 | default=0.0, |
---|
170 | required=False, |
---|
171 | readonly=False, |
---|
172 | ) |
---|
173 | |
---|
174 | r_code = schema.TextLine( |
---|
175 | title=_(u'Response Code'), |
---|
176 | default=None, |
---|
177 | required=False, |
---|
178 | readonly=False, |
---|
179 | ) |
---|
180 | |
---|
181 | r_desc = schema.TextLine( |
---|
182 | title=_(u'Response Description'), |
---|
183 | default=None, |
---|
184 | required=False, |
---|
185 | readonly=False, |
---|
186 | ) |
---|
187 | |
---|
188 | def approve(): |
---|
189 | "Approve an online payment and set to paid." |
---|