How it is done will vary depending on which payment gateway you use. Each one has their own unique way of operating and you have to work with their API to do the actual integration.