schon/payments/signals.py
Egor fureunoir Gorbunov 489ceeaa2a 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`.
2025-06-22 20:26:51 +03:00

28 lines
963 B
Python

from django.db.models.signals import post_save
from django.dispatch import receiver
from payments.models import Balance, Transaction
from payments.utils.emailing import balance_deposit_email
from vibes_auth.models import User
@receiver(post_save, sender=User)
def create_balance_on_user_creation_signal(instance, created, **_kwargs):
if created:
Balance.objects.create(user=instance)
@receiver(post_save, sender=Transaction)
def process_transaction_changes(instance, created, **_kwargs):
if created:
try:
gateway = object()
gateway.process_transaction(instance)
except Exception as e: # noqa:
instance.process = {"status": "NOGATEWAY", "error": str(e)}
if not created:
status = instance.process.get("status", "").lower()
success = instance.process.get("success", False)
if "success" in status or success:
balance_deposit_email.delay(instance.uuid)