answear/inpost-pickup-point-bundle
Installation:
composer require answear/inpost-pickup-point-bundle
Note: In Laravel, manually add to config/app.php under providers:
Answear\InpostBundle\AnswearInpostBundle::class,
Configuration:
Add Inpost API credentials to .env:
INPOST_API_KEY=your_api_key
INPOST_BASE_URI=https://api.inpost.pl/shipx/v1
First Use Case: Search for pickup points by postcode in a Laravel controller:
use Answear\InpostBundle\Request\FindPointsRequestBuilder;
use Answear\InpostBundle\Command\FindPoints;
public function findPickupPoints(Request $request)
{
$requestBuilder = new FindPointsRequestBuilder();
$requestBuilder->setPostCode($request->postcode);
$findPointsCommand = app(FindPoints::class);
$response = $findPointsCommand->findPoints($requestBuilder->build());
return response()->json($response->getPoints());
}
Where to Look First:
FindPointsRequestBuilder for filtering (e.g., setPostCode, setType).FindPointsResponse for parsing results (e.g., getPoints(), getTotalItemsCount()).FindPointsRequestBuilder with setPostCode().// In a Livewire component
public function searchPickupPoints($postcode)
{
$request = (new FindPointsRequestBuilder())
->setPostCode($postcode)
->setPerPage(10)
->build();
$response = app(FindPoints::class)->findPoints($request);
cache()->put("inpost_points_{$postcode}", $response, now()->addHour());
return $response->getPoints();
}
setPostCodes(array) and setPage() for pagination.public function fetchBulkPickupPoints(array $postcodes)
{
$points = [];
foreach ($postcodes as $postcode) {
$request = (new FindPointsRequestBuilder())
->setPostCodes([$postcode])
->setPerPage(50)
->build();
$response = app(FindPoints::class)->findPoints($request);
$points[$postcode] = $response->getPoints();
}
return $points;
}
// app/Console/Commands/FetchInpostPoints.php
use Illuminate\Console\Command;
use Answear\InpostBundle\Request\FindPointsRequestBuilder;
use Answear\InpostBundle\Command\FindPoints;
class FetchInpostPoints extends Command
{
protected $signature = 'inpost:fetch {--postcode=*}';
protected $description = 'Fetch and cache Inpost pickup points';
public function handle()
{
$postcodes = $this->option('postcode') ?: ['00-001', '00-999'];
foreach ($postcodes as $postcode) {
$request = (new FindPointsRequestBuilder())
->setPostCode($postcode)
->build();
$response = app(FindPoints::class)->findPoints($request);
cache()->forever("inpost_{$postcode}", $response);
$this->info("Cached {$postcode}: " . count($response->getPoints()) . " points");
}
}
}
Run with:
php artisan inpost:fetch --postcode=02-123 --postcode=01-234
Illuminate\Cache\Events\KeyGenerated to invalidate cached pickup points when postcode data changes (e.g., via a webhook).// In EventServiceProvider
protected $listen = [
'Illuminate\Cache\Events\KeyGenerated' => [
'App\Listeners\InvalidateInpostCache',
],
];
Laravel Service Container:
Bind the Symfony command to Laravel’s container in AppServiceProvider:
public function register()
{
$this->app->bind(
Answear\InpostBundle\Command\FindPoints::class,
function ($app) {
return new Answear\InpostBundle\Command\FindPoints(
$app->make(Answear\InpostBundle\Client\InpostClient::class)
);
}
);
}
API Client Customization: Extend the Guzzle client for Laravel-specific needs (e.g., middleware for logging):
// config/inpost.php
'client' => [
'timeout' => 30,
'headers' => [
'Accept' => 'application/json',
'User-Agent' => 'Laravel-Inpost-Integration/1.0',
],
'middleware' => [
\App\Http\Middleware\LogInpostRequests::class,
],
],
Response Wrapping: Create a Laravel-friendly response DTO:
namespace App\DTO;
class InpostPickupPoint
{
public function __construct(
public string $id,
public string $name,
public string $address,
public string $postCode,
public string $city,
public float $distance,
) {}
}
Transform the bundle’s response:
$points = collect($response->getPoints())->map(function ($point) {
return new InpostPickupPoint(
$point['id'],
$point['name'],
$point['address']['street'],
$point['address']['postCode'],
$point['address']['city'],
$point['distance'] ?? 0,
);
});
Testing:
Mock the FindPoints command in Laravel tests:
use Answear\InpostBundle\Command\FindPoints;
use Answear\InpostBundle\Request\FindPointsRequest;
use Answear\InpostBundle\Response\FindPointsResponse;
$mockResponse = new FindPointsResponse([], 10);
$mockCommand = Mockery::mock(FindPoints::class);
$mockCommand->shouldReceive('findPoints')
->withArgs(function (FindPointsRequest $request) {
return $request->getPostCode() === '00-001';
})
->andReturn($mockResponse);
$this->app->instance(FindPoints::class, $mockCommand);
Symfony Dependency Conflicts:
PropertyInfo and Serializer. If your Laravel app uses these components elsewhere (e.g., API Platform), conflicts may arise.symfony/property-info, symfony/serializer) or use Laravel’s native alternatives (e.g., spatie/laravel-array-to-object).PHP 8.4+ Requirement:
laravel-shift) or pin PHP 8.2 in composer.json:
"config": {
"platform": {
"php": "8.2.0"
}
}
GET Request Body Issue:
>=4.1.0.composer update answear/inpost-pickup-point-bundle
Rate Limiting:
How can I help you explore Laravel packages today?