Initial commit: ws_vatcheck at v1.0.3
Includes the fix for the GR/EL VAT prefix bug that broke exemption for every Greek VAT number (in_array-on-values vs array_key_exists in CacheTaxManager/VatNumber, plus the missing use import in EuValidatorAdapter). Adds IMPROVEMENTS.txt with a checklist of features adopted from comparing against the vatchecker module (offline-fallback policy, failure logging, company-name check, configurable EU country list, per-product exclusion, GB/XI mapping, AJAX live validation, address-priority strategy). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Websmid\VatCheck\Adapter;
|
||||
|
||||
use PH7\Eu\Vat\Validator;
|
||||
use PH7\Eu\Vat\Provider\Europa;
|
||||
use PH7\Eu\Vat\Exception;
|
||||
use Websmid\VatCheck\Config\Config;
|
||||
use Websmid\VatCheck\Model\VatCache;
|
||||
|
||||
class EuValidatorAdapter
|
||||
{
|
||||
protected $vatNr = '';
|
||||
|
||||
protected $isoCode = '';
|
||||
|
||||
private $checkStatus;
|
||||
|
||||
public function __construct(string $vatNr, string $isoCode)
|
||||
{
|
||||
$this->vatNr = str_replace($isoCode, '', $vatNr);
|
||||
$this->isoCode = $isoCode;
|
||||
}
|
||||
|
||||
public function checkAndStore()
|
||||
{
|
||||
try {
|
||||
$euVatValidator = new Validator(new Europa, $this->vatNr, $this->isoCode);
|
||||
} catch(Exception $e){
|
||||
return false;
|
||||
}
|
||||
|
||||
if( $euVatValidator instanceof Validator ){
|
||||
$fullVat = $this->isoCode.$this->vatNr;
|
||||
$vatCache = VatCache::getOrCreateByVat($fullVat);
|
||||
$vatCache->vat_nr = $fullVat;
|
||||
$vatCache->valid = $euVatValidator->check();
|
||||
|
||||
$vatCache->save();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user