From 489ceeaa2af31de87f1f5e36b63baa1502969d2b Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Sun, 22 Jun 2025 20:26:51 +0300 Subject: [PATCH] Features: 1) Add `AbstractGateway` base class with `process_transaction` and `process_callback` methods. Fixes: 1) Correct gateway status handling logic in `payments/signals.py`. Extra: 1) Remove redundant condition checks in `payments/signals.py`. --- payments/gateways/__init__.py | 10 ++++++++++ payments/signals.py | 7 ++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/payments/gateways/__init__.py b/payments/gateways/__init__.py index 2c38824e..9159967f 100644 --- a/payments/gateways/__init__.py +++ b/payments/gateways/__init__.py @@ -1,2 +1,12 @@ class UnknownGatewayError(Exception): pass + + +class AbstractGateway: + @staticmethod + def process_transaction(transaction): + raise NotImplementedError + + @staticmethod + def process_callback(transaction): + raise NotImplementedError diff --git a/payments/signals.py b/payments/signals.py index 79fbd86a..62e6549c 100644 --- a/payments/signals.py +++ b/payments/signals.py @@ -21,7 +21,8 @@ def process_transaction_changes(instance, created, **_kwargs): except Exception as e: # noqa: instance.process = {"status": "NOGATEWAY", "error": str(e)} if not created: - if "success" in str(instance.process).lower() and "notify" in str(instance.process).lower(): + status = instance.process.get("status", "").lower() + success = instance.process.get("success", False) + + if "success" in status or success: balance_deposit_email.delay(instance.uuid) - if "fail" in str(instance.process).lower() and "notify" in str(instance.process).lower(): - pass