Let's take for an example oDesk and pretend that they have affiliate program for their constructors. If a constructor gets someone to sign up, he gets $10. Does company(in this case oDesk) need to pay out those $10 separately from his earnings, or can it just be added to his balance and paid out altogether?
The actual process of this is based on the company policy. I deal with some companies that will not mix the two types of income at all, while other companies treat all of it as earnings.
As far as the legality of it when you receive the funds, it is totally up to the applicable tax laws for your particular case. The best way to clear this up would be to talk to an accountant specializing in affiliates.