freeleaps-service-hub/apps/payment/backend/services/payment/models.py

73 lines
1.9 KiB
Python

from typing import List, Dict, Optional
from decimal import Decimal
from time import time
from beanie import Document
from pydantic import BaseModel, validator
from decimal import Decimal
from bson import Decimal128
from backend.services.payment.constants import PaymentGateway
from backend.infra.payment.constants import MoneyCollectionType, PaymentLocation
class PaymentMethod(BaseModel):
setup: bool = False
verified: bool = False
channel: Optional[PaymentGateway]
location: Optional[PaymentLocation]
priority: int = 0 # less number has high priority to be used.
class MoneyCollectingMethod(BaseModel):
setup: bool = False
verified: bool = False
channel: Optional[PaymentGateway]
type: Optional[MoneyCollectionType]
location: Optional[PaymentLocation]
priority: int = 0 # less number has high priority to be used.
stripe_account_id: Optional[str]
last_update_time: Optional[int] = None
class CurrencyAmount(BaseModel):
amount: Decimal
currency: str
@validator("amount", pre=True)
def convert_decimal128(cls, value):
if isinstance(value, Decimal128):
return value.to_decimal() # Convert MongoDB Decimal128 to Python Decimal
return value
class Wallet(BaseModel):
payment_methods: List[PaymentMethod]
deposit: CurrencyAmount
class BankAccount(BaseModel):
money_collecting_methods: List[MoneyCollectingMethod]
class IncomeProfileDoc(Document):
user_id: str
bank_account: BankAccount
total: CurrencyAmount
payment_location: PaymentLocation
preferred_channel: Optional[PaymentGateway] = None
class Settings:
name = "income_profile"
class PaymentProfileDoc(Document):
user_id: str
wallet: Wallet
total: CurrencyAmount
payment_location: PaymentLocation
preferred_currency: str
class Settings:
name = "payment_profile"