Skip to main content
3 of 3
added 106 characters in body
Khoa TruongDinh
  • 32.3k
  • 11
  • 90
  • 156

Edit:

This is a not good answer, you can follow the @adjco answer. Try to use Service Contract.

Try to inject Magento\Sales\Api\Data\TransactionSearchResultInterfaceFactory into your constructor:

protected $transactions;

public function __constructor(
  \Magento\Sales\Api\Data\TransactionSearchResultInterfaceFactory $transactions,
  ......
)
{
  $this->transactions = $transactions;
}

In your method:

$transactions = $this->transactions->create()->addOrderIdFilter($orderId);
$transactions->getItems();

If Magento\Sales\Api\Data\TransactionSearchResultInterfaceFactory doesn't work, try to use \Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\CollectionFactory. I'm not test yet both of them.

Khoa TruongDinh
  • 32.3k
  • 11
  • 90
  • 156