invoice: fix some errors relating to service credit, allow the handling of non-json data to provide an error code