filterVat() public static method

Filters a VAT number and normalizes it to an alfanumeric string
public static filterVat ( string $vatNumber ) : string
$vatNumber string
return string
Exemplo n.º 1
0
 /**
  * @dataProvider vatNumberProvider
  * @covers \DragonBe\Vies\Vies::filterVat
  */
 public function testVatNumberFilter($vatNumber, $filteredNumber)
 {
     $this->assertEquals($filteredNumber, Vies::filterVat($vatNumber));
 }
Exemplo n.º 2
0
use DragonBe\Vies\ViesServiceException;
require_once dirname(__DIR__) . '/vendor/autoload.php';
$vies = new Vies();
if (false === $vies->getHeartBeat()->isAlive()) {
    echo 'Back-end VIES service is not available at the moment, please try again later.' . PHP_EOL;
} else {
    $splQueue = new SplQueue();
    foreach (vatinProvider() as $vatin) {
        $splQueue->enqueue($vatin);
    }
    foreach ($splQueue as $item) {
        $vatin = $splQueue->dequeue();
        echo 'Validating ' . $vatin . '... ';
        $countryCode = substr($vatin, 0, 2);
        $vatNumber = substr($vatin, 2);
        $vatNumber = $vies->filterVat($vatNumber);
        try {
            $result = $vies->validateVat($countryCode, $vatNumber);
            // Validation routine worked as expected.
            echo $result->isValid() ? 'VALID' : 'INVALID';
        } catch (ViesServiceException $e) {
            // Recoverable exception. There is probably a temporary problem
            echo $e->getMessage();
            // with back-end VIES service. Try again. Add VATIN back to queue.
            $splQueue->enqueue($vatin);
        } catch (ViesException $e) {
            // Unrecoverable exception. Invalid country code etc.
            echo $e->getMessage();
            // Do not try again.
        }
        echo PHP_EOL;