Features: 1) Add pre_save signal handling for Transaction model; 2) Enhance error status handling within process_transaction_changes.
Fixes: 1) Correct type conversion for process status to a string for consistency. Extra: 1) Adjust signal usage from post_save to pre_save for improved transaction handling.
This commit is contained in:
parent
8ed5bc4c17
commit
4ed76b85de
1 changed files with 4 additions and 4 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import post_save, pre_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
|
||||||
from payments.gateways import AbstractGateway
|
from payments.gateways import AbstractGateway
|
||||||
|
|
@ -13,7 +13,7 @@ def create_balance_on_user_creation_signal(instance, created, **_kwargs):
|
||||||
Balance.objects.create(user=instance)
|
Balance.objects.create(user=instance)
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Transaction)
|
@receiver(pre_save, sender=Transaction)
|
||||||
def process_transaction_changes(instance, created, **_kwargs):
|
def process_transaction_changes(instance, created, **_kwargs):
|
||||||
if created:
|
if created:
|
||||||
try:
|
try:
|
||||||
|
|
@ -26,9 +26,9 @@ def process_transaction_changes(instance, created, **_kwargs):
|
||||||
gateway = AbstractGateway()
|
gateway = AbstractGateway()
|
||||||
gateway.process_transaction(instance)
|
gateway.process_transaction(instance)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
instance.process = {"status": "NOGATEWAY", "error": str(e)}
|
instance.process = {"status": "ERRORED", "error": str(e)}
|
||||||
if not created:
|
if not created:
|
||||||
status = instance.process.get("status", "").lower()
|
status = str(instance.process.get("status", "")).lower()
|
||||||
success = instance.process.get("success", False)
|
success = instance.process.get("success", False)
|
||||||
|
|
||||||
if ("success" in status or success) and (instance.process.get("notify", False)):
|
if ("success" in status or success) and (instance.process.get("notify", False)):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue