common-gateway/sim-tax-to-zgw-bundle
Installation Add the bundle to your Laravel project via Composer:
composer require common-gateway/sim-tax-to-zgw-bundle
Register the bundle in config/bundles.php:
return [
// ...
CommonGateway\SimTaxToZGWBundle\SimTaxToZGWBundle::class => ['all' => true],
];
Configuration Publish the default configuration:
php artisan vendor:publish --tag=sim-tax-to-zgw-config
Update config/sim_tax_to_zgw.php with your API endpoints, credentials, and schema paths.
First Use Case Convert a SimTax XML file to a ZGW-compliant JSON payload:
use CommonGateway\SimTaxToZGWBundle\Service\TaxConverter;
$converter = app(TaxConverter::class);
$simTaxXml = file_get_contents('path/to/sim_tax.xml');
$zgwPayload = $converter->convertToZGW($simTaxXml);
TaxConverter for core conversion logic.config/sim_tax_to_zgw.php for API endpoints and validation rules.tests/ for usage examples and edge cases.XML-to-ZGW Conversion
Use TaxConverter to transform SimTax XML into ZGW-compliant JSON:
$converter = app(TaxConverter::class);
$result = $converter->convertToZGW($xmlContent, [
'schema_version' => '2.0',
'target_api' => 'pink-open-belastingen',
]);
ZGW-to-XML Conversion Reverse the process for responses or debugging:
$zgwJson = '{"api_version": "2.0", ...}';
$simTaxXml = $converter->convertFromZGW($zgwJson);
Validation Validate XML/JSON against schemas before conversion:
$validator = app(\CommonGateway\SimTaxToZGWBundle\Validator\TaxValidator::class);
$errors = $validator->validate($xmlContent);
API Layer
Integrate with Laravel HTTP clients (e.g., Guzzle) for API calls:
$client = app(\Illuminate\Support\Facades\Http::class);
$response = $client->post('https://api.zgw.nl/pink-open-belastingen', [
'headers' => ['Authorization' => 'Bearer ' . config('sim_tax_to_zgw.api_token')],
'body' => $zgwPayload,
]);
Event Handling Dispatch events for pre/post-conversion logic:
event(new \CommonGateway\SimTaxToZGWBundle\Events\TaxConversionStarted($xmlContent));
$result = $converter->convertToZGW($xmlContent);
event(new \CommonGateway\SimTaxToZGWBundle\Events\TaxConversionCompleted($result));
Schema Customization Extend default schemas by overriding config paths:
'schemas' => [
'sim_tax' => resource_path('schemas/custom_sim_tax.xsd'),
'zgw' => resource_path('schemas/custom_zgw.json'),
],
Batch Processing Use Laravel queues for large-scale conversions:
dispatch(new \CommonGateway\SimTaxToZGWBundle\Jobs\ConvertTaxJob($xmlContent, $zgwEndpoint));
Schema Mismatches
config/sim_tax_to_zgw.php and update them if needed.$validator->setVerbose(true);
API Rate Limits
use Illuminate\Support\Facades\Http;
$response = Http::retry(3, 100)->post($endpoint, $data);
Namespace Collisions
'mappings' => [
'custom_namespace' => [
'element' => 'zgw_element',
'attributes' => ['attr1' => 'zgw_attr'],
],
],
Date/Time Formatting
YYYY-MM-DD), while SimTax may use other formats.$normalizedXml = preg_replace('/<date>[^-]+-([0-9]{2})-([0-9]{2})-([0-9]{4})<\/date>/', '<date>\3-\1-\2</date>', $xml);
Enable Logging
Configure Monolog in config/logging.php to log conversion steps:
'channels' => [
'tax_conversion' => [
'driver' => 'single',
'path' => storage_path('logs/tax_conversion.log'),
'level' => 'debug',
],
],
Then inject the logger:
$logger = app(\Psr\Log\LoggerInterface::class)->withName('tax_conversion');
$logger->debug('Conversion started', ['xml_snippet' => substr($xml, 0, 200)]);
Dump Intermediate Data
Use Laravel’s dd() or dump() to inspect objects:
$mappedData = $converter->mapXmlToZGW($xml);
dump($mappedData); // Inspect before JSON encoding
Test with Minimal Payloads Start with a small, valid XML snippet to isolate issues:
<SimTax xmlns="http://example.com/simtax">
<BelastingAangifte id="123">
<Soort>Inkomstenbelasting</Soort>
</BelastingAangifte>
</SimTax>
Custom Converters
Extend TaxConverter for domain-specific logic:
namespace App\Services;
use CommonGateway\SimTaxToZGWBundle\Service\TaxConverter as BaseConverter;
class CustomTaxConverter extends BaseConverter {
protected function customizeMapping(array $data): array {
$data['custom_field'] = 'app_specific_value';
return $data;
}
}
Register the service in config/services.php:
'tax_converter' => App\Services\CustomTaxConverter::class,
Hooks for Pre/Post Processing Use Laravel’s service provider to bind custom logic:
public function boot() {
$this->app->afterResolving(\CommonGateway\SimTaxToZGWBundle\Service\TaxConverter::class, function ($converter) {
$converter->setPreProcessor(function ($xml) {
return str_replace('old_value', 'new_value', $xml);
});
});
}
Schema Validation Extensions
Add custom validation rules by extending TaxValidator:
use CommonGateway\SimTaxToZGWBundle\Validator\TaxValidator;
class ExtendedTaxValidator extends TaxValidator {
protected function getCustomRules() {
return [
'required_field' => 'required|string',
];
}
}
Bind the validator in the service provider:
$this->app->bind(\CommonGateway\SimTaxToZGWBundle\Validator\TaxValidator::class, ExtendedTaxValidator::class);
How can I help you explore Laravel packages today?