PHP code example of hyraiq / abnlookup

1. Go to this page and download the library: Download hyraiq/abnlookup library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hyraiq / abnlookup example snippets


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

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

$abrGuid = '<insert your ABR GUID here>'

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

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

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

$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

$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);
}

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