Skip to content

An unofficial PHP SDK consuming the FCA API

License

Notifications You must be signed in to change notification settings

craigpotter/fca-php-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FCA API SDK for PHP

Latest Version on Packagist Tests Total Downloads

This is an unofficial PHP SDK for FCA's API and is powered by Saloon.

Note: This SDK is still in development and is not yet ready for production use. Use at your own risk.

Installation

You can install the package via composer:

composer require craigpotter/fca-php-sdk

Requirements

You will need to have a valid API key from FCA to use this SDK.

You can obtain one by registering as a developer.

Example Usage

use CraigPotter\Fca\Fca;

// Create a new FCA instance (This is required for all requests)
$fca = new Fca('my.email@dev.test', 'my-api-key');

// 12345 is the FCA firm reference number

$firmFrnExists = $fca->firm(12345)->exists(); // Returns a boolean

$response = $fca->firm(12345)->get();

$firm = $response->dto(); // Returns a Firm DTO
$json = $response->json(); // Returns the raw JSON response

Documentation

Warning: This documentation is still a work in progress.

Some responses have the option of a DTO (Data Transfer Object) which can be used to access the response data.

This does not work for all responses, but is documented where it is available.
For all other responses, you can access the raw JSON response using $response->json().

Firms

Check an FRN exists

use CraigPotter\Fca\Fca;

// Create a new FCA instance (This is required for all requests)
$fca = new Fca('my.email@dev.test', 'my-api-key');

// 12345 is the FCA firm reference number

$firmFrnExists = $fca->firm(12345)->exists(); // Returns a boolean

Get a firm by FRN

use CraigPotter\Fca\Fca;

// Create a new FCA instance (This is required for all requests)
$fca = new Fca('my.email@dev.test', 'my-api-key');

// 12345 is the FCA firm reference number

$response = $fca->firm(12345)->get(); // Returns a Saloon response object

$firm = $response->dto(); // Returns a Firm DTO
$firm->frn; // 12345
$firm->name; // "My Firm"
$firm->status; // "Active"
$firm->statusDate; // "2021-01-01"
$firm->statusReason; // "Active"
$firm->companiesHouseNumber; // "12345678"

$json = $response->json(); // Returns the raw JSON response

Get the individuals associated with a firm by FRN

This endpoint is paginated and will return a maximum of 20 results per page.
You should loop through the pages to get all results.

use CraigPotter\Fca\Fca;

// Create a new FCA instance (This is required for all requests)
use CraigPotter\Fca\Fca;

// Create a new FCA instance (This is required for all requests)
$fca = new Fca('my.email@dev.test', 'my-api-key');

// 12345 is the FCA firm reference number

$paginatedData = $fca->firm(12345)->individuals(); // Returns a Saloon response object

$paginatedData->totalPages(); // Returns the total number of pages
$paginatedData->totalResults(); // Returns the total number of results
foreach ($paginatedData as $page) {
    $paginatedData->getCurrentPage(); // Returns the current page number
    $individuals = $page->dto(); // Returns an array of Individual DTOs for this page
    $json = $page->json(); // Returns the raw JSON response for this page
    
    
    foreach ($individuals as $individual) {
        $individual->irn; // "JOHNSMITH12345"
        $individual->name; // "John Smith"
        $individual->status; // "Approved by regulator"
    }
}

Get the addresses associated with a firm by FRN

This endpoint is paginated and will return a maximum of 20 results per page.
You should loop through the pages to get all results.

use CraigPotter\Fca\Fca;

// Create a new FCA instance (This is required for all requests)
use CraigPotter\Fca\Fca;

// Create a new FCA instance (This is required for all requests)
$fca = new Fca('my.email@dev.test', 'my-api-key');

// 12345 is the FCA firm reference number

$paginatedData = $fa->firm(12345)->addresses(); // Returns a Saloon response object

$paginatedData->totalPages(); // Returns the total number of pages
$paginatedData->totalResults(); // Returns the total number of results
foreach ($paginatedData as $page) {
    $paginatedData->getCurrentPage(); // Returns the current page number
    $addresses = $page->dto(); // Returns an array of Address DTOs for this page
    $json = $page->json(); // Returns the raw JSON response for this page
    
    
    foreach ($addresses as $address) {
        $address->website; // "www.example.org"
        $address->phoneNumber; // "44123456778"
        $address->type; // "Principal Place of Business"
        $address->contactName; // "John Smith"
        $address->addressLine1; // "1 Example Street"
        $address->addressLine2; // "Aberdeen"
        $address->addressLine3; // "Aberdeen"
        $address->addressLine4; // "Aberdeen"
        $address->town; // "Aberdeen"
        $address->county; // "Aberdeenshire"
        $address->country; // "United Kingdom"
        $address->postcode; // "AB1 2CD"
    }
}

Testing

Copy .env.example to .env and update accordingly.

vendor/bin/pest

Credits

License

The MIT License (MIT). Please see License File for more information.