20steps/collmex-bundle
Symfony2 bundle exposing Collmex accounting as a configurable service. Configure URL/account/login/password, inject or fetch the service, and call methods like getCustomerCount(). Early, incomplete implementation with plans for full CRUD, caching, and KPIs.
Installation:
composer require 20steps/collmex-bundle:dev-master
Add to AppKernel.php:
new twentysteps\Bundle\CollmexBundle\twentystepsCollmexBundle(),
Import services in config.yml:
imports:
- { resource: "@twentystepsCollmexBundle/Resources/config/services.yml" }
Configure API Credentials (parameters.yml):
parameters:
twentysteps_collmex.url: "https://www.collmex.de"
twentysteps_collmex.account_id: "YOUR_ACCOUNT_ID"
twentysteps_collmex.api_key: "YOUR_API_KEY" # Add if required (not in README)
First Use Case:
Inject the collmex.client service into a controller/service and call a basic API method:
use twentysteps\Bundle\CollmexBundle\Service\CollmexClient;
class MyController extends Controller
{
public function index(CollmexClient $collmex)
{
$response = $collmex->get('/api/v1/accounts'); // Example endpoint
return new JsonResponse($response);
}
}
Dependency Injection:
CollmexClient into controllers/services to avoid hardcoding API calls.public function __construct(private CollmexClient $collmex) {}
Request/Response Handling:
get(), post()).JsonResponse or custom DTOs:
$data = $collmex->get('/api/v1/invoices')->getData();
Configuration Overrides:
config.yml:
twentysteps_collmex:
url: "%env(COLLMEX_API_URL)%"
timeout: 30
Caching (Future-Proofing):
$collmex->setCache(new SymfonyCacheAdapter());
Error Handling:
CollmexException:
try {
$collmex->post('/api/v1/transactions', $payload);
} catch (\Exception $e) {
$this->addFlash('error', $e->getMessage());
}
Missing API Key:
api_key in parameters.yml, but Collmex likely requires it. Add it or risk 403 errors.Rate Limiting:
HttpCache to avoid hitting limits.Endpoint Documentation:
Symfony 2 vs. 4+:
config/services.yaml:
services:
twentysteps_collmex.client:
alias: twentystepsCollmexBundle.collmex.client
Debugging:
$collmex->setClient(new \GuzzleHttp\Client([
'handler' => \GuzzleHttp\HandlerStack::create(new \GuzzleHttp\Middleware::tap(function ($request) {
error_log($request->getUri());
})),
]));
Environment Variables:
api_key) in .env:
parameters:
twentysteps_collmex.api_key: "%env(COLLMEX_API_KEY)%"
Testing:
CollmexClient in PHPUnit:
$this->collmex = $this->createMock(CollmexClient::class);
$this->collmex->method('get')->willReturn(new Response(json_encode(['test' => true])));
Extending Functionality:
class InvoiceService {
public function __construct(private CollmexClient $client) {}
public function fetchInvoices() {
return $this->client->get('/api/v1/invoices')->getData();
}
}
Logging:
$response = $collmex->get('/api/v1/accounts');
$this->logger->info('Collmex API Response', ['data' => $response->getData()]);
Fallbacks:
RetryMiddleware.How can I help you explore Laravel packages today?