patchBonus method

Future<ApiCallback<void>> patchBonus(
  1. {@required Bonus bonus,
  2. String cartId}
)

Implementation

Future<ApiCallback<void>> patchBonus(
    {@required Bonus bonus, String cartId}) async {
  try {
    if (cartId == null) cartId = await _getDefaultCartId();

    var response = await _requester.patch(
        BONUS.replaceAll(PARAMETER_CART_ID, cartId),
        data: bonus.toJson());
    // Parse the new cart
    var parsedCart = Cart.fromJson(response.data);
    // Save it locally
    await CartDao().insertOrUpdate(parsedCart);

    return ApiCallback<void>(isSuccessful: true);
  } on DioError catch (e) {
    return ApiCallback<void>().defaultErrorCallback(e);
  }
}