getInvoicesByStatus method

  1. @override
Future<List> getInvoicesByStatus(
  1. dynamic status, {
  2. String? walletId,
})
override

Get all invoices with a specific status.

Parameters:

  • status: Invoice status to filter by
  • walletId: Optional wallet ID to filter further

Returns: List of invoices matching the status

Implementation

@override
Future<List<dynamic>> getInvoicesByStatus(
  dynamic status, {
  String? walletId,
}) async {
  _ensureInitialized();

  var sql = '''
    SELECT invoice_id, wallet_id, addresses_json, amount, description,
           status, created_at, expires_at, paid_at, payment_txid,
           amount_received, metadata_json
    FROM invoices
    WHERE status = @status
  ''';

  final params = <String, dynamic>{
    'status': (status as InvoiceStatus).name,
  };

  if (walletId != null) {
    sql += ' AND wallet_id = @walletId';
    params['walletId'] = walletId;
  }

  sql += ' ORDER BY created_at DESC';

  final result = await _pool!.execute(Sql.named(sql), parameters: params);
  return result.map(_rowToInvoice).toList();
}