On certain website you can buy things online or topup an account using your credit card. Your credit card get's charged directly from their website.

I want to create a website which allows people to purchase products dirrectly from the website but first I need to ask,

how is this done?

How do I charge the credit card and get confirmation that transaction went through?