On the click of buy button. First you should do some local validations like amount, quantity according to your business logic. Then call the payment gateway APIs using a server action. There may be multiple APIs for payment like first authorization or get some token, then request the API and there may be some callback action as well to get the payment status in your application. It depends and vary according to payment gateway you choosed.
Regards