You can only purchase a handgun in the state with which you reside. Now, they can sell it to you and ship it to your local FFL dealer to affect the transfer.
Additionally, legally speaking, if your state is bordered by the state in which you are trying to purchase a long gun, that FFL dealer is legally allowed to transfer it to you. They don’t have to, but the ATF and Federal Law allows them. It is their choice.