Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
VoidPayment.php
Go to the documentation of this file.
1 <?php
7 
9 {
15  public function execute()
16  {
17  $order = $this->_initOrder();
18  $resultRedirect = $this->resultRedirectFactory->create();
19  if ($order) {
20  try {
21  // workaround for backwards compatibility
22  $order->getPayment()->void(new \Magento\Framework\DataObject());
23  $order->save();
24  $this->messageManager->addSuccessMessage(__('The payment has been voided.'));
25  } catch (\Magento\Framework\Exception\LocalizedException $e) {
26  $this->messageManager->addErrorMessage($e->getMessage());
27  } catch (\Exception $e) {
28  $this->messageManager->addErrorMessage(__('We can\'t void the payment right now.'));
29  $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
30  }
31  $resultRedirect->setPath('sales/*/view', ['order_id' => $order->getId()]);
32  return $resultRedirect;
33  }
34  $resultRedirect->setPath('sales/*/');
35  return $resultRedirect;
36  }
37 }
$order
Definition: order.php:55
__()
Definition: __.php:13