55 lines
1.3 KiB
Python
55 lines
1.3 KiB
Python
import uuid
|
|
from datetime import datetime
|
|
from decimal import Decimal
|
|
from typing import Annotated, Any
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field, HttpUrl
|
|
|
|
from app.models import Currency, PaymentStatus
|
|
|
|
Amount = Annotated[Decimal, Field(gt=0, max_digits=18, decimal_places=2)]
|
|
|
|
|
|
class PaymentCreate(BaseModel):
|
|
amount: Amount
|
|
currency: Currency
|
|
description: str = Field(min_length=1, max_length=500)
|
|
metadata: dict[str, Any] = Field(default_factory=dict)
|
|
webhook_url: HttpUrl
|
|
|
|
|
|
class PaymentAccepted(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
payment_id: uuid.UUID = Field(validation_alias="id")
|
|
status: PaymentStatus
|
|
created_at: datetime
|
|
|
|
|
|
class PaymentDetails(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
payment_id: uuid.UUID = Field(validation_alias="id")
|
|
amount: Decimal
|
|
currency: Currency
|
|
description: str
|
|
metadata: dict[str, Any] = Field(validation_alias="metadata_")
|
|
status: PaymentStatus
|
|
idempotency_key: str
|
|
webhook_url: str
|
|
created_at: datetime
|
|
processed_at: datetime | None
|
|
|
|
|
|
class PaymentCreatedEvent(BaseModel):
|
|
payment_id: uuid.UUID
|
|
|
|
|
|
class PaymentWebhook(BaseModel):
|
|
payment_id: uuid.UUID
|
|
amount: Decimal
|
|
currency: Currency
|
|
status: PaymentStatus
|
|
processed_at: datetime
|
|
metadata: dict[str, Any]
|