Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
Payment.php
Go to the documentation of this file.
1 <?php
7 
9 
16 {
22  protected $_coreRegistry = null;
23 
27  protected $dataFactory;
28 
36  public function __construct(
37  \Magento\Framework\App\Action\Context $context,
38  \Magento\Framework\Registry $coreRegistry,
39  \Magento\Authorizenet\Helper\DataFactory $dataFactory
40  ) {
41  $this->_coreRegistry = $coreRegistry;
42  $this->dataFactory = $dataFactory;
43  parent::__construct($context);
44  }
45 
49  protected function _getCheckout()
50  {
51  return $this->_objectManager->get(\Magento\Checkout\Model\Session::class);
52  }
53 
59  protected function _getDirectPostSession()
60  {
61  return $this->_objectManager->get(\Magento\Authorizenet\Model\Directpost\Session::class);
62  }
63 
71  protected function _responseAction($area = 'frontend')
72  {
73  $helper = $this->dataFactory->create($area);
74 
75  $params = [];
76  $data = $this->getRequest()->getParams();
77 
78  /* @var $paymentMethod \Magento\Authorizenet\Model\DirectPost */
79  $paymentMethod = $this->_objectManager->create(\Magento\Authorizenet\Model\Directpost::class);
80 
81  $result = [];
82  if (!empty($data['x_invoice_num'])) {
83  $result['x_invoice_num'] = $data['x_invoice_num'];
84  $params['order_success'] = $helper->getSuccessOrderUrl($result);
85  }
86 
87  try {
88  if (!empty($data['store_id'])) {
89  $paymentMethod->setStore($data['store_id']);
90  }
91  $paymentMethod->process($data);
92  $result['success'] = 1;
93  } catch (\Magento\Framework\Exception\LocalizedException $e) {
94  $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
95  $result['success'] = 0;
96  $result['error_msg'] = $e->getMessage();
97  } catch (\Exception $e) {
98  $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
99  $result['success'] = 0;
100  $result['error_msg'] = __('We can\'t process your order right now. Please try again later.');
101  }
102 
103  if (!empty($data['controller_action_name'])
104  && strpos($data['controller_action_name'], 'sales_order_') === false
105  ) {
106  if (!empty($data['key'])) {
107  $result['key'] = $data['key'];
108  }
109  $result['controller_action_name'] = $data['controller_action_name'];
110  $result['is_secure'] = isset($data['is_secure']) ? $data['is_secure'] : false;
111  $params['redirect'] = $helper->getRedirectIframeUrl($result);
112  }
113 
114  //registering parameter for iframe content
115  $this->_coreRegistry->register(Iframe::REGISTRY_KEY, $params);
116  }
117 
125  protected function _returnCustomerQuote($cancelOrder = false, $errorMsg = '')
126  {
127  $incrementId = $this->_getDirectPostSession()->getLastOrderIncrementId();
128  if ($incrementId && $this->_getDirectPostSession()->isCheckoutOrderIncrementIdExist($incrementId)) {
129  /* @var $order \Magento\Sales\Model\Order */
130  $order = $this->_objectManager->create(\Magento\Sales\Model\Order::class)->loadByIncrementId($incrementId);
131  if ($order->getId()) {
132  try {
134  $quoteRepository = $this->_objectManager->create(\Magento\Quote\Api\CartRepositoryInterface::class);
136  $quote = $quoteRepository->get($order->getQuoteId());
137 
138  $quote->setIsActive(1)->setReservedOrderId(null);
139  $quoteRepository->save($quote);
140  $this->_getCheckout()->replaceQuote($quote);
141  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
142  }
143  $this->_getDirectPostSession()->removeCheckoutOrderIncrementId($incrementId);
144  $this->_getDirectPostSession()->unsetData('quote_id');
145  if ($cancelOrder) {
146  $order->registerCancellation($errorMsg)->save();
147  }
148  }
149  }
150  }
151 }
$helper
Definition: iframe.phtml:13
__construct(\Magento\Framework\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Authorizenet\Helper\DataFactory $dataFactory)
Definition: Payment.php:36
$quote
$order
Definition: order.php:55
__()
Definition: __.php:13
$quoteRepository
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18