/** * @inheritdoc */ public function execute() { $requestData = json_decode($this->getRequest()->getPostValue('result', '{}'), true); $quote = $this->checkoutSession->getQuote(); try { $this->validateQuote($quote); if ($this->validateRequestData($requestData)) { $this->quoteUpdater->execute($requestData['nonce'], $requestData['details'], $quote); } elseif (!$quote->getPayment()->getAdditionalInformation(self::$paymentMethodNonce)) { throw new LocalizedException(__('We can\'t initialize checkout.')); } /** @var \Magento\Framework\View\Result\Page $resultPage */ $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); /** @var \Magento\Braintree\Block\Paypal\Checkout\Review $reviewBlock */ $reviewBlock = $resultPage->getLayout()->getBlock('braintree.paypal.review'); $reviewBlock->setQuote($quote); $reviewBlock->getChildBlock('shipping_method')->setData('quote', $quote); return $resultPage; } catch (\Exception $e) { $this->messageManager->addExceptionMessage($e, $e->getMessage()); } /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath('checkout/cart', ['_secure' => true]); }
public function testExecute() { $details = $this->getDetails(); $quoteMock = $this->getQuoteMock(); $paymentMock = $this->getPaymentMock(); $quoteMock->expects(self::once())->method('getPayment')->willReturn($paymentMock); $paymentMock->expects(self::once())->method('setMethod')->with(ConfigProvider::PAYPAL_CODE); $paymentMock->expects(self::once())->method('setAdditionalInformation')->with(DataAssignObserver::PAYMENT_METHOD_NONCE, self::TEST_NONCE); $this->updateQuoteStep($quoteMock, $details); $this->quoteUpdater->execute(self::TEST_NONCE, $details, $quoteMock); }
public function testExecuteException() { $result = '{}'; $quoteMock = $this->getQuoteMock(); $resultRedirectMock = $this->getResultRedirectMock(); $quoteMock->expects(self::once())->method('getItemsCount')->willReturn(0); $this->requestMock->expects(self::once())->method('getPostValue')->with('result', '{}')->willReturn($result); $this->checkoutSessionMock->expects(self::once())->method('getQuote')->willReturn($quoteMock); $this->quoteUpdaterMock->expects(self::never())->method('execute'); $this->messageManagerMock->expects(self::once())->method('addExceptionMessage')->with(self::isInstanceOf('\\InvalidArgumentException'), 'We can\'t initialize checkout.'); $this->resultFactoryMock->expects(self::once())->method('create')->with(ResultFactory::TYPE_REDIRECT)->willReturn($resultRedirectMock); $resultRedirectMock->expects(self::once())->method('setPath')->with('checkout/cart')->willReturnSelf(); self::assertEquals($this->review->execute(), $resultRedirectMock); }