In order to get an unlock code from T-Mobile, you will have to meet the requirements found here: Unlock your mobile wireless device. If you do not meet those requirements, and want to get your device unlocked by a 3rd party, you have the option to do so. Once you return to the US, you will not have any problems using your device, with your old T-Mobile SIM.
I'm qualified to unlock my phone; sent Tmobile my IMEI code and received the instructions:
hours after receiving this email please follow the below instructions for
unlocking your T-Mobile iPhone device.
1. Perform a backup (we suggest backing up through iCloud backup, however
iTunes backup will work if you haven't setup iCloud)
2. Connect your iPhone to iTunes
o Important: This step must be performed using the USB cable connected to your
PC or Mac in order to trigger the process.
3. Within a few minutes, a screen will appear, "Congratulations, your
iPhone has been unlocked".
4. The device is now unlocked. You may now insert any non T-Mobile SIM card
into the iPhone.
If the above steps do not work, then the 'restore device' process must be
completed and an iTunes activation completed. In the re-activation of the
device, the device unlock will be pulled down once activation is complete.
But I never see "Congratulations, ..." and with new SIM card, the device always complains "invalid sm card", what shall I do next?
Nomal1: tmobile had a policy of 40 days of service (or 2 monthly biling cycles). Subsequently they changed that to say that the phone must be paid in full if under EIP.
You have some options.
1) You may be able to return the phone purchased under EIP during a certain time frame for a full refund from tmobile. Google "tmobile EIP lawsuit". Then buy an unlocked phone directly from APPLE. It will come with a t-mobile SIM installed.
2) Buy an online unlock code as suggested.
3) Pay the full balance on the phone and have it unlocked by t-mo.