PHPackages                             hyraiq/abnlookup - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. hyraiq/abnlookup

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

hyraiq/abnlookup
================

ABN validation and verification using the ABR web services API

2.0.0(12mo ago)9291.0k↓19.2%MITPHPPHP &gt;=8.2CI passing

Since Dec 8Pushed 12mo agoCompare

[ Source](https://github.com/hyraiq/abnlookup)[ Packagist](https://packagist.org/packages/hyraiq/abnlookup)[ RSS](/packages/hyraiq-abnlookup/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (20)Versions (13)Used By (0)

hyraiq/abnlookup
================

[](#hyraiqabnlookup)

A PHP SDK to validate Australian Business Numbers (ABNs) and verify them with the [Australian Business Register Web Services API](https://abr.business.gov.au/Tools/WebServices). The difference between validation and verification can be outlined as follows:

- Validation uses the official checksum calculation to check that a given number is a valid ABN. This *does not* contact the ABR to ensure that the given ABN is assigned to a business
- Verification contact the ABR through their API to retrieve information registered against the ABN. It will tell you if the ABN actually belongs to a business.

In order to use the API (only necessary for verification), you'll need to [register an account](https://abr.business.gov.au/Tools/WebServices) to receive a GUID which is used as an API key. Once you register you can play with the API using the [official demo](https://abr.business.gov.au/json/)(note that this SDK uses the JSON services instead of XML).

Type safety
-----------

[](#type-safety)

The SDK utilises the [Symfony Serializer](https://symfony.com/doc/current/components/serializer.html) and the [Symfony Validator](https://symfony.com/doc/current/components/validator.html) to deserialize and validate data returned from the ABR API in order to provide valid [AbnResponse](./src/Model/AbnResponse.php) and [NamesResponse](./src/Model/NamesResponse.php) models. This means that if you receive a response from the SDK, it is guaranteed to be valid.

Invalid responses from the ABR fall into three categories, which are handled with exceptions:

- `AbrConnectionException`: Unable to connect to the ABR, or the ABR returned an unexpected response
- `InvalidAbnException`: The ABN is invalid (ie. validation failed)
- `AbnNotFoundException`: The ABN is valid, however it is not assigned to a business (ie. verification failed)

Usage
-----

[](#usage)

### Installation

[](#installation)

```
$ composer require hyraiq/abnlookup
```

### Configuration with Symfony

[](#configuration-with-symfony)

In `services.yaml`, you need to pass you ABR GUID to the `AbnClient` and register the `AbnClient` with the `AbnClientInterface`:

```
Hyra\AbnLookup\AbnClientInterface: '@Hyra\AbnLookup\AbnClient'
Hyra\AbnLookup\AbnClient:
    arguments:
        $abnLookupGuid: "%env(ABN_LOOKUP_GUID)%"
```

You can then inject the `AbnClientInterface` directly into your controllers/services.

```
class VerifyAbnController extends AbtractController
{
    public function __construct(
        private AbnClientInterface $abnClient,
    ) {
    }

    // ...
}
```

### Configuration outside of Symfony

[](#configuration-outside-of-symfony)

If you're not using Symfony, you'll need to instantiate the ABN client yourself, which can be registered in your service container or just used directly. We have provided some helpers in the `Dependencies` class in order to create the Symfony Serializer and Validator with minimal options.

```
use Hyra\AbnLookup\Dependencies;
use Hyra\AbnLookup\AbnClient;

$abrGuid = ''

// Whichever http client you choose
$httpClient = new HttpClient();

$denormalizer = Dependencies::serializer();
$validator = Dependencies::validator();

$abnClient = new AbnClient($denormalizer, $validator, $httpClient, $abrGuid);
```

### Looking up an ABN

[](#looking-up-an-abn)

Once you have configured your `AbnClient` you can lookup an individual ABN. Note, this will validate the ABN before calling the API in order to prevent unnecessary API requests.

```
$abn = '12620650553';

try {
    $abnResponse = $abnClient->lookupAbn($abn);
} catch (AbrConnectionException $e) {
    die($e->getMessage())
} catch (InvalidAbnException) {
    die('Invalid ABN');
} catch (AbnNotFoundException) {
    die('ABN not found');
}

echo $abnResponse->abn; // 12620650553
echo $abnResponse->entityName; // Blenktech PTY LTD
echo $abnResponse->status; // Active
```

### Searching by name

[](#searching-by-name)

You can also search the ABR by name, to receive a list of registered businesses that match the search term:

```
$namesResponse = $abnClient->lookupName('Hyra iQ');

echo \sprintf('Received %d results', \count($namesResponse->names));
foreach ($namesResponse->names as $name) {
    echo \sprintf('%s: %s', $name->abn, $name->name);
}
```

Testing
-------

[](#testing)

In automated tests, you can replace the `AbnClient` with the `StubAbnClient` in order to mock responses from the ABR. There is also the `AbnFaker` which you can use during tests to get both valid and invalid ABNs.

```
use Hyra\AbnLookup\Stubs\AbnFaker;
use Hyra\AbnLookup\Stubs\StubAbnClient;

$stubClient = new StubAbnClient();

$stubClient->lookupAbn(AbnFaker::invalidAbn()); // InvalidAbnException - Note, the stub still uses the validator

$stubClient->lookupAbn(AbnFaker::validAbn()); // LogicException - You need to tell the stub how to respond to specific queries

$abn = AbnFaker::validAbn();
$stubClient->addNotFoundAbns($abn);
$stubClient->lookupAbn($abn); // AbnNotFoundException

$abn = AbnFaker::validAbn();
$mockResponse = new AbnResponse();
$response->abn = $abn;
$response->abnStatus = 'active';
$response->abnStatusEffectiveFrom = new \DateTimeImmutable('2 years ago');
$response->entityTypeCode = 'PRV';
$response->entityTypeName = 'Australian Private Company';

$stubClient->addMockResponse($mockResponse);
$abnResponse = $stubClient->lookupAbn($abn); // $abnResponse === $mockResponse
```

Contributing
------------

[](#contributing)

All contributions are welcome! You'll need [docker](https://docs.docker.com/engine/install/) installed in order to run tests and CI processes locally. These will also be run against your pull request with any failures added as GitHub annotations in the Files view.

```
# First build the required docker container
$ docker compose build

# Then you can install composer dependencies
$ docker compose run php make vendor

# Now you can run tests and other tools
$ docker compose run php make (fix|psalm|phpstan|phpunit)
```

In order for you PR to be accepted, it will need to be covered by tests and be accepted by:

- [php-cs-fixer](https://github.com/FriendsOfPhp/PHP-CS-Fixer)
- [psalm](https://github.com/vimeo/psalm/)
- [phpstan](https://github.com/phpstan/phpstan)

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance50

Moderate activity, may be stable

Popularity40

Moderate usage in the ecosystem

Community12

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 52.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~126 days

Recently: every ~172 days

Total

11

Last Release

361d ago

Major Versions

1.3.4 → 2.0.0-beta12025-05-22

PHP version history (2 changes)1.0.0PHP &gt;=8.0

2.0.0-beta1PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/3cfed44ee6ac4e4cec6e652326847c4f71d5acc5bd535c7e6fecde526846a5d9?d=identicon)[procurepro](/maintainers/procurepro)

---

Top Contributors

[![ndench](https://avatars.githubusercontent.com/u/2062388?v=4)](https://github.com/ndench "ndench (10 commits)")[![kielabokkie](https://avatars.githubusercontent.com/u/1221750?v=4)](https://github.com/kielabokkie "kielabokkie (4 commits)")[![tomtomau](https://avatars.githubusercontent.com/u/2062363?v=4)](https://github.com/tomtomau "tomtomau (2 commits)")[![cborgas](https://avatars.githubusercontent.com/u/27918855?v=4)](https://github.com/cborgas "cborgas (1 commits)")[![pm0](https://avatars.githubusercontent.com/u/3173150?v=4)](https://github.com/pm0 "pm0 (1 commits)")[![shruvaradarajan-dev](https://avatars.githubusercontent.com/u/190482719?v=4)](https://github.com/shruvaradarajan-dev "shruvaradarajan-dev (1 commits)")

---

Tags

abnabrsdk-php

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hyraiq-abnlookup/health.svg)

```
[![Health](https://phpackages.com/badges/hyraiq-abnlookup/health.svg)](https://phpackages.com/packages/hyraiq-abnlookup)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[web-auth/webauthn-framework

FIDO2/Webauthn library for PHP and Symfony Bundle.

50570.7k1](/packages/web-auth-webauthn-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
