{
    "openapi": "3.0.3",
    "info": {
        "title": "eRačun API",
        "version": "1.0.0",
        "description": "API usluge eRačun (eracun.eu): izdavanje B2B eRačuna (vrsta 380), popis i sinkronizacija poslanih i primljenih računa, stavke, PDF, UBL XML i evidencija plaćanja.\n\nAutentikacija: `Authorization: Bearer eracun_live_...` (ili `X-Api-Key`). Ključ generira administrator tvrtke u aplikaciji (API pristup). Testni ključ `eracun_test_...` sve provjerava, ali ništa ne sprema ni šalje.\n\nOgraničenja: 120 zahtjeva u minuti po ključu, 500 stavki i 1 MB po računu. Dokumentacija: https://eracun.eu/api-dokumentacija",
        "contact": {
            "name": "eRačun",
            "email": "info@eracun.eu",
            "url": "https://eracun.eu/api-dokumentacija"
        }
    },
    "servers": [
        {
            "url": "https://eracun.eu/api/v1"
        }
    ],
    "security": [
        {
            "bearerAuth": []
        },
        {
            "apiKeyHeader": []
        }
    ],
    "paths": {
        "/ping": {
            "get": {
                "summary": "Provjera ključa",
                "operationId": "ping",
                "responses": {
                    "200": {
                        "description": "Ključ je ispravan",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "ok": {
                                            "type": "boolean"
                                        },
                                        "test": {
                                            "type": "boolean",
                                            "description": "true za testni ključ"
                                        },
                                        "company": {
                                            "type": "object",
                                            "properties": {
                                                "id": {
                                                    "type": "integer"
                                                },
                                                "name": {
                                                    "type": "string"
                                                },
                                                "oib": {
                                                    "type": "string"
                                                }
                                            }
                                        },
                                        "key": {
                                            "type": "object",
                                            "properties": {
                                                "name": {
                                                    "type": "string"
                                                },
                                                "prefix": {
                                                    "type": "string"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "429": {
                        "$ref": "#/components/responses/RateLimited"
                    }
                }
            }
        },
        "/invoices": {
            "get": {
                "summary": "Popis računa ili jedan račun po external_id",
                "operationId": "listInvoices",
                "description": "Bez `external_id` vraća stranicu računa (poslani i primljeni). Za sinkronizaciju: `updated_since` = `server_time` iz prethodnog odgovora; rezultati su poredani od najstarije promjene, isti račun može doći više puta (ažurirajte po `id`).\n\nS `external_id` vraća jedan račun (objekt Invoice, ne popis).",
                "parameters": [
                    {
                        "name": "external_id",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        },
                        "description": "Vaša oznaka računa; vraća jedan račun"
                    },
                    {
                        "name": "direction",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "out",
                                "in"
                            ]
                        },
                        "description": "out = poslani, in = primljeni (zadano oboje)"
                    },
                    {
                        "name": "status",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        },
                        "description": "Jedan ili više statusa odvojenih zarezom: draft, not_sent, processing, delivered, received, accepted, rejected, partially_paid, paid, cancelled, error"
                    },
                    {
                        "name": "from",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "format": "date"
                        },
                        "description": "Datum izdavanja od"
                    },
                    {
                        "name": "to",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "format": "date"
                        },
                        "description": "Datum izdavanja do"
                    },
                    {
                        "name": "updated_since",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        },
                        "description": "Samo računi promijenjeni od tog trenutka, npr. `2026-10-28 14:30:00` ili ISO 8601"
                    },
                    {
                        "name": "partner_oib",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        },
                        "description": "OIB kupca (poslani) ili dobavljača (primljeni)"
                    },
                    {
                        "name": "type",
                        "in": "query",
                        "schema": {
                            "type": "integer"
                        },
                        "description": "Vrsta dokumenta (380, 381, 384, 386...)"
                    },
                    {
                        "name": "source",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "api",
                                "panel"
                            ]
                        }
                    },
                    {
                        "name": "include_drafts",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "enum": [
                                0,
                                1
                            ]
                        },
                        "description": "1 = i skice i računi koji nisu otišli"
                    },
                    {
                        "name": "page",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "minimum": 1,
                            "default": 1
                        }
                    },
                    {
                        "name": "per_page",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 200,
                            "default": 50
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Popis (ili jedan račun kad je zadan external_id)",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "oneOf": [
                                        {
                                            "$ref": "#/components/schemas/InvoiceList"
                                        },
                                        {
                                            "$ref": "#/components/schemas/Invoice"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Račun s tim external_id ne postoji",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "Neispravni parametri",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "429": {
                        "$ref": "#/components/responses/RateLimited"
                    }
                }
            },
            "post": {
                "summary": "Izdaj i pošalji B2B račun (vrsta 380)",
                "operationId": "createInvoice",
                "description": "Isti put kao gumb Pošalji u aplikaciji: provjera, fiskalizacija, dostava (interno ili AS4). Iznose eRačun računa iz stavki.\n\nS istim `external_id` ponovljen poziv vraća već poslan račun (200, `duplicate: true`) ili ponovno šalje račun koji nije otišao. Testni ključ vraća 200 s `test: true` i ništa ne sprema.",
                "parameters": [
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "schema": {
                            "type": "string"
                        },
                        "description": "Zamjena za external_id u tijelu"
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/InvoiceCreate"
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Račun izdan i poslan",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Invoice"
                                }
                            }
                        }
                    },
                    "200": {
                        "description": "Već poslan (duplicate: true) ili testni ključ (test: true)",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Invoice"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Tijelo nije JSON objekt",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "IP_NOT_ALLOWED, FORBIDDEN_TYPE (B2C) ili COMPANY_SUSPENDED",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "NUMBER_IN_USE, ALREADY_SENT, SEND_IN_PROGRESS, EXTERNAL_ID_CONFLICT",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "413": {
                        "description": "Zahtjev veći od 1 MB",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "VALIDATION_ERROR, TOTAL_MISMATCH, RECIPIENT_NOT_REGISTERED, INVALID_OIB",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "FISCALIZATION_FAILED ili AS4_FAILED: ponovite s istim external_id",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "429": {
                        "$ref": "#/components/responses/RateLimited"
                    }
                }
            }
        },
        "/invoices/{id}": {
            "get": {
                "summary": "Račun",
                "operationId": "getInvoice",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        },
                        "description": "ID računa"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Račun",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Invoice"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Račun ne postoji",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "429": {
                        "$ref": "#/components/responses/RateLimited"
                    }
                }
            }
        },
        "/invoices/{id}/items": {
            "get": {
                "summary": "Stavke računa",
                "operationId": "getInvoiceItems",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        },
                        "description": "ID računa"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Stavke",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "invoice_id": {
                                            "type": "integer"
                                        },
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Item"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Račun ne postoji",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "429": {
                        "$ref": "#/components/responses/RateLimited"
                    }
                }
            }
        },
        "/invoices/{id}/payments": {
            "get": {
                "summary": "Uplate računa",
                "operationId": "getInvoicePayments",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        },
                        "description": "ID računa"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Uplate",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "invoice_id": {
                                            "type": "integer"
                                        },
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Payment"
                                            }
                                        },
                                        "totals": {
                                            "$ref": "#/components/schemas/Totals"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Račun ne postoji",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "429": {
                        "$ref": "#/components/responses/RateLimited"
                    }
                }
            },
            "post": {
                "summary": "Evidentiraj uplatu poslanog računa",
                "operationId": "createPayment",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        },
                        "description": "ID računa"
                    }
                ],
                "description": "Kao gumb Plaćeno u aplikaciji: račun postaje partially_paid / paid, plaćanje B2B računa prijavljuje se Poreznoj upravi. Iznos ne smije premašiti totals.remaining.",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "amount"
                                ],
                                "properties": {
                                    "amount": {
                                        "type": "number",
                                        "minimum": 0.01,
                                        "description": "Iznos, najviše 2 decimale"
                                    },
                                    "code": {
                                        "type": "string",
                                        "enum": [
                                            "T",
                                            "O",
                                            "Z"
                                        ],
                                        "default": "T",
                                        "description": "T transakcijski račun, O obračunsko plaćanje, Z ostalo"
                                    },
                                    "description": {
                                        "type": "string",
                                        "maxLength": 255
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Uplata evidentirana",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "payment": {
                                            "$ref": "#/components/schemas/Payment"
                                        },
                                        "invoice": {
                                            "$ref": "#/components/schemas/Invoice"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "200": {
                        "description": "Testni ključ: uplata provjerena, ništa nije spremljeno",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Račun ne postoji",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "INVALID_STATE: nije poslani izlazni račun, ili je odbijen/storniran",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "VALIDATION_ERROR ili AMOUNT_EXCEEDS_REMAINING",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "429": {
                        "$ref": "#/components/responses/RateLimited"
                    }
                }
            }
        },
        "/invoices/{id}/pdf": {
            "get": {
                "summary": "PDF računa",
                "operationId": "getInvoicePdf",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        },
                        "description": "ID računa"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "PDF",
                        "content": {
                            "application/pdf": {
                                "schema": {
                                    "type": "string",
                                    "format": "binary"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Račun ne postoji",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "NOT_FISCALIZED",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "429": {
                        "$ref": "#/components/responses/RateLimited"
                    }
                }
            }
        },
        "/invoices/{id}/xml": {
            "get": {
                "summary": "UBL XML računa",
                "operationId": "getInvoiceXml",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        },
                        "description": "ID računa"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "UBL 2.1 XML",
                        "content": {
                            "application/xml": {
                                "schema": {
                                    "type": "string",
                                    "format": "binary"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Račun ne postoji ili još nije poslan",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "429": {
                        "$ref": "#/components/responses/RateLimited"
                    }
                }
            }
        },
        "/recipients/{oib}": {
            "get": {
                "summary": "Može li OIB primati eRačun",
                "operationId": "checkRecipient",
                "parameters": [
                    {
                        "name": "oib",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Rezultat",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "oib": {
                                            "type": "string"
                                        },
                                        "can_receive": {
                                            "type": "boolean"
                                        },
                                        "channel": {
                                            "type": "string",
                                            "nullable": true,
                                            "enum": [
                                                "internal",
                                                "as4",
                                                null
                                            ]
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "Neispravan OIB",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "429": {
                        "$ref": "#/components/responses/RateLimited"
                    }
                }
            }
        },
        "/openapi.json": {
            "get": {
                "summary": "Ova specifikacija",
                "operationId": "openapi",
                "security": [],
                "responses": {
                    "200": {
                        "description": "OpenAPI 3 JSON"
                    }
                }
            }
        },
        "/invoices/ubl": {
            "post": {
                "summary": "Izdaj i pošalji gotov UBL 2.1 račun",
                "operationId": "createInvoiceUbl",
                "description": "Vrste 380, 381, 384, 386. Dokument se ne prosljeđuje doslovno: eRačun iz njega čita podatke i izdaje eRačun kao u aplikaciji. Iznosi moraju biti jednaki izračunu (PDV po stavci), inače TOTAL_MISMATCH. Popusti/troškovi na razini računa nisu podržani. Elementi koji se ne prenose navedeni su u warnings.",
                "parameters": [
                    {
                        "name": "external_id",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        },
                        "description": "Vaša jedinstvena oznaka"
                    },
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "schema": {
                            "type": "string"
                        },
                        "description": "Zamjena za external_id"
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/xml": {
                            "schema": {
                                "type": "string",
                                "description": "UBL 2.1 Invoice ili CreditNote (sa SBDH ili bez), do 10 MB"
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Račun izdan i poslan",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Invoice"
                                }
                            }
                        }
                    },
                    "200": {
                        "description": "Već poslan (duplicate) ili testni ključ (test)",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Invoice"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "INVALID_UBL",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "NUMBER_IN_USE, ALREADY_SENT, SEND_IN_PROGRESS, EXTERNAL_ID_CONFLICT",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "413": {
                        "description": "XML veći od 10 MB",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "VALIDATION_ERROR (fields, warnings), TOTAL_MISMATCH (totals), RECIPIENT_NOT_REGISTERED",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "FISCALIZATION_FAILED ili AS4_FAILED",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "429": {
                        "$ref": "#/components/responses/RateLimited"
                    }
                }
            }
        },
        "/invoices/validate": {
            "post": {
                "summary": "Sve provjere računa bez spremanja i slanja (JSON ili UBL)",
                "operationId": "validateInvoice",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/InvoiceCreate"
                            }
                        },
                        "application/xml": {
                            "schema": {
                                "type": "string",
                                "description": "UBL 2.1 Invoice ili CreditNote (sa SBDH ili bez), do 10 MB"
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Ispravno: valid=true, račun kakav bi bio izdan, items, recipient_check, warnings",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Invoice"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "INVALID_JSON ili INVALID_UBL",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "NUMBER_IN_USE",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "VALIDATION_ERROR, TOTAL_MISMATCH",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "429": {
                        "$ref": "#/components/responses/RateLimited"
                    }
                }
            }
        },
        "/invoices/{id}/reject": {
            "post": {
                "summary": "Odbij primljeni račun",
                "operationId": "rejectInvoice",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        },
                        "description": "ID računa"
                    }
                ],
                "description": "Do 15 dana od primitka. Izdavatelju ide aplikacijski odgovor, Poreznoj prijava odbijanja (i kad odgovor izdavatelju ne uspije).",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "kind"
                                ],
                                "properties": {
                                    "kind": {
                                        "type": "string",
                                        "enum": [
                                            "N",
                                            "U",
                                            "O"
                                        ],
                                        "description": "N netočni podaci bez utjecaja na porez, U s utjecajem na porez, O ostalo"
                                    },
                                    "reason": {
                                        "type": "string",
                                        "maxLength": 500,
                                        "description": "Obavezno za O"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Odbijen",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "invoice": {
                                            "$ref": "#/components/schemas/Invoice"
                                        },
                                        "application_response": {
                                            "type": "object",
                                            "nullable": true,
                                            "properties": {
                                                "sent": {
                                                    "type": "boolean"
                                                },
                                                "internal": {
                                                    "type": "boolean"
                                                },
                                                "error": {
                                                    "type": "string",
                                                    "nullable": true
                                                }
                                            }
                                        },
                                        "fiscal": {
                                            "type": "object",
                                            "properties": {
                                                "accepted": {
                                                    "type": "boolean"
                                                },
                                                "id": {
                                                    "type": "string",
                                                    "nullable": true
                                                },
                                                "error": {
                                                    "type": "string",
                                                    "nullable": true
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Račun ne postoji",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "INVALID_STATE, ALREADY_REJECTED, REJECT_PERIOD_EXPIRED",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "VALIDATION_ERROR",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "429": {
                        "$ref": "#/components/responses/RateLimited"
                    }
                }
            }
        },
        "/invoices/{id}/accept": {
            "post": {
                "summary": "Označi primljeni račun prihvaćenim",
                "operationId": "acceptInvoice",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        },
                        "description": "ID računa"
                    }
                ],
                "description": "Samo interna evidencija: izdavatelju i Poreznoj se ništa ne šalje.",
                "responses": {
                    "200": {
                        "description": "Prihvaćen",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Invoice"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Račun ne postoji",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "INVALID_STATE, ALREADY_REJECTED",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "429": {
                        "$ref": "#/components/responses/RateLimited"
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "description": "eracun_live_... ili eracun_test_..."
            },
            "apiKeyHeader": {
                "type": "apiKey",
                "in": "header",
                "name": "X-Api-Key"
            }
        },
        "responses": {
            "Unauthorized": {
                "description": "Nedostaje, neispravan ili opozvan ključ",
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/Error"
                        }
                    }
                }
            },
            "RateLimited": {
                "description": "Previše zahtjeva; pričekajte Retry-After sekundi",
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/Error"
                        }
                    }
                }
            }
        },
        "schemas": {
            "Error": {
                "type": "object",
                "properties": {
                    "error": {
                        "type": "object",
                        "properties": {
                            "code": {
                                "type": "string",
                                "description": "Strojni kod greške"
                            },
                            "message": {
                                "type": "string",
                                "description": "Opis za čovjeka"
                            },
                            "fields": {
                                "type": "object",
                                "additionalProperties": {
                                    "type": "string"
                                },
                                "description": "Polje s problemom i opis"
                            },
                            "invoice_id": {
                                "type": "integer"
                            },
                            "remaining": {
                                "type": "number"
                            },
                            "totals": {
                                "type": "object",
                                "description": "TOTAL_MISMATCH: po iznosu {document, computed}"
                            },
                            "warnings": {
                                "type": "array",
                                "items": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                }
            },
            "InvoiceCreate": {
                "type": "object",
                "required": [
                    "recipient",
                    "items"
                ],
                "properties": {
                    "external_id": {
                        "type": "string",
                        "description": "Vaša jedinstvena oznaka (preporučeno)",
                        "maxLength": 100,
                        "pattern": "^[A-Za-z0-9._:/-]{1,100}$"
                    },
                    "invoice_number": {
                        "type": "string",
                        "description": "Vlastiti broj; bez njega eRačun dodjeljuje sljedeći",
                        "maxLength": 50
                    },
                    "recipient_type": {
                        "type": "string",
                        "enum": [
                            "B2B"
                        ],
                        "default": "B2B"
                    },
                    "type": {
                        "type": "string",
                        "enum": [
                            "380"
                        ],
                        "default": "380"
                    },
                    "business_process": {
                        "type": "string",
                        "enum": [
                            "P1",
                            "P2",
                            "P3",
                            "P5",
                            "P6",
                            "P7",
                            "P8",
                            "P11"
                        ],
                        "default": "P1"
                    },
                    "issue_date": {
                        "type": "string",
                        "format": "date",
                        "description": "Zadano danas"
                    },
                    "delivery_date": {
                        "type": "string",
                        "format": "date",
                        "description": "Zadano datum izdavanja"
                    },
                    "due_date": {
                        "type": "string",
                        "format": "date",
                        "description": "Zadano 3 dana nakon izdavanja"
                    },
                    "recipient": {
                        "type": "object",
                        "required": [
                            "oib",
                            "name"
                        ],
                        "properties": {
                            "oib": {
                                "type": "string",
                                "description": "OIB kupca",
                                "pattern": "^\\d{11}$"
                            },
                            "name": {
                                "type": "string",
                                "maxLength": 255
                            },
                            "address": {
                                "type": "string",
                                "maxLength": 255
                            },
                            "city": {
                                "type": "string",
                                "maxLength": 100
                            },
                            "zip": {
                                "type": "string",
                                "maxLength": 10
                            },
                            "email": {
                                "type": "string",
                                "format": "email"
                            }
                        }
                    },
                    "items": {
                        "type": "array",
                        "minItems": 1,
                        "maxItems": 500,
                        "items": {
                            "$ref": "#/components/schemas/ItemCreate"
                        }
                    },
                    "note": {
                        "oneOf": [
                            {
                                "type": "string"
                            },
                            {
                                "type": "array",
                                "items": {
                                    "type": "string"
                                }
                            }
                        ]
                    },
                    "payment_terms": {
                        "type": "string",
                        "description": "Zadano standardni tekst iz aplikacije"
                    },
                    "payment_reference": {
                        "type": "string",
                        "description": "Poziv na broj, zadano HR00 broj-godina",
                        "maxLength": 150
                    },
                    "contract_reference": {
                        "type": "string",
                        "maxLength": 100
                    },
                    "operator": {
                        "type": "object",
                        "properties": {
                            "name": {
                                "type": "string",
                                "description": "Zadano naziv ključa"
                            },
                            "oib": {
                                "type": "string",
                                "description": "Zadano OIB osobe koja je izradila ključ"
                            }
                        }
                    },
                    "expected_total": {
                        "type": "number",
                        "description": "Kontrola ukupnog iznosa s PDV-om"
                    }
                }
            },
            "ItemCreate": {
                "type": "object",
                "required": [
                    "description",
                    "product_code",
                    "quantity",
                    "unit_price"
                ],
                "properties": {
                    "description": {
                        "type": "string",
                        "maxLength": 100
                    },
                    "description_extra": {
                        "type": "string",
                        "maxLength": 1024
                    },
                    "product_code": {
                        "type": "string",
                        "description": "KPD šifra, 6 znamenki (npr. 62.10.11)"
                    },
                    "quantity": {
                        "type": "number",
                        "exclusiveMinimum": true,
                        "minimum": 0,
                        "description": "Do 3 decimale"
                    },
                    "unit_price": {
                        "type": "number",
                        "description": "Bez PDV-a, do 10 decimala, različita od 0"
                    },
                    "unit": {
                        "type": "string",
                        "description": "UN/ECE Rec 20",
                        "default": "H87"
                    },
                    "tax_category": {
                        "type": "string",
                        "enum": [
                            "S",
                            "Z",
                            "E",
                            "AE"
                        ],
                        "default": "S"
                    },
                    "tax_rate": {
                        "type": "number",
                        "enum": [
                            25,
                            13,
                            5,
                            0
                        ],
                        "default": 25
                    },
                    "tax_exemption_reason": {
                        "type": "string",
                        "description": "Obavezno za E i AE"
                    }
                }
            },
            "Totals": {
                "type": "object",
                "properties": {
                    "net": {
                        "type": "number"
                    },
                    "vat": {
                        "type": "number"
                    },
                    "gross": {
                        "type": "number"
                    },
                    "prepaid": {
                        "type": "number"
                    },
                    "credited": {
                        "type": "number",
                        "description": "Storna i odobrenja na račun (negativno)"
                    },
                    "payable": {
                        "type": "number"
                    },
                    "paid": {
                        "type": "number"
                    },
                    "remaining": {
                        "type": "number"
                    }
                }
            },
            "Invoice": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "integer",
                        "nullable": true
                    },
                    "direction": {
                        "type": "string",
                        "enum": [
                            "out",
                            "in"
                        ]
                    },
                    "external_id": {
                        "type": "string",
                        "nullable": true
                    },
                    "invoice_number": {
                        "type": "string"
                    },
                    "type": {
                        "type": "integer"
                    },
                    "business_process": {
                        "type": "string"
                    },
                    "recipient_type": {
                        "type": "string",
                        "enum": [
                            "B2B",
                            "B2C"
                        ]
                    },
                    "issue_date": {
                        "type": "string",
                        "format": "date"
                    },
                    "issue_time": {
                        "type": "string",
                        "nullable": true
                    },
                    "delivery_date": {
                        "type": "string",
                        "nullable": true
                    },
                    "due_date": {
                        "type": "string",
                        "nullable": true
                    },
                    "currency": {
                        "type": "string"
                    },
                    "sender": {
                        "type": "object",
                        "properties": {
                            "oib": {
                                "type": "string",
                                "description": "OIB"
                            },
                            "name": {
                                "type": "string"
                            },
                            "address": {
                                "type": "string",
                                "nullable": true
                            },
                            "city": {
                                "type": "string",
                                "nullable": true
                            },
                            "zip": {
                                "type": "string",
                                "nullable": true
                            },
                            "email": {
                                "type": "string",
                                "nullable": true
                            },
                            "country": {
                                "type": "string",
                                "nullable": true
                            },
                            "iban": {
                                "type": "string",
                                "nullable": true
                            }
                        }
                    },
                    "recipient": {
                        "type": "object",
                        "properties": {
                            "oib": {
                                "type": "string",
                                "description": "OIB"
                            },
                            "name": {
                                "type": "string"
                            },
                            "address": {
                                "type": "string",
                                "nullable": true
                            },
                            "city": {
                                "type": "string",
                                "nullable": true
                            },
                            "zip": {
                                "type": "string",
                                "nullable": true
                            },
                            "email": {
                                "type": "string",
                                "nullable": true
                            }
                        }
                    },
                    "totals": {
                        "$ref": "#/components/schemas/Totals"
                    },
                    "payment": {
                        "type": "object",
                        "properties": {
                            "terms": {
                                "type": "string",
                                "nullable": true
                            },
                            "reference": {
                                "type": "string",
                                "nullable": true
                            },
                            "iban": {
                                "type": "string",
                                "nullable": true
                            }
                        }
                    },
                    "references": {
                        "type": "object",
                        "properties": {
                            "previous_invoice": {
                                "type": "string",
                                "nullable": true
                            },
                            "previous_invoice_date": {
                                "type": "string",
                                "nullable": true
                            },
                            "contract": {
                                "type": "string",
                                "nullable": true
                            }
                        }
                    },
                    "operator": {
                        "type": "object",
                        "properties": {
                            "name": {
                                "type": "string",
                                "nullable": true
                            },
                            "oib": {
                                "type": "string",
                                "nullable": true
                            }
                        }
                    },
                    "note": {
                        "type": "array",
                        "nullable": true,
                        "items": {
                            "type": "string"
                        }
                    },
                    "status": {
                        "type": "string",
                        "enum": [
                            "draft",
                            "not_sent",
                            "processing",
                            "delivered",
                            "received",
                            "accepted",
                            "rejected",
                            "partially_paid",
                            "paid",
                            "cancelled",
                            "error",
                            "test"
                        ]
                    },
                    "status_raw": {
                        "type": "string",
                        "description": "Interni status"
                    },
                    "delivery": {
                        "type": "object",
                        "properties": {
                            "channel": {
                                "type": "string",
                                "nullable": true,
                                "enum": [
                                    "internal",
                                    "as4",
                                    null
                                ]
                            },
                            "message_id": {
                                "type": "string",
                                "nullable": true
                            },
                            "delivered_at": {
                                "type": "string",
                                "nullable": true
                            }
                        }
                    },
                    "fiscal_id": {
                        "type": "string",
                        "nullable": true,
                        "description": "Fiskalizacija 2.0: idZahtjeva"
                    },
                    "rejection": {
                        "type": "object",
                        "nullable": true,
                        "properties": {
                            "at": {
                                "type": "string",
                                "nullable": true
                            },
                            "reason": {
                                "type": "string",
                                "nullable": true
                            },
                            "kind": {
                                "type": "string",
                                "nullable": true
                            }
                        }
                    },
                    "paid_at": {
                        "type": "string",
                        "nullable": true
                    },
                    "source": {
                        "type": "string",
                        "nullable": true,
                        "enum": [
                            "api",
                            "panel",
                            null
                        ]
                    },
                    "created_at": {
                        "type": "string",
                        "nullable": true
                    },
                    "updated_at": {
                        "type": "string",
                        "nullable": true
                    },
                    "links": {
                        "type": "object",
                        "nullable": true,
                        "properties": {
                            "self": {
                                "type": "string"
                            },
                            "items": {
                                "type": "string"
                            },
                            "payments": {
                                "type": "string"
                            },
                            "pdf": {
                                "type": "string"
                            },
                            "xml": {
                                "type": "string"
                            }
                        }
                    },
                    "duplicate": {
                        "type": "boolean",
                        "description": "POST: račun je već bio poslan ranije"
                    },
                    "test": {
                        "type": "boolean",
                        "description": "POST testnim ključem: ništa nije spremljeno ni poslano"
                    },
                    "items": {
                        "type": "array",
                        "items": {
                            "$ref": "#/components/schemas/Item"
                        },
                        "description": "Samo u odgovoru testnog ključa"
                    },
                    "recipient_check": {
                        "type": "object",
                        "description": "Samo u odgovoru testnog ključa",
                        "properties": {
                            "can_receive": {
                                "type": "boolean"
                            },
                            "channel": {
                                "type": "string",
                                "nullable": true
                            }
                        }
                    },
                    "delivery_result": {
                        "type": "string",
                        "enum": [
                            "internal",
                            "as4"
                        ],
                        "description": "POST 201: kako je račun dostavljen"
                    },
                    "errors": {
                        "type": "object",
                        "nullable": true,
                        "description": "Razlog neuspjele dostave ili fiskalizacije",
                        "properties": {
                            "delivery": {
                                "type": "string",
                                "nullable": true
                            },
                            "fiscal": {
                                "type": "string",
                                "nullable": true
                            }
                        }
                    },
                    "warnings": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        },
                        "description": "UBL: elementi koji se ne prenose i prilagodbe; provjera: upozorenja"
                    },
                    "valid": {
                        "type": "boolean",
                        "description": "Odgovor provjere bez slanja"
                    }
                }
            },
            "InvoiceList": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "array",
                        "items": {
                            "$ref": "#/components/schemas/Invoice"
                        }
                    },
                    "pagination": {
                        "type": "object",
                        "properties": {
                            "page": {
                                "type": "integer"
                            },
                            "per_page": {
                                "type": "integer"
                            },
                            "total": {
                                "type": "integer"
                            },
                            "pages": {
                                "type": "integer"
                            }
                        }
                    },
                    "server_time": {
                        "type": "string",
                        "description": "Vrijeme poslužitelja; sljedeći updated_since"
                    }
                }
            },
            "Item": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "integer"
                    },
                    "description": {
                        "type": "string"
                    },
                    "description_extra": {
                        "type": "string",
                        "nullable": true
                    },
                    "product_code": {
                        "type": "string",
                        "nullable": true
                    },
                    "unit": {
                        "type": "string"
                    },
                    "quantity": {
                        "type": "number"
                    },
                    "unit_price": {
                        "type": "number"
                    },
                    "discount_percent": {
                        "type": "number"
                    },
                    "tax_category": {
                        "type": "string"
                    },
                    "tax_rate": {
                        "type": "number"
                    },
                    "tax_exemption_reason": {
                        "type": "string",
                        "nullable": true
                    },
                    "totals": {
                        "type": "object",
                        "properties": {
                            "net": {
                                "type": "number"
                            },
                            "vat": {
                                "type": "number"
                            },
                            "gross": {
                                "type": "number"
                            }
                        }
                    }
                }
            },
            "Payment": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "integer",
                        "nullable": true
                    },
                    "amount": {
                        "type": "number"
                    },
                    "code": {
                        "type": "string",
                        "enum": [
                            "T",
                            "O",
                            "Z"
                        ]
                    },
                    "description": {
                        "type": "string",
                        "nullable": true
                    },
                    "created_at": {
                        "type": "string"
                    }
                }
            }
        }
    }
}
