schon/engine/payments/graphene/mutations.py
Egor fureunoir Gorbunov ad320235d6 feat(payments, vibes_auth, core): introduce decimal fields, 2FA, and admin OTP
- Refactored monetary fields across models to use `DecimalField` for improved precision.
- Implemented two-factor authentication (2FA) for admin logins with OTP codes.
- Added ability to generate admin OTP via management commands.
- Updated Docker Compose override for dev-specific port bindings.
- Included template for 2FA OTP verification to enhance security.

Additional changes:
- Upgraded and downgraded various dependencies (e.g., django-celery-beat and yarl).
- Replaced float-based calculations with decimal for consistent rounding behavior.
- Improved admin user management commands for activation and OTP generation.
2026-03-03 00:42:21 +03:00

28 lines
990 B
Python

import graphene
from graphene import Mutation
from rest_framework.exceptions import PermissionDenied
from engine.core.utils.messages import permission_denied_message
from engine.payments.graphene.object_types import TransactionType
from engine.payments.models import Transaction
from schon.utils.ratelimit import graphql_ratelimit
class Deposit(Mutation):
class Arguments:
amount = graphene.Float(required=True)
transaction = graphene.Field(TransactionType)
@graphql_ratelimit(rate="10/h")
def mutate(self, info, amount):
if info.context.user.is_authenticated:
transaction = Transaction.objects.create(
balance=info.context.user.payments_balance,
amount=amount,
currency="EUR",
)
# noinspection PyTypeChecker
return Deposit(transaction=transaction) # ty: ignore[unknown-argument]
else:
raise PermissionDenied(permission_denied_message)