/**
  * Save order into registry to use it in the overloaded controller.
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /* @var $order Order */
     $order = $this->coreRegistry->registry('directpost_order');
     if (!$order || !$order->getId()) {
         return $this;
     }
     $payment = $order->getPayment();
     if (!$payment || $payment->getMethod() != $this->payment->getCode()) {
         return $this;
     }
     $result = $observer->getData('result')->getData();
     if (!empty($result['error'])) {
         return $this;
     }
     // if success, then set order to session and add new fields
     $this->session->addCheckoutOrderIncrementId($order->getIncrementId());
     $this->session->setLastOrderIncrementId($order->getIncrementId());
     $requestToAuthorizenet = $payment->getMethodInstance()->generateRequestFromOrder($order);
     $requestToAuthorizenet->setControllerActionName($observer->getData('action')->getRequest()->getControllerName());
     $requestToAuthorizenet->setIsSecure((string) $this->storeManager->getStore()->isCurrentlySecure());
     $result[$this->payment->getCode()] = ['fields' => $requestToAuthorizenet->getData()];
     $observer->getData('result')->setData($result);
     return $this;
 }
Beispiel #2
0
 /**
  * Set data for response of frontend saveOrder action
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function addAdditionalFieldsToResponseFrontend(\Magento\Framework\Event\Observer $observer)
 {
     /* @var $order \Magento\Sales\Model\Order */
     $order = $this->_coreRegistry->registry('directpost_order');
     if ($order && $order->getId()) {
         $payment = $order->getPayment();
         if ($payment && $payment->getMethod() == $this->_payment->getCode()) {
             /** @var \Magento\Checkout\Controller\Action $controller */
             $controller = $observer->getEvent()->getData('controller_action');
             $request = $controller->getRequest();
             $response = $controller->getResponse();
             $result = $this->_coreData->jsonDecode($response->getBody('default'));
             if (empty($result['error'])) {
                 $payment = $order->getPayment();
                 //if success, then set order to session and add new fields
                 $this->_session->addCheckoutOrderIncrementId($order->getIncrementId());
                 $this->_session->setLastOrderIncrementId($order->getIncrementId());
                 $requestToAuthorizenet = $payment->getMethodInstance()->generateRequestFromOrder($order);
                 $requestToAuthorizenet->setControllerActionName($request->getControllerName());
                 $requestToAuthorizenet->setIsSecure((string) $this->_storeManager->getStore()->isCurrentlySecure());
                 $result['directpost'] = array('fields' => $requestToAuthorizenet->getData());
                 $response->clearHeader('Location');
                 $response->representJson($this->_coreData->jsonEncode($result));
             }
         }
     }
     return $this;
 }
Beispiel #3
0
 /**
  * Render block HTML
  * If method is not directpost - nothing to return
  *
  * @return string
  */
 protected function _toHtml()
 {
     return $this->getMethod()->getCode() == $this->_model->getCode() ? parent::_toHtml() : '';
 }