getTaxRates method

Future<List<WooTaxRate>> getTaxRates({
  1. int? page,
  2. int? perPage,
  3. int? offset,
  4. String? order,
  5. String? orderBy,
  6. String? taxClass,
})

Returns a list of all WooTaxRate, with filter options.

Related endpoint: https://woocommerce.github.io/woocommerce-rest-api-docs/#tax-rates.

Implementation

Future<List<WooTaxRate>> getTaxRates(
    {int? page,
    int? perPage,
    int? offset,
    String? order,
    String? orderBy,
    String? taxClass}) async {
  Map<String, dynamic> payload = {};

  ({
    'page': page,
    'per_page': perPage,
    'offset': offset,
    'order': order,
    'orderby': orderBy,
    'class': taxClass,
  }).forEach((k, v) {
    if (v != null) payload[k] = v.toString();
  });
  List<WooTaxRate> taxRates = [];
  _printToLog('Getting Taxrates With Payload : ' + payload.toString());
  _setApiResourceUrl(path: 'taxes', queryParameters: payload);
  final response = await get(queryUri.toString());
  for (var t in response) {
    var tax = WooTaxRate.fromJson(t);
    _printToLog('prod gotten here : ' + order.toString());
    taxRates.add(tax);
  }
  return taxRates;
}