SBanken
The SBanken integration is made to connect with the SBanken public API (https://sbanken.no)
You can read more about the APIs in use here:
Accounts API
Customers API
Note: This API is in current development and BETA. Bugs can occur.
Getting started
To start using this integration you will need to initate a class object that will be used later to connect to the different APIs. To start with this, you will need to create a ClientID
and a ClientSecret
at SBanken (only available in Norwegian)
When this has been created, you can initiate an instance of the SBanken class using one of the following examples:
use Teskon\PSD2PHP\PSD2PHP;
require 'vendor/autoload.php';
$SBanken = new PSD2PHP("SBanken", "ClientID", "ClientSecret");
use Teskon\PSD2PHP\Banks\SBanken\SBanken;
require 'vendor/autoload.php';
$SBanken = new SBanken("ClientID", "ClientSecret");
Note: All examples listed below will use the SBanken class initiated above.
Configuration
We allow you to change the configuration values on each bank before sending the API requests.
Available configuration values
You can change the following configuration values:
Type | Key | Description | Default |
---|---|---|---|
bool | auth_init | Set to true if you want the auth token to be retrieved on the initalization of the class. If set to false, the auth token will be retrieved before the first request. Useful if you need the auth token without sending a request first. | false |
int | auth_retries | Number of retries before shutting down. Use 0 for none, and -1 for infinite. We don't recommend using infinite due to resource usage. | 1 |
array | auth_retries_codes | HTTP codes for when we should regain the auth token and try the request again. Should be an array of integers. | [500] |
int | batch_concurrency | Number of requests sent per batch when sending batch requests. | 15 |
bool | debug | Set to true to print data sent and received on each request. This does not return said data, and should not be set to true on a production server. | false |
int | max | Maximum number of allowed redirects. | 5 |
int | max | Maximum number of allowed redirects. | 5 |
bool | strict | Set to true to use strict redirects. Strict RFC compliant redirects mean that POST redirect requests are sent as POST requests vs. doing what most browsers do which is redirect POST requests with GET requests. | false |
bool | referer | Set to true to enable adding the Referer header when redirecting. | false |
array | protocols | Specified which protocols are allowed for redirect requests. | ['http', 'https'] |
callable | on_redirect | PHP callable that is invoked when a redirect is encountered. The callable is invoked with the original request and the redirect response that was received. Any return value from the on_redirect function is ignored. | null |
bool | track_redirects | When set to true, each redirected URI and status code encountered will be tracked in the X-Guzzle-Redirect-History and X-Guzzle-Redirect-Status-History headers respectively. All URIs and status codes will be stored in the order which the redirects were encountered. | false |
Overwrite default configuration
If you want to overwrite the default configuration values when initiating the SBanken class you can pass an array
as a parameter to the class with the values you want to change.
use Teskon\PSD2PHP\PSD2PHP;
require 'vendor/autoload.php';
$SBanken = new PSD2PHP("SBanken", "ClientID", "ClientSecret", [
'max' => 3
]);
use Teskon\PSD2PHP\Banks\SBanken\SBanken;
require 'vendor/autoload.php';
$SBanken = new SBanken("ClientID", "ClientSecret", [
'max' => 3
]);
The example above will create an instance of the SBanken class with a maximum number of allowed redirects of 3.
Change configuration values
If you want to change the configuration values you can do so by using the setConfiguration
method.
$customer = $SBanken->getCustomer($customerID);
$customerWithReferer = $SBanken->setConfiguration(['referer' => true])->getCustomer($customerID);
This example will run two API requests, the first with referer
set to false
, and the second with referer
set to true
.
Note: The
setConfiguration
function will only change the configuration until the next API request is sent. After that it will change back to the previous configuration values. If you want to change the global configuration values, follow the steps below.
Change global configuration values
If you want to change the configuration values on every request, you can use the setGlobalConfiguration
method.
$customer = $SBanken->getCustomer($customerID);
$customerWithReferer = $SBanken->setGlobalConfiguration(['referer' => true])->getCustomer($customerID);
If you use the code example above all requests sent after $customerWithReferer
will have referer
set to true
.
Get current configuration
If you need to check which configuration values are currently active, you can do so by using the getConfiguration
method.
$configuration = $SBanken->getConfiguration();
var_dump($configuration);
Available requests
Note: No required parameters has a default value.
Get Customer information
You can get the customer information by running the getCustomer
method.
$customerID = '12345678910';
$customer = $SBanken->getCustomer($customerID);
Parameters:
Parameter | Type | Description |
---|---|---|
$customerID required | string | Your social security numbers (11 characters long). |
Get Accounts
You can get the accounts owned by a customer by running the getAccounts
method.
$customerID = '12345678910';
$accounts = $SBanken->getAccounts($customerID);
Parameters:
Parameter | Type | Description |
---|---|---|
$customerID required | string | Your social security numbers (11 characters long). |
Get Account
You can get a specific account owned by a customer by running the getAccount
method.
$customerID = '12345678910';
$accountID = 'abc';
$account = $SBanken->getAccount($customerID, $accountID);
Parameters:
Parameter | Type | Description |
---|---|---|
$customerID required | string | Your social security numbers (11 characters long). |
$accountID required | string | Account ID retrieved from getAccounts |
Get Transactions
You can get transactions beloning to an account by running the getTransactions
method.
$customerID = '12345678910';
$accountID = 'abc';
$index = 0;
$length = 100;
$startDate = '2018-01-01';
$endDate = '2018-01-31';
$transactions = $SBanken->getTransactions($customerID, $accountID, $index, $length, $startDate, $endDate);
Parameters:
Parameter | Type | Description |
---|---|---|
$customerID required | string | Your social security numbers (11 characters long). |
$accountID required | string | Account ID retrieved from getAccounts |
$index | int | Starting index of retrieved results Default: 0 |
$length | int | Result limit. Minimum value is 1. Maximum value is 1000. Default: 100 |
$startDate | string | Date to start retrieving transactions from. Minimum date is 2000-01-01. Maximum date is current date + 1 day. Default: current date - 30 days |
$endDate | string | Date to stop retrieving transactions from. Minimum date is $startDate. Maximum date is current date + 1 day. Default: current date |
Transfer money between owned accounts
You can transfer money between your accounts by using the postTransfer
method
Note: This will only work between your own accounts. You can't currently transfer money between your accounts and accounts owned by other people.
$customerID = '12345678910';
$fromAccountID = 'abc';
$toAccountID = 'abc';
$message = 'My transfer';
$amount = 100.00;
$transfer = $SBanken->postTransfer($customerID, $fromAccountID, $toAccountID, $message, $amount);
Note: The account IDs (
$fromAccountID
and$toAccountID
) is the IDs of the accounts retrieved fromgetAccounts
. Do not mix this with the account numbers. This will only work when using the account IDs.
Parameters:
Parameter | Type | Description |
---|---|---|
$customerID required | string | Your social security numbers (11 characters long). |
$fromAccountID required | string | ID of account you're transfering money from. |
$toAccountID required | string | ID of account you're transfering money to. |
$message required | string | Message. Must be between 1 and 30 characters long. |
$amount required | float | Amount you want to transfer in NOK. Must be between 1.00 and 100 000 000 000 000 000.00 NOK |
Get Electronic Invoices
You can get electronic invoices belonging to a customer by running the getEInvoices
method.
$customerID = '12345678910';
$status = 'ALL';
$index = 0;
$length = 100;
$startDate = '2018-01-01';
$endDate = '2018-01-31';
$eInvoices = $SBanken->getEInvoices($customerID, $status, $index, $length, $startDate, $endDate);
Parameters:
Parameter | Type | Description |
---|---|---|
$customerID required | string | Your social security numbers (11 characters long). |
$status | string | Current status of e-invoices you want returned. Possible values: ALL , NEW , PROCESSED and DELETED |
$index | int | Starting index of retrieved results Default: 0 |
$length | int | Result limit. Minimum value is 1. Maximum value is 1000. Default: 100 |
$startDate | string | Date to start retrieving transactions from. Minimum date is 2000-01-01. Maximum date is current date + 60 day. Default: current date - 60 days |
$endDate | string | Date to stop retrieving transactions from. Minimum date is $startDate. Maximum date is current date + 60 days. Default: current date + 60 days |
Get Electronic Invoice
You can get specific e-invoices belonging to a customer by running the getEInvoice
method.
$customerID = '12345678910';
$eInvoiceID = 'abc';
$eInvoice = $SBanken->getEInvoice($customerID, $eInvoiceID);
Parameters:
Parameter | Type | Description |
---|---|---|
$customerID required | string | Your social security numbers (11 characters long). |
$eInvoiceID required | string | ID of specified E-Invoice retrieved from getEInvoices |
Pay Electronic Invoice
You can pay any non-provessed/new electronic invoices using the postEInvoce
method.
Note: There is currently no way to specify the amount you want to pay on an e-invoice. You can only pay the minimum amount or the entire sum.
$customerID = '12345678910';
$eInvoiceID = 'abc';
$accountID = 'abc';
$payOnlyMinimumAmount = true;
$payment = $SBanken->postEInvoice($customerID, $eInvoiceID, $accountID, $payOnlyMinimumAmount);
Note: The account ID (
$accountID
) is corresponding to the IDs ofthe accounts retrieved fromgetAccounts
. Do not mix this with the account numbers. This will only work when using the account ID.
Parameters:
Parameter | Type | Description |
---|---|---|
$customerID required | string | Your social security numbers (11 characters long). |
$eInvoiceID required | string | ID of specified E-Invoice retrieved from getEInvoices |
$accountID required | string | ID of account you're using to pay the e-invoice |
$payOnlyMinimumAmount | bool | Set to true if you only want to pay the minimum amount of the e-invoice. If set to false, you will pay the entire sum. Default: false |
Batch requests
You can send multiple requests at the same time if you want to using batch requests.
Note: By using the
queue
method you will set the queue as default. No requests will be sent before you call theget
method, and all responses will return an instance of self.
$limit = null;
$responses = $SBanken->queue()->getAccounts('12345678910')->getCustomer('12345678910')->get($limit);
Note: The example above will send two requests at the same time, trying to get both the accounts and the customer data of
$customerID
and will return them in an array with the order being the order you've queued the requests.
Parameters:
Parameter | Type | Description |
---|---|---|
$limit | int|null | The number of requests to send. If set to null, it will send all queued requests. Default: null |
New features
If you have a new feature you would like us to consider adding to this module, you can post it here