Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Exception/InvalidInputException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types = 1);

namespace Ddeboer\Vatin\Exception;

class InvalidInputException extends \RuntimeException implements ViesExceptionInterface
{
public function __construct(?\Throwable $previous = null)
{
parent::__construct('The provided country code is invalid or the VAT number is empty', previous: $previous);
}
}
13 changes: 13 additions & 0 deletions src/Exception/MaxConcurrentRequestsException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types = 1);

namespace Ddeboer\Vatin\Exception;

class MaxConcurrentRequestsException extends \RuntimeException implements ViesExceptionInterface
{
public function __construct(?\Throwable $previous = null)
{
parent::__construct('The maximum number of concurrent requests has been reached', previous: $previous);
}
}
13 changes: 13 additions & 0 deletions src/Exception/MaxConcurrentStateRequestsException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types = 1);

namespace Ddeboer\Vatin\Exception;

class MaxConcurrentStateRequestsException extends \RuntimeException implements ViesExceptionInterface
{
public function __construct(?\Throwable $previous = null)
{
parent::__construct('The maximum number of concurrent requests for this member state has been reached', previous: $previous);
}
}
13 changes: 13 additions & 0 deletions src/Exception/ServiceUnavailableException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types = 1);

namespace Ddeboer\Vatin\Exception;

class ServiceUnavailableException extends \RuntimeException implements ViesExceptionInterface
{
public function __construct(?\Throwable $previous = null)
{
parent::__construct('An error was encountered at the network or web application level', previous: $previous);
}
}
13 changes: 13 additions & 0 deletions src/Exception/StateServiceUnavailableException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types = 1);

namespace Ddeboer\Vatin\Exception;

class StateServiceUnavailableException extends \RuntimeException implements ViesExceptionInterface
{
public function __construct(?\Throwable $previous = null)
{
parent::__construct('The application at the member state is not replying or not available', previous: $previous);
}
}
13 changes: 13 additions & 0 deletions src/Exception/TimeoutException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types = 1);

namespace Ddeboer\Vatin\Exception;

class TimeoutException extends \RuntimeException implements ViesExceptionInterface
{
public function __construct(?\Throwable $previous = null)
{
parent::__construct('The application did not receive a reply within the allocated time period', previous: $previous);
}
}
16 changes: 15 additions & 1 deletion src/Vies/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

namespace Ddeboer\Vatin\Vies;

use Ddeboer\Vatin\Exception\InvalidInputException;
use Ddeboer\Vatin\Exception\MaxConcurrentRequestsException;
use Ddeboer\Vatin\Exception\MaxConcurrentStateRequestsException;
use Ddeboer\Vatin\Exception\ServiceUnavailableException;
use Ddeboer\Vatin\Exception\ServiceUnreachableException;
use Ddeboer\Vatin\Exception\StateServiceUnavailableException;
use Ddeboer\Vatin\Exception\TimeoutException;
use Ddeboer\Vatin\Exception\ViesException;
use Ddeboer\Vatin\Exception\ViesExceptionInterface;
use Ddeboer\Vatin\Vies\Response\CheckVatResponse;
Expand Down Expand Up @@ -82,6 +88,14 @@ private function buildExceptionFromSoapFault(\SoapFault $e): ViesExceptionInterf
return new ServiceUnreachableException($e);
}

return new ViesException($e);
return match($e->faultstring) {
'INVALID_INPUT' => new InvalidInputException($e),
'GLOBAL_MAX_CONCURRENT_REQ' => new MaxConcurrentRequestsException($e),
'MS_MAX_CONCURRENT_REQ' => new MaxConcurrentStateRequestsException($e),
'SERVICE_UNAVAILABLE' => new ServiceUnavailableException($e),
'MS_UNAVAILABLE' => new StateServiceUnavailableException($e),
'TIMEOUT' => new TimeoutException($e),
default => new ViesException($e),
};
}
}
9 changes: 9 additions & 0 deletions tests/Vies/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Ddeboer\Vatin\Test\Vies;

use Ddeboer\Vatin\Exception\InvalidInputException;
use Ddeboer\Vatin\Vies\Client;
use PHPUnit\Framework\TestCase;

Expand All @@ -19,4 +20,12 @@ public function testCheckVat(): void
$this->assertEquals('---', $response->name);
$this->assertEquals('---', $response->address);
}

public function testInvalidInputException(): void
{
$this->expectException(InvalidInputException::class);

$client = new Client();
$client->checkVat('XYZ', '123');
}
}