refactor discount code calculation method