ExCius.InvoiceUtils (ExCius v0.3.2)

View Source

Utility functions for working with UBL 2.1 Invoice XML documents.

Provides functions to:

  • Extract attachments from invoices
  • Detect if an invoice is digitally signed

Summary

Functions

Extracts all attachments from the given UBL Invoice XML.

Extracts all attachments from the given UBL Invoice XML.

Checks if the given UBL Invoice XML is digitally signed.

Checks if the given UBL Invoice XML is digitally signed.

Functions

extract_attachments(xml_content)

Extracts all attachments from the given UBL Invoice XML.

Returns a list of attachment maps, each containing:

  • :id - The document reference ID
  • :filename - The filename of the attachment (if provided)
  • :mime_type - The MIME type of the attachment
  • :content - The Base64-decoded binary content of the attachment

Parameters

  • xml_content - UBL Invoice XML document as a string

Returns

  • {:ok, list} - List of attachment maps
  • {:error, reason} - If XML parsing fails

Examples

iex> xml = File.read!("priv/examples/signed_with_pdf.xml")
iex> {:ok, attachments} = ExCius.InvoiceUtils.extract_attachments(xml)
iex> length(attachments)
1
iex> hd(attachments).filename
"vizualizacija_63-1-1.pdf"
iex> hd(attachments).mime_type
"application/pdf"

extract_attachments!(xml_content)

Extracts all attachments from the given UBL Invoice XML.

Returns a list of attachment maps. Raises an error if XML parsing fails.

Parameters

  • xml_content - UBL Invoice XML document as a string

Returns

  • list - List of attachment maps

Examples

iex> xml = File.read!("priv/examples/signed_with_pdf.xml")
iex> attachments = ExCius.InvoiceUtils.extract_attachments!(xml)
iex> length(attachments)
1

signed!(xml_content)

Checks if the given UBL Invoice XML is digitally signed.

Returns true if the invoice contains a digital signature, false otherwise. Raises an error if XML parsing fails.

Parameters

  • xml_content - UBL Invoice XML document as a string

Returns

  • boolean - Whether the invoice is signed

Examples

iex> xml = File.read!("priv/examples/signed_with_pdf.xml")
iex> ExCius.InvoiceUtils.signed!(xml)
true

signed?(xml_content)

Checks if the given UBL Invoice XML is digitally signed.

Returns true if the invoice contains a digital signature, false otherwise.

Parameters

  • xml_content - UBL Invoice XML document as a string

Returns

  • {:ok, boolean} - Whether the invoice is signed
  • {:error, reason} - If XML parsing fails

Examples

iex> xml = File.read!("priv/examples/signed_with_pdf.xml")
iex> ExCius.InvoiceUtils.signed?(xml)
{:ok, true}

iex> xml = File.read!("priv/examples/basic_invoice.xml")
iex> ExCius.InvoiceUtils.signed?(xml)
{:ok, false}