[7195] | 1 | ## $Id: interfaces.py 12138 2014-12-04 04:01:07Z uli $ |
---|
[6861] | 2 | ## |
---|
[7195] | 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 | ## |
---|
[12113] | 18 | import decimal |
---|
[6864] | 19 | from zope import schema |
---|
[11949] | 20 | from waeup.ikoba.interfaces import ( |
---|
[12115] | 21 | IIkobaObject, SimpleIkobaVocabulary, ContextualDictSourceFactoryBase) |
---|
[11949] | 22 | from waeup.ikoba.interfaces import MessageFactory as _ |
---|
[6861] | 23 | |
---|
[12113] | 24 | |
---|
| 25 | #: Possible states of payments |
---|
| 26 | STATE_UNPAID = 1 |
---|
| 27 | STATE_PAID = 2 |
---|
| 28 | STATE_FAILED = 4 |
---|
| 29 | |
---|
[11949] | 30 | payment_states = SimpleIkobaVocabulary( |
---|
[12113] | 31 | (_('Not yet paid'), STATE_UNPAID), |
---|
| 32 | (_('Paid'), STATE_PAID), |
---|
| 33 | (_('Failed'), STATE_FAILED), |
---|
[7627] | 34 | ) |
---|
| 35 | |
---|
[12113] | 36 | |
---|
[9405] | 37 | class PaymentCategorySource(ContextualDictSourceFactoryBase): |
---|
[9864] | 38 | """A payment category source delivers all categories of payments. |
---|
| 39 | |
---|
[9405] | 40 | """ |
---|
[11949] | 41 | #: name of dict to deliver from ikoba utils. |
---|
[9405] | 42 | DICT_NAME = 'PAYMENT_CATEGORIES' |
---|
[7627] | 43 | |
---|
[12115] | 44 | |
---|
[11949] | 45 | class IPaymentsContainer(IIkobaObject): |
---|
[6861] | 46 | """A container for all kind of payment objects. |
---|
| 47 | |
---|
| 48 | """ |
---|
[6864] | 49 | |
---|
[12115] | 50 | |
---|
[11949] | 51 | class IPayment(IIkobaObject): |
---|
[6864] | 52 | """A base representation of payments. |
---|
| 53 | |
---|
[12138] | 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 | |
---|
[6864] | 57 | """ |
---|
[12113] | 58 | payment_id = schema.TextLine( |
---|
[12115] | 59 | title=u'Payment Identifier', |
---|
| 60 | default=None, |
---|
| 61 | required=True, |
---|
[6864] | 62 | ) |
---|
| 63 | |
---|
[12113] | 64 | payer_id = schema.TextLine( |
---|
[12115] | 65 | title=u'Payer', |
---|
| 66 | default=None, |
---|
| 67 | required=True, |
---|
[6864] | 68 | ) |
---|
| 69 | |
---|
[12113] | 70 | payed_item_id = schema.TextLine( |
---|
[12115] | 71 | title=u'Payed Item', |
---|
| 72 | default=None, |
---|
| 73 | required=True, |
---|
[8245] | 74 | ) |
---|
| 75 | |
---|
[12113] | 76 | state = schema.Choice( |
---|
[12115] | 77 | title=_(u'Payment State'), |
---|
| 78 | default=STATE_UNPAID, |
---|
| 79 | vocabulary=payment_states, |
---|
| 80 | required=True, |
---|
[7020] | 81 | ) |
---|
| 82 | |
---|
[8170] | 83 | creation_date = schema.Datetime( |
---|
[12132] | 84 | title=_(u'Creation Datetime'), |
---|
[12115] | 85 | readonly=False, |
---|
| 86 | required=False, |
---|
[6864] | 87 | ) |
---|
| 88 | |
---|
[8170] | 89 | payment_date = schema.Datetime( |
---|
[12132] | 90 | title=_(u'Payment Datetime'), |
---|
[12115] | 91 | required=False, |
---|
| 92 | readonly=False, |
---|
[6864] | 93 | ) |
---|
| 94 | |
---|
[12113] | 95 | amount = schema.Decimal( |
---|
[12115] | 96 | title=_(u'Amount'), |
---|
| 97 | description=_( |
---|
[12113] | 98 | 'The overall sum payed, including all taxes fees, etc.'), |
---|
[12115] | 99 | default=decimal.Decimal("0.00"), |
---|
| 100 | required=True, |
---|
| 101 | readonly=False, |
---|
[6864] | 102 | ) |
---|
| 103 | |
---|
[12138] | 104 | def approve(): |
---|
| 105 | """Approve a payment. |
---|
[12113] | 106 | |
---|
[12138] | 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 | |
---|
[6864] | 120 | class IOnlinePayment(IPayment): |
---|
| 121 | """A payment via payment gateways. |
---|
| 122 | |
---|
| 123 | """ |
---|
| 124 | |
---|
[6930] | 125 | ac = schema.TextLine( |
---|
[12115] | 126 | title=_(u'Activation Code'), |
---|
| 127 | default=None, |
---|
| 128 | required=False, |
---|
| 129 | readonly=False, |
---|
[6930] | 130 | ) |
---|
| 131 | |
---|
[7927] | 132 | r_amount_approved = schema.Float( |
---|
[12115] | 133 | title=_(u'Response Amount Approved'), |
---|
| 134 | default=0.0, |
---|
| 135 | required=False, |
---|
| 136 | readonly=False, |
---|
[6864] | 137 | ) |
---|
| 138 | |
---|
| 139 | r_code = schema.TextLine( |
---|
[12115] | 140 | title=_(u'Response Code'), |
---|
| 141 | default=None, |
---|
| 142 | required=False, |
---|
| 143 | readonly=False, |
---|
[6864] | 144 | ) |
---|
[8420] | 145 | |
---|
[8429] | 146 | r_desc = schema.TextLine( |
---|
[12115] | 147 | title=_(u'Response Description'), |
---|
| 148 | default=None, |
---|
| 149 | required=False, |
---|
| 150 | readonly=False, |
---|
[8429] | 151 | ) |
---|
| 152 | |
---|
[8420] | 153 | def approve(): |
---|
| 154 | "Approve an online payment and set to paid." |
---|