cyborgfinance/fcaregisterlaravel
Installation
composer require cyborgfinance/fcaregisterlaravel
Publish the config file:
php artisan vendor:publish --provider="CyborgFinance\FCARegisterLaravel\FCARegisterLaravelServiceProvider" --tag="config"
Configuration
Edit .env with your FCA API credentials:
FCA_REGISTER_API_KEY=your_api_key_here
FCA_REGISTER_BASE_URL=https://api.fca.org.uk
First Use Case
Fetch a firm by its FCA reference number (e.g., FRN=123456):
use CyborgFinance\FCARegisterLaravel\Facades\FCARegister;
$firm = FCARegister::firm('FRN=123456');
dd($firm->name, $firm->registrationNumber);
FCARegister (easiest for quick queries).\CyborgFinance\FCARegisterLaravel\Services\FCARegisterService (for custom logic).Firm, Individual, Product (auto-populated from API responses).Searching Firms
Use the search() method with filters (e.g., status=active, firmType=bank):
$results = FCARegister::search([
'status' => 'active',
'firmType' => 'bank',
'limit' => 10,
]);
Bulk Data Fetching Loop through paginated results:
$page = 1;
while (true) {
$firms = FCARegister::search(['limit' => 100, 'page' => $page]);
if ($firms->isEmpty()) break;
foreach ($firms as $firm) {
// Process firm (e.g., store in DB)
}
$page++;
}
Caching Responses Leverage Laravel’s cache to avoid rate-limiting:
$firm = FCARegister::firm('FRN=123456', cache: true, ttl: 3600);
Event-Driven Updates
Use Laravel’s queue:work to fetch updates periodically:
// In a scheduled job or command
FCARegister::updateFirmCache('FRN=123456');
Custom Endpoints Extend the service for unsupported endpoints:
$client = FCARegister::getClient();
$response = $client->get('/firm-browse', [
'query' => ['status' => 'active'],
]);
$firmData = FCARegister::firm('FRN=123456')->toArray();
Firm::updateOrCreate(['fcaReference' => 'FRN=123456'], $firmData);
X-RateLimit-* headers; implement exponential backoff for retries.try-catch for FCAException:
try {
$firm = FCARegister::firm('FRN=invalid');
} catch (\CyborgFinance\FCARegisterLaravel\Exceptions\FCAException $e) {
Log::error("FCA API Error: " . $e->getMessage());
}
API Key Leaks
.env or hardcode keys. Use Laravel’s env() or a secure secrets manager.config/fcaregister.php:
'validate_key' => env('FCA_REGISTER_VALIDATE_KEY', false),
Rate Limiting
$response = FCARegister::getClient()->get('/firm', ['query' => [...]]);
Log::debug('RateLimit-Remaining: ' . $response->getHeaderLine('X-RateLimit-Remaining'));
Deprecated Endpoints
Data Mismatches
FCARegister::firm()->toArray() to inspect raw data before mapping.Timeouts
config/fcaregister.php:
'timeout' => 30, // seconds
FCARegister::setDebug(true); // Logs raw API responses
$response = FCARegister::getClient()->get('/firm');
dd($response->getHeaders());
$this->mock(\CyborgFinance\FCARegisterLaravel\Services\FCARegisterService::class)
->shouldReceive('getFirm')
->andReturn(new Firm(['name' => 'Test Firm']));
Custom Models Extend the base models to add business logic:
namespace App\Models;
use CyborgFinance\FCARegisterLaravel\Models\Firm as BaseFirm;
class Firm extends BaseFirm {
public function isAuthorised() {
return $this->status === 'authorised';
}
}
New Endpoints Add support for unsupported endpoints by extending the service:
namespace App\Services;
use CyborgFinance\FCARegisterLaravel\Services\FCARegisterService;
class ExtendedFCARegisterService extends FCARegisterService {
public function getProducts() {
return $this->get('/product', []);
}
}
Webhooks Poll for updates and trigger webhooks when data changes:
$lastUpdated = Firm::where('fcaReference', 'FRN=123456')->value('lastUpdated');
$firm = FCARegister::firm('FRN=123456');
if ($firm->lastUpdated !== $lastUpdated) {
event(new FirmUpdated($firm));
}
FCA_REGISTER_BASE_URL matches the FCA’s production/sandbox environment.FRN=, status=, etc. Check the FCA API docs for exact parameter names.100; adjust in config/fcaregister.php:
'default_limit' => 500,
How can I help you explore Laravel packages today?