Example #1
0
from django.db import models
from order.models import UnawareOrder
from mamona.models import build_payment_model

# We build the final Payment model here, in external app,
# without touching the code containing UnawareObject.
build_payment_model(UnawareOrder, unique=False, related_name='payments')
import listeners
Example #2
0
    @property
    def total_budget(self):
        if self.bonus:
            return self.budget + self.bonus
        else:
            return self.budget

class BonusAdvertisingTransaction(models.Model):
    budget = MoneyField(max_digits=10, decimal_places=2, default_currency='CAD')
    campaign = models.ForeignKey(AdvertisingCampaign)
    processed_at = models.DateTimeField(auto_now_add=True, default=datetime.datetime.now)
    order = models.OneToOneField(AdvertisingOrder, null=True)        


AdvertisingPayment = build_payment_model(AdvertisingOrder, unique=True)

def get_items(self):
        """Retrieves item list using signal query. Listeners must fill
        'items' list with at least one item. Each item is expected to be
        a dictionary, containing at least 'name' element and optionally
        'unit_price' and 'quantity' elements. If not present, 'unit_price'
        and 'quantity' default to 0 and 1 respectively.

        Listener is responsible for providing item list with sum of prices
        consistient with Payment.amount. Otherwise the final amount may
        differ and lead to unpredictable results, depending on the backend used.
        """
        items = []
        signals.order_items_query.send(sender=type(self), instance=self, items=items)
Example #3
0
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from mamona.models import build_payment_model
from satchless.payment.models import PaymentVariant

class MamonaPaymentVariant(PaymentVariant):
    def __unicode__(self):
        try:
            payment = self.payments.get()
        except ObjectDoesNotExist:
            return u"(empty mamona payment)"
        if payment.status == 'paid':
            return u"%.2f %s via %s on %s (by mamona)" % (
                    payment.amount,
                    payment.get_status_display(),
                    payment.backend,
                    payment.paid_on)
        else:
            return u"%.2f %s via %s created on %s (by mamona)" % (
                    payment.amount,
                    payment.get_status_display(),
                    payment.backend,
                    payment.created_on)

Payment = build_payment_model(MamonaPaymentVariant, unique=True, related_name='payments')