Install the package:
composer require answear/acs-bundle
Symfony Flex auto-registers the bundle in config/bundles.php.
Configure credentials in config/packages/answear_acs.yaml:
answear_gls:
apiKey: "your_api_key"
companyId: "your_company_id"
companyPassword: "your_company_password"
userId: "your_user_id"
userPassword: "your_user_password"
language: "GR" # Default (Greece)
First use case: Fetch parcel shops for Greece (default country):
use Answear\AcsBundle\Service\ParcelShopsService;
use Answear\AcsBundle\Enum\CountryIdEnum;
$parcelShopService = $this->container->get(ParcelShopsService::class);
$shops = $parcelShopService->getList(CountryIdEnum::GREECE);
ParcelShopsService: Core service for fetching parcel shops.CountryIdEnum: Enumeration for supported countries (e.g., GREECE, CYPRUS).ParcelShop DTO: Response object containing shop details (ID, address, etc.).Fetching Parcel Shops by Country:
// All shops in Greece
$shops = $parcelShopService->getList(CountryIdEnum::GREECE);
// Only convenience shops (kind=1)
$shops = $parcelShopService->getList(CountryIdEnum::GREECE, 1);
Integration with Laravel:
AppServiceProvider:
$this->app->bind(ParcelShopsService::class, function ($app) {
return new ParcelShopsService(
$app->get('answear_acs.client'),
$app->get('answear_acs.serializer')
);
});
ParcelShopsService into controllers/services:
public function __construct(private ParcelShopsService $parcelShopService) {}
Caching Responses (Recommended for Performance):
use Symfony\Component\Cache\Adapter\AdapterInterface;
public function getList(CountryIdEnum $countryId, ?int $kind = null): array
{
$cacheKey = "acs_shops_{$countryId->value}_{$kind}";
if ($cache = $this->cache->get($cacheKey)) {
return $cache;
}
$shops = parent::getList($countryId, $kind);
$this->cache->set($cacheKey, $shops, 3600); // Cache for 1 hour
return $shops;
}
Handling Pagination (If ACS API supports it):
// Extend the service to support pagination tokens
public function getListWithPagination(CountryIdEnum $countryId, ?int $kind = null, ?string $token = null): array
{
$response = $this->client->request('GET', '/shops', [
'query' => [
'country' => $countryId->value,
'kind' => $kind,
'token' => $token,
],
]);
// Parse response and return shops + next token
}
Configuration Errors:
apiKey, companyId, etc.) will throw GuzzleException.config/packages/answear_acs.yaml before use.Country/Kind Validation:
CountryIdEnum only supports GREECE and CYPRUS. Passing unsupported values throws InvalidArgumentException.CountryIdEnum::from() or validate input:
if (!CountryIdEnum::tryFrom($countryId)) {
throw new \InvalidArgumentException("Unsupported country: {$countryId}");
}
Rate Limiting:
ServiceUnavailable exceptions gracefully:
try {
$shops = $parcelShopService->getList(CountryIdEnum::GREECE);
} catch (ServiceUnavailable $e) {
// Retry logic or notify admin
$this->logger->error("ACS API unavailable: {$e->getMessage()}");
}
Response Parsing:
MalformedResponse.$response = $this->client->request('GET', '/shops');
$this->logger->debug("Raw ACS response: {$response->getBody()}");
Testing:
ParcelShopsService in PHPUnit:
$mockService = $this->createMock(ParcelShopsService::class);
$mockService->method('getList')
->willReturn([new ParcelShop(/* ... */)]);
$this->app->instance(ParcelShopsService::class, $mockService);
Extending Functionality:
// src/Service/CustomAcsService.php
class CustomAcsService extends ParcelShopsService
{
public function getShopDetails(int $shopId): array
{
$response = $this->client->request('GET', "/shops/{$shopId}");
return $this->serializer->deserialize($response->getBody(), ParcelShop::class, 'json');
}
}
Logging:
# config/packages/answear_acs.yaml
answear_gls:
debug: true # Adds logging middleware
PHP Version Compatibility:
Error Handling:
try {
$shops = $parcelShopService->getList(CountryIdEnum::GREECE);
} catch (MalformedResponse $e) {
// Handle parsing errors
} catch (ServiceUnavailable $e) {
// Handle API downtime
}
How can I help you explore Laravel packages today?