/**
  * @inheritdoc
  */
 public function execute()
 {
     $isAjax = $this->getRequest()->getParam('isAjax');
     $quote = $this->checkoutSession->getQuote();
     try {
         $this->validateQuote($quote);
         $this->shippingMethodUpdater->execute($this->getRequest()->getParam('shipping_method'), $quote);
         if ($isAjax) {
             /** @var Page $response */
             $response = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
             $layout = $response->addHandle('paypal_express_review_details')->getLayout();
             $response = $layout->getBlock('page.block')->toHtml();
             $this->getResponse()->setBody($response);
             return;
         }
     } catch (\Exception $e) {
         $this->messageManager->addExceptionMessage($e, $e->getMessage());
     }
     $path = $this->_url->getUrl('*/*/review', ['_secure' => true]);
     if ($isAjax) {
         $this->getResponse()->setBody(sprintf('<script>window.location.href = "%s";</script>', $path));
         return;
     }
     $this->_redirect($path);
 }
 public function testExecute()
 {
     $quoteMock = $this->getQuoteMock();
     $quoteMock->expects(self::exactly(2))->method('getIsVirtual')->willReturn(false);
     $quoteMock->expects(self::exactly(2))->method('getShippingAddress')->willReturn($this->shippingAddressMock);
     $this->shippingAddressMock->expects(self::once())->method('getShippingMethod')->willReturn(self::TEST_SHIPPING_METHOD . '-bad');
     $this->disabledQuoteAddressValidationStep($quoteMock);
     $this->shippingAddressMock->expects(self::once())->method('setShippingMethod')->willReturn(self::TEST_SHIPPING_METHOD);
     $this->shippingAddressMock->expects(self::once())->method('setCollectShippingRates')->willReturn(true);
     $quoteMock->expects(self::once())->method('collectTotals');
     $this->quoteRepositoryMock->expects(self::once())->method('save')->with($quoteMock);
     $this->shippingMethodUpdater->execute(self::TEST_SHIPPING_METHOD, $quoteMock);
 }
 public function testExecuteException()
 {
     $redirectPath = 'path/to/redirect';
     $quoteMock = $this->getQuoteMock();
     $quoteMock->expects(self::once())->method('getItemsCount')->willReturn(0);
     $this->requestMock->expects(self::exactly(1))->method('getParam')->willReturnMap([['isAjax', null, true]]);
     $this->checkoutSessionMock->expects(self::once())->method('getQuote')->willReturn($quoteMock);
     $this->shippingMethodUpdaterMock->expects(self::never())->method('execute');
     $this->messageManagerMock->expects(self::once())->method('addExceptionMessage')->with(self::isInstanceOf('\\InvalidArgumentException'), 'We can\'t initialize checkout.');
     $this->urlMock->expects(self::once())->method('getUrl')->with('*/*/review', ['_secure' => true])->willReturn($redirectPath);
     $this->responseMock->expects(self::once())->method('setBody')->with(sprintf('<script>window.location.href = "%s";</script>', $redirectPath));
     $this->saveShippingMethod->execute();
 }