Updated Transaction.buy method for edge case handling