I am developing a custom payment gateway module which redirects the users to external website for a payment
I have created a custom redirect in a controller but I wanted to get the order id before redirection so that after a callback I would know which order id to change state from pending to completed or paid status
I tried \Magento\Sales\Model\OrderFactory object in the controller that extends from \Magento\Framework\App\Action\Action but I got an error
Recoverable Error: Argument 3 passed to MaroonHost\CustomPayment\Controller\Redirect\Index::__construct() must be an instance of Magento\Sales\Model\OrderFactory
Please provide me instruction on how to get the order id or any thing related to order in my custom controller
Does it need a model that extends or implents som of magento Cart models and then use them in my controller?
Thanks
Solved! Go to Solution.
hi,
you can get order id from checkout session
protected $_checkoutSession; public function __construct( \Magento\Checkout\Model\Session $checkoutSession, ) { $this->_checkoutSession = $checkoutSession; }
to get id use this code
$order = $this->_checkoutSession->getLastRealOrder(); $orderId=$order->getEntityId();
hi,
you can get order id from checkout session
protected $_checkoutSession; public function __construct( \Magento\Checkout\Model\Session $checkoutSession, ) { $this->_checkoutSession = $checkoutSession; }
to get id use this code
$order = $this->_checkoutSession->getLastRealOrder(); $orderId=$order->getEntityId();
I could get the order id but it wont return the current order that was redirected to my custom controller instead in showed the previous order number
the current is#89 which could get order #88
I this is also my javascript function which handles the order click button
let me know if this is some thing I have done correctly
continueToMellat: function (data, event) { if (this.validate() && additionalValidators.validate()) { this.isPlaceOrderActionAllowed(false); this.getPlaceOrderDeferredObject() .fail( function () { self.isPlaceOrderActionAllowed(true); } ).done( function () { self.afterPlaceOrder(); if (self.redirectAfterPlaceOrder) { redirectOnSuccessAction.execute(); } } ); } //update payment method information if additional data was changed $.mage.redirect(url.build('redirect/redirect')); this.selectPaymentMethod(); setPaymentMethodAction(this.messageContainer); return false; }