fetchBalanceHistory function

Future<BalanceHistoryListModel> fetchBalanceHistory(
  1. String userId,
  2. String currency,
  3. String startDate,
  4. String endDate,
  5. Config config,
)

Implementation

Future<BalanceHistoryListModel> fetchBalanceHistory(String userId,
    String currency, String startDate, String endDate, Config config) async {
  String path =
      '${constants.API_HOST}/tenant/${config.applicationId}/reports/get-partner-balances-report-by-date?filter%5BuserId%5D=$userId&filter%5Bcurrency%5D=$currency&filter%5BdateRange%5D%5B%5D=$startDate&filter%5BdateRange%5D%5B%5D=$endDate';

  final response = await http.post(Uri.parse(path),
      body: jsonEncode(<String, String>{
        "application_id": config.applicationId,
        "client_secret": config.clientSecret,
        "client_id": config.clientId,
        "version": config.version,
      }),
      headers: <String, String>{
        'Content-Type': 'application/json; charset=UTF-8',
      });

  if (response.statusCode == 200) {
    // If the server did return a 200 OK response,
    // then parse the JSON.
    var rb = response.body;

    // store json data into list
    var jsonResponse = jsonDecode(rb);

    BalanceHistoryListModel balanceHistoryListModel =
        BalanceHistoryListModel.fromJson(jsonResponse);

    return balanceHistoryListModel;
  } else {
    // If the server did not return a 200 OK response,
    // then throw an exception.
    throw Exception('Failed to fetch balance');
  }
}