How do I programmatically empty a cart?
You must use the commerce_cart.cart_manager service instead.

So $this-&gt;cartManager-&gt;emptyCart($cart); should do the trick.

Update: The reason why you get an error is because you try to call emptyCart on $cart then it's NULL.

You must wrap the line where you empty the cart in an if statement, like this:

if (!empty($cart)) {
  $this-&gt;cartManager-&gt;emptyCart($cart);
}