Пример #1
0
 /**
  * @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]);
 }
Пример #2
0
 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);
 }