logger = $logger; $this->customerRepository = $customerRepository; $this->cartRepository = $cartRepository; $this->guestCartRepository = $guestCartRepository; } /** * Get token data * * @return ResultInterface */ public function execute(): ResultInterface { $controllerResult = $this->resultFactory->create(ResultFactory::TYPE_JSON); $responseContent = [ 'success' => true, 'error_message' => '', ]; try { $token = $this->getToken(); if ($token === null) { $token = false; } $this->_initToken($token); $responseContent['token'] = $token; } catch (LocalizedException $exception) { $this->logger->critical($exception); $responseContent['success'] = false; $responseContent['error_message'] = $exception->getMessage(); } catch (\Exception $exception) { $this->logger->critical($exception); $responseContent['success'] = false; $responseContent['error_message'] = __('Sorry, but something went wrong'); } return $controllerResult->setData($responseContent); } /** * Get paypal token * * @return string|null * @throws LocalizedException */ private function getToken(): ?string { $quoteId = $this->getRequest()->getParam('quote_id'); $customerId = $this->getRequest()->getParam('customer_id') ?: $this->_customerSession->getId(); $hasButton = (bool)$this->getRequest()->getParam(Checkout::PAYMENT_INFO_BUTTON); if ($quoteId) { $quote = $customerId ? $this->cartRepository->get($quoteId) : $this->guestCartRepository->get($quoteId); } else { $quote = $this->_getQuote(); } $this->_initCheckout($quote); if ($quote->getIsMultiShipping()) { $quote->setIsMultiShipping(0); $quote->removeAllAddresses(); } if ($customerId) { $customerData = $this->customerRepository->getById((int)$customerId); $this->_checkout->setCustomerWithAddressChange( $customerData, $quote->getBillingAddress(), $quote->getShippingAddress() ); } // giropay urls $this->_checkout->prepareGiropayUrls( $this->_url->getUrl('checkout/onepage/success'), $this->_url->getUrl('paypal/express/cancel'), $this->_url->getUrl('checkout/onepage/success') ); return $this->_checkout->start( $this->_url->getUrl('*/*/return'), $this->_url->getUrl('*/*/cancel'), $hasButton ); } }