SessionValidator.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * This file is part of the Klarna KP module
  4. *
  5. * (c) Klarna Bank AB (publ)
  6. *
  7. * For the full copyright and license information, please view the NOTICE
  8. * and LICENSE files that were distributed with this source code.
  9. */
  10. namespace Klarna\Kp\Gateway\Validator;
  11. use Magento\Framework\App\Config\ScopeConfigInterface;
  12. use Magento\Payment\Gateway\Validator\AbstractValidator;
  13. use Magento\Payment\Gateway\Validator\ResultInterface;
  14. use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
  15. use Magento\Store\Api\Data\StoreInterface;
  16. use Magento\Store\Model\ScopeInterface;
  17. use Magento\Store\Model\StoreManagerInterface;
  18. /**
  19. * Class SessionValidator
  20. *
  21. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  22. */
  23. class SessionValidator extends AbstractValidator
  24. {
  25. /**
  26. * @var StoreInterface
  27. */
  28. private $store;
  29. /**
  30. * @var ScopeConfigInterface
  31. */
  32. private $config;
  33. /**
  34. * Constructor
  35. *
  36. * @param ResultInterfaceFactory $resultFactory
  37. * @param StoreManagerInterface $storeManager
  38. * @param ScopeConfigInterface $config
  39. */
  40. public function __construct(
  41. ResultInterfaceFactory $resultFactory,
  42. StoreManagerInterface $storeManager,
  43. ScopeConfigInterface $config
  44. ) {
  45. parent::__construct($resultFactory);
  46. $this->store = $storeManager->getStore();
  47. $this->config = $config;
  48. }
  49. /**
  50. * Validate
  51. *
  52. * @param bool $isValid
  53. * @param array $fails
  54. * @return ResultInterface
  55. * @SuppressWarnings(PMD.UnusedFormalParameter)
  56. */
  57. public function validate(array $validationSubject)
  58. {
  59. $merchant_id = $this->config->getValue('klarna/api/merchant_id', ScopeInterface::SCOPE_STORES, $this->store);
  60. $secret = $this->config->getValue('klarna/api/shared_secret', ScopeInterface::SCOPE_STORES, $this->store);
  61. if (empty($merchant_id) || empty($secret)) {
  62. return $this->createResult(false, [__('Klarna API Credentials are required')]);
  63. }
  64. return $this->createResult(true);
  65. }
  66. }