protected function setUp() { $this->markTestIncomplete(); $this->messageManager = $this->getMockForAbstractClass('Magento\\Framework\\Message\\ManagerInterface'); $this->config = $this->getMock('Magento\\Paypal\\Model\\Config', [], [], '', false); $this->request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false); $this->quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false); $this->quote->expects($this->any())->method('hasItems')->will($this->returnValue(true)); $this->redirect = $this->getMockForAbstractClass('Magento\\Framework\\App\\Response\\RedirectInterface'); $this->response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false); $this->customerData = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false); $this->checkout = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout', [], [], '', false); $this->customerSession = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false); $this->customerSession->expects($this->any())->method('getCustomerDataObject')->will($this->returnValue($this->customerData)); $this->checkoutSession = $this->getMock('Magento\\Checkout\\Model\\Session', [], [], '', false); $this->checkoutFactory = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout\\Factory', [], [], '', false); $this->checkoutFactory->expects($this->any())->method('create')->will($this->returnValue($this->checkout)); $this->checkoutSession->expects($this->any())->method('getQuote')->will($this->returnValue($this->quote)); $this->session = $this->getMock('Magento\\Framework\\Session\\Generic', [], [], '', false); $objectManager = $this->getMock('Magento\\Framework\\ObjectManagerInterface'); $this->objectManagerCallback = function ($className) { if ($className == 'Magento\\Paypal\\Model\\Config') { return $this->config; } return $this->getMock($className, [], [], '', false); }; $objectManager->expects($this->any())->method('get')->will($this->returnCallback(function ($className) { return call_user_func($this->objectManagerCallback, $className); })); $objectManager->expects($this->any())->method('create')->will($this->returnCallback(function ($className) { return call_user_func($this->objectManagerCallback, $className); })); $helper = new ObjectManagerHelper($this); $this->model = $helper->getObject('\\Magento\\\\Paypal\\Controller\\Express\\' . $this->name, ['messageManager' => $this->messageManager, 'response' => $this->response, 'redirect' => $this->redirect, 'request' => $this->request, 'customerSession' => $this->customerSession, 'checkoutSession' => $this->checkoutSession, 'checkoutFactory' => $this->checkoutFactory, 'paypalSession' => $this->session, 'objectManager' => $objectManager]); }
/** * @return \Magento\Framework\View\Element\AbstractBlock */ protected function _beforeToHtml() { $result = parent::_beforeToHtml(); /** @var \Magento\Paypal\Model\Config $config */ $config = $this->_paypalConfigFactory->create(); $config->setMethod($this->_paymentMethodCode); $isInCatalog = $this->getIsInCatalogProduct(); if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) { $this->_shouldRender = false; return $result; } $quote = $isInCatalog || !$this->_checkoutSession ? null : $this->_checkoutSession->getQuote(); // set misc data $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_'))->setCheckoutUrl($this->getUrl($this->_startAction)); // use static image if in catalog if ($isInCatalog || null === $quote) { $this->setImageUrl($config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale())); } else { /**@todo refactor checkout model. Move getCheckoutShortcutImageUrl to helper or separate model */ $parameters = ['params' => ['quote' => $quote, 'config' => $config]]; $checkoutModel = $this->_checkoutFactory->create($this->_checkoutType, $parameters); $this->setImageUrl($checkoutModel->getCheckoutShortcutImageUrl()); } // ask whether to create a billing agreement $customerId = $this->currentCustomer->getCustomerId(); // potential issue for caching if ($this->_paypalData->shouldAskToCreateBillingAgreement($config, $customerId)) { $this->setConfirmationUrl($this->getUrl($this->_startAction, [\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1])); $this->setConfirmationMessage(__('Would you like to sign a billing agreement to streamline further purchases with PayPal?')); } return $result; }
/** * Instantiate quote and checkout * * @return void * @throws \Magento\Framework\Exception\LocalizedException */ protected function _initCheckout() { $quote = $this->_getQuote(); if (!$quote->hasItems() || $quote->getHasError()) { $this->getResponse()->setStatusHeader(403, '1.1', 'Forbidden'); throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t initialize Express Checkout.')); } if (!isset($this->_checkoutTypes[$this->_checkoutType])) { $parameters = ['params' => ['quote' => $quote, 'config' => $this->_config]]; $this->_checkoutTypes[$this->_checkoutType] = $this->_checkoutFactory->create($this->_checkoutType, $parameters); } $this->_checkout = $this->_checkoutTypes[$this->_checkoutType]; }
/** * @return \Magento\Framework\View\Element\AbstractBlock */ protected function _beforeToHtml() { $result = parent::_beforeToHtml(); $isInCatalog = $this->getIsInCatalogProduct(); if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) { $this->_shouldRender = false; return $result; } $quote = $isInCatalog || !$this->_checkoutSession ? null : $this->_checkoutSession->getQuote(); // set misc data $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_'))->setCheckoutUrl($this->getUrl($this->_startAction)); // use static image if in catalog if ($isInCatalog || null === $quote) { $this->setImageUrl($this->config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale())); } else { /**@todo refactor checkout model. Move getCheckoutShortcutImageUrl to helper or separate model */ $parameters = ['params' => ['quote' => $quote, 'config' => $this->config]]; $checkoutModel = $this->_checkoutFactory->create($this->_checkoutType, $parameters); $this->setImageUrl($checkoutModel->getCheckoutShortcutImageUrl()); } return $result; }
/** * Instantiate quote and checkout * * @return void * @throws \Magento\Framework\Model\Exception */ protected function _initCheckout() { $quote = $this->_getQuote(); if (!$quote->hasItems() || $quote->getHasError()) { $this->getResponse()->setHeader('HTTP/1.1', '403 Forbidden'); throw new \Magento\Framework\Model\Exception(__('We can\'t initialize Express Checkout.')); } if (!isset($this->_checkoutTypes[$this->_checkoutType])) { $parameters = array('params' => array('quote' => $quote, 'config' => $this->_config)); $this->_checkoutTypes[$this->_checkoutType] = $this->_checkoutFactory->create($this->_checkoutType, $parameters); } $this->_checkout = $this->_checkoutTypes[$this->_checkoutType]; }