batchOrderRead method

Future<List<Order>> batchOrderRead({
  1. required BatchOrderRequest request,
  2. String? authToken,
})

Retrieves a set of orders by their IDs. If a given order ID does not exist, the ID is ignored instead of generating an error.

Implementation

Future<List<Order>> batchOrderRead({
  required BatchOrderRequest request,
  String? authToken,
}) async {

  authToken ??= authenticationService.getCachedToken()?.accessToken;

  Map<String, String> headers = {
    "Authorization": "Bearer ${authToken ?? ""}",
    'Content-Type': 'application/json; charset=UTF-8',
    'Accept': 'application/json',

  };

  Uri endpoint = Uri.https(
      baseUrl, "/v2/orders/batch-retrieve");

  //print (endpoint.toString());

  var response = await
  http.post(endpoint, body: jsonEncode(request.toJson()), headers: headers);

  if (response.statusCode == 200) {
    print (jsonDecode(response.body));
    return OrderResponse.fromJson(jsonDecode(response.body)).orders ?? List.empty();
  }
  else {
    print (response.body);
    throw OrderException(statusCode: response.statusCode, message: TerminalCheckoutResponse.fromJson(jsonDecode(response.body)).errors?[0].detail?.toString());
  }
}