fetchTransactionsReport function

Future<TransactionReportListModel> fetchTransactionsReport(
  1. String? filter,
  2. String? startDate,
  3. String? endDate,
  4. bool? suspense,
  5. int? limit,
  6. Config config,
)

Implementation

Future<TransactionReportListModel> fetchTransactionsReport(
  String? filter,
  String? startDate,
  String? endDate,
  bool? suspense,
  int? limit,
  Config config,
) async {
  String filterQuery = filter ?? "";
  String startingDate =
      startDate != null ? "&filter%5BCreatedAtRange%5D=$startDate" : "&";
  String endingDate =
      endDate != null ? "&filter%5BCreatedAtRange%5D=$endDate" : "&";
  String suspensed = suspense != null ? "&suspense=$suspense" : "&";
  String limitValue = limit != null ? "&Limit=${limit}" : "&";

  String path =
      '${constants.REPORTING_API_HOST}/tenant/${config.applicationId}/transactions?$filterQuery$startingDate$endingDate$suspensed$limitValue';

  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;
    var jsonResponse = jsonDecode(rb);

    TransactionReportListModel transactions =
        TransactionReportListModel.fromJson(jsonResponse);

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