PHP code example of allekurier / api_v1
1. Go to this page and download the library: Download allekurier/api_v1 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/ */
allekurier / api_v1 example snippets
allekurier\api_v1\AutoLoader::init(__DIR__ . '/my_path');
$credentials = new allekurier\api_v1\Credentials('login', 'hasło');
$api = new allekurier\api_v1\AKAPI($credentials);
$order = new allekurier\api_v1\model\Order(
'nazwa usługi',
'typ opakowania',
'opis przesyłki',
'metoda odbioru',
'kwota pobrania',
'kwota ubezpieczenia',
'numer referencyjny',
'wartość towaru',
'voucher'
);
$sender = new allekurier\api_v1\model\Sender(
'nazwa nadawcy',
'osoba kontaktowa',
'kod pocztowy',
'adres',
'miasto',
'telefon',
'email',
'kod państwa',
'punkt przewoźnika',
'numer konta bankowego'
);
$recipient = new allekurier\api_v1\model\Recipient(
'nazwa odbiorcy',
'osoba kontaktowa',
'kod pocztowy',
'adres',
'miasto',
'telefon',
'email',
'kod państwa',
'punkt przewoźnika',
'kod stanu'
);
// Wymagany gdy Order - metoda odbioru = register
$pickup = new allekurier\api_v1\model\Pickup(
'data odbioru',
'od godz',
'do godz'
);
$packages = new allekurier\api_v1\model\Packages([
new allekurier\api_v1\model\Package('waga', 'szerokość', 'wysokość', 'długość', 'czy standardowa')
]);
$additionalServices = [
'sms',
'email_notif_delivered'
];
$action = new allekurier\api_v1\action\CreateOrderAction(
$order,
$sender,
$recipient,
$packages,
$pickup,
$additionalServices
);
$response = $api->call($action);
if ($response->hasErrors()) {
var_dump($response->getErrors());
} else {
echo $response->number();
echo $response->hid();
echo $response->cost();
echo $response->status();
}
$action = new allekurier\api_v1\action\GetOrderStatusAction('hid przesyłki');
$response = $api->call($action);
if ($response->hasErrors()) {
var_dump($response->getErrors());
} else {
echo $response->hid();
echo $response->number();
echo $response->traceNumber();
echo $response->created();
echo $response->sent();
echo $response->delivered();
echo $response->date();
echo $response->name();
echo $response->status();
}
$action = new allekurier\api_v1\action\GetOrderLabelAction(
'numer przesyłki',
'czy pobierać małe etykiety?' // true/false (parametr opcjonalny)
);
$response = $api->call($action);
if ($response->hasErrors()) {
var_dump($response->getErrors());
} else {
file_put_contents('my_path/label.pdf', $response->label());
}
$action = new allekurier\api_v1\action\GetOrderHistoryAction('numer przesyłki');
$response = $api->call($action);
if ($response->hasErrors()) {
var_dump($response->getErrors());
} else {
foreach ($response->history() as $event) {
echo $event->date();
echo $event->name();
echo $event->status();
}
}
$action = new allekurier\api_v1\action\CancelOrderAction('numer przesyłki');
$response = $api->call($action);
if ($response->hasErrors()) {
var_dump($response->getErrors());
} else {
if ($response->isCanceled()) {
echo 'Anulowane';
}
}
$order = allekurier\api_v1\model\Order::createForPricing(
'typ opakowania',
'kwota pobrania',
'kwota ubezpieczenia'
);
$sender = allekurier\api_v1\model\Sender::createForPricing(
'kod państwa',
'kod pocztowy tylko dla palet'
);
$recipient = allekurier\api_v1\model\Recipient::createForPricing(
'kod państwa',
'kod pocztowy tylko dla palet'
);
$packages = new allekurier\api_v1\model\Packages([
new allekurier\api_v1\model\Package('waga', 'szerokość', 'wysokość', 'długość', 'czy standardowa')
]);
$action = new allekurier\api_v1\action\GetServicesAction($order, $sender, $recipient, $packages);
$response = $api->call($action);
if ($response->hasErrors()) {
var_dump($response->getErrors());
} else {
foreach ($response->services() as $service) {
echo $service->carrierCode();
echo $service->carrierName();
echo $service->code();
echo $service->name();
echo $service->net();
echo $service->gross();
}
}
$action = new allekurier\api_v1\action\GetAdditionalServicesAction('nazwa uslugi', 'typ opakowania');
$response = $api->call($action);
if ($response->hasErrors()) {
var_dump($response->getErrors());
} else {
foreach ($response->services() as $service) {
echo $service->code();
echo $service->name();
echo $service->net();
}
}
$action = new allekurier\api_v1\action\GetPickupDatesAction('przewoźnik', 'kod pocztowy', 'kod państwa');
$response = $api->call($action);
if ($response->hasErrors()) {
var_dump($response->getErrors());
} else {
foreach ($response->dates() as $date) {
echo $date->date();
echo $date->description();
var_dump($date->from());
var_dump($date->to());
}
}
$action = new allekurier\api_v1\action\GetDropoffPointsAction('przewoźnik', 'kod pocztowy');
$response = $api->call($action);
if ($response->hasErrors()) {
var_dump($response->getErrors());
} else {
foreach ($response->points() as $point) {
echo $point->id();
echo $point->latitude();
echo $point->longitude();
echo $point->name();
echo $point->code();
echo $point->address();
echo $point->postalCode();
echo $point->image();
echo $point->openHours();
echo $point->isSupportCod();
}
}
$action = new allekurier\api_v1\action\GetUserBalanceAction;
$response = $api->call($action);
if ($response->hasErrors()) {
var_dump($response->getErrors());
} else {
echo $response->balance();
}
json
{
"Error":[],
"Response":{
"Coordinates":{
"longitude":"",
"latitude":""
},
"AccessPoints":[
{
"AccessPoints":{
"id":"",
"latitude":"",
"longitude":"",
"code":"",
"name":"",
"address":"",
"address2":null,
"postal_code":"",
"city":"",
"image_url":null,
"open_hours":null,
"cod":"0"
},
"0":{
"diff":""
}
},
...
]
}
}
json
{
"Error": [],
"Response": [
{
"User": {
"hid": "XXXXXX",
"balance": "0.00",
"free": "0.00"
}
}
]
}