Skip to content

QR Codes

Generating QR payloads from finalized/signed invoices and reading embedded QR payloads from signed invoices.

Example

pub fn main() {
    use fatoora_core::invoice::xml::parse::parse_signed_invoice_xml;

    // Doc example: extract QR payload from signed XML.
    let signed_xml_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
        .join("tests/fixtures/invoices/sample-simplified-invoice.xml");
    let signed_xml = std::fs::read_to_string(&signed_xml_path).expect("read signed invoice xml");
    let signed = parse_signed_invoice_xml(&signed_xml).expect("parse signed invoice");
    let qr = signed.qr_code();
    assert!(!qr.is_empty());
}
from fatoora.invoice import parse_signed_invoice_xml

# signed_xml_path = "path/to/signed_invoice.xml"
signed_xml = signed_xml_path.read_text(encoding="utf-8")
signed = parse_signed_invoice_xml(signed_xml)
qr = signed.qr_code()
assert qr
#include "fatoora.h"

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifndef FATOORA_DOC_SIGNED_XML
#define FATOORA_DOC_SIGNED_XML "path/to/signed_invoice.xml"
#endif

static char *read_file(const char *path);

int main(void) {
  const char *signed_xml_path = FATOORA_DOC_SIGNED_XML;
  char *xml_cstr = read_file(signed_xml_path);

  /* signed_xml_path = "path/to/signed_invoice.xml" */
  struct FfiResult_FfiSignedInvoice signed_invoice =
      fatoora_parse_signed_invoice_xml(xml_cstr);

  struct FfiResult_FfiString qr =
      fatoora_signed_invoice_qr_code(&signed_invoice.value);

  assert(qr.value.ptr && strstr(qr.value.ptr, "AW/YtNix2YPYqSDY"));

  /* use qr.value.ptr, then free */
  fatoora_string_free(qr.value);
  free(xml_cstr);
  fatoora_signed_invoice_free(&signed_invoice.value);
  return 0;
}
fatoora-rs-cli qr --invoice invoice.xml
fatoora-rs-cli qr --invoice signed.xml
fatoora-rs-cli qr --invoice signed.xml --fail-on-signed
fatoora-rs-cli qr-read --invoice signed.xml

Notes

  • The QR payload is a base64-encoded TLV string. Tag ordering follows ZATCA (seller, VAT, timestamp, totals) and includes signing tags when available.

See also: QR Reference