How do I manage a transaction between two commands?

Suppose I have two commands: creditCommand, debitCommand and transfer.
I want to implement a transfer method (debit the source account and credit the destination account)
Void transfer(){

HERE, the problem is that if credit fails (Exception), the debit method will already be executed correctly.
How can I rollback to cancel the debit command? How can we make this method transactional?
or should I implement an action to compensate for the debit method?