Auspost API Client Library for PHP
This library is a Guzzle-based client for integrating PHP applications with
Australia Post's web services., (*1)
Documentation on how to use this library can be found in the Postage
Assessment Calculation and Postcode Search and the
Delivery Choices specifications., (*2)
Table of Contents
Getting Started
Register to use Australia Post services
You will need to apply for an API key if you want to use the Postage Assessment
Calculator and Postcode Search services. Similarly, you
will also need to apply for permission to use the Delivery Choices service., (*3)
Minimum requirements
- PHP 5.3.10 compiled with the cURL extension
- cURL 7.22.0
Note: The library is likely to work with earlier versions of PHP and cURL,
but they have not been tested., (*4)
Install using Composer
-
Add fontis/auspost-api-php
as a Composer dependency in your project's composer.json
file:, (*5)
{
"require": {
"fontis/auspost-api-php": "*"
}
}
-
Download and install Composer into the repo:, (*6)
$ curl -sS https://getcomposer.org/installer | php
-
Install the library dependencies:, (*7)
$ php composer.phar install
-
Add the library to your PHP application:, (*8)
require_once 'vendor/autoload.php';
Install using Git
-
Clone this repo to an appropriate location:, (*9)
$ git clone https://github.com/fontis/auspost-api-php
-
Download and install Composer into the repo:, (*10)
$ cd auspost-api-php
$ curl -sS https://getcomposer.org/installer | php
-
Install the library dependencies:, (*11)
$ php composer.phar install
-
Add the library to your PHP application:, (*12)
require_once 'vendor/autoload.php';
Quick Example
Calculate domestic parcel postage cost
<?php
require 'vendor/autoload.php';
use Auspost\Common\Auspost;
use Auspost\Postage\Enum\ServiceCode;
// Instantiate a Postage Assessment Calculator service
$client = Auspost::factory('/path/to/config.php')->get('postage');
$result = $client->calculateDomesticParcelPostage(array(
'from_postcode' => 3000,
'to_postcode' => 3011,
'length' => 10,
'width' => 10,
'height' => 10,
'weight' => 10,
'service_code' => ServiceCode::AUS_PARCEL_REGULAR
));
Contributions
This project is open source. You are encouraged to fork and submit pull
requests., (*13)
Guidelines
Please ensure your code adheres to the following guidelines in order for your
pull request to be accepted., (*14)
-
Follow the PHP-FIG standards recommendations - This library is written
with adherence to the PSR-0, PSR-1 and PSR-2 standard recommendations.
-
Write unit tests - Any new functionality should include corresponding
tests.
-
Add the licence header to new files - We would appreciate having licence
headers been added to the top of new files.