RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.78% (6.81%*) • Investment PI: 5.49% (6.32%*)

Australian ABN, ACN, and Name Lookup With PHP

Australian ABN, ACN, and Name Lookup With PHP

Many of the Australian businesses we work with often have the need to lookup Australian Business Numbers (ABN) or Australian Company Numbers (ACN). We plan on writing a quick WordPress plugin in the next few weeks that'll integrate form validation and lookup functionality into a WordPress website, and we expect that we'll initially provide the plugin to our Mortgage Broker mailing list as a giveaway before building it into a more generic product for download on our website. The PHP functions provided in this article provides you with enough information to integrate the ABN/ACN number validation or lookup service on your own website.

If you're unfamiliar with our website mantra, we know that having resources and tools on your website will attract repeat visitation and increase the trust your visitors have in your online presence... and this is an area where the finance industry generally performs very poorly.

The entire ABN database may be downloaded from Data.gov.au at any time although the size makes it virtually unusable for most small-scale applications, and the frequency of updates means that there's always a portion of numbers that aren't available. However, Business.gov.au does provide an API that returns data in various formats via POST and GET requests. While JSON support is limited, it's the a JSON function we've provided below (our plugin uses the XML-style response since it supports more search options ).

To use the API you'll need to register for access. While it' said that your GUID (or Globally Unique Identifier) will be made available within five working days, we've found that it rarely takes more than a few hours.

Validating the Australian Business and Company Numbers

The method to validate the Aussie ABN and ACN is detailed below and can be used independently of our primary function. It's a necessary feature of our plugin to validate the supplied number server-side so as to avoid making an unnecessary request to the API.

Australian Company Number

The method for validating the ACN is detailed on the ASIC website . The PHP function returns either true or false.

1
<?php 
2
/*
3
 Validate Australian ACN Number
4
 https://www.beliefmedia.com.au/abn-acn-lookup
5
*/
6
 
7
function beliefmedia_valid_acn($acn) {
8
 
9
  $weights = array(8, 7, 6, 5, 4, 3, 2, 1, 0);
10
 
11
  /* Strip anything other than numbers */
12
  $acn = preg_replace('/[^0-9]/', '', $acn);
13
 
14
  /* Check string lenth is 9 characters */
15
  if (strlen($acn) != 9) return false;
16
 
17
  /* Add the products */
18
  $sum = 0; foreach (str_split($acn) as $key => $digit) {
19
    $sum += $digit * $weights[$key];
20
  }
21
 
22
  /* Get remainder */
23
  $remainder = $sum % 10;
24
 
25
  /* Remainder compliment */
26
  $complement = (string)(10 - $remainder);
27
 
28
  /* If complement is 10, set to 0 */
29
  if ($complement === "10") $complement = "0";
30
 
31
 return ($acn[8] === $complement) ? true : false;
32
}

Australian Business Number

The method for validating the ACN is detailed on the Business.gov.au webiste. The PHP function returns either true or false.

1
<?php 
2
/*
3
 Validate Australian ABN Number
4
 https://www.beliefmedia.com.au/abn-acn-lookup
5
*/
6
 
7
function beliefmedia_valid_abn($abn) {
8
 
9
  $weights = array(10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19);
10
 
11
  /* Strip anything other than numbers */
12
  $abn = preg_replace('/[^0-9]/', '', $abn);
13
 
14
  /* 11 characters */
15
  if (strlen($abn) != 11) return false;
16
 
17
  /* Subtract one from first digit */
18
  $abn[0] = ((int) $abn[0] - 1);
19
 
20
  /* Add the products */
21
  $sum = 0; foreach (str_split($abn) as $key => $digit) {
22
    $sum += ($digit * $weights[$key]);
23
  }
24
 
25
  if (($sum % 89) != 0) {
26
    return false;
27
  }
28
 
29
 return true;
30
}

PHP ABN/ACN Function

The JSON API we're using returns JSONP. To convert it back to naked JSON the following hacky function works (if you're planning on using the callback for cross-domain requests you obviously don't need it).

1
<?php 
2
/*
3
 Convert JSONP to Simple JSON
4
 https://www.beliefmedia.com.au/abn-acn-lookup
5
*/
6
 
7
function beliefmedia_jsonp_decode($jsonp, $assoc = true) {
8
  if ($jsonp[0] !== '[' && $jsonp[0] !== '{') {
9
    $jsonp = substr($jsonp, strpos($jsonp, '('));
10
  }
11
 
12
 return json_decode(trim($jsonp,'();'), $assoc);
13
}

To make the call to the API, we first determine if the request only includes numeric characters. If so, we strip white spaces and make either an ABN or ACN request based on length (9 digits for the ACN and 11 for an ABN). If neither condition is true or the number doesn't validate we'll return false. If the string contains permitted characters as detailed on the ASIC website we'll make a name search request. If no case is satisfied we'll return false.

1
<?php 
2
/*
3
 Australian ABN, ACN, and Name Lookup With PHP
4
 https://www.beliefmedia.com.au/abn-acn-lookup
5
*/
6
 
