76 lines
2.1 KiB
Python
76 lines
2.1 KiB
Python
"""Schemas for delivery payment initialization."""
|
|
|
|
from typing import Literal
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
|
|
|
|
class PaymentPhone(BaseModel):
|
|
number: str = Field(min_length=1)
|
|
|
|
|
|
class PaymentParty(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
name: str = Field(min_length=1)
|
|
email: str = Field(min_length=1)
|
|
phone: PaymentPhone
|
|
|
|
@model_validator(mode="before")
|
|
@classmethod
|
|
def reject_company_field(cls, value: object) -> object:
|
|
if isinstance(value, dict) and "company" in value:
|
|
raise ValueError("company is not allowed")
|
|
return value
|
|
|
|
|
|
class DeliveryLocation(BaseModel):
|
|
address: str = Field(min_length=1)
|
|
city: str = Field(min_length=1)
|
|
country_code: str = Field(min_length=2, max_length=2)
|
|
|
|
|
|
class PaymentService(BaseModel):
|
|
code: str = Field(min_length=1)
|
|
parameter: str = Field(min_length=1)
|
|
|
|
|
|
class PaymentPackage(BaseModel):
|
|
number: str = Field(min_length=1)
|
|
weight: int = Field(gt=0)
|
|
length: int = Field(gt=0)
|
|
width: int = Field(gt=0)
|
|
height: int = Field(gt=0)
|
|
comment: str | None = None
|
|
|
|
|
|
class InitPaymentRequest(BaseModel):
|
|
order_uuid: str = Field(min_length=1)
|
|
price: int = Field(gt=0, strict=True, description="Payment amount in kopecks.")
|
|
type: Literal[2]
|
|
tariff_code: Literal[535]
|
|
comment: str | None = None
|
|
sender: PaymentParty
|
|
recipient: PaymentParty
|
|
from_location: DeliveryLocation
|
|
to_location: DeliveryLocation
|
|
services: list[PaymentService] | None = Field(default=None, min_length=1)
|
|
packages: list[PaymentPackage] = Field(min_length=1)
|
|
|
|
|
|
class InitPaymentResponse(BaseModel):
|
|
payment_url: str = Field(min_length=1)
|
|
|
|
|
|
class TBankPaymentNotification(BaseModel):
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
TerminalKey: str = Field(min_length=1)
|
|
OrderId: str = Field(min_length=1)
|
|
Success: bool
|
|
Status: str = Field(min_length=1)
|
|
PaymentId: int = Field(gt=0, strict=True)
|
|
ErrorCode: str = Field(min_length=1)
|
|
Amount: int
|
|
Token: str = Field(min_length=1)
|