I got the solution. I am writing it for those who will come here for the solution in the future.
First, the problem was in the backend.I was using 'live mode' while creating the Razorpay order. And in the frontend, we are using the testID.It wasn't matching and I got an error.