Example #1
0
 /**
  * Retrieve params and put javascript into iframe
  *
  * @return \Magento\Framework\View\Result\Layout
  */
 public function execute()
 {
     $redirectParams = $this->getRequest()->getParams();
     $params = [];
     if (!empty($redirectParams['success']) && isset($redirectParams['x_invoice_num']) && isset($redirectParams['controller_action_name'])) {
         $params['redirect_parent'] = $this->helper->getSuccessOrderUrl($redirectParams);
         $directpostSession = $this->_objectManager->get('Magento\\Authorizenet\\Model\\Directpost\\Session');
         $directpostSession->unsetData('quote_id');
         //cancel old order
         $oldOrder = $this->_getOrderCreateModel()->getSession()->getOrder();
         if ($oldOrder->getId()) {
             /* @var $order \Magento\Sales\Model\Order */
             $order = $this->_objectManager->create('Magento\\Sales\\Model\\Order')->loadByIncrementId($redirectParams['x_invoice_num']);
             if ($order->getId()) {
                 $oldOrder->cancel()->save();
                 $order->save();
                 $this->_getOrderCreateModel()->getSession()->unsOrderId();
             }
         }
         //clear sessions
         $this->_getSession()->clearStorage();
         $directpostSession->removeCheckoutOrderIncrementId($redirectParams['x_invoice_num']);
         $this->_objectManager->get('Magento\\Backend\\Model\\Session')->clearStorage();
         $this->messageManager->addSuccess(__('You created the order.'));
     }
     if (!empty($redirectParams['error_msg'])) {
         $cancelOrder = empty($redirectParams['x_invoice_num']);
         $this->_returnQuote($cancelOrder, $redirectParams['error_msg']);
     }
     $this->_coreRegistry->register(Iframe::REGISTRY_KEY, array_merge($params, $redirectParams));
     return $this->resultLayoutFactory->create();
 }
Example #2
0
 public function testGetRelayUrl()
 {
     $baseUrl = 'http://base.url/';
     $defaultStoreMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $defaultStoreMock->expects($this->once())->method('getBaseUrl')->with(\Magento\Framework\UrlInterface::URL_TYPE_LINK)->willReturn($baseUrl);
     $this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn(null);
     $this->storeManagerMock->expects($this->once())->method('getStores')->willReturn([$defaultStoreMock]);
     $this->assertSame('http://base.url/authorizenet/directpost_payment/backendResponse', $this->dataHelper->getRelayUrl());
 }
 public function testExecuteSuccess()
 {
     $params = ['success' => 1, 'controller_action_name' => 'action', 'x_invoice_num' => 1];
     $this->requestMock->expects($this->once())->method('getParams')->willReturn($params);
     $this->helperMock->expects($this->once())->method('getSuccessOrderUrl')->willReturn('redirect_parent_url');
     $this->directpostSessionMock->expects($this->once())->method('unsetData')->with('quote_id');
     $this->orderMock->expects($this->once())->method('getId')->willReturn(null);
     $this->sessionQuoteMock->expects($this->atLeastOnce())->method('getOrder')->willReturn($this->orderMock);
     $this->adminOrderCreateMock->expects($this->atLeastOnce())->method('getSession')->willReturn($this->sessionQuoteMock);
     $this->coreRegistryMock->expects($this->once())->method('register')->with(Iframe::REGISTRY_KEY);
     $this->assertInstanceOf('\\Magento\\Framework\\View\\Result\\Layout', $this->controller->execute());
 }