Microscopic formalism for intermediate energy transfer reactions: Application to the (p,d) and (d,p) reactions