forked from apoloz/alfa-bank-sdk
fix(statements/transactions)
This commit is contained in:
@@ -1,48 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
// MODULE_CONTRACT: Represents the API call to retrieve a list of account transactions.
|
||||
// RESPONSIBILITY: To define the HTTP method, endpoint, and query parameters for fetching statement data, and to map the response to a structured collection DTO.
|
||||
// INPUTS: Account number, date range, and pagination parameters.
|
||||
// OUTPUTS: TransactionCollectionData (a DTO containing a list of transactions).
|
||||
// LINKS: AlfaBankConnector.php#paginate
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Requests\Statement;
|
||||
|
||||
// <SECTION name="module_imports" intent="Import the response DTO and Saloon framework components.">
|
||||
// <BELIEF_STATE "This request requires the `TransactionCollectionData` DTO to structure its response. It's a GET request, so it doesn't need body-related traits.">
|
||||
use Apoloz\AlfaBank\Data\Statement\TransactionCollectionData;
|
||||
use Apoloz\AlfaBank\Traits\HasAlfaPagination;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Http\Response;
|
||||
|
||||
class GetTransactionsRequest extends Request
|
||||
{
|
||||
use HasAlfaPagination;
|
||||
|
||||
protected Method $method = Method::GET;
|
||||
|
||||
public function __construct(
|
||||
protected string $accountNumber,
|
||||
protected string $statementDate,
|
||||
?int $limit = 1000,
|
||||
?int $offset = 0
|
||||
) {
|
||||
$this->limit = $limit;
|
||||
$this->offset = $offset;
|
||||
}
|
||||
protected int $page = 1,
|
||||
protected ?string $curFormat = null,
|
||||
) {}
|
||||
|
||||
public function resolveEndpoint(): string
|
||||
{
|
||||
return '/api/jp/v1/statement/transactions';
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="response_dto_caster" intent="Transform the raw API JSON response into a structured collection DTO.">
|
||||
// <BELIEF_STATE "The API returns a list of transactions. Casting this directly to a `TransactionCollectionData` DTO provides a type-safe, iterable object for the end-user, which is a significant improvement over dealing with raw arrays.">
|
||||
public function createDtoFromResponse(Response $response): TransactionCollectionData
|
||||
{
|
||||
return TransactionCollectionData::from($response->json());
|
||||
@@ -50,10 +32,11 @@ class GetTransactionsRequest extends Request
|
||||
|
||||
protected function defaultQuery(): array
|
||||
{
|
||||
return array_merge([
|
||||
return array_filter([
|
||||
'accountNumber' => $this->accountNumber,
|
||||
'statementDate' => $this->statementDate,
|
||||
], $this->getPaginationQuery());
|
||||
'page' => $this->page,
|
||||
'curFormat' => $this->curFormat,
|
||||
], fn ($v) => $v !== null);
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user