Installation:
composer require astina/solvency-bundle:dev-master
Add to AppKernel.php:
new Astina\Bundle\SolvencyBundle\AstinaSolvencyBundle(),
Configure:
Add to config.yml:
astina_solvency:
provider:
deltavista:
wsdl_url: "http://example.org/path/to.wsdl"
user: "your_username"
password: "your_password"
First Use Case:
Inject the SolvencyService in a controller or service:
use Astina\Bundle\SolvencyBundle\Service\SolvencyService;
class MyController extends Controller
{
public function checkSolvencyAction(Request $request, SolvencyService $solvencyService)
{
$result = $solvencyService->checkSolvency([
'param1' => 'value1',
'param2' => 'value2',
]);
return $this->json($result);
}
}
Service Integration:
Use dependency injection to access SolvencyService in controllers, commands, or other services.
Example in a command:
use Astina\Bundle\SolvencyBundle\Service\SolvencyService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SolvencyCheckCommand extends Command
{
protected static $defaultName = 'app:solvency:check';
private $solvencyService;
public function __construct(SolvencyService $solvencyService)
{
$this->solvencyService = $solvencyService;
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$result = $this->solvencyService->checkSolvency(['customer_id' => 123]);
$output->writeln('Solvency check result: ' . print_r($result, true));
}
}
Request Handling:
Pass an associative array of parameters to checkSolvency(). The bundle maps these to the DeltaVista API.
Example:
$result = $solvencyService->checkSolvency([
'customer_id' => 'CUST123',
'amount' => 1000.00,
'currency' => 'EUR',
]);
Response Handling:
The bundle returns a structured response (e.g., ['status' => 'approved', 'risk_score' => 0.8]). Validate this in your logic:
if ($result['status'] === 'approved') {
// Proceed with transaction
}
Custom Providers:
Extend the bundle to support additional providers by implementing Astina\Bundle\SolvencyBundle\Provider\ProviderInterface and register them in the bundle configuration.
Event Listeners:
Listen for solvency check events (e.g., solvency.check.before, solvency.check.after) to log, transform, or validate requests/responses:
# config/services.yml
services:
app.solvency_listener:
class: AppBundle\EventListener\SolvencyListener
tags:
- { name: kernel.event_listener, event: solvency.check.before, method: onSolvencyCheckBefore }
Caching Strategy:
Leverage the built-in caching to reduce API calls. Customize cache lifetime and directory in config.yml:
astina_solvency:
cache:
cache_dir: "%kernel.cache_dir%/solvency"
lifetime: 3600 # Cache for 1 hour
Testing:
Mock the SolvencyService in unit tests or use the endpoint_url config to point to a test endpoint:
astina_solvency:
provider:
deltavista:
endpoint_url: "http://test-endpoint.org"
WSDL/Endpoint Mismatch:
Ensure wsdl_url and endpoint_url are correct. A misconfigured endpoint will cause silent failures or SOAP faults. Test with a tool like SoapUI first.
Authentication Issues:
DeltaVista may reject requests with invalid credentials. Verify user and password in config.yml and check for typos.
Caching Overrides:
If lifetime is set to null, responses are cached indefinitely. This may lead to stale data. Set a reasonable lifetime (e.g., 3600 for 1 hour) for dynamic data.
Parameter Validation:
The bundle does not validate input parameters by default. Ensure your application validates inputs before passing them to checkSolvency() to avoid malformed API calls.
SOAP Exceptions: SOAP faults may not be caught gracefully. Wrap calls in a try-catch block:
try {
$result = $solvencyService->checkSolvency($params);
} catch (\SoapFault $e) {
// Log error and handle gracefully
$this->logger->error('Solvency check failed: ' . $e->getMessage());
return $this->json(['error' => 'Solvency check failed'], 500);
}
Enable SOAP Debugging:
Add this to config.yml to log SOAP requests/responses:
astina_solvency:
debug: true
Logs will appear in var/log/dev.log.
Check Cache Directory:
Ensure the cache_dir is writable by the web server. Permissions like 755 are typically sufficient.
Validate WSDL:
Use php -r 'new SoapClient("http://example.org/path/to.wsdl");' to test WSDL connectivity. If this fails, the WSDL URL is incorrect.
Monitor API Usage: DeltaVista may throttle or block excessive requests. Use caching and monitor API call volumes to avoid hitting limits.
Custom Response Transformers:
Override the default response handling by extending Astina\Bundle\SolvencyBundle\Transformer\ResponseTransformer and binding your class in services.yml:
services:
app.solvency.response_transformer:
class: AppBundle\Transformer\CustomSolvencyResponseTransformer
tags:
- { name: astina_solvency.response_transformer }
Add New Providers:
Implement ProviderInterface and register it in the bundle’s Resources/config/services.xml:
<service id="app.solvency.provider.custom" class="AppBundle\Provider\CustomProvider">
<tag name="astina_solvency.provider" provider="custom" />
</service>
Override Default Configuration:
Use parameter bags to override bundle defaults in config.yml:
parameters:
astina_solvency.cache_dir: "%kernel.cache_dir%/custom_solvency_cache"
How can I help you explore Laravel packages today?