getAvailableTerminals method
Returns all available (online, payment-capable) terminals for a business.
Implementation
Future<List<CloudPosTerminal>> getAvailableTerminals(
String businessId,
) async {
final url = '$baseUrl/cloudpos/api/cloudpos/terminals/$businessId';
_logger.info(this, 'getAvailableTerminals called for business $businessId');
final response = await _httpClient.get(url: url, user: _authService.user);
if (response != null && response.statusCode == HttpStatus.ok) {
final List<dynamic> items = response.data is String
? jsonDecode(response.data as String) as List<dynamic>
: response.data as List<dynamic>;
_logger.debug(
this,
'getAvailableTerminals returned ${items.length} terminals',
);
return items
.map((e) => CloudPosTerminal.fromJson(e as Map<String, dynamic>))
.toList();
}
_logger.error(
this,
'getAvailableTerminals failed: ${response?.statusCode} ${response?.statusMessage}',
);
throw PlatformException(
code: 'GET_TERMINALS_FAILED',
message:
'Failed to fetch available terminals: ${response?.statusCode ?? 'no response'}',
);
}