Files
Fulfillment-Backend/external/billing/schemas.py
2025-03-20 13:34:31 +03:00

104 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import re
from typing import List, Optional
from pydantic import field_validator
from schemas.base import BaseSchema
from .enums import NotificationChannel
from datetime import datetime as dt
from datetime import date
phone_regexp = re.compile(r'^((\+7)([0-9]){10})$')
class CreateBillingRequestValue(BaseSchema):
name: str = ""
unit: str = "Руб"
vat: str = "None"
price: int
amount: int = 1
class CreateBillRequestItems(BaseSchema):
values: List[CreateBillingRequestValue]
class CreateBillRequestSchema(BaseSchema):
listener_transaction_id: int | str
payer_name: str
payer_inn: str
payer_phone: str | None
items: CreateBillRequestItems
@field_validator("payer_phone", mode="before")
def payer_phone_validator(cls, phone: str) -> str:
if phone is None:
return None
phone = phone.replace('-', '')
phone = phone.replace(' ', '')
if not phone.startswith("+"):
phone = f"+{phone}"
if phone_regexp.match(phone):
return phone
return None
class DeleteBillRequestSchema(BaseSchema):
listener_transaction_id: int | str
class DeleteBillResponseSchema(BaseSchema):
ok: bool
class NotifyReceivedBillRequestSchema(BaseSchema):
listener_transaction_id: int | str
channel: NotificationChannel
received: bool
class CreateBillingResponseSchema(BaseSchema):
ok: bool
message:Optional[str]
class NotifyReceivedBillResponseSchema(BaseSchema):
ok: bool
class BillPaymentInfo(BaseSchema):
pdf_url: str
due_date: date
payment_amount: int
invoice_number: str
@field_validator('due_date', mode='plain')
def serialize_due_date(value: str) -> date:
date = dt.strptime(value, '%Y-%m-%d').date()
return date
class BillPaymentStatus(BaseSchema):
payed: bool
class BillStatusUpdateRequest(BaseSchema):
listener_transaction_id: int | str
channel: NotificationChannel
info: BillPaymentInfo | BillPaymentStatus
class ServiceBillingDocumentPdf(BaseSchema):
name: str = ""
price: int
quantity: int
class ProductBillingDocumentPdf(BaseSchema):
article: str = ""
size: str = ""
price: int
quantity: int