Example #1
0
 public function prepare()
 {
     $this->contextMock = $this->getMock('Magento\\Framework\\View\\Element\\Template\\Context', [], [], '', false);
     $this->checkoutSessionMock = $this->getMock('Magento\\Checkout\\Model\\Session', [], [], '', false);
     $this->orderFactoryMock = $this->getMock('Magento\\Sales\\Model\\OrderFactory', ['getQuote'], [], '', false);
     $this->hssHelperMock = $this->getMock('Magento\\Paypal\\Helper\\Hss', [], [], '', false);
     $this->paymentDataMock = $this->getMock('Magento\\Payment\\Helper\\Data', [], [], '', false);
     $this->quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['getPayment', '__wakeup'], [], '', false);
     $this->paymentMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Payment', [], [], '', false);
     $this->checkoutSessionMock->expects($this->any())->method('getQuote')->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->any())->method('getPayment')->will($this->returnValue($this->paymentMock));
     $this->hssHelperMock->expects($this->any())->method('getHssMethods')->will($this->returnValue([]));
 }
Example #2
0
 /**
  * Internal constructor
  *
  * @return void
  */
 protected function _construct()
 {
     parent::_construct();
     $paymentCode = $this->_getCheckout()->getQuote()->getPayment()->getMethod();
     if (in_array($paymentCode, $this->_hssHelper->getHssMethods())) {
         $this->_paymentMethodCode = $paymentCode;
         $templatePath = str_replace('_', '', $paymentCode);
         $templateFile = "{$templatePath}/iframe.phtml";
         $directory = $this->_filesystem->getDirectoryRead(DirectoryList::MODULES);
         $file = $this->resolver->getTemplateFileName($templateFile, ['module' => 'Magento_Paypal']);
         if ($file && $directory->isExist($directory->getRelativePath($file))) {
             $this->setTemplate($templateFile);
         } else {
             $this->setTemplate('hss/iframe.phtml');
         }
     }
 }
 /**
  * Set data for response of frontend saveOrder action
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     /* @var $order \Magento\Sales\Model\Order */
     $order = $this->_coreRegistry->registry('hss_order');
     if ($order && $order->getId()) {
         $payment = $order->getPayment();
         if ($payment && in_array($payment->getMethod(), $this->_paypalHss->getHssMethods())) {
             $result = $observer->getData('result')->getData();
             if (empty($result['error'])) {
                 $this->_view->loadLayout('checkout_onepage_review', true, true, false);
                 $html = $this->_view->getLayout()->getBlock('paypal.iframe')->toHtml();
                 $result['update_section'] = ['name' => 'paypaliframe', 'html' => $html];
                 $result['redirect'] = false;
                 $result['success'] = false;
                 $observer->getData('result')->setData($result);
             }
         }
     }
 }
 /**
  * Run setResponseAfterSaveOrder method test
  *
  * @return void
  */
 public function testSetResponseAfterSaveOrderSuccess()
 {
     $testData = $this->getSetResponseAfterSaveOrderTestData();
     $observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $paymentMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Payment')->disableOriginalConstructor()->getMock();
     $resultMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
     $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $blockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\BlockInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->coreRegistryMock->expects($this->once())->method('registry')->with('hss_order')->willReturn($orderMock);
     $orderMock->expects($this->once())->method('getId')->willReturn($testData['order.getId']);
     $orderMock->expects($this->once())->method('getPayment')->willReturn($paymentMock);
     $paymentMock->expects($this->once())->method('getMethod')->willReturn($testData['payment.getMethod']);
     $this->paypalHssMock->expects($this->once())->method('getHssMethods')->willReturn($testData['paypalHss.getHssMethods']);
     $observerMock->expects($this->atLeastOnce())->method('getData')->with('result')->willReturn($resultMock);
     $resultMock->expects($this->once())->method('getData')->willReturn($testData['result.getData']);
     $this->viewMock->expects($this->once())->method('loadLayout')->with('checkout_onepage_review', true, true, false);
     $this->viewMock->expects($this->once())->method('getLayout')->willReturn($layoutMock);
     $layoutMock->expects($this->once())->method('getBlock')->with('paypal.iframe')->willReturn($blockMock);
     $blockMock->expects($this->once())->method('toHtml')->willReturn($testData['block.toHtml']);
     $resultMock->expects($this->once())->method('setData')->with($testData['result.setData']);
     $this->_model->execute($observerMock);
 }
Example #5
0
 /**
  * Set data for response of frontend saveOrder action
  *
  * @param EventObserver $observer
  * @return $this
  */
 public function setResponseAfterSaveOrder(EventObserver $observer)
 {
     /* @var $order \Magento\Sales\Model\Order */
     $order = $this->_coreRegistry->registry('hss_order');
     if ($order && $order->getId()) {
         $payment = $order->getPayment();
         if ($payment && in_array($payment->getMethod(), $this->_paypalHss->getHssMethods())) {
             /* @var $controller \Magento\Framework\App\Action\Action */
             $controller = $observer->getEvent()->getData('controller_action');
             $result = $this->_coreData->jsonDecode($controller->getResponse()->getBody('default'));
             if (empty($result['error'])) {
                 $this->_view->loadLayout('checkout_onepage_review', true, true, false);
                 $html = $this->_view->getLayout()->getBlock('paypal.iframe')->toHtml();
                 $result['update_section'] = array('name' => 'paypaliframe', 'html' => $html);
                 $result['redirect'] = false;
                 $result['success'] = false;
                 $controller->getResponse()->clearHeader('Location');
                 $controller->getResponse()->representJson($this->_coreData->jsonEncode($result));
             }
         }
     }
     return $this;
 }