- Timestamp:
- 11 Mar 2015, 17:08:34 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/payment.py
r12721 r12734 101 101 102 102 class PaymentProviderServiceBase(grok.GlobalUtility): 103 103 """Base for IPaymentGatewayServices. 104 """ 104 105 grok.baseclass() 105 106 grok.implements(IPaymentGatewayService) … … 107 108 title = u'Sample Credit Card Service' 108 109 109 110 @attrs_to_fields 111 class Payment(grok.Container, Logger): 110 def store(self, payment): 111 """Store `payment` in site. 112 """ 113 site = grok.getSite() 114 payments = site['payments'] 115 if payment.payment_id in payments: 116 del site['payments'][payment.payment_id] 117 site['payments'][payment.payment_id] = payment 118 119 120 @attrs_to_fields 121 class Payment(grok.Model, Logger): 112 122 """This is a payment. 113 123 """ … … 119 129 logger_format_str = '"%(asctime)s","%(user)s",%(message)s' 120 130 121 @property 122 def amount(self): 123 """The amount of a payment. 124 125 Equals the sum of items contained. 126 """ 127 return sum( 128 [item.amount for item in self.values()], 129 decimal.Decimal("0.00") # default value 130 ) 131 132 def __init__(self): 131 def __init__(self, payer, payable, payee=None): 133 132 super(Payment, self).__init__() 133 item_amounts = [decimal.Decimal("0.00"), ] 134 item_amounts += [item.amount for item in payable.payment_items] 135 self.amount = sum(item_amounts) 136 self.payer_id = payer.payer_id 137 self.payable_id = payable.payable_id 138 self.title = payable.title 134 139 self.creation_date = datetime.utcnow() 135 140 self.payment_date = None 136 141 self.payment_id = u'PAY_' + unicode(uuid.uuid4().hex) 137 142 self.state = STATE_UNPAID 143 self.currency = payable.currency 144 if payee is not None: 145 self.payee_id = payee.payee_id 138 146 return 139 147 … … 162 170 notify(grok.ObjectModifiedEvent(self)) 163 171 164 def add_payment_item(self, item):165 """Add `item`166 167 Returns the key under which the `item` was stored. Please do168 not make anby assumptions about the key. It will be a169 string. That is all we can tell.170 171 """172 cnt = 0173 while str(cnt) in self:174 cnt += 1175 self[str(cnt)] = item176 return str(cnt)177 178 172 179 173 @attrs_to_fields … … 187 181 188 182 @attrs_to_fields 189 class PaymentItem( grok.Model):183 class PaymentItem(object): 190 184 191 185 grok.implements(IPaymentItem) 192 186 193 def __init__(self): 187 def __init__( 188 self, item_id=u"0", title=u"", amount=decimal.Decimal("0.00")): 194 189 super(PaymentItem, self).__init__() 190 self.item_id = item_id 191 self.title = title 192 self.amount = amount 195 193 196 194
Note: See TracChangeset for help on using the changeset viewer.