invoice middleware