listAllDiscountRedemptions method

Future<Map<String, dynamic>> listAllDiscountRedemptions({
  1. int? discountId,
  2. int? orderId,
})

Implementation

Future<Map<String, dynamic>> listAllDiscountRedemptions(
    {int? discountId, int? orderId}) 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/discount-redemptions";

  if (discountId != null) {
    url += "?filter[discount_id]=$discountId";
  } else if (orderId != null) {
    url += "?filter[order_id]=$orderId";
  }

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

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