viruschidai / validate-vat-ts

A library for validating VAT number
32 stars 13 forks source link

GB VAT numbers #39

Open AllanJard opened 2 years ago

AllanJard commented 2 years ago

This is a follow on from #24 which rightly notes that GB VAT numbers are no longer validated by VIES.

HMRC provide this service for validating VAT numbers. If I were to send a PR to add that (perhaps behind an option flag such as includeGB: bool) would it be accepted (assuming it works and all that!), or is this a feature this library wouldn't be interested in?

AllanJard commented 2 years ago

This comment is kind of a note to self should you consider this a valid feature request (so I remember what the API is!). The following is the code is used to do this in my PHP VAT validator I use for a different application:

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "https://api.service.hmrc.gov.uk/organisations/vat/check-vat-number/lookup/".$number);
curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$this->response = [
        "is_valid" => $code < 300 ? true : false
];