You are here

public function TaxNumberController::verify in Commerce Core 8.2

Verifies the given tax number.

Parameters

string $tax_number: The tax number.

string $context: The encoded context.

Return value

\Symfony\Component\HttpFoundation\Response A response.

Throws

\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException If the context is invalid or the user doesn't have access to update the parent entity.

1 string reference to 'TaxNumberController::verify'
commerce_tax.routing.yml in modules/tax/commerce_tax.routing.yml
modules/tax/commerce_tax.routing.yml

File

modules/tax/src/Controller/TaxNumberController.php, line 77

Class

TaxNumberController

Namespace

Drupal\commerce_tax\Controller

Code

public function verify($tax_number, $context) {
  $context = $this
    ->prepareContext($context);
  if (!$context) {
    throw new AccessDeniedHttpException();
  }

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $context['entity'];
  if (!$entity
    ->access('update')) {
    throw new AccessDeniedHttpException();
  }

  /** @var \Drupal\commerce_tax\Plugin\Field\FieldType\TaxNumberItemInterface $field */
  $field = $entity
    ->get('tax_number')
    ->first();
  $type_plugin = $field
    ->getTypePlugin();
  if ($type_plugin instanceof SupportsVerificationInterface) {
    $result = $type_plugin
      ->verify($tax_number);
    $field
      ->applyVerificationResult($result);
    $entity
      ->save();
    $this
      ->messenger()
      ->addStatus($this
      ->t('The tax number @number has been reverified.', [
      '@number' => $tax_number,
    ]));
  }
  return new RedirectResponse(Url::fromRoute('<front>', [], [
    'absolute' => TRUE,
  ])
    ->toString());
}