Backend (Django 4.2 + DRF): - accounts: phone OTP login, JWT, profile, addresses - catalog: categories, products, images, filters, search, hits/new/related - orders: creation with Idempotency-Key, stock reservation, status history, cancel - loyalty: bonus accounts, promo codes, gift certificates - payments: payment records and YooKassa webhook handling - content: static pages, banners, site settings - integration: 1C exchange (catalog sync, order push via outbox, statuses, bonuses) - common: error envelope, pagination, request-id, integration auth, admin dashboard Infrastructure: Dockerfile, docker-compose (Postgres, Redis, Celery worker/beat, Nginx), requirements split by environment, OpenAPI contracts for site and 1C, architecture doc. Tests: 22 pytest cases covering catalog, orders, idempotency, OTP, integration.
498 lines
14 KiB
YAML
498 lines
14 KiB
YAML
openapi: 3.0.3
|
|
info:
|
|
title: HOMM — Integration API (1C → site)
|
|
version: 1.0.0
|
|
description: |
|
|
Контракт API, которое реализует сайт HOMM и вызывает сторона 1С.
|
|
|
|
Аутентификация: заголовок `X-Integration-Token` (или
|
|
`Authorization: Bearer <token>`). Значение задаётся переменной окружения
|
|
`INTEGRATION_API_TOKEN`.
|
|
|
|
Все суммы передаются строками с двумя знаками после запятой, даты — ISO 8601
|
|
с часовым поясом.
|
|
servers:
|
|
- url: https://shop.example.com/api/v1/integration/1c
|
|
description: Production
|
|
- url: http://localhost:8000/api/v1/integration/1c
|
|
description: Local development
|
|
security:
|
|
- IntegrationToken: []
|
|
tags:
|
|
- name: health
|
|
description: Проверка доступности
|
|
- name: catalog
|
|
description: Синхронизация каталога
|
|
- name: orders
|
|
description: Заказы
|
|
- name: customers
|
|
description: Клиенты и бонусы
|
|
paths:
|
|
/health/:
|
|
get:
|
|
tags: [health]
|
|
summary: Проверка доступности интеграционного API
|
|
security: []
|
|
responses:
|
|
'200':
|
|
description: Сервис доступен
|
|
content:
|
|
application/json:
|
|
schema:
|
|
type: object
|
|
properties:
|
|
status:
|
|
type: string
|
|
example: ok
|
|
time:
|
|
type: string
|
|
format: date-time
|
|
/catalog/sync/:
|
|
post:
|
|
tags: [catalog]
|
|
summary: Пакетная синхронизация каталога
|
|
description: |
|
|
Применяет пакет категорий, товаров, цен, остатков и изображений.
|
|
Идемпотентно по `external_id`. Удаление — мягкое (`is_active=false`).
|
|
requestBody:
|
|
required: true
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/CatalogSyncRequest'
|
|
responses:
|
|
'200':
|
|
description: Пакет применён
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/CatalogSyncResponse'
|
|
'400':
|
|
$ref: '#/components/responses/BadRequest'
|
|
'401':
|
|
$ref: '#/components/responses/Unauthorized'
|
|
/orders/pending/:
|
|
get:
|
|
tags: [orders]
|
|
summary: Заказы, ожидающие подтверждения 1С
|
|
description: |
|
|
Возвращает заказы без `external_id`, кроме отменённых. 1С может
|
|
использовать этот метод вместо push-уведомлений.
|
|
responses:
|
|
'200':
|
|
description: Список заказов
|
|
content:
|
|
application/json:
|
|
schema:
|
|
type: object
|
|
properties:
|
|
orders:
|
|
type: array
|
|
items:
|
|
$ref: '#/components/schemas/PendingOrder'
|
|
'401':
|
|
$ref: '#/components/responses/Unauthorized'
|
|
/orders/{number}/status/:
|
|
post:
|
|
tags: [orders]
|
|
summary: Обновить статус заказа
|
|
parameters:
|
|
- $ref: '#/components/parameters/OrderNumber'
|
|
requestBody:
|
|
required: true
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/OrderStatusRequest'
|
|
responses:
|
|
'200':
|
|
description: Статус обновлён
|
|
content:
|
|
application/json:
|
|
schema:
|
|
type: object
|
|
properties:
|
|
status:
|
|
type: string
|
|
example: ok
|
|
order:
|
|
type: string
|
|
example: HOMM-20261106-ABC123
|
|
order_status:
|
|
type: string
|
|
enum: [new, processing, delivering, completed, cancelled]
|
|
'400':
|
|
$ref: '#/components/responses/BadRequest'
|
|
'401':
|
|
$ref: '#/components/responses/Unauthorized'
|
|
'404':
|
|
$ref: '#/components/responses/NotFound'
|
|
/orders/{number}/ack/:
|
|
post:
|
|
tags: [orders]
|
|
summary: Подтвердить приём заказа
|
|
description: Сохраняет номер заказа в 1С (`external_id`) и время синхронизации.
|
|
parameters:
|
|
- $ref: '#/components/parameters/OrderNumber'
|
|
requestBody:
|
|
required: true
|
|
content:
|
|
application/json:
|
|
schema:
|
|
type: object
|
|
required: [external_id]
|
|
properties:
|
|
external_id:
|
|
type: string
|
|
maxLength: 64
|
|
description: Номер/ID заказа в 1С
|
|
responses:
|
|
'200':
|
|
description: Подтверждено
|
|
content:
|
|
application/json:
|
|
schema:
|
|
type: object
|
|
properties:
|
|
status:
|
|
type: string
|
|
example: ok
|
|
'401':
|
|
$ref: '#/components/responses/Unauthorized'
|
|
'404':
|
|
$ref: '#/components/responses/NotFound'
|
|
/customers/bonus/:
|
|
post:
|
|
tags: [customers]
|
|
summary: Начислить или списать бонусы
|
|
description: |
|
|
Положительная сумма — начисление, отрицательная — списание.
|
|
Клиент ищется по нормализованному телефону.
|
|
requestBody:
|
|
required: true
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/BonusRequest'
|
|
responses:
|
|
'200':
|
|
description: Операция применена
|
|
content:
|
|
application/json:
|
|
schema:
|
|
type: object
|
|
properties:
|
|
status:
|
|
type: string
|
|
example: ok
|
|
phone:
|
|
type: string
|
|
example: '+79991234567'
|
|
'400':
|
|
$ref: '#/components/responses/BadRequest'
|
|
'401':
|
|
$ref: '#/components/responses/Unauthorized'
|
|
'404':
|
|
$ref: '#/components/responses/NotFound'
|
|
components:
|
|
securitySchemes:
|
|
IntegrationToken:
|
|
type: apiKey
|
|
in: header
|
|
name: X-Integration-Token
|
|
parameters:
|
|
OrderNumber:
|
|
name: number
|
|
in: path
|
|
required: true
|
|
schema:
|
|
type: string
|
|
example: HOMM-20261106-ABC123
|
|
responses:
|
|
BadRequest:
|
|
description: Ошибка валидации или применения пакета
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/Error'
|
|
Unauthorized:
|
|
description: Неверный или отсутствующий токен
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/Error'
|
|
NotFound:
|
|
description: Объект не найден
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/Error'
|
|
schemas:
|
|
Error:
|
|
type: object
|
|
properties:
|
|
error:
|
|
type: object
|
|
properties:
|
|
code:
|
|
type: string
|
|
message:
|
|
type: string
|
|
details:
|
|
type: object
|
|
additionalProperties: true
|
|
CategoryPayload:
|
|
type: object
|
|
required: [external_id, name]
|
|
properties:
|
|
external_id:
|
|
type: string
|
|
maxLength: 64
|
|
parent_external_id:
|
|
type: string
|
|
maxLength: 64
|
|
nullable: true
|
|
name:
|
|
type: string
|
|
maxLength: 255
|
|
slug:
|
|
type: string
|
|
maxLength: 255
|
|
description:
|
|
type: string
|
|
image_url:
|
|
type: string
|
|
format: uri
|
|
is_active:
|
|
type: boolean
|
|
default: true
|
|
sort_order:
|
|
type: integer
|
|
default: 0
|
|
ProductImagePayload:
|
|
type: object
|
|
required: [url]
|
|
properties:
|
|
url:
|
|
type: string
|
|
format: uri
|
|
maxLength: 1000
|
|
alt:
|
|
type: string
|
|
maxLength: 255
|
|
sort_order:
|
|
type: integer
|
|
default: 0
|
|
is_main:
|
|
type: boolean
|
|
default: false
|
|
ProductPayload:
|
|
type: object
|
|
required: [external_id, sku, name, price]
|
|
properties:
|
|
external_id:
|
|
type: string
|
|
maxLength: 64
|
|
sku:
|
|
type: string
|
|
maxLength: 64
|
|
name:
|
|
type: string
|
|
maxLength: 500
|
|
slug:
|
|
type: string
|
|
maxLength: 500
|
|
category_external_id:
|
|
type: string
|
|
maxLength: 64
|
|
nullable: true
|
|
brand:
|
|
type: string
|
|
maxLength: 255
|
|
short_description:
|
|
type: string
|
|
description:
|
|
type: string
|
|
price:
|
|
type: string
|
|
example: '49990.00'
|
|
old_price:
|
|
type: string
|
|
nullable: true
|
|
example: '59990.00'
|
|
stock:
|
|
type: integer
|
|
default: 0
|
|
stock_status:
|
|
type: string
|
|
enum: [in_stock, preorder, out_of_stock]
|
|
is_hit:
|
|
type: boolean
|
|
default: false
|
|
is_new:
|
|
type: boolean
|
|
default: false
|
|
is_active:
|
|
type: boolean
|
|
default: true
|
|
attributes:
|
|
type: object
|
|
additionalProperties: true
|
|
images:
|
|
type: array
|
|
items:
|
|
$ref: '#/components/schemas/ProductImagePayload'
|
|
external_updated_at:
|
|
type: string
|
|
format: date-time
|
|
nullable: true
|
|
CatalogSyncRequest:
|
|
type: object
|
|
properties:
|
|
sync_id:
|
|
type: string
|
|
maxLength: 64
|
|
description: Идентификатор пакета на стороне 1С
|
|
categories:
|
|
type: array
|
|
items:
|
|
$ref: '#/components/schemas/CategoryPayload'
|
|
products:
|
|
type: array
|
|
items:
|
|
$ref: '#/components/schemas/ProductPayload'
|
|
deleted_product_external_ids:
|
|
type: array
|
|
items:
|
|
type: string
|
|
deleted_category_external_ids:
|
|
type: array
|
|
items:
|
|
type: string
|
|
CatalogSyncResponse:
|
|
type: object
|
|
properties:
|
|
status:
|
|
type: string
|
|
example: ok
|
|
sync_id:
|
|
type: string
|
|
stats:
|
|
type: object
|
|
properties:
|
|
categories_created:
|
|
type: integer
|
|
categories_updated:
|
|
type: integer
|
|
products_created:
|
|
type: integer
|
|
products_updated:
|
|
type: integer
|
|
products_deleted:
|
|
type: integer
|
|
categories_deleted:
|
|
type: integer
|
|
images_replaced:
|
|
type: integer
|
|
OrderStatusRequest:
|
|
type: object
|
|
required: [status]
|
|
properties:
|
|
status:
|
|
type: string
|
|
description: Название статуса в 1С или код
|
|
example: Выполнен
|
|
comment:
|
|
type: string
|
|
changed_at:
|
|
type: string
|
|
format: date-time
|
|
external_id:
|
|
type: string
|
|
maxLength: 64
|
|
BonusRequest:
|
|
type: object
|
|
required: [amount]
|
|
properties:
|
|
phone:
|
|
type: string
|
|
example: '+79991234567'
|
|
external_customer_id:
|
|
type: string
|
|
maxLength: 64
|
|
description: Зарезервировано; в MVP требуется phone
|
|
amount:
|
|
type: string
|
|
description: Положительное — начисление, отрицательное — списание
|
|
example: '500.00'
|
|
reason:
|
|
type: string
|
|
enum: [accrual, spend, refund, adjustment]
|
|
default: accrual
|
|
comment:
|
|
type: string
|
|
order_number:
|
|
type: string
|
|
maxLength: 32
|
|
PendingOrderItem:
|
|
type: object
|
|
properties:
|
|
sku:
|
|
type: string
|
|
product_external_id:
|
|
type: string
|
|
name:
|
|
type: string
|
|
price:
|
|
type: string
|
|
quantity:
|
|
type: integer
|
|
total:
|
|
type: string
|
|
PendingOrder:
|
|
type: object
|
|
properties:
|
|
number:
|
|
type: string
|
|
external_id:
|
|
type: string
|
|
status:
|
|
type: string
|
|
payment_status:
|
|
type: string
|
|
customer_name:
|
|
type: string
|
|
phone:
|
|
type: string
|
|
email:
|
|
type: string
|
|
delivery_method:
|
|
type: string
|
|
delivery_address:
|
|
type: string
|
|
delivery_cost:
|
|
type: string
|
|
comment:
|
|
type: string
|
|
subtotal:
|
|
type: string
|
|
discount_total:
|
|
type: string
|
|
bonus_applied:
|
|
type: string
|
|
certificate_applied:
|
|
type: string
|
|
total:
|
|
type: string
|
|
promo_code:
|
|
type: string
|
|
certificate_code:
|
|
type: string
|
|
created_at:
|
|
type: string
|
|
format: date-time
|
|
items:
|
|
type: array
|
|
items:
|
|
$ref: '#/components/schemas/PendingOrderItem'
|