tigamadou / emecef-laravel
Laravel adapter for the e-MECeF (Electronic Tax Invoice) SDK – Benin Republic
Requires
- php: >=8.2
- illuminate/database: ^10.0|^11.0
- illuminate/http: ^10.0|^11.0
- illuminate/log: ^10.0|^11.0
- illuminate/routing: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
- illuminate/view: ^10.0|^11.0
- tigamadou/emecef-core-php: ^0.0.2
Requires (Dev)
- larastan/larastan: ^2.0
- orchestra/testbench: ^8.0|^9.0
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.0
- squizlabs/php_codesniffer: ^3.10
README
Laravel adapter for the Benin Republic e-MECeF (Electronic Tax Invoice) SDK. It wires emecef-core-php into Laravel via config, a facade, and Laravel’s HTTP and logging.
Part of the e-MECeF SDK ecosystem.
Requirements
- PHP ≥ 8.2
- Laravel 10.x or 11.x
- emecef/emecef-core-php ^1.0
Installation
composer require tigamadou/emecef-laravel
The package auto-registers its service provider and the Emecef facade (Laravel 11+ package discovery). For older Laravel, add the provider and alias in config/app.php if needed.
Configuration
-
Publish the config file:
php artisan vendor:publish --tag=emecef-config
-
Store token, ifu, nim, and environment in the
emecef_configtable (see migrations). Config file is for Laravel-specific options only (e.g.log_channel). -
Publish and run migrations to create invoice and config tables:
php artisan vendor:publish --tag=emecef-migrations php artisan migrate
Models:
Emecef\Laravel\Models\EmecefConfig,EmecefInvoice,EmecefInvoiceItem,EmecefInvoicePayment -
Optionally set
log_channelfor e-MECeF logs. -
(Optional) Publish views to customize the web interface:
php artisan vendor:publish --tag=emecef-views
Views are copied to
resources/views/vendor/emecef.
See docs/configuration.md for the full config reference.
Web interface
The package includes a web interface for all e-MECeF actions. After migrations and config, visit /{prefix}/ (default: /emecef/):
| Route | Action |
|---|---|
GET /emecef/ |
Dashboard (API status, recent invoices) |
GET /emecef/invoices |
List invoices |
GET /emecef/invoices/create |
Create invoice form |
GET /emecef/invoices/{id} |
View invoice (confirm/cancel if pending) |
GET /emecef/config |
View configuration |
GET /emecef/config/edit |
Create or edit configuration (single row) |
Configure route_prefix and route_middleware in config/emecef.php. See docs/configuration.md.
Quick start
Use the facade or inject Emecef\Core\Client:
use Emecef\Laravel\Facades\Emecef; $status = Emecef::getStatusResponse();
use Emecef\Core\Client; public function __construct(private readonly Client $emecef) {} // $this->emecef->getStatusResponse(), submitInvoiceRequest(), confirmResponse(), cancelResponse(), etc.
All operations and DTOs are the same as in the core package. Example: submit an invoice and confirm:
use Emecef\Core\Dto\Request\InvoiceRequestDataDto; use Emecef\Core\Dto\Request\ItemDto; use Emecef\Core\Dto\Request\OperatorDto; use Emecef\Core\Enum\InvoiceType; use Emecef\Core\Enum\TaxGroupType; use Emecef\Laravel\Facades\Emecef; $request = new InvoiceRequestDataDto( ifu: '9999900000001', type: InvoiceType::FV, items: [ new ItemDto('Article A', 1000, 2.0, TaxGroupType::A), ], operator: new OperatorDto('Opérateur 1') ); $response = Emecef::submitInvoiceRequest($request); if ($response->uid !== null) { $security = Emecef::confirmResponse($response->uid); // $security->qrCode, $security->codeMECeFDGI for the printed invoice }
See docs/examples.md for more examples and error handling.
Documentation
| Document | Description |
|---|---|
| Overview | What the package does and does not do, dependencies |
| Configuration | Config file, routes, views, and how the client is built |
| Examples | Facade, dependency injection, web interface, submit/confirm/cancel, errors |
| Schema | Full database schema with API field mapping and descriptions |
| Core: DTOs and API | All enums, request/response DTOs, and API operations |
What this package provides
- Config:
config/emecef.phpwith log channel, route prefix, and route middleware. - Bindings:
HttpClientInterface→ Laravel HTTP client,LoggerInterface→ Laravel Log (optional channel),Clientas singleton. - Facade:
Emecef\Laravel\Facades\Emecef→Emecef\Core\Client. - Web interface: Dashboard, invoice list/create/show, config management. Views are publishable (
emecef-views). - Routes: Prefixed by
route_prefix(defaultemecef), protected byroute_middleware(defaultweb).
Business logic, DTOs, and API contract live in emecef-core-php; this adapter only integrates them with Laravel.
Development
composer install
composer phpcs
composer phpcbf
composer phpmd
composer test
composer phpstan
- Code style: PHP_CodeSniffer (PSR-12).
- Mess detection: PHPMD.
- Tests: PHPUnit (Orchestra Testbench).
- Static analysis: PHPStan.
License
Proprietary. See repository root for governance.