I'm trying to redirect from block but it's not working. But same methods work in different projects.
1. Process 1
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Vendor\PaymentGateway\Helper\Data $storeHelper,
\Magento\Sales\Api\Data\OrderInterface $order,
\Magento\Framework\App\Response\Http $response,
\Magento\Sales\Model\Order $orderModel,
\Vendor\PaymentGateway\Model\CreateorderFactory $createorder,
\Vendor\PaymentGateway\Model\PaymentresponseFactory $paymentResponse,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Sales\Model\OrderFactory $orderFactory,
\Magento\Sales\Model\Order\Email\Sender\OrderSender $orderEmailSender,
\Magento\Framework\Controller\Result\RedirectFactory $redirectFactory,
array $data = []
) {
parent::__construct($context, $data);
$this->storeHelper = $storeHelper;
$this->order = $order;
$this->response = $response;
$this->orderModel = $orderModel;
$this->createorder = $createorder;
$this->paymentResponse = $paymentResponse;
$this->checkoutSession = $checkoutSession;
$this->orderFactory = $orderFactory;
$this->orderEmailSender = $orderEmailSender;
$this->redirectFactory = $redirectFactory;
}
public function redirectAccordingToStatus($status='30')
{
echo 'redirect from here ' , $this->getBaseUrl().$this->REDIRECT_URL[$status] ;
//return $this->redirectFactory->create()->setPath($this->REDIRECT_URL[$status]);
$this->response->setRedirect($this->getBaseUrl().$this->REDIRECT_URL[$status]);
exit;
}
2. Process 2: With same constructor but different approach.
return $this->redirectFactory->create()->setPath('paym/payment/cancel');
None of these methods are working. I thought some of the classes could be conflicting with it that is why I have pasted the whole code of constructor.
Also there is no error during setup:di:compile
and in logs. If you know of any another approach then please suggest that one.