Ignore:
Timestamp:
11 Mar 2015, 17:08:34 (10 years ago)
Author:
uli
Message:

Restructure things a bit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/payment.py

    r12721 r12734  
    101101
    102102class PaymentProviderServiceBase(grok.GlobalUtility):
    103 
     103    """Base for IPaymentGatewayServices.
     104    """
    104105    grok.baseclass()
    105106    grok.implements(IPaymentGatewayService)
     
    107108    title = u'Sample Credit Card Service'
    108109
    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
     121class Payment(grok.Model, Logger):
    112122    """This is a payment.
    113123    """
     
    119129    logger_format_str = '"%(asctime)s","%(user)s",%(message)s'
    120130
    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):
    133132        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
    134139        self.creation_date = datetime.utcnow()
    135140        self.payment_date = None
    136141        self.payment_id = u'PAY_' + unicode(uuid.uuid4().hex)
    137142        self.state = STATE_UNPAID
     143        self.currency = payable.currency
     144        if payee is not None:
     145            self.payee_id = payee.payee_id
    138146        return
    139147
     
    162170        notify(grok.ObjectModifiedEvent(self))
    163171
    164     def add_payment_item(self, item):
    165         """Add `item`
    166 
    167         Returns the key under which the `item` was stored. Please do
    168         not make anby assumptions about the key. It will be a
    169         string. That is all we can tell.
    170 
    171         """
    172         cnt = 0
    173         while str(cnt) in self:
    174             cnt += 1
    175         self[str(cnt)] = item
    176         return str(cnt)
    177 
    178172
    179173@attrs_to_fields
     
    187181
    188182@attrs_to_fields
    189 class PaymentItem(grok.Model):
     183class PaymentItem(object):
    190184
    191185    grok.implements(IPaymentItem)
    192186
    193     def __init__(self):
     187    def __init__(
     188            self, item_id=u"0", title=u"", amount=decimal.Decimal("0.00")):
    194189        super(PaymentItem, self).__init__()
     190        self.item_id = item_id
     191        self.title = title
     192        self.amount = amount
    195193
    196194
Note: See TracChangeset for help on using the changeset viewer.