applyCoupon method
Apply coupon to cart
Implementation
Future<Cart> applyCoupon({
required String cartId,
required String couponCode,
}) async {
try {
final response = await _client.guestRequest<Map<String, dynamic>>(
'/rest/V1/guest-carts/$cartId/coupons/$couponCode',
options: Options(method: 'PUT'),
);
if (response.statusCode == 200) {
return Cart.fromJson(response.data!);
} else {
throw Exception('Failed to apply coupon: ${response.statusMessage}');
}
} on DioException catch (e) {
throw Exception('Failed to apply coupon: ${e.message}');
} catch (e) {
throw Exception('Failed to apply coupon: $e');
}
}