mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-20 08:21:34 +02:00
VAT number checker
This commit is contained in:
parent
6485e48896
commit
310d14fd9c
@ -22,12 +22,29 @@ class TaxService
|
||||
|
||||
public function validateVat(): self
|
||||
{
|
||||
if(!extension_loaded('soap')) {
|
||||
nlog("Install the PHP SOAP extension if you wish to check VAT Numbers. See https://www.php.net/manual/en/soap.installation.php for more information on installing the PHP");
|
||||
return $this;
|
||||
}
|
||||
|
||||
$client_country_code = $this->client->shipping_country ? $this->client->shipping_country->iso_3166_2 : $this->client->country->iso_3166_2;
|
||||
|
||||
$vat_check = (new VatNumberCheck($this->client->vat_number, $client_country_code))->run();
|
||||
|
||||
nlog($vat_check);
|
||||
|
||||
if($vat_check->isValid()) {
|
||||
|
||||
$this->client->has_valid_vat_number = true;
|
||||
|
||||
if(!$this->client->name && strlen($vat_check->getName()) > 2) {
|
||||
$this->client->name = $vat_check->getName();
|
||||
}
|
||||
|
||||
if(empty($this->client->private_notes) && strlen($vat_check->getAddress()) > 2) {
|
||||
$this->client->private_notes = $vat_check->getAddress();
|
||||
}
|
||||
|
||||
$this->client->saveQuietly();
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ class VatNumberCheck
|
||||
{
|
||||
private array $response = [];
|
||||
|
||||
public function __construct(protected string $vat_number, protected string $country_code)
|
||||
public function __construct(protected ?string $vat_number, protected string $country_code)
|
||||
{
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ class VatNumberCheck
|
||||
$client = new \SoapClient($wsdl);
|
||||
$params = [
|
||||
'countryCode' => $this->country_code,
|
||||
'vatNumber' => $this->vat_number
|
||||
'vatNumber' => $this->vat_number ?? ''
|
||||
];
|
||||
$response = $client->checkVat($params);
|
||||
|
||||
@ -63,4 +63,14 @@ class VatNumberCheck
|
||||
{
|
||||
return $this->response['valid'];
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return isset($this->response['name']) ? $this->response['name'] : '';
|
||||
}
|
||||
|
||||
public function getAddress()
|
||||
{
|
||||
return isset($this->response['address']) ? $this->response['address'] : '';
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user