How to add gratuity when a commerce cart is updated?
I would use the Rules module for this, with trigger event "add item to cart" and action being "add another product to the cart", where the second product is a gratuity. You might need to use a further rule to set the price of the "gratuity" product as proportional to the original product.

If you don't need to do it separately for each item, like if it's the same percentage for all, you could apply it as if it were a tax, a (negative) discount, or a handling fee, using the relevant modules for those.