getBalance method

  1. @override
Future<List<Wallet>> getBalance()
override

Get your merchant Wallet assets with corresponding balance.

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

Implementation

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

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