invoiceEncode function
String
invoiceEncode(
- InvoiceDataModel model, [
- InvoiceEncodeOptions options = const InvoiceEncodeOptions()
Encodes an InvoiceDataModel into a Base32Hex QR string.
Uses bysquareType=1; the InvoiceDataModel.documentType nibble selects the specific sub-type (Invoice, ProformaInvoice, CreditNote, etc.).
Implementation
String invoiceEncode(
InvoiceDataModel model, [
InvoiceEncodeOptions options = const InvoiceEncodeOptions(),
]) {
if (options.validate) {
validateInvoiceDataModel(model);
}
final tabbed = invoiceSerialize(model);
final checked = addChecksum(tabbed);
final compressed = lzmaCompress(checked);
// Strip the 13-byte LZMA header - bysquare stores only the body
final lzmaBody = compressed.sublist(13);
final output = Uint8List.fromList([
...buildBysquareHeader(
bySquareType: 0x01, // TYPE_INVOICE
version: options.version,
documentType: model.documentType,
),
...buildPayloadLength(checked.length),
...lzmaBody,
]);
return base32hexEncode(output, addPadding: false);
}