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(1y ago)9306.6k↓66.4%MITPHPPHP &gt;=8.2CI passing

Since Dec 8Pushed 1y agoCompare

[ Source](https://github.com/hyraiq/abnlookup)[ Packagist](https://packagist.org/packages/hyraiq/abnlookup)[ RSS](/packages/hyraiq-abnlookup/feed)WikiDiscussions main Synced 3d 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

46

—

FairBetter than 92% of packages

Maintenance46

Moderate activity, may be stable

Popularity39

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity70

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

407d 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

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[web-auth/webauthn-framework

FIDO2/Webauthn library for PHP and Symfony Bundle.

515100.5k3](/packages/web-auth-webauthn-framework)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M572](/packages/shopware-core)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k51.2M339](/packages/api-platform-core)[oro/platform

Business Application Platform (BAP)

645143.5k115](/packages/oro-platform)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M508](/packages/pimcore-pimcore)

PHPackages © 2026

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