PHP code example of omnibus / canpar

1. Go to this page and download the library: Download omnibus/canpar 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/ */

    

omnibus / canpar example snippets




mnibus\Canpar\CanparGatewayFactory;
use Omnibus\Testing\RecordedHttpClient;

// Canpar's answer, recorded: no account, and nothing leaves the process.
$http = new RecordedHttpClient([
    'body:trackByBarcode' => '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:trackByBarcodeResponse xmlns:ns="http://ws.business.canshipws.canpar.com">'
        .'<ns:return xmlns:ax="http://dto.canshipws.canpar.com"><ax:result><ax:barcode>D420000000012345</ax:barcode><ax:delivered_date_time>2026-10-02T10:15:00</ax:delivered_date_time>'
        .'<ax:events><ax:code>DEL</ax:code><ax:code_description_en>Delivered</ax:code_description_en><ax:local_date_time>2026-10-02T10:15:00</ax:local_date_time>'
        .'<ax:address><ax:city>TORONTO</ax:city><ax:province>ON</ax:province></ax:address></ax:events></ax:result></ns:return></ns:trackByBarcodeResponse></soapenv:Body></soapenv:Envelope>',
]);
$gateway = (new CanparGatewayFactory($http))->create(['user_id' => '[email protected]', 'password' => 'pass', 'shipper_number' => '99999999', 'sandbox' => true]);

$tracking = $gateway->track('D420000000012345');
echo $tracking->status->value, ' - ', $tracking->latest()?->description, "\n";   // delivered - Delivered

$gateway = (new CanparGatewayFactory($http))->create($options);   // $http: the application's HTTP client - none given, the factory makes its own; the options below