How to set order payment transaction id and transaction data for an order?

Use the \Magento\Sales\Model\Order\Payment::setTransactionId() method to set an ID for a transaction and the \Magento\Sales\Model\Order\Payment::setTransactionAdditionalInfo() method to set an additional information to a transaction.