It is very simple. First implement the manual method by following @gsreddy’s referenced tutorial. I mean setup it like you can make account transactions manually. After completing it we can automatize it by using actions.
This tutorial about supplier payouts might give an idea as well.