7
function beliefmedia_abn_lookup($abn, $results = '20', $guid = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx') {
8
 
9
  /* ABN or ACN */
10
  if (preg_match('#^[0-9\s?]+$#', $abn)) {
11
 
12
    /* Strip white space & get length */
13
    $abn = preg_replace('/\s+/', '', $abn);
14
    $abn_length = strlen($abn);
15
 
16
    switch ($abn_length) {
17
      case '9':
18
        if (beliefmedia_valid_abn($abn) === false) return false;
19
        $data = @file_get_contents('https://abr.business.gov.au/json/AcnDetails.aspx?acn=' . $abn . '&callback=callback&guid=' . $guid);
20
        $data = beliefmedia_jsonp_decode($data);
21
        return $data;
22
        break;
23
 
24
      case '11':
25
        if (beliefmedia_valid_acn($abn) === false) return false;
26
        $data = @file_get_contents('https://abr.business.gov.au/json/AbnDetails.aspx?abn=' . $abn . '&callback=callback&guid=' . $guid);
27
        $data = beliefmedia_jsonp_decode($data);
28
        return $data;
29
 
30
      default:
31
        return false;
32
    }
33
 
34
  /* Else it's a text search */
35
  } elseif (preg_match('#(a-Z0-9\!\?\#\$\&\'\%\(\)\*\?\-/\:\;\=@,.\s\{\|\})*#', $abn)) {
36
 
37
    $data = @file_get_contents('https://abr.business.gov.au/json/MatchingNames.aspx?name=' . str_replace(' ', '+', $abn) . '&maxResults=' . $results . '&guid=' . $guid);
38
    $data = beliefmedia_jsonp_decode($data);
39
    return $data;
40
 
41
  } else {
42
 
43
    return false;
44
 
45
  }
46
 
47
}

Usage

1
echo '
2
<pre>' . print_r(beliefmedia_abn_lookup($abn) , true) . '</pre>
3
 
4
';

The $abn is either the ABN, ACN, or search term. You'll need to close the pre tags to print the example array.

Note that the JSON API doesn't include pagination so it might be best to request a large number of results, cache the resulting array, and then chop it up page-by-page.

The Result

Searching the ABN for Coca-Cola (68 076 594 119) returns the following array:

1
Array
2
(
3
    [Abn] => 68076594119
4
    [AbnStatus] => Active
5
    [AddressDate] => 2014-09-16
6
    [AddressPostcode] => 2060
7
    [AddressState] => NSW
8
    [BusinessName] => Array
9
        (
10
            [0] => AMATIL X
11
            [1] => exchange for change recycling
12
            [2] => GRINDERS COFFEE HOUSE
13
            [3] => CAFE DIRECT
14
            [4] => GRINDERS COFFEE HOUSE
15
            [5] => GRINDERS COFFEE HOUSE
16
            [6] => CAFE DIRECT
17
            [7] => VENDING SOLUTIONS
18
            [8] => CAFE DIRECT
19
        )
20
 
21
    [EntityName] => COCA-COLA AMATIL (AUST) PTY LTD
22
    [EntityTypeCode] => PRV
23
    [EntityTypeName] => Australian Private Company
24
    [Gst] => 2000-07-01
25
    [Message] =>
26
)

An ACN for Qantas (009 661 901) will return the following array.

1
Array
2
(
3
    [Abn] => 009661901
4
    [AbnStatus] => Active
5
    [AddressDate] => 2014-09-19
6
    [AddressPostcode] => 2020
7
    [AddressState] => NSW
8
    [BusinessName] => Array
9
        (
10
            [0] => Qantas Store Australia
11
            [1] => Airlines for Australia and New Zealand
12
        )
13
 
14
    [EntityName] => QANTAS AIRWAYS LIMITED
15
    [EntityTypeCode] => PUB
16
    [EntityTypeName] => Australian Public Company
17
    [Gst] => 2000-07-01
18
    [Message] =>
19
)

A free-text name search for 'Virgin' returns the following (we've limited the number of results and removed some identifying data).

1
Array
2
(
3
    [Message] =>
4
    [Names] => Array
5
        (
6
            [0] => Array
7
                (
8
                    [Abn] => 266xxx83xx5
9
                    [AbnStatus] => 0000000001
10
                    [IsCurrent] => 1
11
                    [Name] => AU VIRGIN PTY LTD
12
                    [NameType] => Entity Name
13
                    [Postcode] => 3145
14
                    [Score] => 97
15
                    [State] => VIC
16
                )
17
 
18
                <snip>
19
 
20
            [4] => Array
21
                (
22
                    [Abn] => 232xxx15xx8
23
                    [AbnStatus] => 0000000002
24
                    [IsCurrent] => 1
25
                    [Name] => xxxxxxxxxxx VIRGIN
26
                    [NameType] => Trading Name
27
                    [Postcode] => 2250
28
                    [Score] => 97
29
                    [State] => NSW
30
                )
31
 
32
        )
33
 
34
)

Considerations

  • If you would like a copy of our plugin, ensure you subscribe to our mailing list (below). Our finance mailing list can expect a download link to the plug-and-play addition to their website within a couple of weeks.

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  Want to have a chat?
 

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment