File: /var/www/vhost/disk-apps/magento.bikenow.co/vendor/klarna/module-kp/Model/PaymentMethodList.php
<?php
/**
* This file is part of the Klarna KP module
*
* (c) Klarna Bank AB (publ)
*
* For the full copyright and license information, please view the NOTICE
* and LICENSE files that were distributed with this source code.
*/
namespace Klarna\Kp\Model;
use Klarna\Kp\Api\QuoteRepositoryInterface;
use Klarna\Kp\Model\Payment\Kp;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Payment\Model\Method\Factory;
use Magento\Quote\Api\Data\CartInterface;
use Psr\Log\LoggerInterface;
class PaymentMethodList implements \Klarna\Kp\Api\PaymentMethodListInterface
{
/**
* Factory for payment method models
*
* @var Factory
*/
private $methodFactory;
/**
* @var QuoteRepositoryInterface
*/
private $quoteRepository;
/**
* @var LoggerInterface
*/
private $log;
/**
* @var \Klarna\Kp\Model\Payment\Kp[]
*/
private $paymentMethods = [];
/**
* @param Factory $methodFactory
* @param QuoteRepositoryInterface $quoteRepository
* @param LoggerInterface $log
*/
public function __construct(
Factory $methodFactory,
QuoteRepositoryInterface $quoteRepository,
LoggerInterface $log
) {
$this->methodFactory = $methodFactory;
$this->quoteRepository = $quoteRepository;
$this->log = $log;
}
/**
* {@inheritdoc}
*/
public function getKlarnaMethodCodes(CartInterface $quote = null)
{
if (!$quote) {
return [];
}
try {
return $this->quoteRepository->getActiveByQuote($quote)->getPaymentMethods();
} catch (NoSuchEntityException $e) {
return [];
}
}
/**
* {@inheritdoc}
*/
public function getPaymentMethod($method)
{
if (!isset($this->paymentMethods[$method])) {
$this->paymentMethods[$method] = $this->methodFactory->create(\Klarna\Kp\Model\Payment\Kp::class)
->setCode($method);
}
return $this->paymentMethods[$method];
}
/**
* {@inheritdoc}
*/
public function getKlarnaMethodInfo(CartInterface $quote)
{
try {
return $this->quoteRepository->getActiveByQuote($quote)->getPaymentMethodInfo();
} catch (NoSuchEntityException $e) {
return null;
}
}
}