Vue Storefront is now Alokai! Learn More
RemoveCouponFromCart

RemoveCouponFromCart

Implements RemoveCouponFromCart Unified Method.

Source

import { HttpStatusCode } from "@alokai/connect/middleware";

import { defineApi, getCartId } from "@vsf-enterprise/unified-api-bigcommerce";
import { methods } from "@vsf-enterprise/unified-api-bigcommerce";
const { getCart } = methods;

export const removeCouponFromCart = defineApi.removeCouponFromCart(async (context, args) => {
  if (args?.cartId != null) {
    throw context.createHttpError({
      message: "Multiple carts feature is not available.",
      statusCode: HttpStatusCode.BAD_REQUEST,
    });
  }
  const cartId = getCartId(context);
  // response doesn't include LineItemsPhysicalItemsOptions, so we have to get cart again
  const { api } = await context.getApiClient();
  await api.deleteCoupon({
    checkoutId: cartId,
    couponCode: args.couponId,
  });

  return getCart(context);
});