def default_status_check(sender, instance, **kwargs): if not isinstance(instance, OrderPayment): return # Send status change notification when record first created # This is to ensure any components listening for a status # on the Sender will also receive the initial status. # Get the default status for the status field on Sender default_status = StatusDefinition.CREATED from bluebottle.payments_logger.adapters import PaymentLogAdapter # adding a Log when the status changes payment_logger = PaymentLogAdapter() try: # if there is no Payment associated to the order_payment do not log # The log will be created in the adapter payment = Payment.objects.get(order_payment=instance) payment_logger.log(payment, "info", "a new payment status {0}".format(instance.status)) except Payment.DoesNotExist: pass except Payment.MultipleObjectsReturned: payment = Payment.objects.order("-created").filter(order_payment=instance).all()[0] payment_logger.log(payment, "info", "a new payment status {0}".format(instance.status)) finally: # Signal new status if current status is the default value if instance.status == default_status: signal_kwargs = {"sender": sender, "instance": instance, "target": instance.status} post_transition.send(**signal_kwargs)
def default_status_check(sender, instance, **kwargs): if not (isinstance(instance, Payment) or isinstance(instance, OrderPayment)): return # Send status change notification when record first created # This is to ensure any components listening for a status # on the Sender will also receive the initial status. # Get the default status for the status field on Sender default_status = sender._meta.get_field_by_name('status')[0].get_default() from bluebottle.payments_logger.adapters import PaymentLogAdapter # adding a Log when the status changes payment_logger = PaymentLogAdapter() try: # if there is no Payment associated to the order_payment do not log # The log will be created in the adapter payment = Payment.objects.get(order_payment=instance) payment_logger.log(payment, 'info', 'a new payment status {0}'.format(instance.status)) except Payment.DoesNotExist: pass except Payment.MultipleObjectsReturned: payment = Payment.objects.order('-created').filter(order_payment=instance).all()[0] payment_logger.log(payment, 'info', 'a new payment status {0}'.format(instance.status)) finally: # Signal new status if current status is the default value if (instance.status == default_status): signal_kwargs = { 'sender': sender, 'instance': instance, 'target': instance.status } post_transition.send(**signal_kwargs)
def __init__(self, order_payment): self.payment_tracer = str(uuid.uuid4()) self.payment_logger = PaymentLogAdapter() self.order_payment = order_payment self.payment = None cls = self.MODEL_CLASSES[0].__class__ if len(self.MODEL_CLASSES) == 1 and cls == Payment: raise Exception("Please override MODEL_CLASSES with extended " "payment model(s).") for i in range(0, len(self.MODEL_CLASSES)): cls = self.MODEL_CLASSES[i] try: self.payment = cls.objects.get( order_payment=self.order_payment) break except cls.MultipleObjectsReturned: raise Exception("Multiple payments for OrderPayment " "{0}".format(self.order_payment)) except cls.DoesNotExist: # Pass here to allow for other classes in MODEL_CLASSES pass # Finally if no payment found then create a new one if not self.payment: self.payment = self.create_payment()
def test_payment_log_adapter(self): """ Tests the adapter creating different log messages """ payment = self.order_payment.payment payment_logger = PaymentLogAdapter() payment_logger.log(payment=payment, level='ERROR', message='Test Error log') payment_logger.log(payment=payment, level='INFO', message='Test Info log') payment_logger.log(payment=payment, level='WARN', message='Test Warn log') self.assertEqual(3, PaymentLogEntry.objects.all().count())
def default_status_check(sender, instance, **kwargs): if not isinstance(instance, OrderPayment): return # Send status change notification when record first created # This is to ensure any components listening for a status # on the Sender will also receive the initial status. # Get the default status for the status field on Sender default_status = StatusDefinition.CREATED from bluebottle.payments_logger.adapters import PaymentLogAdapter # adding a Log when the status changes payment_logger = PaymentLogAdapter() try: # if there is no Payment associated to the order_payment do not log # The log will be created in the adapter payment = Payment.objects.get(order_payment=instance) payment_logger.log(payment, 'info', 'a new payment status {0}'.format(instance.status)) except Payment.DoesNotExist: pass except Payment.MultipleObjectsReturned: payment = Payment.objects.order('-created').filter( order_payment=instance).all()[0] payment_logger.log(payment, 'info', 'a new payment status {0}'.format(instance.status)) finally: # Signal new status if current status is the default value if (instance.status == default_status): signal_kwargs = { 'sender': sender, 'instance': instance, 'target': instance.status } post_transition.send(**signal_kwargs)