Files
g2s-aggregator/app/adapters/delivery_providers/base.py
T
Раис Юсупалиев 843175f12e
Deploy / deploy (push) Successful in 18m5s
Рефактор
2026-06-26 20:16:04 +03:00

50 lines
1.2 KiB
Python

"""Base interface for delivery providers."""
from abc import ABC, abstractmethod
from typing import Protocol, runtime_checkable
from app.schemas.payment import InitPaymentRequest
from app.schemas.request import DeliveryCalculationRequest
from app.schemas.response import DeliveryPrice
class DeliveryProvider(ABC):
name: str
@abstractmethod
async def get_prices(
self, request: DeliveryCalculationRequest
) -> list[DeliveryPrice]:
"""Fetch provider tariffs for a delivery request."""
raise NotImplementedError
@runtime_checkable
class PaymentPriceValidationProvider(Protocol):
name: str
async def get_payment_price(
self,
request: InitPaymentRequest,
) -> DeliveryPrice | None: ...
@runtime_checkable
class OrderRegistrationProvider(Protocol):
name: str
async def register_order(
self,
request: InitPaymentRequest,
order_uuid: str,
) -> object: ...
class ProviderClientError(RuntimeError):
"""Raised when a provider call fails for temporary or provider-side reasons."""
class ProviderRequestError(RuntimeError):
"""Raised when a provider rejects input request data."""