If the iPhone you've purchased from your friend is a T-Mobile device, it can be unlocked by T-Mobile. Here is the link.
Please keep in mind, T-Mobile has very specific unlock requirements for every customer, to prevent fraud to the company. Please make sure you have read thoroughly.
Manage your T-Mobile account