Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CountryValidator.php
Go to the documentation of this file.
1 <?php
7 
10 use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
11 
19 {
23  private $config;
24 
29  public function __construct(
30  ResultInterfaceFactory $resultFactory,
31  ConfigInterface $config
32  ) {
33  $this->config = $config;
34  parent::__construct($resultFactory);
35  }
36 
43  public function validate(array $validationSubject)
44  {
45  $isValid = true;
46  $storeId = $validationSubject['storeId'];
47 
48  if ((int)$this->config->getValue('allowspecific', $storeId) === 1) {
49  $availableCountries = explode(
50  ',',
51  $this->config->getValue('specificcountry', $storeId)
52  );
53 
54  if (!in_array($validationSubject['country'], $availableCountries)) {
55  $isValid = false;
56  }
57  }
58 
59  return $this->createResult($isValid);
60  }
61 }
$config
Definition: fraud_order.php:17
__construct(ResultInterfaceFactory $resultFactory, ConfigInterface $config)
createResult($isValid, array $fails=[], array $errorCodes=[])