# Payment details extraction
## Create a recognition task
Task for recognition and/or extraction data from document is async process
1. Create task using lambda invocation (http or queue)
a. Persist task in DB with unique guid.
b. Respond to calle with task id and status
2. Making recognitions and\or extractions from document based on passed presets
a. Listen for webhook calls with new statuses
b. Update task status and trigger events
3. Store recognition and extraction details, errors or manual reports
4. Publish final events with recognition/extraction data
Each change with task will be trigger event into dedicated queue. We will send estimation time in these events
### Specification
```typescript
type TaskStatus =
| 'pending'
| 'processing'
| ...
| 'completed'
| 'failed';
type RequestData = {
document: {
id: number;
category: string | null;
subcategory: string | null;
...
createdAt: number;
};
scenarios: [
'payment-extraction',
'line-items-extraction',
]
}
type ResponseData = {
taskId: Guid;
status: TaskStatus;
duration: number;
scenarios: string[];
documentId: number;
documentLink: string | null;
}
type BaseProviderEvent<T extends TaskStatus> = {
taskId: Guid;
status: T;
duration: number;
provider: string;
scenario: string;
documentId: number;
}
type TaskCompletedEvent = BaseEvent<'completed'> & {
payload: {
'payment-extraction': {
...
},
'line-items-extraction': {
}
}
}
```
## Metrics
All metrics contains task id, time, basic document and scenarios information.
Some events also contains information about provider
- ocr.task.created
- ocr.task.process
- ocr.task.waiting
- ocr.task.failed
- ocr.task.completed
- ocr.task.restarted
- ocr.task.reported
## Итог
- Запускаем процесс извлечения реквизитов в текущем процессе
- Создаем отдельную ручку для ручного запуска извлечения
## Статусы документов
-