Hi i m having this issue that the order is created when the user is directed to the payment gateway. How to resolve this issue so that order is generated only after successful payment.
If you are using any third party payment method, then Magento doing below way
When you click on submit the order, it will generate order on Magento site with pending status, and redirect on payment side, when you back from payment side it will update order status to processing or cancel based on your payment response.
If you want to do redirect first, then very hard to manage like session and all thing, if you want to do then you need to study PayPal express method and it is very hard to understand.
Hope it will answer your question.
If it will help you then give kudos or mark as solution.