Installation:
composer require cleverage/colissimo-bundle
Add to config/bundles.php:
CleverAge\ColissimoBundle\CleverAgeColissimoBundle::class => ['all' => true],
Configure:
Create config/packages/cleverage_colissimo.yaml with your Colissimo credentials:
clever_age_colissimo:
testModeEnabled: true # Set to false in production
auth:
contractNumber: 'YOUR_CONTRACT'
password: 'YOUR_PASSWORD'
First Use Case:
Inject PickupPointsService in a controller to fetch pickup points:
use CleverAge\ColissimoBundle\Service\PickupPointsService;
public function getPickupPoints(PickupPointsService $pickupPointsService): Response
{
$points = $pickupPointsService->getPickupPoints('75000', 'PARIS');
return $this->json($points);
}
Shipping Labels:
Use ShippingService to generate labels with pre-configured sender details:
$shippingService = $this->container->get(ShippingService::class);
$label = $shippingService->createLabel(
$recipientData,
$serviceType, // e.g., 'LX' for Colissimo Letter
$weight
);
Tracking Integration:
Fetch tracking status via TrackingService:
$trackingService = $this->container->get(TrackingService::class);
$status = $trackingService->getTrackingStatus('12345678901234567890');
Pickup Points for UX:
Cache pickup points by postal code (e.g., in a PickupPointRepository):
$points = $pickupPointsService->getPickupPoints($zipCode, $city);
$this->cache->set("pickup_points_{$zipCode}", $points, '1 hour');
PickupPoint entities to form fields for user selection:
$builder->add('pickupPoint', EntityType::class, [
'class' => PickupPoint::class,
'choice_label' => 'name',
]);
$dispatcher->addListener(ShippingEvents::LABEL_CREATED, function (LabelEvent $event) {
$this->mailer->send(new LabelGeneratedEmail($event->getLabel()));
});
testModeEnabled: true with hardcoded responses.Authentication:
401 Unauthorized if contractNumber/password are incorrect.config/packages/cleverage_colissimo.yaml and ensure no typos in credentials.Rate Limits:
try {
return $service->getPickupPoints($zipCode);
} catch (RateLimitException $e) {
sleep(2 ** $attempt++);
retry();
}
Test Mode:
testModeEnabled: true bypasses real API calls but returns mock data. Disable in production:
clever_age_colissimo:
testModeEnabled: false # Production!
Deprecated Services:
Enable API Logging:
Add to config/packages/cleverage_colissimo.yaml:
debug: true
Logs will appear in var/log/dev.log.
HTTP Client Errors:
Use HttpClientInterface to inspect raw responses:
$client = $this->container->get(HttpClientInterface::class);
$response = $client->send(new Request('GET', 'https://api.colissimo.fr/...'));
$this->logger->debug($response->getContent());
Custom Responses:
Extend CleverAge\ColissimoBundle\Service\AbstractService to modify API responses:
class CustomPickupPointsService extends AbstractService {
protected function transformResponse($response) {
return array_map(fn($point) => [
'id' => $point['id'],
'formatted' => $point['name'] . ' (' . $point['distance'] . 'm)'
], parent::transformResponse($response));
}
}
Register as a service in services.yaml:
CleverAge\ColissimoBundle\Service\PickupPointsService: '@custom_pickup_points_service'
Async Processing: Use Symfony Messenger to queue label generation:
$this->messageBus->dispatch(new GenerateLabelMessage($data));
Handle in a worker with ColissimoMessageHandler.
Webhooks:
Listen for Colissimo webhook events (e.g., tracking updates) by extending WebhookService:
$webhookService->on('tracking_update', function (TrackingEvent $event) {
$this->notifyUser($event->getTrackingNumber());
});
How can I help you explore Laravel packages today?