How to upgrade Fontis Australia to the new Auspost API

Posted September 06th, 2016 in Computers
The Fontis Australia extension adds functionality to Magento stores running in Australia. This includes postage rates which are sourced from the Auspost API. Recently, Auspost changed the URL for their API which affects older versions of the extension. For those Magento installations which are running an older version of Fontis Australia, you will need to make changes to the extension in order to facilitate the new Auspost API (detailed at http://auspost.com.au/pdfs/pac-api-update-2016.pdf). Although this may seem a daunting task, it is quite simple when using the documentation provided by Fontis located at https://github.com/fontis/auspost-api-php/commit/d0c1f7a58a50c715f795eea1d067d5305b16f558

The obsolete Auspost API was located at https://auspost.com.au/api, and the new one is at https://digitalapi.auspost.com.au

To update the Fontis Australia Magento extension to use the new Auspost API, there are two files which need to be changed:
  1. app/code/community/Fontis/Australia/lib/vendor/fontis/auspost-api-php/src/Auspost/Postage/PostageClient.php
  2. app/code/community/Fontis/Australia/lib/vendor/fontis/auspost-api-php/src/Auspost/Postage/service.json


Changes to PostageClient.php

In the PostageClient.php file, before the line:

Change #1:

public static function factory($config = array()){

add the following:

const API_URL = 'https://digitalapi.auspost.com.au';

This line sets the API URL in one location, making it easier to change in the future.

Change #2:

Locate any instances of the following:

$baseUrl[$developerMode]
$config->get('base_url')

and change them to:

self::API_URL

This sets the API URL to the one that was specified in the first change.

Change #3:

Remove the following lines of code:

$baseUrl = array(
'https://auspost.com.au',
'https://test.npe.auspost.com.au'
);

// Ignore unnecessary user-specified configuration values
if ($developerMode) {
unset($config['auth_key']);
}

The test URL is no longer used as it does not resolve.


Changes to service.json

In the service.json file, remove the 'api/' from the start of each uri. For example, the following line:

"uri": "api/postcode/search",

becomes:

"uri": "postcode/search",

Once the above changes have been made, you may need to clear cache (Admin->System->Cache Management). To test if this worked, add an item to the shopping cart and verify that there are Australia Post shipping methods available, either through a postage estimate or on the checkout page.

 

Comments

No comments

Leave a comment