klarnaQuoteRepository = $klarnaQuoteRepository; $this->log = $log; $this->dataObjectFactory = $dataObjectFactory; $this->config = $config; } /** * Observer * * @param Observer $observer * @return void * @throws LocalizedException */ public function execute(Observer $observer) { $method = $this->readMethodArgument($observer); if (false === strpos($method->getCode(), 'klarna_')) { return; } $data = $this->readDataArgument($observer); $additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA); if (!is_array($additionalData)) { return; } $additionalData = $this->dataObjectFactory->create(['data' => $additionalData]); $payment = $this->readPaymentModelArgument($observer); $quote = $payment->getQuote(); if (!$this->config->isSetFlag( 'payment/' . Kp::METHOD_CODE . '/active', ScopeInterface::SCOPE_STORES, $quote->getStore() )) { return; } try { /** @var QuoteInterface $klarnaQuote */ $klarnaQuote = $this->klarnaQuoteRepository->getActiveByQuote($quote); $klarnaQuote->setAuthorizationToken($additionalData->getData('authorization_token')); $payment->setAdditionalInformation('method_title', $additionalData->getData('method_title')); $payment->setAdditionalInformation('logo', $additionalData->getData('logo')); $payment->setAdditionalInformation('method_code', $payment->getMethodInstance()->getCode()); $payment->setAdditionalInformation('klarna_order_id', $klarnaQuote->getSessionId()); $this->klarnaQuoteRepository->save($klarnaQuote); } catch (NoSuchEntityException $npe) { $data = ['klarna_id' => $additionalData->getData('authorization_token')]; $this->log->error($npe, $data); } } }