Refactor apply_gift_codes