Skip to content

PHP REST API Client for Tatra Banka's Open Banking TB.

License

Notifications You must be signed in to change notification settings

pavolbiely/tatrabanka-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tatra Banka - Open banking TB

Build Status Coverage Status Donate

PHP REST API Client for Tatra Banka's Open Banking TB.

Sign up at developer.tatrabanka.sk to get access to the API.

Installation

Use composer to install this package.

Example of usage

Accounts API

Ask for the OAuth2 authorization

use TatraBankaApi\Accounts;

$clientId = '';
$clientSecret = '';
$redirectUri = '';

$tb = new Accounts($clientId, $clientSecret, $redirectUri);
$tb->useSandbox(true);
header('Location: ' . $tb->getAuthorizationUrl());

Exchange the OAuth2 authorization code for an access token

use TatraBankaApi\Accounts;
use TatraBankaApi\TatraBankaApiException;

$clientId = '';
$clientSecret = '';
$redirectUri = '';

try {
    $tb = new Accounts($clientId, $clientSecret, $redirectUri);
    $tb->useSandbox(true);
    $tb->requestAccessToken($_GET['code']); // using authorization_code grand type
} catch (TatraBankaApiException $e) {
    // ...
}

General usage

use TatraBankaApi\Accounts;
use TatraBankaApi\TatraBankaApiException;

$clientId = '';
$clientSecret = '';
$redirectUri = '';

try {
    $tb = new Accounts($clientId, $clientSecret, $redirectUri);
    $tb->useSandbox(true);

    if ($tb->isAuthorized()) {
        // The operation provides the relevant data about bank customer's accounts in form of a list.
        print_r($tb->getAccounts());

        // The operation provides the relevant data from a bank customer's account identified by IBAN.
        print_r($tb->postAccountInfo('SK0511000000002600000054'));

        // The list of financial transactions perfomed on a customer's bank account withing a date period.
        print_r($tb->postTransactions('SK0511000000002600000054', Accounts::STATUS_ALL, new \DateTime('-1 month'),  new \DateTime('now'), 1, 10));
    }
} catch (TatraBankaApiException $e) {
    // ...
}

Payments API

Get the OAuth2 access token and prepare the payment instructions

use TatraBankaApi\Payments;
use TatraBankaApi\PaymentAmount;
use TatraBankaApi\PaymentParticipant;
use TatraBankaApi\TatraBankaApiException;

$clientId = '';
$clientSecret = '';
$redirectUri = '';

try {
    $tb = new Payments($clientId, $clientSecret, $redirectUri);
    $tb->useSandbox(true);
    $tb->requestAccessToken(); // using client_credentials grand type
    $debtor = new PaymentParticipant('John Doe', 'SK0511000000002600000054');
    $creditor = new PaymentParticipant('John Doe', 'DE89370400440532013000');
    $amount = new PaymentAmount(100.15);
    $response = $tb->postPaymentSba(md5(uniqid('', true)), $debtor, $creditor, $amount, new \DateTime('tomorrow'), new \DateTime('now'), '/VS123/SS456/KS0308', 'Test');
    $authUrl = $tb->getAuthorizationUrl(['orderId' => $response->orderId]);
    header('Location: ' . $authUrl);
    exit;
} catch (TatraBankaApiException $e) {
    // ...
}

Exchange the OAuth2 authorization code for an access token and submit the payment

use TatraBankaApi\Payments;
use TatraBankaApi\TatraBankaApiException;

$clientId = '';
$clientSecret = '';
$redirectUri = '';

try {
    $tb = new Payments($clientId, $clientSecret, $redirectUri);
    $tb->useSandbox(true);
    $tb->requestAccessToken($_GET['code']); // using authorization_code grand type
    print_r($tb->postPaymentSubmission());

} catch (TatraBankaApiException $e) {
    // ...
}

Get payment status

use TatraBankaApi\Payments;
use TatraBankaApi\TatraBankaApiException;

$clientId = '';
$clientSecret = '';
$redirectUri = '';
$orderId = ''; // order ID is generated by the postPaymentSba method

try {
    $tb = new Payments($clientId, $clientSecret, $redirectUri);
    $tb->useSandbox(true);
    $tb->requestAccessToken(); // using client_credentials grand type
    print_r($tb->getPaymentStatus(['orderId' => $orderId]));

} catch (TatraBankaApiException $e) {
    // ...
}

How to run tests?

Tests are build with Nette Tester. You can run it like this:

php -f tester ./ -c php.ini-mac --coverage coverage.html --coverage-src ../src

Minimum requirements

  • PHP 7.1+
  • php-curl

License

MIT License (c) Pavol Biely

Read the provided LICENSE file for details.

About

PHP REST API Client for Tatra Banka's Open Banking TB.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published