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
public static string ReadQr(string signedXml)
{
using var invoice = SignedInvoice.FromXml(signedXml);
return invoice.QrCode(); // Base64-encoded TLV payload.
}
#include "fatoora.h"
#include <stdio.h>
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s signed-invoice.xml\n", argv[0]);
return 1;
}
FatooraSignedInvoice *invoice = NULL;
FatooraError *error = NULL;
char *qr = NULL;
FatooraStatus status = fatoora_signed_invoice_from_file(argv[1], &invoice, &error);
if (status == FATOORA_OK)
status = fatoora_signed_invoice_qr_code(invoice, &qr, &error);
if (status == FATOORA_OK) puts(qr);
else fprintf(stderr, "Error %d: %s\n", (int)status, fatoora_error_message(error));
fatoora_string_free(qr);
fatoora_signed_invoice_free(invoice);
fatoora_error_free(error);
return status == FATOORA_OK ? 0 : 1;
}
fatoora qr --invoice invoice.xml
fatoora qr --invoice signed.xml
fatoora qr --invoice signed.xml --fail-on-signed
fatoora 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
C examples include fatoora.h; compile the adapter once with your application.
See the C build instructions.
See the C# / .NET reference for installation, imports, and ownership rules.