Features: 1) Switch transaction signal from pre_save to post_save for processing changes; 2) Add created parameter handling for improved transaction processing logic;
Fixes: 1) Remove unused `pre_save` signal import; Extra: 1) Update conditional logic for `process_transaction_changes` to improve clarity and error handling; 2) Minor formatting adjustments.
This commit is contained in:
parent
220e50c01b
commit
ea236743ae
1 changed files with 5 additions and 7 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from django.db.models.signals import post_save, pre_save
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
from payments.gateways import AbstractGateway
|
||||
|
|
@ -13,11 +13,9 @@ def create_balance_on_user_creation_signal(instance, created, **_kwargs):
|
|||
Balance.objects.create(user=instance)
|
||||
|
||||
|
||||
@receiver(pre_save, sender=Transaction)
|
||||
def process_transaction_changes(instance, **_kwargs):
|
||||
is_new = instance.pk is None
|
||||
|
||||
if is_new:
|
||||
@receiver(post_save, sender=Transaction)
|
||||
def process_transaction_changes(instance, created, **_kwargs):
|
||||
if created:
|
||||
try:
|
||||
match instance.process.get("gateway", "default"):
|
||||
case "gateway":
|
||||
|
|
@ -29,7 +27,7 @@ def process_transaction_changes(instance, **_kwargs):
|
|||
gateway.process_transaction(instance)
|
||||
except Exception as e:
|
||||
instance.process = {"status": "ERRORED", "error": str(e)}
|
||||
else:
|
||||
if not created:
|
||||
status = str(instance.process.get("status", "")).lower()
|
||||
success = instance.process.get("success", False)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue