Refunding merchants with bank transfer, keeping shopify in the loop

We are developing an affiliate app that lets merchants give us discount codes, which when used by our userbase give us x% as sales commission. Now in case of refund we have to return the commission back to the merchant say after 1-2 months, if we do it directly to merchant account, shopify is not in the loop, so merchant can complain not refunded and damage our reputation. So how can we refund or credit merchant automatically using shopify billing or any other api, ie keeping shopify in the loop? this would help as proof + also allow shopify to keep account of correct earnings when charging commission on our payments.