Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReviewPayment.php
Go to the documentation of this file.
1 <?php
7 
9 
11 {
17  const ADMIN_RESOURCE = 'Magento_Sales::review_payment';
18 
26  public function execute()
27  {
28  $resultRedirect = $this->resultRedirectFactory->create();
29  try {
30  $order = $this->_initOrder();
31  if ($order) {
32  $action = $this->getRequest()->getParam('action', '');
33  switch ($action) {
34  case 'accept':
35  $order->getPayment()->accept();
36  $message = __('The payment has been accepted.');
37  break;
38  case 'deny':
39  $order->getPayment()->deny();
40  $message = __('The payment has been denied.');
41  break;
42  case 'update':
43  $order->getPayment()->update();
44  if ($order->getPayment()->getIsTransactionApproved()) {
45  $message = __('Transaction has been approved.');
46  } elseif ($order->getPayment()->getIsTransactionDenied()) {
47  $message = __('Transaction has been voided/declined.');
48  } else {
49  $message = __('There is no update for the transaction.');
50  }
51  break;
52  default:
53  throw new \Exception(sprintf('Action "%s" is not supported.', $action));
54  }
55  $this->orderRepository->save($order);
56  $this->messageManager->addSuccessMessage($message);
57  } else {
58  $resultRedirect->setPath('sales/*/');
59  return $resultRedirect;
60  }
61  } catch (\Magento\Framework\Exception\LocalizedException $e) {
62  $this->messageManager->addErrorMessage($e->getMessage());
63  } catch (\Exception $e) {
64  $this->messageManager->addErrorMessage(__('We can\'t update the payment right now.'));
65  $this->logger->critical($e);
66  }
67  $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getEntityId()]);
68  return $resultRedirect;
69  }
70 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$order
Definition: order.php:55
__()
Definition: __.php:13
$message