How Does the Gaming Payment System Work?

I’ve been curious about how the payment systems work in online gaming platforms. How do they manage transactions for in-game purchases, subscriptions, or any other services? For example, how are players able to use real money to purchase virtual items or currencies? What happens behind the scenes? I understand that there are several payment methods, but how are they processed securely? Would love to know the details from those who are familiar with how it all functions!