56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
from typing import Dict, Any, List
|
||
from ..client import MegaClient
|
||
|
||
class OrdersService:
|
||
"""Service to handle MegaMarket Orders (FBS)."""
|
||
|
||
def __init__(self, client: MegaClient):
|
||
self.client = client
|
||
|
||
def get_new_orders(self, limit: int = 100) -> Dict[str, Any]:
|
||
"""
|
||
Мегамаркет обычно отправляет заказы webhook-ами, но также имеет методы пулинга или запроса списков.
|
||
Endpoint: /orderService/order/search (условно)
|
||
"""
|
||
payload = {
|
||
"data": {
|
||
"statuses": ["NEW"],
|
||
"limit": limit
|
||
}
|
||
}
|
||
return self.client.post("/orderService/order/search", data=payload)
|
||
|
||
def confirm_order(self, order_id: str, items: List[Dict[str, Any]]) -> Dict[str, Any]:
|
||
"""
|
||
Подтвердить заказ (отправить информацию о том, что он принят в работу).
|
||
Endpoint: /orderService/order/confirm
|
||
"""
|
||
payload = {
|
||
"data": {
|
||
"shipments": [
|
||
{
|
||
"shipmentId": order_id,
|
||
"items": items
|
||
}
|
||
]
|
||
}
|
||
}
|
||
return self.client.post("/orderService/order/confirm", data=payload)
|
||
|
||
def reject_order(self, order_id: str, reason: str) -> Dict[str, Any]:
|
||
"""
|
||
Отменить заказ.
|
||
Endpoint: /orderService/order/reject
|
||
"""
|
||
payload = {
|
||
"data": {
|
||
"shipments": [
|
||
{
|
||
"shipmentId": order_id,
|
||
"reason": {"type": reason}
|
||
}
|
||
]
|
||
}
|
||
}
|
||
return self.client.post("/orderService/order/reject", data=payload)
|