> ## Documentation Index
> Fetch the complete documentation index at: https://developers.novatrade24.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Finalization & Export File

> Final invoice based on compliance decision, auto-generated Export File PDF, regeneration, and immutable versioning.

Finalization is the last stage of the workflow. The compliance rollup
transitions to `VALID` or `INVALID`, a **final invoice** is submitted
(matching the VAT decision), and NT24 generates the **Export File** — the
signed PDF your customer's tax authority expects.

## Decision branch

Once the earlier modules are complete, compliance settles on a verdict:

| `complianceStatus` | `decision`       | Final invoice requirement |
| ------------------ | ---------------- | ------------------------- |
| `VALID`            | `VALID_EXPORT`   | VAT-exempt final invoice  |
| `INVALID`          | `VAT_APPLICABLE` | VAT-applied final invoice |

Webhook subscribers learn the outcome via `compliance.decision_made`.
Pollers see `decision` populated on `GET .../compliance`.

## Submit the final invoice

```bash theme={null}
curl -X POST "https://api.novatrade24.com/v1/partners/${SELLER_ID}/orders/${ORDER_UUID}/finalization/final-invoice" \
  -H "Authorization: Bearer ${ACCESS_TOKEN}" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "FINAL",
    "invoiceDate": "2026-04-25",
    "invoiceNumber": "INV-2026-04-00451-F",
    "vatIncluded": false,
    "marginScheme": false,
    "amount": { "value": 1850000, "currency": "EUR" }
  }'
```

Upload the PDF alongside:

```bash theme={null}
curl -X POST "https://api.novatrade24.com/v1/partners/${SELLER_ID}/orders/${ORDER_UUID}/invoice/documents" \
  -H "Authorization: Bearer ${ACCESS_TOKEN}" \
  -H "Idempotency-Key: $(uuidgen)" \
  -F "type=SHIPMENT_INVOICE" \
  -F "documentDate=2026-04-25" \
  -F "file=@/path/to/final-invoice.pdf"
```

When the final invoice is added, the Export File regenerates to include
it — a new document version supersedes the previous.

## Export File

The Export File is a signed PDF bundling:

* Buyer identification and KYC validation results.
* Transaction details (VIN(s), purchase date, amount).
* Invoice(s) preliminary and final.
* Payment validation (amount, IBAN, proof).
* Transport proof (CMR or pickup declaration, delivery confirmation).
* VIES check history.
* Compliance decision rationale (`VALID_EXPORT` or `VAT_APPLICABLE`).

It is generated for **both** `VALID` and `INVALID` outcomes — in the
`INVALID` case it documents why VAT was applied, which tax authorities
also require as an audit artifact.

## Auto-generation

Generation kicks off automatically when:

* `complianceStatus` transitions to `VALID` (first time).
* `complianceStatus` transitions to `INVALID`.
* Final invoice is added and supersedes the earlier version.
* `complianceStatus` recomputes from `INCOMPLETE` back to a terminal state
  (e.g. a missing doc was uploaded late).

Each generation is a Temporal workflow. You don't need to trigger it
manually in the happy path.

## Force regeneration

For exceptional cases (PDF corrupted, template updated, compliance data
manually adjusted):

```bash theme={null}
curl -X POST "https://api.novatrade24.com/v1/partners/${SELLER_ID}/orders/${ORDER_UUID}/finalization/regenerate-export" \
  -H "Authorization: Bearer ${ACCESS_TOKEN}" \
  -H "Idempotency-Key: $(uuidgen)"
```

Returns `202 Accepted`. New version is available shortly; webhook
`export_file.generated` fires.

## Status and download

```bash theme={null}
curl "https://api.novatrade24.com/v1/partners/${SELLER_ID}/orders/${ORDER_UUID}/finalization/export-file" \
  -H "Authorization: Bearer ${ACCESS_TOKEN}"
```

Response:

```json theme={null}
{
  "status": "READY",
  "version": 2,
  "downloadUrl": "/v1/documents/doc_xyz123/download",
  "generatedAt": "2026-04-25T14:30:00Z",
  "decision": "VALID_EXPORT",
  "supersededVersions": [
    {
      "version": 1,
      "generatedAt": "2026-04-24T16:00:00Z",
      "archivedReason": "final_invoice_added"
    }
  ]
}
```

Download the PDF:

```bash theme={null}
curl "https://api.novatrade24.com/v1/documents/doc_xyz123/download" \
  -H "Authorization: Bearer ${ACCESS_TOKEN}" \
  -o export-file-v2.pdf
```

## Statuses

| `status`       | Meaning                                                                                                                        |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `NOT_ELIGIBLE` | Compliance not yet terminal. Cannot generate.                                                                                  |
| `GENERATING`   | Workflow in progress. Typically \< 30s.                                                                                        |
| `READY`        | PDF available for download.                                                                                                    |
| `PENDING`      | Queued for regeneration.                                                                                                       |
| `FAILED`       | Terminal generation failure. Webhook `export_file.generation_failed` fires (Phase 2+ catalog). Use manual regenerate to retry. |

## Versioning & immutability

Every generation produces a new document version. Previous versions are
marked `ARCHIVED` (not deleted) so the tax-authority audit trail is
preserved. Envers retains full revision history.

Your integration should download the **latest** version (`status: READY`)
by default. Older versions remain accessible if you saved their
`documentId` previously.

## Webhook for real-time download

```json theme={null}
{
  "type": "export_file.generated",
  "data": {
    "orderUuid": "o1p2q3r4-...",
    "documentId": "doc_xyz123",
    "version": 2,
    "downloadUrl": "/v1/documents/doc_xyz123/download",
    "generatedAt": "2026-04-25T14:30:00Z",
    "decision": "VALID_EXPORT"
  }
}
```

Download immediately on receipt; the URL is stable for the document's
lifetime.

## Next

<CardGroup cols={2}>
  <Card title="Webhook setup" icon="bell" href="/webhooks/setup">
    Subscribe to `export_file.generated`.
  </Card>

  <Card title="Compliance rollup" icon="gauge" href="/concepts/compliance-rollup">
    Understand what drives the decision.
  </Card>
</CardGroup>
