estimateCustomerCartShipping method
Estimate shipping for customer cart
Implementation
Future<List<ShippingMethod>> estimateCustomerCartShipping(
Address address,
) async {
try {
final response = await _client.authenticatedRequest<Map<String, dynamic>>(
'/rest/V1/carts/mine/estimate-shipping-methods',
options: Options(method: 'POST'),
data: {'address': address.toJson()},
);
if (response.statusCode == 200) {
final List<dynamic> methods = response.data!['shipping_methods'] ?? [];
return methods
.map((method) => ShippingMethod.fromJson(method))
.toList();
} else {
throw Exception(
'Failed to estimate customer cart shipping: ${response.statusMessage}',
);
}
} on DioException catch (e) {
throw Exception(
'Failed to estimate customer cart shipping: ${e.message}',
);
} catch (e) {
throw Exception('Failed to estimate customer cart shipping: $e');
}
}