diff --git a/payments/signals.py b/payments/signals.py index ffd1111f..6853f288 100644 --- a/payments/signals.py +++ b/payments/signals.py @@ -14,20 +14,22 @@ def create_balance_on_user_creation_signal(instance, created, **_kwargs): @receiver(pre_save, sender=Transaction) -def process_transaction_changes(instance, created, **_kwargs): - if created: +def process_transaction_changes(instance, **_kwargs): + is_new = instance.pk is None + + if is_new: try: match instance.process.get("gateway", "default"): case "gateway": - gateway = AbstractGateway + gateway = AbstractGateway() case "default": - gateway = AbstractGateway + gateway = AbstractGateway() case _: gateway = AbstractGateway() gateway.process_transaction(instance) except Exception as e: instance.process = {"status": "ERRORED", "error": str(e)} - if not created: + else: status = str(instance.process.get("status", "")).lower() success = instance.process.get("success", False)