How to create an order and update transaction to order - transaction response from a payment gateway?

Payment methods after reponce from gateway how to create order and set the transaction id and data

As I have stated already, an order should be created BEFORE you redirect a customer to a payment gateway, so the order will exist on the customer’s return from the payment gateway.
Moreover, I recommend update the order not on a customer return, but on the notification from the payment gateway about the order has been successfully paid.
For example, PayPal uses the term Instant Payment Notification (IPN) for such notifications.

As now i created module flow is customer select the payment and click the button customer go to payment gateway page(order not created). After payment success in payment gateway redirect to my response controller, Now creating order and update the transaction details to order and cusomter go to success page…

is it right…?

I have already answered it here.

Yes this is order creating methods. and how about transaction?
my working flow in right ?

I have already answered it here.

ok My working flow is right ?

I recommend update the order not on a customer return, but on the notification from the payment gateway about the order has been successfully paid.

Ok sure. 1st step create order in customer return page and go to success page. and based on the notification update the transaction. right ?