Fio bank REST API implementation in PHP
genericapt install php-mhujer-fio-apiPHP library that allows you to download and iterate through account balance changes from the Fio bank REST API.
Fio bank REST API implementation in PHP. It allows you to download and iterate through account balance changes.
There is a Symfony Bundle for using this library in a Symfony app.
composer require mhujer/fio-api-php<?php
require_once 'vendor/autoload.php';
$downloader = new FioApi\Downloader('TOKEN@todo');
$transactionList = $downloader->downloadSince(new \DateTimeImmutable('-1 week'));
foreach ($transactionList->getTransactions() as $transaction) {
var_dump($transaction); //object with getters
}
downloadFromTo(DateTimeInterface $from, DateTimeInterface $to): TransactionListdownloadSince(DateTimeInterface $since): TransactionListdownloadLast(): TransactionListsetLastId(string $id) - sets the last downloaded ID through the APIFio API enforces a 30-second cooldown between requests using the same token. If you make a request sooner, the API returns HTTP 409.
This library includes a built-in rate limiter that coordinates requests across multiple processes using a shared JSON file with file locking.
<?php
require_once 'vendor/autoload.php';
$store = new FioApi\RateLimit\JsonRateLimitStore('/tmp/fio-rate-limit.json');
$limiter = new FioApi\RateLimit\RateLimiter($store, true);
$downloader = new FioApi\Downloader('TOKEN@todo', null, $limiter);
$transactionList = $downloader->downloadSince(new \DateTimeImmutable('-1 week'));
In wait mode, if less than 30 seconds have passed since the last request for the same token, the limiter will sleep() for the remaining time before proceeding.
<?php
require_once 'vendor/autoload.php';
$store = new FioApi\RateLimit\JsonRateLimitStore('/tmp/fio-rate-limit.json');
$limiter = new FioApi\RateLimit\RateLimiter($store, false);
$downloader = new FioApi\Downloader('TOKEN@todo', null, $limiter);
try {
$transactionList = $downloader->downloadSince(new \DateTimeImmutable('-1 week'));
} catch (FioApi\Exceptions\TooGreedyException $e) {
// Handle: request came too soon, try again later
}
The JsonRateLimitStore uses flock() for file-level locking, so multiple cron jobs or workers sharing the same store file will safely stagger their API calls without colliding.
You can implement FioApi\RateLimit\RateLimitStoreInterface to use a database or other shared storage (e.g. Redis, SQLite) instead of a JSON file.
The library includes unit tests for all rate limiting components:
composer test
Fio API PHP works with PHP 7.4 or higher (including PHP 8.4).
Bugs and feature request are tracked on GitHub
Martin Hujer - https://www.martinhujer.cz
composer/ca-bundle as a required dependency instead of bundled root cert (thx @feldsam!)DateTime replaced with DateTimeImmutable (or DateTimeInterface)specification field in transaction (@soukiii)