Payment Gateway is a software that transmits TRANSACTION Information to ACQUIRING BANKS & RESPONSES from ISSUING BANKS(whether transaction is approved/declined). In a nutshell, Payment Gateway facilitate communication within Banks. A payment gateway helps in selling on-line. It allows to charge a customer’s credit/debit card with the purchase he/she makes on-line. In short, this authorizes you to take card payments directly from your website. You can call it mediator between the transactions that take place on your website and the payment processor.
Payment Processors: They provide all the payment processing services used by an on-line merchant. The payment processor connects to both the merchant account and payment gateway, quickly passing information back and forth, keeping it secure and almost instantaneous for the end user.
Merchant Accounts: Merchant accounts are the types of bank accounts that authorize merchants to accept credit or debit cards payments online. These accounts are required if you want to use a payment gateway to process transactions from your website. You can read about MIDs on paypal , which is merchant IDs!
Create your own payment gateway https://www.konakart.com/docs/modules.html
killbill is an opensource widely popular billing system built with Java Servelts, MySQL and Jetty as a webserver. It is built using servlets and google guice containers as an API application, ready to be consumed from a variety of applications. It support multi tenancy with MySQL datastore.
JBilling is another Java based billing system.
PayumServer is a php based opensource application supporting multiple payment gateways. Built on Symfony framework & MySQL