112 lines
3.5 KiB
Python
112 lines
3.5 KiB
Python
from rest_framework import serializers
|
|
from accounts.models import IAmPrincipal, IAmPrincipalType
|
|
from goodtimes import constants
|
|
from manage_wallets import models
|
|
|
|
|
|
class WalletSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = models.Wallet
|
|
fields = [
|
|
"balance",
|
|
"deposit",
|
|
"earnings",
|
|
"coins",
|
|
"withdrawal_balance",
|
|
]
|
|
|
|
|
|
class TransactionSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = models.Transaction
|
|
fields = [
|
|
"id",
|
|
"principal",
|
|
"principal_subscription",
|
|
"transaction_type",
|
|
"payment_method",
|
|
"transaction_status",
|
|
"amount",
|
|
"coins",
|
|
"comment",
|
|
"order_id",
|
|
"product_id",
|
|
"reference_id",
|
|
]
|
|
extra_kwargs = {
|
|
"principal": {"read_only": True},
|
|
"order_id": {"required": False},
|
|
"product_id": {"required": False},
|
|
"reference_id": {"required": False},
|
|
}
|
|
|
|
def to_representation(self, instance):
|
|
# Customize the representation of the serializer, if necessary
|
|
representation = super().to_representation(instance)
|
|
# For example, to display a human-readable version of the transaction type:
|
|
representation["transaction_type_display"] = (
|
|
instance.get_transaction_type_display()
|
|
)
|
|
representation["payment_method_display"] = instance.get_payment_method_display()
|
|
representation["transaction_status_display"] = (
|
|
instance.get_transaction_status_display()
|
|
)
|
|
return representation
|
|
|
|
|
|
class MerchantDepositSerializer(serializers.Serializer):
|
|
principal_type = serializers.CharField()
|
|
field = serializers.ChoiceField(
|
|
choices=[
|
|
("player_balance", "Player Balance"),
|
|
("merchant_balance", "Merchant Balance"),
|
|
("player_deposit", "Player Deposit"),
|
|
("merchant_deposit", "Merchant Deposit"),
|
|
("player_bonus", "Player Bonus"),
|
|
("merchant_bonus", "Merchant Bonus"),
|
|
("player_winning", "Player Winning"),
|
|
("merchant_commission", "Merchant Commission"),
|
|
]
|
|
)
|
|
amount = serializers.DecimalField(max_digits=14, decimal_places=2)
|
|
|
|
|
|
class PrincipalBankAccountSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = models.PrincipalBankAccount
|
|
fields = ["first_name", "last_name", "account_no", "sort_code"]
|
|
|
|
def create(self, validated_data):
|
|
# Set 'principal', 'created_by' from 'request.user'.
|
|
user = self.context["request"].user
|
|
validated_data["principal"] = user
|
|
validated_data["created_by"] = user
|
|
return super().create(validated_data)
|
|
|
|
def update(self, instance, validated_data):
|
|
# Set 'modified_by' from 'request.user' during update.
|
|
user = self.context["request"].user
|
|
instance.modified_by = user
|
|
return super().update(instance, validated_data)
|
|
|
|
|
|
class WithdrawalRequestSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = models.WithdrawalRequest
|
|
fields = ["notes"]
|
|
|
|
|
|
class WithdrawalRequestViewSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = models.WithdrawalRequest
|
|
fields = [
|
|
"id",
|
|
"coins",
|
|
"amount",
|
|
"notes",
|
|
"reply",
|
|
"status",
|
|
"created_on",
|
|
]
|
|
read_only_fields = ["id", "created_on"]
|