How to evaluate the Gauss sum using Mordell's Trick? I have been working on this problem:

I have shown that the integral equals $G_n$ using the residue theorem.
I have proved that the integral over the horizontal paths $B,D,F,H$ vanish.
I have found the functional equation $f(z+n) - f(z) = g(z) := \exp(2 \pi i z^2 / n)(\exp(2 \pi i z) + 1)$. This allows me to merge the integrals over $A$ and $C$ into one. And I can merge $E$ and $G$ into one. Let $P^-$ denote the path $P$ reversed.
$$\begin{align}
& \int_A f(z) dz + \int_C f(z) dz\\
=& \int_{C^{-}} f(z+n) dz - \int_C^- f(z) dz\\
=& \int_{C^{-}} g(z) dz\\
=& \int_{-R}^{R} a g(a z) dz\\
=& \int_{-R}^{R} a \exp(-z^2)(\exp(2 \pi i a z) + 1) dz\\
=& \int_{-R}^{R} a \exp(-z^2)(\exp(- \sqrt{\pi} \sqrt{n} (1 - i) z) + 1) dz
\end{align}$$
and
$$\begin{align}
& \int_E f(z) dz + \int_G f(z) dz\\
=& \int_{G^{-}} g(z) dz\\
=& \int_{-R}^{R} i g(i z) dz\\
=& \int_{-R}^{R} i \exp(- 2 \pi i z^2 / n)(\exp(- 2 \pi z) + 1) dz\\
\end{align}$$
Now I do not know what to do with these two resulting integrals, I think I should equate them and their values equal $G_n$ and I somehow want to form the boxed expression from them but I am very lost with this. I have evaluated the Gaussian integral as $\sqrt{\pi}$ but I don't know how to apply this here. Any advice would be appreciated!
 A: Lemma $\beta\in\Bbb R $, then
$$\int_{-\infty}^{\infty} e^{-x^2} e^{2\beta x i}\mathrm dx=\sqrt \pi e^{-\beta^2}$$
there are many methods to get $\int_0^{\infty} e^{-x^2} \cos (2\beta x )\mathrm dx=\dfrac{\sqrt \pi}2 e^{-\beta^2}$ , for example, Residue theorem.
back to the problem
$$\lim_{R\to\infty}\int_B f(z) dz = \lim_{R\to\infty}\int_D f(z) dz=0$$
hence
$$\begin{align}
  G_n&= \lim_{R\to\infty}( \int_A f(z)\mathrm dz + \int_C f(z)\mathrm dz)\\
&=  \lim_{R\to\infty}\int_{-R}^{R} a \exp(-x^2)[\exp(- \sqrt{\pi} \sqrt{n} (1 - i) x) + 1]\mathrm dx \\
&= \int_{-\infty}^{\infty} a \exp(-x^2)[\exp(- \sqrt{\pi} \sqrt{n} (1 - i) x) + 1]\mathrm dx\\ 
  &= a\int_{-\infty}^{\infty} \exp(-x^2)\exp(- \sqrt{\pi} \sqrt{n} (1 - i) x) dx +a\int_{-\infty}^{\infty} \exp(-x^2)\mathrm dx\\
&= a\int_{-\infty}^{\infty} \exp(-x^2-\sqrt{\pi} \sqrt{n} x)\exp( \sqrt{n\pi}  i x) dx +a\int_{-\infty}^{\infty} \exp(-x^2)\mathrm dx\\
&= \frac{1+i}2 (1+(-i)^n)\sqrt n
\end{align}$$
It is easy to finish the integral  with the help of  the lemma.
I have a problem: It seems that $\int_{-\infty }^{\infty} i \exp(- 2 \pi i x^2 / n)(\exp(- 2 \pi x) + 1) \mathrm dx $ does not convergent. What's wrong?
