How Can I Create A Transaction Record For An Magento 2 Order Programmtically

How can I insert a transaction record for an Magento 2 order programmtically

You can use “Transaction\BuilderInterface” to build a transaction object and attache to the Magento 2 order

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$ordernumber = 1;
$transaction_id = 1;

$order = $objectManager->create('\Magento\Sales\Model\Order')->load($ordernumber);
$payment = $order->getPayment();

$trans  = $objectManager->create('Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface'); 
$transaction = $trans->setPayment($payment)->setOrder($order)->setTransactionId($transaction_id)->setAdditionalInformation(
[\Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS => (array) $data])->setFailSafe(true)->build(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_CAPTURE);

$payment->addTransactionCommentsToOrder($transaction,$transaction_id );
$payment->save();
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments