Skip to content
This repository was archived by the owner on Oct 27, 2024. It is now read-only.

Commit 78ef408

Browse files
committed
Remove GB from EU tax rules, can still be added back manually with addRateForCountry()
Fix #25
1 parent bb9c66e commit 78ef408

File tree

3 files changed

+64
-34
lines changed

3 files changed

+64
-34
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ The returned array of rates is unsorted. This method can be useful when you want
167167

168168
EU countries are supported as well as some non-EU countries that use VAT. Some countries are not supported even though they also have VAT. Currently, that's the case for the following countries:
169169
- Switzerland (CH)
170+
- United Kingdom (GB)
170171
- Norway (NO)
171172
- Turkey (TR)
172173

src/VatRates.php

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,6 @@ class VatRates
9595
'Mayotte' => 0,
9696
],
9797
],
98-
'GB' => [ // United Kingdom
99-
'rate' => 0.20,
100-
'exceptions' => [
101-
// UK RAF Bases in Cyprus are taxed at Cyprus rate
102-
'Akrotiri' => 0.19,
103-
'Dhekelia' => 0.19,
104-
],
105-
],
10698
'GR' => [ // Greece
10799
'rate' => 0.24,
108100
'exceptions' => [
@@ -200,6 +192,14 @@ class VatRates
200192
self::LOW => 0.025,
201193
],
202194
],
195+
'GB' => [ // United Kingdom
196+
'rate' => 0.20,
197+
'exceptions' => [
198+
// UK RAF Bases in Cyprus are taxed at Cyprus rate
199+
'Akrotiri' => 0.19,
200+
'Dhekelia' => 0.19,
201+
],
202+
],
203203
'NO' => [ // Norway
204204
'rate' => 0.25,
205205
],
@@ -311,18 +311,6 @@ class VatRates
311311
'name' => 'Mayotte',
312312
],
313313
],
314-
'GB' => [
315-
// Akrotiri
316-
[
317-
'postalCode' => '/^BFPO57|BF12AT$/',
318-
'code' => 'CY',
319-
],
320-
// Dhekelia
321-
[
322-
'postalCode' => '/^BFPO58|BF12AU$/',
323-
'code' => 'CY',
324-
],
325-
],
326314
'GR' => [
327315
[
328316
'postalCode' => '/^63086$/',
@@ -358,6 +346,29 @@ class VatRates
358346
],
359347
];
360348

349+
/**
350+
* Optional postal code exceptions.
351+
*
352+
* Non-EU countries with their own VAT requirements and postal code exceptions,
353+
* added with `addRateForCountry()` for the rate and the exceptions to be applied.
354+
*
355+
* @var array<string, array>
356+
*/
357+
private $optionalPostalCodeExceptions = [
358+
'GB' => [
359+
// Akrotiri
360+
[
361+
'postalCode' => '/^BFPO57|BF12AT$/',
362+
'code' => 'CY',
363+
],
364+
// Dhekelia
365+
[
366+
'postalCode' => '/^BFPO58|BF12AU$/',
367+
'code' => 'CY',
368+
],
369+
],
370+
];
371+
361372
/** @var DateTimeImmutable */
362373
private $now;
363374

@@ -379,6 +390,9 @@ public function addRateForCountry(string $country): void
379390
throw new NoVatRulesForCountryException("No optional tax rules specified for {$country}");
380391
}
381392
$this->taxRules[$country] = $this->optionalTaxRules[$country];
393+
if (isset($this->optionalPostalCodeExceptions[$country])) {
394+
$this->postalCodeExceptions[$country] = $this->optionalPostalCodeExceptions[$country];
395+
}
382396
}
383397

384398

tests/VatCalculatorTest.php

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,35 @@ public function testAddNonEuRateShouldCollectValidateThrows(): void
235235
}
236236

237237

238+
public function testAddGbRateShouldCollectWithPostalCodeException(): void
239+
{
240+
$this->assertFalse($this->vatCalculator->shouldCollectVat('GB'));
241+
$this->assertFalse($this->vatCalculator->shouldCollectEuVat('GB'));
242+
$result = $this->vatCalculator->calculate(24.00, 'GB', null, true);
243+
$this->assertEquals(24.00, $result->getPrice());
244+
$this->assertEquals(0.00, $result->getTaxRate());
245+
$this->assertEquals(0.00, $result->getTaxValue());
246+
247+
$this->vatRates->addRateForCountry('GB');
248+
$this->assertTrue($this->vatCalculator->shouldCollectVat('GB'));
249+
$this->assertFalse($this->vatCalculator->shouldCollectEuVat('GB'));
250+
251+
// Valid UK post code
252+
$postalCode = 'S1A 2AA';
253+
$result = $this->vatCalculator->calculate(24.00, 'GB', $postalCode, false);
254+
//Expect standard rate for UK
255+
$this->assertEquals(28.80, $result->getPrice());
256+
$this->assertEquals(0.20, $result->getTaxRate());
257+
$this->assertEquals(4.80, $result->getTaxValue());
258+
259+
$postalCode = 'BFPO58'; // Dhekelia
260+
$result = $this->vatCalculator->calculate(24.00, 'GB', $postalCode, false);
261+
$this->assertEquals(28.56, $result->getPrice());
262+
$this->assertEquals(0.19, $result->getTaxRate());
263+
$this->assertEquals(4.56, $result->getTaxValue());
264+
}
265+
266+
238267
public function testSetBusinessCountryCode(): void
239268
{
240269
$this->vatCalculator->setBusinessCountryCode('DE');
@@ -265,12 +294,6 @@ public function testChecksPostalCodeForVatExceptions(): void
265294
$this->assertEquals(0.19, $result->getTaxRate());
266295
$this->assertEquals(4.56, $result->getTaxValue());
267296

268-
$postalCode = 'BFPO58'; // Dhekelia
269-
$result = $this->vatCalculator->calculate(24.00, 'GB', $postalCode, false);
270-
$this->assertEquals(28.56, $result->getPrice());
271-
$this->assertEquals(0.19, $result->getTaxRate());
272-
$this->assertEquals(4.56, $result->getTaxValue());
273-
274297
$postalCode = '9122'; // Madeira
275298
$result = $this->vatCalculator->calculate(24.00, 'PT', $postalCode, false);
276299
$this->assertEquals(29.28, $result->getPrice());
@@ -288,14 +311,6 @@ public function testPostalCodesWithoutExceptionsGetStandardRate(): void
288311
$this->assertEquals(29.04, $result->getPrice());
289312
$this->assertEquals(0.21, $result->getTaxRate());
290313
$this->assertEquals(5.04, $result->getTaxValue());
291-
292-
// Valid UK post code
293-
$postalCode = 'S1A 2AA';
294-
$result = $this->vatCalculator->calculate(24.00, 'GB', $postalCode, false);
295-
//Expect standard rate for UK
296-
$this->assertEquals(28.80, $result->getPrice());
297-
$this->assertEquals(0.20, $result->getTaxRate());
298-
$this->assertEquals(4.80, $result->getTaxValue());
299314
}
300315

301316

0 commit comments

Comments
 (0)