fetchTransactionsReport function
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');
}
}