Vue Storefront is now Alokai! Learn More
RemoveCouponFromCart

RemoveCouponFromCart

Implements RemoveCouponFromCart Unified Method.

Source

import { getNormalizers } from "@alokai/connect/integration-kit";
import { HttpStatusCode } from "@alokai/connect/middleware";

import { defineApi, getCartVersion } from "@vsf-enterprise/unified-api-commercetools";

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 version = await getCartVersion(context);

  const { api } = await context.getApiClient();
  const updatedCart = await api.removeCartCoupon(version, {
    id: args.couponId,
    typeId: "discount-code",
  });

  const { normalizeCart } = getNormalizers(context);

  return normalizeCart(updatedCart.cart);
});