_customerSession = $customerSession; $this->_checkoutSession = $checkoutSession; $this->_orderFactory = $orderFactory; $this->_checkoutFactory = $checkoutFactory; $this->_paypalSession = $paypalSession; $this->_urlHelper = $urlHelper; $this->_customerUrl = $customerUrl; parent::__construct($context); $parameters = ['params' => [$this->_configMethod]]; $this->_config = $this->_objectManager->create($this->_configType, $parameters); } /** * Instantiate quote and checkout * * @param CartInterface|null $quoteObject * * @return void * @throws \Magento\Framework\Exception\LocalizedException */ protected function _initCheckout(CartInterface $quoteObject = null) { $quote = $quoteObject ? $quoteObject : $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 (!(float)$quote->getGrandTotal()) { throw new \Magento\Framework\Exception\LocalizedException( __( 'PayPal can\'t process orders with a zero balance due. ' . 'To finish your purchase, please go through the standard checkout process.' ) ); } 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]; } /** * Get Proper Checkout Token * * Search for proper checkout token in request or session or (un)set specified one * Combined getter/setter * * @param string|null $setToken * @return $this|string * @throws \Magento\Framework\Exception\LocalizedException */ protected function _initToken($setToken = null) { if (null !== $setToken) { if (false === $setToken) { // security measure for avoid unsetting token twice if (!$this->_getSession()->getExpressCheckoutToken()) { throw new \Magento\Framework\Exception\LocalizedException( __('PayPal Express Checkout Token does not exist.') ); } $this->_getSession()->unsExpressCheckoutToken(); } else { $this->_getSession()->setExpressCheckoutToken($setToken); } return $this; } $setToken = $this->getRequest()->getParam('token'); if ($setToken) { if ($setToken !== $this->_getSession()->getExpressCheckoutToken()) { throw new \Magento\Framework\Exception\LocalizedException( __('A wrong PayPal Express Checkout Token is specified.') ); } } else { $setToken = $this->_getSession()->getExpressCheckoutToken(); } return $setToken; } /** * PayPal session instance getter * * @return \Magento\Framework\Session\Generic */ protected function _getSession() { return $this->_paypalSession; } /** * Return checkout session object * * @return \Magento\Checkout\Model\Session */ protected function _getCheckoutSession() { return $this->_checkoutSession; } /** * Return checkout quote object * * @return \Magento\Quote\Model\Quote */ protected function _getQuote() { if (!$this->_quote) { $this->_quote = $this->_getCheckoutSession()->getQuote(); } return $this->_quote; } /** * @inheritdoc */ public function getCustomerBeforeAuthUrl() { return; } /** * @inheritdoc */ public function getActionFlagList() { return []; } /** * Returns login url parameter for redirect * * @return string */ public function getLoginUrl() { return $this->_customerUrl->getLoginUrl(); } /** * Returns action name which requires redirect * * @return string */ public function getRedirectActionName() { return 'start'; } /** * Redirect to login page * * @return void */ public function redirectLogin() { $this->_actionFlag->set('', 'no-dispatch', true); $this->_customerSession->setBeforeAuthUrl($this->_redirect->getRefererUrl()); $this->getResponse()->setRedirect( $this->_urlHelper->addRequestParam($this->_customerUrl->getLoginUrl(), ['context' => 'checkout']) ); } /** * @inheritdoc */ abstract public function execute(); }