How to Delete Payment transaction details by id Magento 2?

Once you place an order using an online payment gateway, Gateway details will be stored in the database table sales_payment_transaction.

The table contains the transaction id, payment id, additional_information and many more columns to save the payment data.

If you want to delete a specified transaction record from the table, you can easily remove the given record by the transaction id with the use of the Transaction Repository Interface.

namespace Jesadiya\DeleteTransaction\Model;

use Psr\Log\LoggerInterface;
use Magento\Sales\Api\TransactionRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;

class DeleteTransaction
     * @var LoggerInterface
    private $logger;

     * @var TransactionRepositoryInterface
    private $transactionRepository;

    public function __construct(
        TransactionRepositoryInterface $transactionRepository,
        LoggerInterface $logger
    ) {
        $this->transactionRepository = $transactionRepository;
        $this->logger = $logger;

     * Delete a given transaction by id
     * @param int $id
     * @return bool
    public function deleteByTransactionId(int $id)
        $transaction = null;
        try {
            $transaction = $this->transactionRepository->get($id);
            if ($transaction) {
                $isDeleteTransaction = $this->transactionRepository->delete($transaction);
        } catch (NoSuchEntityException $exception) {
        return $transactionData;

Use deleteByTransactionId() method with argument as transaction_id.

You can see in the function, We are loading the Object and passing that object to the delete method.

Use the given code snippet to delete the transaction record in Magento 2.