Skip to content

kduma-OSS/LV-emSzmal-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

emSzmal Banking API wrapper in PHP

Latest Version on Packagist Software License Total Downloads

emSzmal Banking API wrapper in PHP

Install

Via Composer

$ composer require kduma/emszmal-api

Usage

$api = new \KDuma\emSzmalAPI\emSzmalAPI(
    api_id: $api_id, 
    api_key: $api_key,
    timeout: 120,
    cache_provider: new \KDuma\emSzmalAPI\CacheProviders\NoCacheProvider(),
);

$session = $api->SayHello();

$BankCredentials = new \KDuma\emSzmalAPI\DTO\BankCredentials(
    provider: \KDuma\emSzmalAPI\Enums\Bank::PKOiPKO, 
    login: 'Login', 
    password: 'Password',
    user_context: '',
    token_value: '',
);

$accounts = $api->GetAccountsList(
    session: $session,
    credentials: $BankCredentials,
);

$transactions = $api->GetAccountHistory(
    session: $session,
    account_number: "account number", 
    date_since: '2016-10-25', 
    date_to: '2016-10-30', 
    credentials: $BankCredentials,
);

$api->SayBye(
    session: $session,
);

Laravel Usage

Setup

Add following entries to your .env file:

EMSZMAL_API_ID="<api id>"
EMSZMAL_API_KEY=<api key>

EMSZMAL_BANK_PROVIDER_ID=<provider ID>
EMSZMAL_BANK_LOGIN=<login>
EMSZMAL_BANK_PASSWORD=<password>
EMSZMAL_BANK_USER_TOKEN=<token from bank>

Usage

You can resolve emSzmalAPI::class class:

$api = app(\KDuma\emSzmalAPI\emSzmalAPI::class);

$session = $api->SayHello();

$accounts = $api->GetAccountsList(
    session: $session,
);

$transactions = $api->GetAccountHistory(
    session: $session,
    account_number: 'account number', 
    date_since: '2016-10-25', 
    date_to: '2016-10-30',
);

$api->SayBye(
    session: $session,
);

or You can use injection container

Route::get('/api', function (\KDuma\emSzmalAPI\emSzmalAPI $api) {
    $session = $api->SayHello();

    $accounts = $api->GetAccountsList(
        session: $session,
    );
    
    $transactions = $api->GetAccountHistory(
        session: $session,
        account_number: 'account number', 
        date_since: '2016-10-25', 
        date_to: '2016-10-30',
    );

    $api->SayBye(
        session: $session,
    );
});

Multiple Bank Credentials

You can use multiple bank credentials. First, run the following command to copy config file:

php artisan vendor:publish --provider="KDuma\emSzmalAPI\Laravel\ServiceProvider"

In Your config/emszmalapi.php file, in bank_credentials section add additional credentials:

'bank_credentials' => [
    'bank_1' => [
        'provider' => env('EMSZMAL_BANK_1_PROVIDER_ID'),
        'login' => env('EMSZMAL_BANK_1_LOGIN'),
        'password' => env('EMSZMAL_BANK_1_PASSWORD'),
        'user_context' => env('EMSZMAL_BANK_1_USER_CONTEXT', "I"),
        'token_value' => env('EMSZMAL_BANK_1_USER_TOKEN', ''),
    ],
    'bank_2' => [
        'provider' => env('EMSZMAL_BANK_2_PROVIDER_ID'),
        'login' => env('EMSZMAL_BANK_2_LOGIN'),
        'password' => env('EMSZMAL_BANK_2_PASSWORD'),
        'user_context' => env('EMSZMAL_BANK_2_USER_CONTEXT', "I"),
        'token_value' => env('EMSZMAL_BANK_2_USER_TOKEN', ''),
    ],
],

Now you can use the alias when calling API methods:

$api = app(\KDuma\emSzmalAPI\emSzmalAPI::class);

$session = $api->SayHello();

$bank_1_accounts = $api->GetAccountsList(
    session: $session,
    credentials: 'bank_1',
);
$bank_1_transactions = $api->GetAccountHistory(
    session: $session,
    account_number: "account number", 
    date_since: '2016-10-25', 
    date_to: '2016-10-30', 
    credentials: 'bank_1',
);


$bank_2_accounts = $api->GetAccountsList(
    session: $session,
    credentials: 'bank_2',
);

$bank_2_transactions = $api->GetAccountHistory(
    session: $session,
    account_number: "account number", 
    date_since: '2016-10-25', 
    date_to: '2016-10-30', 
    credentials: 'bank_2',
);

$api->SayBye(
    session: $session,
);

Credits

License

The MIT License (MIT). Please see License File for more information.