Facturx (Facturx v0.1.0)

Copy Markdown View Source

Factur-X / ZUGFeRD hybrid e-invoices in pure Elixir.

A Factur-X invoice is a PDF/A-3 document with a machine-readable CII XML (EN 16931) embedded inside it. This module is the public facade; the work is split across:

See docs/adr/0001-perimetre-et-architecture.md for scope decisions.

Summary

Types

Factur-X / ZUGFeRD conformance profiles, from leanest to richest.

Functions

Build a CII XML binary from an Facturx.Invoice struct.

Extract the embedded CII XML (and metadata) from a Factur-X PDF.

Build a Factur-X PDF: embed the CII XML for invoice into a PDF/A-3.

Parse a CII XML binary into an Facturx.Invoice struct.

The supported Factur-X profiles.

Validate CII XML against the EN 16931 Schematron rules.

Types

profile()

@type profile() :: :minimum | :basic_wl | :basic | :en16931 | :extended

Factur-X / ZUGFeRD conformance profiles, from leanest to richest.

Functions

build(invoice, opts \\ [])

@spec build(
  Facturx.Invoice.t(),
  keyword()
) :: {:ok, binary()} | {:error, term()}

Build a CII XML binary from an Facturx.Invoice struct.

extract(pdf)

@spec extract(binary()) ::
  {:ok, %{xml: binary(), profile: profile() | nil, filename: String.t()}}
  | {:error, term()}

Extract the embedded CII XML (and metadata) from a Factur-X PDF.

generate(pdf_a3, invoice_or_xml, opts \\ [])

@spec generate(binary(), Facturx.Invoice.t() | binary(), keyword()) ::
  {:ok, binary()} | {:error, term()}

Build a Factur-X PDF: embed the CII XML for invoice into a PDF/A-3.

pdf_a3 must already be a valid PDF/A-3 (the visual invoice). Pass either an Facturx.Invoice struct or a ready CII XML binary as the payload.

parse(xml)

@spec parse(binary()) :: {:ok, Facturx.Invoice.t()} | {:error, term()}

Parse a CII XML binary into an Facturx.Invoice struct.

profiles()

@spec profiles() :: [profile()]

The supported Factur-X profiles.

validate(xml, opts \\ [])

@spec validate(
  binary(),
  keyword()
) :: {:ok, :valid} | {:error, {:invalid, [map()]}} | {:error, term()}

Validate CII XML against the EN 16931 Schematron rules.

Optional: requires a reachable Saxon endpoint (:endpoint opt) and the req dependency. Disabled by default — see Facturx.Validate.