Compare commits

...

3 Commits

Author SHA1 Message Date
a412af3e07 fix(transactions) 2026-06-02 19:46:51 +03:00
9b62a59705 saloon update 2026-04-25 13:59:25 +03:00
Anatoliy Poloz
d4db68f2e7 refactor(error): handling 2026-04-07 18:47:53 +03:00
4 changed files with 19 additions and 10 deletions

View File

@@ -11,8 +11,8 @@
],
"require": {
"php": "^8.4",
"saloonphp/saloon": "^3.0",
"saloonphp/laravel-plugin": "^3.0",
"saloonphp/saloon": "^4.0",
"saloonphp/laravel-plugin": "^4.0",
"saloonphp/pagination-plugin": "^2.0",
"spatie/laravel-data": "^4.0",
"guzzlehttp/guzzle": "^7.0",

View File

@@ -13,7 +13,6 @@ namespace Apoloz\AlfaBank\Data\Statement;
// <SECTION name="module_imports" intent="Import necessary DTOs and Spatie Laravel Data components.">
// <BELIEF_STATE "This collection DTO relies on `PaginationData` for metadata and `TransactionData` for the individual items. `DataCollection` and `DataCollectionOf` are Spatie Data features for handling typed arrays of DTOs.">
use Apoloz\AlfaBank\Data\PaginationData;
use Spatie\LaravelData\Attributes\DataCollectionOf;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\DataCollection;
@@ -27,9 +26,9 @@ class TransactionCollectionData extends Data
// <SECTION name="constructor_properties" intent="Define the properties of the transaction collection.">
// <BELIEF_STATE "The collection structure includes pagination metadata (`pagination`) and the actual list of transactions (`transactions`). The `#[DataCollectionOf(TransactionData::class)]` attribute is crucial for ensuring that each item in the `transactions` array is automatically cast to a `TransactionData` DTO.">
public function __construct(
public PaginationData $pagination,
#[DataCollectionOf(TransactionData::class)]
public DataCollection $transactions
) {}
) {
}
// </SECTION>
}

View File

@@ -27,8 +27,7 @@ class GetTransactionsRequest extends Request
public function __construct(
protected string $accountNumber,
protected string $executeDateFrom,
protected string $executeDateTo,
protected string $statementDate,
?int $limit = 1000,
?int $offset = 0
) {
@@ -53,8 +52,7 @@ class GetTransactionsRequest extends Request
{
return array_merge([
'accountNumber' => $this->accountNumber,
'executeDateFrom' => $this->executeDateFrom,
'executeDateTo' => $this->executeDateTo,
'statementDate' => $this->statementDate,
], $this->getPaginationQuery());
}
// </SECTION>

View File

@@ -43,7 +43,8 @@ trait HasAlfaErrorHandling
if (str_contains($contentType, 'application/json')) {
$data = $response->json();
$errorCode = $data['error'] ?? $data['ErrorCode'] ?? 'HTTP_' . $response->status();
$errorDescription = $data['error_description'] ?? $data['message'] ?? 'Request failed';
$rawDescription = $data['error_description'] ?? $data['message'] ?? 'Request failed';
$errorDescription = $this->decodeBankMessage($rawDescription);
} else {
$errorCode = 'HTTP_' . $response->status();
$errorDescription = 'Request failed with status ' . $response->status();
@@ -55,4 +56,15 @@ trait HasAlfaErrorHandling
"({$requestId}) {$errorDescription}"
);
}
private function decodeBankMessage(string $message): string
{
$decoded = preg_replace_callback(
'/%u([0-9A-Fa-f]{4})/',
fn ($m) => mb_convert_encoding(pack('H*', $m[1]), 'UTF-8', 'UCS-2BE'),
$message
);
return urldecode($decoded);
}
}