From 4efaeaea8f1c97bceadaaeee07796b8abd745ec5 Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Mon, 30 Jun 2025 18:51:49 +0300 Subject: [PATCH] Features: 1) Add match-case logic for selecting gateway in `process_transaction_changes`. Fixes: None. Extra: 1) Minor adjustment to default `AbstractGateway` instantiation. --- payments/signals.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/payments/signals.py b/payments/signals.py index 7f94297a..b5e3d385 100644 --- a/payments/signals.py +++ b/payments/signals.py @@ -17,7 +17,13 @@ def create_balance_on_user_creation_signal(instance, created, **_kwargs): def process_transaction_changes(instance, created, **_kwargs): if created: try: - gateway = AbstractGateway() + match instance.process.get("gateway", "default"): + case "gateway": + gateway = AbstractGateway + case "default": + gateway = AbstractGateway + case _: + gateway = AbstractGateway() gateway.process_transaction(instance) except Exception as e: # noqa: instance.process = {"status": "NOGATEWAY", "error": str(e)}