billingAddressManagement = $billingAddressManagement; $this->paymentMethodManagement = $paymentMethodManagement; $this->cartManagement = $cartManagement; $this->paymentInformationManagement = $paymentInformationManagement; $this->quoteIdMaskFactory = $quoteIdMaskFactory; $this->cartRepository = $cartRepository; } /** * {@inheritDoc} */ public function savePaymentInformationAndPlaceOrder( $cartId, $email, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress = null ) { $this->savePaymentInformation($cartId, $email, $paymentMethod, $billingAddress); try { $orderId = $this->cartManagement->placeOrder($cartId); } catch (\Magento\Framework\Exception\LocalizedException $e) { throw new CouldNotSaveException( __($e->getMessage()), $e ); } catch (\Exception $e) { $this->getLogger()->critical($e); throw new CouldNotSaveException( __('An error occurred on the server. Please try to place the order again.'), $e ); } return $orderId; } /** * {@inheritDoc} */ public function savePaymentInformation( $cartId, $email, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress = null ) { if ($billingAddress) { $billingAddress->setEmail($email); $this->billingAddressManagement->assign($cartId, $billingAddress); } else { $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); $this->cartRepository->getActive($quoteIdMask->getQuoteId())->getBillingAddress()->setEmail($email); } $this->paymentMethodManagement->set($cartId, $paymentMethod); return true; } /** * {@inheritDoc} */ public function getPaymentInformation($cartId) { $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); return $this->paymentInformationManagement->getPaymentInformation($quoteIdMask->getQuoteId()); } /** * Get logger instance * * @return \Psr\Log\LoggerInterface * @deprecated */ private function getLogger() { if (!$this->logger) { $this->logger = \Magento\Framework\App\ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class); } return $this->logger; } }