Writing my own payment gateways

How can I write my own payment. I want to modify Manual Payments but could not find any documents.