Skip to content

Commit

Permalink
Remove UK VAT checks (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints authored Feb 28, 2025
1 parent 6671959 commit dc7f6da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 53 deletions.
34 changes: 1 addition & 33 deletions src/VatCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,6 @@ class VatCalculator
*/
protected $businessCountryCode = '';

/**
* @var string
*/
protected $ukValidationEndpoint = 'https://api.service.hmrc.gov.uk';

/**
* @param \Illuminate\Contracts\Config\Repository|array
*/
Expand Down Expand Up @@ -901,22 +896,7 @@ public function getVATDetails($vatNumber)
$vatNumber = substr($vatNumber, 2);

if (strtoupper($countryCode) === 'GB') {
$apiHeaders = get_headers("$this->ukValidationEndpoint/organisations/vat/check-vat-number/lookup/$vatNumber");
$apiHeaders = explode(' ', $apiHeaders[0]);
$apiStatusCode = (int) $apiHeaders[1];

if ($apiStatusCode === 400 || $apiStatusCode === 404) {
return false;
}

if ($apiStatusCode === 200) {
$apiResponse = file_get_contents("$this->ukValidationEndpoint/organisations/vat/check-vat-number/lookup/$vatNumber");
$apiResponse = json_decode($apiResponse, true);

return $apiResponse['target'];
}

throw new VATCheckUnavailableException("The UK VAT check service is currently unavailable (status code $apiStatusCode). Please try again later.");
throw new VATCheckUnavailableException('UK VAT checks are no longer available. Please see https://github.com/driesvints/vat-calculator/pull/191.');
} else {
$this->initSoapClient();
$client = $this->soapClient;
Expand Down Expand Up @@ -978,16 +958,4 @@ public function setSoapClient($soapClient)
{
$this->soapClient = $soapClient;
}

/**
* @return $this
*
* @internal This method is not covered by our BC policy.
*/
public function testing()
{
$this->ukValidationEndpoint = 'https://test-api.service.hmrc.gov.uk';

return $this;
}
}
24 changes: 4 additions & 20 deletions tests/VatCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,25 +423,10 @@ public function test_cannot_validate_vat_number_when_service_is_down()
$vatCalculator->isValidVATNumber($vatNumber);
}

public function test_can_validate_valid_ukvat_number()
public function test_cannot_validate_valid_ukvat_numbers()
{
$config = m::mock(Repository::class);
$config->shouldReceive('get')
->once()
->with('vat_calculator', [])
->andReturn([]);

$result = new \stdClass;
$result->valid = true;

$vatNumber = 'GB 553557881';
$vatCalculator = new VatCalculator($config);
$result = $vatCalculator->testing()->isValidVATNumber($vatNumber);
$this->assertTrue($result);
}
$this->expectException(VATCheckUnavailableException::class);

public function test_can_validate_invalid_ukvat_number()
{
$config = m::mock(Repository::class);
$config->shouldReceive('get')
->once()
Expand All @@ -451,10 +436,9 @@ public function test_can_validate_invalid_ukvat_number()
$result = new \stdClass;
$result->valid = true;

$vatNumber = 'GB Invalid';
$vatNumber = 'GB 553557881';
$vatCalculator = new VatCalculator($config);
$result = $vatCalculator->testing()->isValidVATNumber($vatNumber);
$this->assertFalse($result);
$vatCalculator->isValidVATNumber($vatNumber);
}

public function test_company_in_business_country_gets_valid_vat_rate()
Expand Down

0 comments on commit dc7f6da

Please sign in to comment.