A framework agnostic php package to use the Skynet Courier API.
Require the package using composer:
composer require claassenmarius/php-skynet
Create an instance of Claassenmarius\PhpSkynet\Skynet
, passing in your skynet username,
password, account number and system id.
use Claassenmarius\PhpSkynet\Skynet;
$skynet = new Skynet(
'skynet_username',
'skynet_password',
'skynet_system_id',
'skynet_account_number'
);
The following methods are available to get a security token, validate a suburb/postcode combination, get a list of postal
codes for a suburb, get a quote for a parcel, get an ETA between two locations, generate a waybill, obtain a POD image and
track a waybill. Each method returns a new Claassenmarius\PhpSkynet\Response
which
exposes methods to inspect the response.
$response = $skynet->securityToken();
$response = $skynet->validateSuburbAndPostalCode([
'suburb' => 'Brackenfell',
'postal-code' => '7560'
]);
$response = $skynet->postalCodesFromSuburb('Brackenfell');
$response = $skynet->quote([
'collect-city' => 'Brackenfell',
'deliver-city' => 'Stellenbosch',
'deliver-postcode' => '7600',
'service-type' => 'ON1',
'insurance-type' => '1',
'parcel-insurance' => '0',
'parcel-length' => 10, //cm
'parcel-width' => 20, // cm
'parcel-height' => 30, //cm
'parcel-weight' => 20 //kg
]);
$response = $skynet->deliveryETA([
'from-suburb' => 'Brackenfell',
'from-postcode' => '7560',
'to-suburb' => 'Stellenbosch',
'to-postcode' => '7600',
'service-type' => 'ON1'
]);
$response = $skynet->createWaybill([
"customer-reference" => "Customer Reference",
"GenerateWaybillNumber" => true,
"service-type" => "ON1",
"collection-date" => "2021-06-26",
"from-address-1" => "3 Janie Street, Ferndale, Brackenfell",
"from-suburb" => "Brackenfell",
"from-postcode" => "7560",
"to-address-1" => "15 Verreweide Street, Universiteitsoord, Stellenbosch",
"to-suburb" => "Stellenbosch",
"to-postcode" => "7600",
"insurance-type" => "1",
"insurance-amount" => "0",
"security" => "N",
"parcel-number" => "1",
"parcel-length" => 10,
"parcel-width" => 20,
"parcel-height" => 30,
"parcel-weight" => 10,
"parcel-reference" => "12345",
"offsite-collection" => true
]);
$response = $skynet->waybillPOD('your-waybill-number');
$response = $skynet->trackWaybill('your-waybill-number');
Claassenmarius\PhpSkynet\Response
provides the following methods to inspect the response.
$securityToken = $response->body();
// "{"SecurityToken":"2_f77e4922-1407-485e-a0fa-4fdd5c29e9ca"}"
$securityToken = $response->json();
// ["SecurityToken" => "2_c767aa41-bca8-4084-82a0-69d8e27fba2c"]
$securityToken = $response->object();
// { +"SecurityToken": "2_c767aa41-bca8-4084-82a0-69d8e27fba2c" }
$header = $response->header('Content-Type');
// "application/json; charset=utf-8"
$headers = $response->headers();
// Return an array of all headers
$headers = $response->status();
// 200
$headers = $response->successful();
// true
$headers = $response->ok();
// true
$headers = $response->serverError();
// false
$headers = $response->failed();
// false
This package uses the Guzzle PHP HTTP client behind the scenes to send requests.
- In the event of a networking error (connection timeout, DNS errors, etc.), a GuzzleHttp\Exception\RequestException
is thrown. This exception extends from
GuzzleHttp\Exception\TransferException`. Catching this exception will catch any exception that can be thrown while transferring requests.
use GuzzleHttp\Psr7;
use GuzzleHttp\Exception\RequestException;
try {
$response = $skynet->securityToken();
} catch(RequestException $e) {
// Handle the exception
}
- A
GuzzleHttp\Exception\ConnectException
exception is thrown in the event of a networking error. This exception extends fromGuzzleHttp\Exception\TransferException
. - A
GuzzleHttp\Exception\ClientException
is thrown for 400 level errors if the http_errors request option is set to true. This exception extends fromGuzzleHttp\Exception\BadResponseException
andGuzzleHttp\Exception\BadResponseException
extends fromGuzzleHttp\Exception\RequestException
.
use GuzzleHttp\Psr7;
use GuzzleHttp\Exception\ClientException;
try {
$response = $skynet->securityToken();
} catch(ClientException $e) {
// Handle the exception
}
- A
GuzzleHttp\Exception\ServerException
is thrown for 500 level errors if the http_errors request option is set to true. This exception extends fromGuzzleHttp\Exception\BadResponseException
.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT Licence (MIT). Please see Licence File for more information.