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

I have already answered it here.