common-gateway/open-belasting-bundle
Installation Add the bundle via Composer in your Laravel/Symfony project:
composer require common-gateway/open-belasting-bundle
Register the bundle in config/bundles.php (Symfony) or config/app.php (Laravel via Symfony bridge):
CommonGateway\OpenBelastingBundle\OpenBelastingBundle::class => ['all' => true],
Configuration Publish the default config:
php artisan vendor:publish --provider="CommonGateway\OpenBelastingBundle\OpenBelastingBundle" --tag="config"
Update .env with your API credentials:
OPEN_BELASTING_API_KEY=your_api_key
OPEN_BELASTING_BASE_URL=https://api.openbelastingen.nl
First Use Case: Fetching an Assessment
Use the AssessmentClient service to retrieve an assessment:
use CommonGateway\OpenBelastingBundle\Client\AssessmentClient;
$assessmentClient = app(AssessmentClient::class);
$assessment = $assessmentClient->getAssessment('123456789'); // BSN or tax ID
Fetching Assessments
AssessmentClient for single assessments or AssessmentCollectionClient for bulk operations.$assessments = $assessmentClient->getAssessmentsByYear('123456789', 2023);
Submitting Objections
ObjectionClient to create or update objections:
$objection = new Objection();
$objection->setAssessmentId('ASS_123');
$objection->setReason('Disagreement with tax calculation');
$objectionClient = app(ObjectionClient::class);
$objectionClient->submitObjection($objection);
Event-Driven Integrations
AssessmentFetchedEvent or ObjectionSubmittedEvent for real-time processing:
// In a Symfony event subscriber (Laravel: use Laravel's event system)
public function onAssessmentFetched(AssessmentFetchedEvent $event) {
$assessment = $event->getAssessment();
// Process or log the assessment
}
symfony/flex) to integrate with Laravel’s service container.
// In AppServiceProvider@boot()
$this->app->register(new \CommonGateway\OpenBelastingBundle\OpenBelastingBundle());
$assessment = Cache::remember("assessment_{$bsn}", now()->addHours(1), function() use ($assessmentClient, $bsn) {
return $assessmentClient->getAssessment($bsn);
});
API Key Management
.env or Symfony’s %env(resolve:...)% in config.Schema Mismatches
if (!$objection->isValid()) {
throw new \InvalidArgumentException('Invalid objection data: ' . $objection->getErrors());
}
Idempotency
Error Handling
OpenBelastingApiException:
try {
$assessment = $assessmentClient->getAssessment($bsn);
} catch (OpenBelastingApiException $e) {
Log::error('Failed to fetch assessment: ' . $e->getMessage());
// Retry or notify admin
}
debug: true in config to log all API requests/responses./resources/postman. Import it for manual testing.Custom Mappings
AssessmentMapper or ObjectionMapper to transform data before/after API calls:
class CustomAssessmentMapper extends AssessmentMapper {
public function mapToDto(array $data): AssessmentDto {
$dto = parent::mapToDto($data);
$dto->setCustomField($data['custom_field']);
return $dto;
}
}
services:
CommonGateway\OpenBelastingBundle\Mapper\AssessmentMapper:
class: App\CustomAssessmentMapper
Webhooks
Route::post('/open-belasting/webhook', [OpenBelastingWebhookController::class, 'handle']);
Testing
OpenBelastingBundleTestCase base class for unit/integration tests:
use CommonGateway\OpenBelastingBundle\Tests\OpenBelastingBundleTestCase;
class MyTest extends OpenBelastingBundleTestCase {
public function testAssessmentFetch() {
// Mock API responses here
}
}
How can I help you explore Laravel packages today?