- PHP >= 7.0
- ext-curl
- ext-json
Require the package via composer
composer require firewizard/fancourier-api
If used without composer, you will need to manually require the autoload.php
file
require_once '/path/to/fancourier-api/src/autoload.php';
Create a new instance of Fancourier.php
supplying the client_id
, username
and password
.
$clientId = 'your_client_id';
$username = 'your_username';
$password = 'your_password';
$fan = new Fancourier\Fancourier($clientId, $username, $password);
Or you can use the test instance static method:
$fan = Fancourier\Fancourier::testInstance();
Request
$request = new Fancourier\Request\GetRates();
$request
->setParcels(1)
->setWeight(2)
->setRegion('Arad')
->setCity('Aciuta')
->setDeclaredValue(125);
Response
$response = $fan->getRates($request);
if ($response->isOk()) {
var_dump($response->getBody());
} else {
var_dump($response->getErrorMessage());
}
Request
$request = new Fancourier\Request\CreateAwb();
$request
->setParcels(1)
->setWeight(2)
->setReimbursement(125)
->setDeclaredValue(125)
->setNotes('testing notes')
->setContents('SKU-1, SKU-2')
->setRecipient("John Ivy")
->setPhone('0723000000')
->setRegion('Arad')
->setCity('Aciuta')
->setStreet('Str Lunga nr 1');
Response
$response = $fan->createAwb($request);
if ($response->isOk()) {
var_dump($response->getBody());
} else {
var_dump($response->getErrorMessage());
}
Request
$batchRequest = new Fancourier\Request\CreateAwbBulk();
$request = new Fancourier\Request\CreateAwb();
$request
->setParcels(1)
->setWeight(2)
->setReimbursement(125)
->setDeclaredValue(125)
->setNotes('testing notes')
->setContents('SKU-1, SKU-2')
->setRecipient("John Ivy")
->setPhone('0723000000')
->setRegion('Arad')
->setCity('Aciuta')
->setStreet('Str Lunga nr 1')
;
$batchRequest->append($request);
$request
->setParcels(1)
->setWeight(1.5)
->setReimbursement(50)
->setDeclaredValue(50)
->setContents('SKU-7')
->setRecipient("Tester Testerson")
->setPhone('0722111000')
->setRegion('Sibiu')
->setCity('Sibiu')
->setStreet('Calea Bucuresti nr 1')
;
$batchRequest->append($request);
$response = $fan->createAwbBulk($batchRequest);
if (!$response->isOk()) {
//general error
die($response->getErrorMessage());
}
foreach ($response->getBody() as $lineResponse) {
/** @var CreateAwb $lineResponse */
if ($lineResponse->isOk()) {
echo $lineResponse->getBody() . "\n";
} else {
echo $lineResponse->getErrorMessage() . "\n";
}
}
Request
$request = new Fancourier\Request\TrackAwb();
$request
->setAwb('2150900120086')
->setDisplayMode(Fancourier\Request\TrackAwb::MODE_LAST_STATUS);
Response
$response = $fan->trackAwb($request);
if ($response->isOk()) {
var_dump($response->getBody());
} else {
var_dump($response->getErrorMessage());
}
Request
$request = new Fancourier\Request\PrintAwb();
$request->setAwb('2150900120086');
Response
$response = $fan->printAwb($request);
if ($response->isOk()) {
echo $response->getBody();
} else {
var_dump($response->getErrorMessage());
}
Request
$request = new Fancourier\Request\PrintAwbHtml();
$request->setAwb('2150900120086');
Response
$response = $fan->printAwbHtml($request);
if ($response->isOk()) {
echo $response->getBody();
} else {
var_dump($response->getErrorMessage());
}
Request
$request = new Fancourier\Request\DeleteAwb();
$request->setAwb('2150900120086');
Response
$response = $fan->deleteAwb($request);
if ($response->isOk()) {
var_dump($response->getBody());
} else {
var_dump($response->getErrorMessage());
}
Request
$request = new Fancourier\Request\TrackAwbBulk();
$request->setAwbs(['2162900120047']);
Response
$response = $fan->trackAwbBulk($request);
if ($response->isOk()) {
print_r($response->getBody());
} else {
var_dump("ERROR: " . $response->getErrorMessage());
}
Request - There's no request for this method
Response - will return an array of cities (and other info)
$response = $fan->getCities();
if ($response->isOk()) {
print_r($response->getBody());
} else {
var_dump("ERROR: " . $response->getErrorMessage());
}
Thank you for considering contributing to the Fancourier Api!
Fancourier Api is open-source software licensed under the MIT license.