schon/engine/payments/graphene/mutations.py

24 lines
857 B
Python

import graphene
from rest_framework.exceptions import PermissionDenied
from engine.core.graphene import BaseMutation
from engine.core.utils.messages import permission_denied_message
from engine.payments.graphene.object_types import TransactionType
from engine.payments.models import Transaction
class Deposit(BaseMutation):
class Arguments:
amount = graphene.Float(required=True)
transaction = graphene.Field(TransactionType)
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)
else:
raise PermissionDenied(permission_denied_message)