Skip to content

Commit 7192c90

Browse files
tanthammarclaude
andcommitted
BREAKING CHANGE: Refactor BusinessNameFromVatID to return VAT details object instead of translated strings
- Add BusinessNameLookupError enum for error cases (Unknown, ServiceUnavailable) - BusinessNameFromVatID::lookup() now returns object|BusinessNameLookupError instead of string - On success: returns full VAT details object with name, address, vatNumber properties - On error: returns BusinessNameLookupError enum instead of translated error messages - Update README.md with new usage examples showing error handling patterns This change provides access to complete VAT information while maintaining clean error handling through enums. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 31d02e8 commit 7192c90

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,23 @@ $plusgiro = FakePlusgiro::make();
174174
```php
175175
use TantHammar\LaravelRules\Services\BusinessNameFromVatID;
176176
use TantHammar\LaravelRules\Services\VatDetailsFromVatID;
177-
178-
// Get business name from VAT ID
179-
$businessName = BusinessNameFromVatID::lookup('SE556556567801');
177+
use TantHammar\LaravelRules\Enums\BusinessNameLookupError;
178+
179+
// Get business details from VAT ID
180+
$result = BusinessNameFromVatID::lookup('SE556556567801');
181+
182+
if ($result instanceof BusinessNameLookupError) {
183+
// Handle error cases
184+
match ($result) {
185+
BusinessNameLookupError::Unknown => 'VAT ID not found',
186+
BusinessNameLookupError::ServiceUnavailable => 'VAT service temporarily unavailable',
187+
};
188+
} else {
189+
// Success - $result is the VAT details object
190+
$businessName = $result->name;
191+
$address = $result->address;
192+
$vatNumber = $result->vatNumber;
193+
}
180194

181195
// Get full VAT details
182196
$details = VatDetailsFromVatID::lookup('SE556556567801');
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace TantHammar\LaravelRules\Enums;
4+
5+
enum BusinessNameLookupError: string
6+
{
7+
case Unknown = 'unknown';
8+
case ServiceUnavailable = 'service_unavailable';
9+
}

src/Services/BusinessNameFromVatID.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44

55
use Mpociot\VatCalculator\Exceptions\VATCheckUnavailableException;
66
use Mpociot\VatCalculator\VatCalculator;
7+
use TantHammar\LaravelRules\Enums\BusinessNameLookupError;
78

89
class BusinessNameFromVatID
910
{
10-
public static function lookup(string $vatID): string
11+
public static function lookup(string $vatID): object
1112
{
12-
$unknown = trans('laravel-rules::messages.vat-name-unknown');
13-
1413
if (blank($vatID)) {
15-
return $unknown;
14+
return BusinessNameLookupError::Unknown;
1615
}
1716

1817
try {
@@ -21,13 +20,11 @@ public static function lookup(string $vatID): string
2120

2221
$object = $calculator->getVATDetails($vatID);
2322

24-
return is_object($object) ? $object->name : $unknown;
23+
return is_object($object) ? $object : BusinessNameLookupError::Unknown;
2524

2625
} catch (VATCheckUnavailableException $e) {
2726
//if Country != GB, less verbose messages are returned.
28-
return ($message = $e->getMessage()) === "MS_UNAVAILABLE"
29-
? trans('laravel-rules::messages.vies-eu-unavailable')
30-
: $message;
27+
return BusinessNameLookupError::ServiceUnavailable;
3128
}
3229
}
3330
}

0 commit comments

Comments
 (0)