getkevin / kevin-php
PHP client for kevin. platform.
Installs: 470 382
Dependents: 1
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 3
Open Issues: 0
Requires
- php: >=5.6
- ext-json: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.19
README
PHP client implementing kevin. API.
Prerequisites
- PHP 5.6 or later
Installation
Composer
- To install latest kevin. PHP Client repository using composer:
composer require getkevin/kevin-php
- Using Composer autoloader, include kevin. PHP Client:
require('vendor/autoload.php');
Detailed information about available versions can be found at packagist repository:
Usage Examples
Parameter names and response data match those defined in API documentation.
Detailed API documentation can be found here.
Initialization
use Kevin\Client; $clientId = 'my-client-id'; $clientSecret = 'my-client-secret'; $options = ['error' => 'array', 'version' => '0.3', 'lang' => 'en']; $kevinClient = new Client($clientId, $clientSecret, $options);
$clientId
- Your client id. Your can get it in kevin. platform console.
$clientSecret
- Your client secret. Your can get it in kevin. platform console.
$options
- Optional options array.
error
- Defines return type of error data. Possible values are:array
- returns an array on error,exception
- throws an exception on error, default value isexception
.
version
- Selects API versions to use. Default value is0.3
. Possible values are0.1
,0.2
or0.3
.
lang
- a two-letter lowercase language code defined in ISO 639-1 standart. Sets the language of the frame page.
1. Authentication
1.1 Get supported countries
$response = $kevinClient->auth()->getCountries();
1.2 Get supported banks
$attr = ['countryCode' => 'LT']; $response = $kevinClient->auth()->getBanks($attr);
1.3 Get supported bank
$bankId = 'SEB_LT_SAND'; $response = $kevinClient->auth()->getBank($bankId);
1.4 Get project settings
$response = $kevinClient->auth()->getProjectSettings();
1.5 Start authentication
$attr = [ 'redirectPreferred' => 'false', 'scopes' => 'payments,accounts_basic', 'Request-Id' => 'your-guid', 'Redirect-URL' => 'https://redirect.kevin.eu/authorization.html' ]; $response = $kevinClient->auth()->authenticate($attr);
1.6 Receive token
$attr = ['code' => 'your-auth-code']; // ...or $attr = 'your-auth-code'; $response = $kevinClient->auth()->receiveToken($attr);
1.7 Refresh token
$attr = ['refreshToken' => 'your-refresh-token']; // ...or $attr = 'your-refresh-token'; $response = $kevinClient->auth()->refreshToken($attr);
1.8 Receive token content
$attr = ['Authorization' => 'your-bearer-token']; // ...or $attr = 'your-bearer-token'; // ...or $attr = 'Bearer your-bearer-token'; $response = $kevinClient->auth()->receiveTokenContent($attr);
2. Payment
2.1 Initiate bank payment
$attr = [ 'Redirect-URL' => 'https://redirect.kevin.eu/payment.html', 'description' => 'Test', 'currencyCode' => 'EUR', 'amount' => '0.01', 'bankPaymentMethod' => [ 'endToEndId' => '1', 'creditorName' => 'John Smith', 'creditorAccount' => [ 'iban' => 'LT0000000000000000' ], ], ]; $response = $kevinClient->payment()->initPayment($attr);
2.2 Initiate card payment
$attr = [ 'Redirect-URL' => 'https://redirect.kevin.eu/payment.html', 'description' => 'Test', 'currencyCode' => 'EUR', 'amount' => '0.01', 'bankPaymentMethod' => [ 'endToEndId' => '1', 'creditorName' => 'John Smith', 'creditorAccount' => [ 'iban' => 'LT0000000000000000', ], ], 'cardPaymentMethod' => [], 'paymentMethodPreferred' => 'card', ]; $response = $kevinClient->payment()->initPayment($attr);
2.3 Initiate hybrid payment
$attr = [ 'Redirect-URL' => 'https://redirect.kevin.eu/payment.html', 'description' => 'Test', 'currencyCode' => 'EUR', 'amount' => '0.01', 'bankPaymentMethod' => [ 'endToEndId' => '1', 'creditorName' => 'John Smith', 'creditorAccount' => [ 'iban' => 'LT0000000000000000' ], ], 'cardPaymentMethod' => [], ]; $response = $kevinClient->payment()->initPayment($attr);
2.4 Get payment
$paymentId = 'your-payment-id'; $response = $kevinClient->payment()->getPayment($paymentId);
2.5 Get payment status
$paymentId = 'your-payment-id'; $response = $kevinClient->payment()->getPaymentStatus($paymentId);
2.6 Initiate payment refund
$paymentId = 'your-payment-id'; $attr = [ 'amount' => '1.00', 'Webhook-URL' => 'https://yourapp.com/notify' ]; $response = $kevinClient->payment()->initiatePaymentRefund($paymentId, $attr);
2.7 Get payment refunds
$paymentId = 'your-payment-id'; $response = $kevinClient->payment()->getPaymentRefunds($paymentId);
3. Account
3.1 Get accounts
$accessToken = 'your-bearer-token'; $attr = [ 'Authorization' => $accessToken, 'PSU-IP-Address' => 'your-ip-address', 'PSU-User-Agent' => 'your-user-agent', 'PSU-IP-Port' => 'your-ip-port', 'PSU-Http-Method' => 'GET', 'PSU-Device-ID' => 'your-device-id' ]; $response = $kevinClient->account()->getAccountList($attr);
3.2 Get account details
$accountId = 'your-account-id'; $accessToken = 'your-bearer-token'; $attr = [ 'Authorization' => $accessToken, 'PSU-IP-Address' => 'your-ip-address', 'PSU-User-Agent' => 'your-user-agent', 'PSU-IP-Port' => 'your-ip-port', 'PSU-Http-Method' => 'GET', 'PSU-Device-ID' => 'your-device-id' ]; $response = $kevinClient->account()->getAccountDetails($accountId, $attr);
3.3 Get account transactions
$accountId = 'your-account-id'; $accessToken = 'your-bearer-token'; $attr = [ 'Authorization' => $accessToken, 'PSU-IP-Address' => 'your-ip-address', 'PSU-User-Agent' => 'your-user-agent', 'PSU-IP-Port' => 'your-ip-port', 'PSU-Http-Method' => 'GET', 'PSU-Device-ID' => 'your-device-id', 'dateFrom' => '2021-09-01', 'dateTo' => '2021-09-15' ]; $response = $kevinClient->account()->getAccountTransactions($accountId, $attr);
3.4 Get account balance
$accountId = 'your-account-id'; $accessToken = 'your-bearer-token'; $attr = [ 'Authorization' => $accessToken, 'PSU-IP-Address' => 'your-ip-address', 'PSU-User-Agent' => 'your-user-agent', 'PSU-IP-Port' => 'your-ip-port', 'PSU-Http-Method' => 'GET', 'PSU-Device-ID' => 'your-device-id' ]; $response = $kevinClient->account()->getAccountBalance($accountId, $attr);
4. Security
4.1 Verify signature
❗ We recommend ignoring the webhook if the signature is older than 5 minutes.
use Kevin\SecurityManager; $endpointSecret = 'your-endpoint-secret'; $webhookUrl = 'your-webhook-url'; // Timestamp is provided in milliseconds $timestampTimeout = 300000; $requestBody = file_get_contents("php://input"); $headers = getallheaders(); $isValid = SecurityManager::verifySignature($endpointSecret, $requestBody, $headers, $webhookUrl, $timestampTimeout);
Contributing
Before making any code changes, make sure to run composer install
to install development requirements.
We are using PHP CS Fixer GitHub action to conduct code style checks for each commit and pull request. Make sure to run composer fix-style
before
committing changes to make sure your code matches our style standards. Pull requests with failed style checks will not
be approved.
WARNING: we use risky rules so make sure to check for breaking style fixes.
Style errors and violated rules log can be viewed by running composer check-style
command.
Support
Email: help@kevin.eu
License
- MIT license
- Copyright© 2020 kevin.