Skip to content

Commit 63973f9

Browse files
committed
Added balances
1 parent 245b0ad commit 63973f9

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

src/Config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ private function __construct(
3434
public string $authTokenUri,
3535
public string $adaaApiKey,
3636
public string $adaaUri,
37-
) {}
37+
) {
38+
}
3839

3940

4041
public static function createFromDotEnv(SplFileInfo $filePath): self

src/Entity/Balance.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace SpojeNet\KbAccountsApi\Entity;
4+
5+
class Balance
6+
{
7+
public function __construct(
8+
public readonly BalanceType $type,
9+
public readonly Amount $amount,
10+
public readonly CreditDebit $creditDebitIndicator,
11+
public readonly \DateTimeImmutable $validAt,
12+
) {
13+
}
14+
}

src/Entity/BalanceType.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace SpojeNet\KbAccountsApi\Entity;
4+
5+
enum BalanceType: string
6+
{
7+
/**
8+
* Opening balance of the day = closing balance of the previous day, i.e. day - 1.
9+
* Are only the booked transactions, what the day opens with, closed with the previous day's accounting.
10+
*/
11+
case Opening = 'PREVIOUSLY_CLOSED_BOOK';
12+
13+
/**
14+
* This type of balance is not used.
15+
*/
16+
case Booked = 'CLOSING_BOOKED';
17+
18+
/**
19+
* Includes everything, even unbooked transactions = current balance available to you.
20+
*/
21+
case Available = 'CLOSING_AVAILABLE';
22+
}

src/KbClient.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use SplFileInfo;
1414
use SpojeNet\KbAccountsApi\Entity\Account;
1515
use SpojeNet\KbAccountsApi\Entity\ApplicationReq;
16+
use SpojeNet\KbAccountsApi\Entity\Balance;
1617
use SpojeNet\KbAccountsApi\Entity\ClientReq;
1718
use SpojeNet\KbAccountsApi\Entity\ClientRes;
1819
use SpojeNet\KbAccountsApi\Entity\Statement;
@@ -27,6 +28,7 @@
2728
use SpojeNet\KbAccountsApi\Utils\Random;
2829

2930
use function array_filter;
31+
use function array_map;
3032
use function array_unique;
3133
use function base64_decode;
3234
use function base64_encode;
@@ -398,6 +400,21 @@ public function statementPdf(string $accessToken, StatementPdfSelection $selecti
398400
);
399401
}
400402

403+
404+
/**
405+
* @throws KbClientException
406+
* @return Balance[]
407+
*/
408+
public function balances(string $accessToken, string $accountId): array
409+
{
410+
$data = $this->sendAdaaRequest(
411+
accessToken: $accessToken,
412+
endpoint: "/accounts/{$accountId}/balances",
413+
);
414+
415+
return array_map(static fn (array $item) => DtoMapper::map(Balance::class, $item), $data);
416+
}
417+
401418
/* Utilities */
402419

403420
/**

0 commit comments

Comments
 (0)