Install the Bundle
composer require alexandret/evc-bundle
For Symfony Flex projects, this auto-configures the bundle. For manual setups, add to config/bundles.php:
Alexandre\EvcBundle\AlexandreEvcBundle::class => ['all' => true],
Configure Environment Variables
Add to .env:
###> alexandret/evc-bundle ###
EVC_API="your_api_key"
EVC_USERNAME="your_username"
EVC_PASSWORD="your_api_password" # NOT your evc.de account password
###< alexandret/evc-bundle ###
Verify Configuration
Create config/packages/alexandre_evc.yaml:
alexandre_evc:
api_id: '%env(EVC_API)%'
username: '%env(EVC_USERNAME)%'
password: '%env(EVC_PASSWORD)%'
First Use Case: Check Customer Status
Inject EvcService and call:
$customerId = '12345';
$isPersonal = $this->evcService->isPersonal($customerId);
$credits = $this->evcService->getCredits($customerId);
Customer Lookup
Use getCustomer() to fetch details (e.g., credits, status):
$customer = $this->evcService->getCustomer('12345');
Personal Customer Filtering
Fetch all personal customers with getPersonalCustomers():
$personalCustomers = $this->evcService->getPersonalCustomers();
Credit Management Check credits for a customer:
$credits = $this->evcService->getCredits('12345');
Dependency Injection
Register EvcService in your controller/service:
use Alexandre\EvcBundle\Service\EvcService;
public function __construct(private EvcService $evcService) {}
Event-Driven Workflows Trigger actions (e.g., credit alerts) via Symfony events when customer data changes:
$this->evcService->getCustomer($id)->then(function ($customer) {
if ($customer->getCredits() < 5) {
$this->dispatchEvent('low_credits', $customer);
}
});
Command-Line Automation Use Symfony Console commands to sync customer data:
use Symfony\Component\Console\Command\Command;
use Alexandre\EvcBundle\Service\EvcService;
protected function execute(InputInterface $input, OutputInterface $output): int {
$customers = $this->evcService->getPersonalCustomers();
// Process customers...
}
Caching Responses Cache API responses (e.g., with Symfony Cache) to reduce calls:
$cache = $this->container->get('cache.app');
$customer = $cache->get("evc_customer_{$id}", function() use ($id) {
return $this->evcService->getCustomer($id);
});
Credential Mismatch
CredentialException if EVC_USERNAME/EVC_PASSWORD are incorrect.# config/packages/dev/service.yaml
alexandre_evc_request:
class: Alexandre\EvcBundle\Service\EmulationService
arguments:
$api: '%env(EVC_API)%'
$username: '%env(EVC_USERNAME)%'
$password: '%env(EVC_PASSWORD)%'
Network Issues
NetworkException if EVC API is unreachable.try {
$customer = $this->evcService->getCustomer($id);
} catch (NetworkException $e) {
$customer = $this->getCachedCustomer($id);
}
API Response Changes
LogicException if the API response format changes.EmulationService to mock new responses.PHPUnit Version Conflicts
phpunit version in composer.json:
"require-dev": {
"phpunit/phpunit": "^8.5.4"
}
Enable Emulation in Dev/Test
Use predefined test customers (11111, 22222, etc.) to simulate edge cases without hitting the real API.
Log API Responses
Extend RequesterService to log raw responses:
use Psr\Log\LoggerInterface;
public function __construct(
private LoggerInterface $logger,
private string $apiId,
private string $username,
private string $password
) {}
protected function sendRequest(string $endpoint, array $params): array {
$response = parent::sendRequest($endpoint, $params);
$this->logger->debug('EVC API Response', ['endpoint' => $endpoint, 'response' => $response]);
return $response;
}
Handle Exceptions Gracefully Catch specific exceptions to provide user-friendly messages:
try {
$this->evcService->getCustomer($id);
} catch (CredentialException $e) {
$this->addFlash('error', 'Invalid EVC credentials. Contact support.');
} catch (NetworkException $e) {
$this->addFlash('error', 'EVC service unavailable. Try again later.');
}
Custom Emulation Logic
Extend EmulationService to add test cases:
class CustomEmulationService extends EmulationService {
protected function getMockedResponse(string $customerId): array {
if ($customerId === '99999') {
return ['credits' => 0, 'is_personal' => true];
}
return parent::getMockedResponse($customerId);
}
}
Add API Endpoints
Extend EvcService to wrap new API methods:
public function getCustomerTransactions(string $customerId, int $limit = 10): array {
$response = $this->requester->sendRequest(
'/transactions',
['customer_id' => $customerId, 'limit' => $limit]
);
return $this->mapTransactions($response);
}
Webhook Integration Use Symfony Messenger to process EVC webhook events:
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
public function handleEvcWebhook(EvcWebhook $webhook) {
// Process webhook (e.g., credit updates)
}
How can I help you explore Laravel packages today?