tigamadou / emecef-core-php
Framework-agnostic Core SDK for the Benin Republic e-MECeF (Electronic Tax Invoice) system
Requires
- php: >=8.2
Requires (Dev)
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.0
- squizlabs/php_codesniffer: ^3.10
README
Framework-agnostic Core SDK for the Benin Republic e-MECeF (Electronic Tax Invoice) system.
Part of the e-MECeF SDK ecosystem. This package contains all e-MECeF protocol logic; framework adapters (Laravel, Symfony, etc.) and CMS plugins depend on it and must not reimplement business rules.
Requirements
- PHP ≥ 8.2
Installation
composer require tigamadou/emecef-core-php
Or from the monorepo (development):
cd php/packages/core/emecef-core
composer install
Quick Start
The Core does not read configuration. You inject base URL, JWT token, an HTTP client implementation, and a logger:
use Emecef\Core\Client; use Emecef\Core\Contract\HttpClientInterface; use Emecef\Core\Contract\LoggerInterface; $client = new Client( baseUrl: 'https://sygmef.impots.bj/emcf/api/invoice', token: 'your-jwt-from-dgi', httpClient: $yourHttpClient, // must implement HttpClientInterface logger: $yourLogger // must implement LoggerInterface );
For full configuration and usage, see the docs in this package:
- Overview
- Configuration
- Examples
- DTOs and API reference — all DTOs, enums, fields, and request/response mapping
Data objects (DTOs) and enums
The package models all request and response structures from the e-MECeF API v1.0 specification. For field-by-field descriptions and request/return shapes, see DTOs and API reference:
- Enums:
Emecef\Core\Enum\InvoiceType,AibGroupType,TaxGroupType,PaymentType - Request DTOs (build payloads, call
toArray()ortoJson()):Emecef\Core\Dto\Request\InvoiceRequestDataDto,ItemDto,ClientDto,OperatorDto,PaymentDto - Response DTOs (create from API array via
fromArray()):Emecef\Core\Dto\Response\StatusResponseDto,PendingRequestDto,InvoiceResponseDataDto,SecurityElementsDto
You can use the client with raw JSON (array in/out) or with typed DTOs:
// Array-based (unchanged) $status = $client->getStatus(); // array $result = $client->submitInvoice($json); // array $client->confirm($uid); // array $client->cancel($uid); // array // DTO-based (typed request/response) $statusDto = $client->getStatusResponse(); // StatusResponseDto $requestDto = new InvoiceRequestDataDto(...); // build request $responseDto = $client->submitInvoiceRequest($requestDto); // InvoiceResponseDataDto $securityDto = $client->confirmResponse($uid); // SecurityElementsDto $cancelDto = $client->cancelResponse($uid); // SecurityElementsDto
Package Rules
- Framework-agnostic: No Laravel, Symfony, or CMS dependencies.
- No env access: Configuration is passed in by the caller.
- Transport abstraction: HTTP via
HttpClientInterface; logging viaLoggerInterface.
Development
composer install composer phpcs # code style check (mandatory) composer phpcbf # code style fix (mandatory) composer phpmd # mess detector (mandatory) composer test composer phpstan
- Code style: PHP_CodeSniffer (phpcs + phpcbf) mandatory; PSR-12.
- Mess detection: PHPMD mandatory.
- Tests: PHPUnit, unit tests only; coverage target ≥ 95%.
- Static analysis: PHPStan (max level).
License
Proprietary. See repository root for governance.