Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PaymentMethodValidationRule.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 use Magento\Framework\Validation\ValidationResultFactory;
12 
17 {
21  private $generalMessage;
22 
26  private $validationResultFactory;
27 
32  public function __construct(
33  ValidationResultFactory $validationResultFactory,
34  string $generalMessage = ''
35  ) {
36  $this->validationResultFactory = $validationResultFactory;
37  $this->generalMessage = $generalMessage;
38  }
39 
43  public function validate(Quote $quote): array
44  {
45  $validationErrors = [];
46  $validationResult = $quote->getPayment()->getMethod();
47  if (!$validationResult) {
48  $validationErrors = [__($this->generalMessage)];
49  }
50 
51  return [$this->validationResultFactory->create(['errors' => $validationErrors])];
52  }
53 }
$quote
__()
Definition: __.php:13
__construct(ValidationResultFactory $validationResultFactory, string $generalMessage='')