Skip to content

Commit dc7f6da

Browse files
authored
Remove UK VAT checks (#191)
1 parent 6671959 commit dc7f6da

File tree

2 files changed

+5
-53
lines changed

2 files changed

+5
-53
lines changed

src/VatCalculator.php

+1-33
Original file line numberDiff line numberDiff line change
@@ -594,11 +594,6 @@ class VatCalculator
594594
*/
595595
protected $businessCountryCode = '';
596596

597-
/**
598-
* @var string
599-
*/
600-
protected $ukValidationEndpoint = 'https://api.service.hmrc.gov.uk';
601-
602597
/**
603598
* @param \Illuminate\Contracts\Config\Repository|array
604599
*/
@@ -901,22 +896,7 @@ public function getVATDetails($vatNumber)
901896
$vatNumber = substr($vatNumber, 2);
902897

903898
if (strtoupper($countryCode) === 'GB') {
904-
$apiHeaders = get_headers("$this->ukValidationEndpoint/organisations/vat/check-vat-number/lookup/$vatNumber");
905-
$apiHeaders = explode(' ', $apiHeaders[0]);
906-
$apiStatusCode = (int) $apiHeaders[1];
907-
908-
if ($apiStatusCode === 400 || $apiStatusCode === 404) {
909-
return false;
910-
}
911-
912-
if ($apiStatusCode === 200) {
913-
$apiResponse = file_get_contents("$this->ukValidationEndpoint/organisations/vat/check-vat-number/lookup/$vatNumber");
914-
$apiResponse = json_decode($apiResponse, true);
915-
916-
return $apiResponse['target'];
917-
}
918-
919-
throw new VATCheckUnavailableException("The UK VAT check service is currently unavailable (status code $apiStatusCode). Please try again later.");
899+
throw new VATCheckUnavailableException('UK VAT checks are no longer available. Please see https://github.com/driesvints/vat-calculator/pull/191.');
920900
} else {
921901
$this->initSoapClient();
922902
$client = $this->soapClient;
@@ -978,16 +958,4 @@ public function setSoapClient($soapClient)
978958
{
979959
$this->soapClient = $soapClient;
980960
}
981-
982-
/**
983-
* @return $this
984-
*
985-
* @internal This method is not covered by our BC policy.
986-
*/
987-
public function testing()
988-
{
989-
$this->ukValidationEndpoint = 'https://test-api.service.hmrc.gov.uk';
990-
991-
return $this;
992-
}
993961
}

tests/VatCalculatorTest.php

+4-20
Original file line numberDiff line numberDiff line change
@@ -423,25 +423,10 @@ public function test_cannot_validate_vat_number_when_service_is_down()
423423
$vatCalculator->isValidVATNumber($vatNumber);
424424
}
425425

426-
public function test_can_validate_valid_ukvat_number()
426+
public function test_cannot_validate_valid_ukvat_numbers()
427427
{
428-
$config = m::mock(Repository::class);
429-
$config->shouldReceive('get')
430-
->once()
431-
->with('vat_calculator', [])
432-
->andReturn([]);
433-
434-
$result = new \stdClass;
435-
$result->valid = true;
436-
437-
$vatNumber = 'GB 553557881';
438-
$vatCalculator = new VatCalculator($config);
439-
$result = $vatCalculator->testing()->isValidVATNumber($vatNumber);
440-
$this->assertTrue($result);
441-
}
428+
$this->expectException(VATCheckUnavailableException::class);
442429

443-
public function test_can_validate_invalid_ukvat_number()
444-
{
445430
$config = m::mock(Repository::class);
446431
$config->shouldReceive('get')
447432
->once()
@@ -451,10 +436,9 @@ public function test_can_validate_invalid_ukvat_number()
451436
$result = new \stdClass;
452437
$result->valid = true;
453438

454-
$vatNumber = 'GB Invalid';
439+
$vatNumber = 'GB 553557881';
455440
$vatCalculator = new VatCalculator($config);
456-
$result = $vatCalculator->testing()->isValidVATNumber($vatNumber);
457-
$this->assertFalse($result);
441+
$vatCalculator->isValidVATNumber($vatNumber);
458442
}
459443

460444
public function test_company_in_business_country_gets_valid_vat_rate()

0 commit comments

Comments
 (0)