PHP code example of rechtlogisch / evatr

1. Go to this page and download the library: Download rechtlogisch/evatr library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rechtlogisch / evatr example snippets


use Rechtlogisch\Evatr\Evatr;

$result = (new Evatr(
  vatIdOwn: 'DE123456789',     // Your German VAT-ID (

$result = checkVatId(vatIdOwn: 'DE123456789', vatIdForeign: 'ATU12345678');

use Rechtlogisch\Evatr\Evatr;

$result = (new Evatr(
  vatIdOwn: 'DE123456789',            // Your German VAT-ID (ompany name (treet address (optional)
  zip: '12345',                       // Postal code (optional)
))->check();

$result = confirmVatId(
  vatIdOwn: 'DE123456789',
  vatIdForeign: 'ATU12345678',
  company: 'Musterhaus GmbH & Co KG',
  street: 'Musterstrasse 22',
  zip: '12345',
  location: 'Musterort',
);

$result = (new Evatr(
  vatIdOwn: 'DE123456789',
  vatIdForeign: 'ATU12345678'
))->

$result = checkVatId(
  vatIdOwn: 'DE123456789',
  vatIdForeign: 'ATU12345678',
  

$evatr = new Evatr(
  vatIdOwn: string,      // Your German VAT-ID ( ?string,      // Company name (optional, Street address (optional)
  zip: ?string,          // Postal code (optional)
);

$request = new RequestDto(
  vatIdOwn: 'DE123456789',
  vatIdForeign: 'ATU12345678',
  // ... other parameters
);
$evatr = new Evatr($request);

$result = $evatr->check();

$evatr->

$result->getVatIdOwn(): string;         // Own VAT-ID which was used for the request
$result->getVatIdForeign(): string;     // Foreign VAT-ID which was checked
$result->getId(): string;              // Unique ID from API, related to request
$result->getHttpStatusCode(): ?int;     // HTTP status code
$result->getTimestamp(): ?string;       // Query timestamp (ISO-8601 string)
$result->getStatus(): ?Status;          // Status enum
$result->getMessage(): ?string;         // Human-readable message based on EVATR_LANG
$result->getDateFrom(): ?string;        // Valid from date
$result->getDateTill(): ?string;        // Valid until date
$result->getCompany(): ?QualifiedResult;   // Company validation result
$result->getStreet(): ?QualifiedResult;    // Street validation result
$result->getZip(): ?QualifiedResult;       // ZIP validation result
$result->getLocation(): ?QualifiedResult;  // Location validation result
$result->getRaw(): ?string;             // Raw API response (if requested)
$result->toArray(): array;              // Convert to array

use Rechtlogisch\Evatr\Enum\Status;

// Check the status
if ($result->getStatus() === Status::EVATR_0000) {
  // VAT-ID is valid
}

// Get human-readable description
$description = $result->getStatus()->description();

use Rechtlogisch\Evatr\Enum\QualifiedResult;

if ($result->getCompany() === QualifiedResult::A) {
  // Company name matches
}

function checkVatId(
    string $vatIdOwn,
    string $vatIdForeign,
    bool $

function confirmVatId(
  string $vatIdOwn,
  string $vatIdForeign,
  ?string $company,
  ?string $street,
  ?string $zip,
  ?string $location,
  bool $

$messages = Evatr::getStatusMessages(); // array of DTO\StatusMessage

use Rechtlogisch\Evatr\DTO\StatusMessage;

$statusMessage = new StatusMessage(
  status: 'evatr-0000',
  category: 'Result', // category is always English and language-invariant: Result | Error | Hint
  http: 200,
  field: null, 
  message: 'Die angefragte Ust-IdNr. ist zum Anfragezeitpunkt gültig.'
);

$states = Evatr::getAvailability(); // array<string,bool> map of code => available
// Example: [ 'DE' => true, 'AT' => false, ... ]

// Only not available:
$notAvailable = Evatr::getAvailability(onlyNotAvailable: true); // [ 'AT' => false, ... ]

use Rechtlogisch\Evatr\Exception\ErrorResponse;
use Rechtlogisch\Evatr\Exception\InputError;
use Rechtlogisch\Evatr\Enum\Status;

try {
    $result = checkVatId('DE123456789', 'ATU12345678');
    // handle result
} catch (InputError|ErrorResponse $e) {
    // Log/handle error: $e->getMessage()
    // Get original exception: $e->getException()
}

use Rechtlogisch\Evatr\Exception\ErrorResponse;

try {
    $result = checkVatId('DE123456789', 'ATU12345678');
} catch (ErrorResponse $e) {
    $code = $e->getHttpCode();
    $msg  = $e->getError();
    $previous = $e->getException(); // underlying Throwable (e.g., JsonException, GuzzleException, or RuntimeException)
    $raw  = $e->getRaw();   // may be null
    $meta = $e->getMeta();  // ['endpoint' => ..., 'errorType' => ...]
    // Handle/log accordingly
}

// Simple validation test
$testRequest = [
  'vatIdOwn' => 'DE123456789',
  'vatIdForeign' => 'ATU12345678',
];

// Qualified confirmation test
$qualifiedTestRequest = [
  'vatIdOwn' => 'DE123456789',
  'vatIdForeign' => 'ATU12345678',
  'company' => 'Musterhaus GmbH & Co KG',
  'street' => 'Musterstrasse 22',
  'zip' => '12345',
  'location' => 'Musterort',
];