refactor some billing code
update the tests
increase test coverage by going through the simplates
Merge pull request #3016 from gratipay/refactor-billing

Refactor some billing code