You are here

public function VatNumberController::check in VAT Number 8

Checks the VAT number format on the database.

File

src/Controller/VatNumberController.php, line 31

Class

VatNumberController
Defines a controller to validate the VAT Number.

Namespace

Drupal\vat_number\Controller

Code

public function check() {
  $this
    ->checkVatFormat();
  if (!isset($this->vatInfo['message'])) {
    if ($this
      ->validateVatNumber() === FALSE) {
      $this->vatInfo['message'] = $this
        ->t('The VAT number could not be validated by the European VAT Database. Please go back and input a correct VAT number.');
    }
    else {
      $this->vatInfo['message'] = NULL;
    }
  }
  return [
    'status' => $this->valid,
    'message' => $this->vatInfo['message'],
  ];
}