_initOrder(); $resultRedirect = $this->resultRedirectFactory->create(); if ($order) { try { // workaround for backwards compatibility $order->getPayment()->void(new \Magento\Framework\DataObject()); $order->save(); $this->messageManager->addSuccess(__('The payment has been voided.')); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addError(__('We can\'t void the payment right now.')); $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); } $resultRedirect->setPath('sales/*/view', ['order_id' => $order->getId()]); return $resultRedirect; } $resultRedirect->setPath('sales/*/'); return $resultRedirect; } }