I wanted to ask if there is a way to do a 3 way affiliate

Hello,

I wanted to ask if there is a way to do a 3 way affiliate system. One who is taking the order, another going to the company, and the other one being rewarded is the company of the one taking the order.

Thanks,
Virgil