dev-master
9999999-devTatra Banka - Open banking TB - REST API Client
MIT
The Requires
- php >=7.1
- nette/tester 2.0.x
by Pavol Biely
Wallogit.com
2017 © Pedro Peláez
Tatra Banka - Open banking TB - REST API Client
PHP REST API Client for Tatra Banka's Open Banking TB., (*2)
Sign up at developer.tatrabanka.sk to get access to the API., (*3)
Use composer to install this package., (*4)
Ask for the OAuth2 authorization, (*5)
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, (*6)
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, (*7)
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) {
// ...
}
Get the OAuth2 access token and prepare the payment instructions, (*8)
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, (*9)
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, (*10)
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) {
// ...
}
Tests are build with Nette Tester. You can run it like this:, (*11)
php -f tester ./ -c php.ini-mac --coverage coverage.html --coverage-src ../src
MIT License (c) Pavol Biely, (*12)
Read the provided LICENSE file for details., (*13)
Tatra Banka - Open banking TB - REST API Client
MIT