fromJsonList static method
Liest invoicePayments vom Draht. Ein Eintrag ohne Rechnungs-ID, Nummer, Zahlungs-ID oder
ganzzahligen Betrag faellt weg (lesen tolerant, der Beleg bleibt anzeigbar); ohne brauchbaren
Eintrag gibt es keinen Bezug (null). taxNote gilt nur mit einem der drei bekannten Werte, sonst
null (kein Hinweis): ein Beleg behauptet nie eine Steuer, die er nicht kennt.
Implementation
static List<InvoicePaymentRef>? fromJsonList(Object? raw) {
if (raw is! List) return null;
String? text(Object? w) => w is String && w.isNotEmpty ? w : null;
final raus = <InvoicePaymentRef>[];
for (final e in raw) {
if (e is! Map) continue;
final id = text(e['invoiceId']);
final nummer = text(e['invoiceNumber']);
final zahlung = text(e['paymentId']);
final betrag = e['amountCents'];
if (id == null || nummer == null || zahlung == null) continue;
if (betrag is! num || betrag != betrag.truncate()) continue;
raus.add(InvoicePaymentRef(
invoiceId: id,
invoiceNumber: nummer,
paymentId: zahlung,
customerId: text(e['customerId']),
amountCents: betrag.toInt(),
partial: e['partial'] == true,
paidOn: text(e['paidOn']),
taxNote: e['taxNote'] is String && taxNotes.contains(e['taxNote']) ? e['taxNote'] as String : null,
));
}
return raus.isEmpty ? null : raus;
}