I am unable to set payment transaction id after successful payment processing...
I have got payment confirmation transaction details by payment gateway on my controller action. Now I need to save the payment transaction id in \Magento\Payment\Model\InfoInterface $payment
by using setTransactionId
method of above interface.
But unable to use the \Magento\Payment\Model\InfoInterface
Using code
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$payment = $objectManager->get('\Magento\Payment\Model\InfoInterface');
$payment->setTransactionId(htmlentities($transaction_result->id))
->setIsTransactionClosed(0);
Getting error as: Cannot instantiate interface Magento\Payment\Model\InfoInterface
Please suggest way to get payment instance for save/update order transaction in custom method of model.
I am in return url page of payment
As I have redirected payment gateways after payment done or failed at payment on a controller action.
On the url's at controller, I need to get current order/payment and then update truncation id to that order/payment object.
I have just tried below solution:
protected $_checkoutSession;
public function __construct(
...
\Magento\Checkout\Model\Session $checkoutSession,
.....
) {
$this->_checkoutSession = $checkoutSession;
}
public function execute(){
$order = $this->_checkoutSession->getLastRealOrder();
$payment = $order->getPayment();
$payment->setTransactionId(htmlentities($transaction_result->id));
$payment->setIsTransactionClosed(0)
->setTransactionAdditionalInfo(
"some text",
htmlentities($transaction_result->id)
);
}
But $this->_checkoutSession
comes with empty array...
It means after coming back from payment gateway session get flushed... but how and why.. then how to get order object?
I have got order Increment id... Now how to get order object with order increment id?
I have also used below links:
Magento 2.1.1 How to load Order with Increment ID using OrderRepository object
https://github.com/magento/magento2/issues/3534#issuecomment-227413082
for get order object by order increment id but don't found order object yet for get payment object.
Update:
When i am coming back from payment gateway as redirect url on my module controller execute function i am not getting object manager or session object or order object... I dont know much about dependency injection... please elaborate if i have to create and put any code in the di file in etc folder...
below code are not working in my module controller execute function:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$payment = $objectManager->get('\Magento\Payment\Model\InfoInterface');
It return null/empty
And if I am using below code:
protected $_checkoutSession;
public function __construct(
...
\Magento\Checkout\Model\Session $checkoutSession,
.....
) {
$this->_checkoutSession = $checkoutSession;
}
public function execute(){
$order = $this->_checkoutSession->getLastRealOrder();
$payment = $order->getPayment();
$payment->setTransactionId(htmlentities($transaction_result->id));
$payment->setIsTransactionClosed(0)
->setTransactionAdditionalInfo(
"some text",
htmlentities($transaction_result->id)
);
}
then this also not working...
Please help to resolve the issue...