Features: 1) Restructure transaction processing to handle unsaved instances using pk check; 2) Instantiate AbstractGateway to prevent potential shared reference issues;
Fixes: 1) Correct logic to properly detect new transactions for processing; Extra: 1) Minor code tidy-up with consistent case handling;
This commit is contained in:
parent
4ed76b85de
commit
220e50c01b
1 changed files with 7 additions and 5 deletions
|
|
@ -14,20 +14,22 @@ def create_balance_on_user_creation_signal(instance, created, **_kwargs):
|
||||||
|
|
||||||
|
|
||||||
@receiver(pre_save, sender=Transaction)
|
@receiver(pre_save, sender=Transaction)
|
||||||
def process_transaction_changes(instance, created, **_kwargs):
|
def process_transaction_changes(instance, **_kwargs):
|
||||||
if created:
|
is_new = instance.pk is None
|
||||||
|
|
||||||
|
if is_new:
|
||||||
try:
|
try:
|
||||||
match instance.process.get("gateway", "default"):
|
match instance.process.get("gateway", "default"):
|
||||||
case "gateway":
|
case "gateway":
|
||||||
gateway = AbstractGateway
|
gateway = AbstractGateway()
|
||||||
case "default":
|
case "default":
|
||||||
gateway = AbstractGateway
|
gateway = AbstractGateway()
|
||||||
case _:
|
case _:
|
||||||
gateway = AbstractGateway()
|
gateway = AbstractGateway()
|
||||||
gateway.process_transaction(instance)
|
gateway.process_transaction(instance)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
instance.process = {"status": "ERRORED", "error": str(e)}
|
instance.process = {"status": "ERRORED", "error": str(e)}
|
||||||
if not created:
|
else:
|
||||||
status = str(instance.process.get("status", "")).lower()
|
status = str(instance.process.get("status", "")).lower()
|
||||||
success = instance.process.get("success", False)
|
success = instance.process.get("success", False)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue