1. Go to this page and download the library: Download vesselind/econt-integration 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/ */
vesselind / econt-integration example snippets
declare(strict_types=1);
use Econt\EcontApi\EcontClient;
use Econt\EcontApi\EcontConfiguration;
use Econt\EcontApi\Http\SymfonyHttpAdapter;
use Symfony\Component\HttpClient\HttpClient;
// 1. Configure — use the factory for the demo/test endpoint (credentials pre-filled)
$config = EcontConfiguration::forDemo();
// Or with explicit credentials for production
$config = new EcontConfiguration(
username: 'your-username',
password: 'your-password',
baseUrl: EcontConfiguration::PRODUCTION_URL,
timeout: 30,
language: 'bg' // 'bg' or 'en'
);
// 2. Create adapter + client
$adapter = new SymfonyHttpAdapter(HttpClient::create());
$client = new EcontClient($config, $adapter);
// 3. Start querying
$countries = $client->address()->getCountries();
foreach ($countries as $country) {
echo $country->nameEn . PHP_EOL;
}
use Econt\EcontApi\Http\Psr18HttpAdapter;
use Nyholm\Psr7\Factory\Psr17Factory;
use Symfony\Component\HttpClient\Psr18Client;
$psr17Factory = new Psr17Factory();
$adapter = new Psr18HttpAdapter(new Psr18Client(), $psr17Factory, $psr17Factory);
$client = new EcontClient($config, $adapter);
$addressService = $client->address();
// Countries
$countries = $addressService->getCountries(); // CountryCollection
// Cities for a country
$cities = $addressService->getCities('BGR'); // CityCollection
// Streets for a city (cityID from City model)
$streets = $addressService->getStreets(41); // StreetCollection
// Quarters for a city
$quarters = $addressService->getQuarters(41); // QuarterCollection
// Validate an address
use Econt\EcontApi\Model\Location\Address;
use Econt\EcontApi\Model\Location\City;
use Econt\EcontApi\Model\Location\Country;
$address = new Address(
city: City::create(
country: Country::bulgaria(),
postCode: '7000',
name: 'Русе',
nameEn: 'Ruse',
),
street: 'Славянска',
num: '16',
);
$validated = $addressService->validateAddress($address);
echo $validated->validationStatus; // "normal" | "processed" | "invalid"
$officeService = $client->office();
// All offices / Econtomats in Bulgaria
$offices = $officeService->getOffices(countryCode: 'BGR');
// Offices in a specific city
$offices = $officeService->getOffices(countryCode: 'BGR', cityId: 41);
// Filter only physical offices (exclude Econtomat/APS machines)
$regularOffices = array_filter(
iterator_to_array($offices),
fn($o) => !$o->isAPS
);
use Econt\EcontApi\Enum\TariffSubCode;
$label = new ShippingLabel(
senderClient: new ClientProfile(name: 'Иван Иванов', phones: ['0888888888']),
receiverClient: new ClientProfile(name: 'Богдан Богданов', phones: ['0878787878']),
packCount: 1,
shipmentType: ShipmentType::PACK,
weight: 2.5,
senderAddress: $senderAddress, // sender's door address
receiverOfficeCode: '1127', // Office::getCode() from getOffices()
tariffSubCode: TariffSubCode::DOOR_OFFICE,
shipmentDescription: 'Книги',
);
$result = $client->shipment()->createLabel($label);
$label = new ShippingLabel(
senderClient: new ClientProfile(name: 'Иван Иванов', phones: ['0888888888']),
receiverClient: new ClientProfile(name: 'Богдан Богданов', phones: ['0878787878']),
packCount: 1,
shipmentType: ShipmentType::PACK,
weight: 2.5,
senderOfficeCode: '1034', // sender drops off at this office
receiverOfficeCode: '1127', // receiver picks up at this office
tariffSubCode: TariffSubCode::OFFICE_OFFICE,
shipmentDescription: 'Книги',
);
use Econt\EcontApi\Exception\EcontException;
use Econt\EcontApi\Exception\EcontApiException;
use Econt\EcontApi\Exception\EcontNetworkException;
use Econt\EcontApi\Exception\EcontValidationException;
try {
$offices = $client->office()->getOffices('BGR', 41);
} catch (EcontValidationException $e) {
// Invalid input before any HTTP call is made
echo implode(', ', $e->getViolations());
} catch (EcontApiException $e) {
// API returned an error response
echo $e->getApiErrorCode() . ': ' . $e->getApiErrorMessage();
} catch (EcontNetworkException $e) {
// HTTP transport failure
echo 'Network error: ' . $e->getMessage();
} catch (EcontException $e) {
// Base catch-all for all library exceptions
}
// Factory method for the demo/test endpoint (official demo credentials pre-filled)
$config = EcontConfiguration::forDemo();
// Override language or timeout while still targeting demo
$config = EcontConfiguration::forDemo(language: 'bg', timeout: 10);
// Full constructor for production
$config = new EcontConfiguration(
username: 'your-username',
password: 'your-password',
baseUrl: EcontConfiguration::PRODUCTION_URL,
timeout: 30,
language: 'bg' // 'bg' (Bulgarian) or 'en' (English)
);