Add your own bank
We have made PSD2PHP with the goal of easily adding other banks as a module as needed. Follow this guide to add your own bank.
Note: This guide takes into consideration that you've finished the getting started guide and included the
vendor/autoload.php
file in your project.
Create a new bank
To create a new bank, we recommend that you're using our abstract class to get started as it gives you a host of different built in functionality to send and retrieve requests.
To get started with implementing your new bank, we suggest creating a class for it that you can reference later. For our purposes we're going to store this file in classes/TestBank.php
use Teskon\PSD2PHP\Banks\Bank;
class TestBank extends Bank {
/**
* API endpoint
*
* @var string $endpoint
*/
protected $endpoint = 'https://www.api.example.com/';
/**
* Access token retrieved from bank
*
* @var string|null $token
*/
public $token = null;
/**
* Set default configuration variables for TestBank
*
* @return array
*/
protected function getDefaultConfigurationVariables(){
return [
/**
* (string) base URI to API endpoint
*/
'base_uri' => $this->endpoint,
];
}
/**
* Get default headers
*
* @return array
*/
protected function getDefaultHeaders(){
return [
'header' => 'header'
];
}
/**
* Get data
*
* @var string $var1
* @var string $var2
*
* @return array
*/
public function getData(string $var1, string $var2){
$data = $this->request('GET', 'Data?var1=' . urlencode($var1) . '&var2=' . urlencode($var2), [], [
'header' => $header
]);
return $data;
}
}
The class above will be able to run a method called getData
that will send a GET
request to https://www.api.example.com/Data
with the parameters var1
= $var1
and var2
= $var2
Methods and variables explained
The methods that are used can be easily explained here:
protected $endpoint
Base endpoint of API (website all requests will be sent to)public $token
Used to store token that will be sent with the request if needed.protected function getDefaultConfigurationVariables()
Function to get default configuration variables from. Here you can store the default values without having to callsetConfiguration
. Should always return the base_uri as the current endpoint.protected function getDefaultHeaders()
Function to get default headers from. If you need a header posted to your API this is the place to store it. Should return an array with key value pairs.public function getData(string $var1, string $var2)
A function that can be called using$TestBank->getData("a", "b")
in your code to get the data fromhttps://www.api.example.com/Data
Methods that can be overwritten
Most of the functionality of Teskon\PSD2PHP\Banks\Bank
can be overwritten if you want to use your own code. This includes, but might not be limited to:
public function __construct()
Override this function if you want another constructor. Please note that the constructor we're using is responsible for populating configuration values, default headers and the request function. If you're overriding this you should consider what you need to add to make it work. If you just want to change the parameters that the constructor takes and do something with them we recommend that you look at the source code of this file and changing your constructor accordingly.protected function getBasicAuthorization()
Function used to return urlencoded basicAuthorization
for APIs that need it. This is typically for endpoints where you're retrieving your token from.protected function getBearerAuthorization()
Function to return a string version of theAuthorization
header that are used to connect to the secure endpoints to retrieve customer data. This is only returning aBearer
token ofpublic $token
protected function setHttpClient()
This is the function used to set the http client that we use to connect to the API with in therequest
method. If you change this you might have to change therequest
method too as this is intended to work with guzzlephpprotected function request()
Request function to send requests to the API. If you change this you can change how the parameters are received and change what you want to send to therequest
method.protected function returnJson()
This function is responsible for converting a json string to an array.public function getConfiguration()
This function is responsible for returning an array of the configuration values.public function setConfiguration()
This function is responsible for updating the configuration values on a request by request basis.public function setGlobalConfiguration()
This function is responsible for updating the global configuration values making them last between requests.
Making your bank available for others
If you want to contribute and make your bank available for others to use you can push it to our Github repository and open a merge request to the master branch. We will review your code and merge it if everything works fine with PSD2PHP.
Note: We're not guaranteeing that your code will be merged, or that it will make it to a relase immediately if it is merged.
Note: Please follow our guidelines when pushing your bank to us. If the guidelines are not met, we will reject your merge request.
- Comment your code. Make sure that all functions and variables are commented with their type, and what they do.
- Our code is
psr-4
compliant, so we therefore ask you to use the correct file structure. Push the bank in a separate folder in thesrc/Banks/
folder with the correct namespace (Teskon\PSD2PHP\Banks\YourBank
) We also ask that your classes has the same name as the file. - Add a test file in the
tests/Banks/
folder for your bank. This should includephpunit
tests for syntax errors and your functions.
If everything works and our guidelines are met we will merge the code. If not, we will give you feedback on what you need to improve and we will take another look if you push it again.