getInvoices method

  1. @override
Future<List<Invoice>> getInvoices()
override

Get your merchant invoices.

Throw UnauthorizedException when the secret key is invalid, otherwise it throws exception TelePayException with any other error.

Implementation

@override
Future<List<Invoice>> getInvoices() async {
  try {
    final response = await _dio.get<Map<String, dynamic>>(
      'getInvoices',
      options: Options(headers: _headers),
    );
    if (response.statusCode == 200 && response.data != null) {
      final data = response.data!['invoices']! as List<dynamic>;
      final invoices = data.cast<Map<String, dynamic>>();

      return invoices.map(Invoice.fromJson).toList();
    }
  } on DioError catch (e) {
    _handlerError(e, 'get invoices');
  }
  throw const TelePayException('Failed to get invoices info');
}