listAllOrderItems method

Future<Map<String, dynamic>> listAllOrderItems({
  1. int? orderId,
  2. int? productId,
  3. int? variantId,
})

Implementation

Future<Map<String, dynamic>> listAllOrderItems(
    {int? orderId, int? productId, int? variantId}) async {
  if (apiKey.isEmpty) {
    return {'error': 'API key is empty'};
  }

  Options dioOptions = Options(
    headers: {
      "Authorization": "Bearer $apiKey",
      "Accept": "application/vnd.api+json",
      "Content-Type": "application/vnd.api+json",
    },
  );

  String url = "https://api.lemonsqueezy.com/v1/order-items";

  if (orderId != null || productId != null || variantId != null) {
    url += "?";
    if (orderId != null) {
      url += "filter[order_id]=$orderId";
      if (productId != null || variantId != null) url += "&";
    }
    if (productId != null) {
      url += "filter[product_id]=$productId";
      if (variantId != null) url += "&";
    }
    if (variantId != null) {
      url += "filter[variant_id]=$variantId";
    }
  }

  try {
    Response response = await dio.get(
      url,
      options: dioOptions,
    );

    return response.data;
  } catch (e) {
    return {'error': e.toString()};
  }
}