I am trying to prove that if $R$ is a principal integer domain, then any finitely generated projective $R$-module is isomorphic to $R$. To do so, I've fixed $P$ as a finitely generated projective and proved the following:
There is an epimorphism $f: R^n \rightarrow P$, for some integer $n$. This is quite easy: If $P = \langle x_1, \ldots, x_n \rangle$, then define $f(a_1, \ldots, a_n) := \sum_{i = 1}^n x_i a_i$.
There is a non-zero morphism $g: P \rightarrow R$. To show this, recall that it follows from $P$ projective that the exact sequence $$0 \rightarrow \operatorname{Ker}(f) \rightarrow R^n \xrightarrow{f} P \rightarrow 0$$ splits, hence $f$ is a retraction. Let $h: P \rightarrow R^n$ be the right inverse of $f$. For every $x \in P$, the element $h(x)$ is written as $h(x) = (a_1, \ldots, a_n)$, and particularly one can define $h_j: P \rightarrow R$ by $h_j(x) = a_j$. Since $h$ is non-zero, there must be some $j$ satisfying $h_j(x) \neq 0$. Take $g = h_j$.
My plan was to show that $g$ is an isomorphism, but I did not found a way to do so. I am in the right track? If so, can anyone point out how do I finish the argument?