View Source ExFiskal (ExFiskal v1.2.0)

Documentation for ExFiskal.

Summary

Functions

Fiscalizes the recepit taking in params and the extracted private key and public certificate.

Parses the XML response from the fiscalization service and extracts the JIR (Jedinstveni identifikator računa / Unique Invoice Identifier).

Functions

extract_certificate_data!(certificate, password)

fiscalize!(params, certificate_data)

Fiscalizes the recepit taking in params and the extracted private key and public certificate.

Example

The following is the "minimal" example for fiscalizing a recepit/invoice.

You will need:

  • Tax number (OIB) of the entity issuing the invoice (d.o.o., j.d.o.o., obrt, or d.d.)
  • Tax number (OIB) of the operator
  • Certificate from Fina in P12 format and it's password
params = %{
  tax_number: "23618229102",
  invoice_number: "1",
  business_unit: "1",
  device_number: "1",
  total_amount: 10000,
  invoice_datetime: ~U[2024-12-12 14:46:49.258317Z],
  sequence_mark: ExFiskal.Enums.SequenceMark.business_unit(),
  payment_method: ExFiskal.Enums.PaymentMethod.cards(),
  vat: [
    %{rate: 2500, base: 10000, amount: 2000}
  ],
  operator_tax_number: "37501579645",
  # Optional: Invoice recipient's OIB for B2B transactions (v2.6 spec)
  # Note: Cannot be used with payment_method: "T" (Transaction Account)
  oib_primatelja_racuna: "12345678901"
}

certificate = File.read!("/tmp/cert.p12")
password = "ExamplePassword"

# First extract the certificate keys
certificate_data = ExFiskal.extract_certificate_data!(certificate, password)

# Then fiscalize with the extracted keys
ExFiskal.fiscalize(params, certificate_data)

parse_response(xml_response)

Parses the XML response from the fiscalization service and extracts the JIR (Jedinstveni identifikator računa / Unique Invoice Identifier).

Parameters

  • xml_response - The XML string response from the fiscalization service

Returns

  • {:ok, jir} - Returns the JIR string if found
  • {:error, reason} - Returns an error if parsing fails or JIR is not found

Example

iex> xml = File.read!("priv/examples/response.xml")
iex> ExFiskal.parse_response(xml)
{:ok, "a70a985a-8882-4390-83e6-3a091970ed99"}