Files
alfa-bank-sdk/src/Requests/NominalAccounts/UniversalRecipients/GetUniversalRecipientsRequest.php
Anatoliy Poloz b15d29f8e9 fix(formating)
2026-01-28 03:36:26 +03:00

75 lines
3.4 KiB
PHP

<?php
declare(strict_types=1);
/*
// MODULE_CONTRACT: Represents the API call to retrieve a list of universal recipients.
// RESPONSIBILITY: To define the GET request for fetching a filtered, paginated list of universal recipients.
// INPUTS: Account number, type, and various optional filters.
// OUTPUTS: A collection of UniversalRecipientData DTOs.
*/
namespace Apoloz\AlfaBank\Requests\NominalAccounts\UniversalRecipients;
// <SECTION name="module_imports" intent="Import DTOs and Saloon components.">
// <BELIEF_STATE "This request returns a collection of `UniversalRecipientData` DTOs.">
use Apoloz\AlfaBank\Data\NominalAccounts\UniversalRecipients\UniversalRecipientData;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Spatie\LaravelData\DataCollection;
// </SECTION>
// <SECTION name="class_definition" intent="Define the request to get a list of universal recipients.">
// <BELIEF_STATE "This class encapsulates a complex query with multiple optional filters, simplifying its use.">
class GetUniversalRecipientsRequest extends Request
{
// <SECTION name="http_method" intent="Declare the HTTP verb.">
// <BELIEF_STATE "GET is the correct verb for retrieving a collection of resources.">
protected Method $method = Method::GET;
// </SECTION>
// <SECTION name="constructor" intent="Inject required filters and optional pagination parameters.">
// <BELIEF_STATE "The `accountNumber` and `type` are mandatory filters. Other fields are optional filters or pagination parameters, allowing for flexible querying.">
public function __construct(
protected string $accountNumber,
protected string $type,
protected ?int $limit = 100,
protected ?int $offset = 0,
protected ?bool $isActive = null,
protected ?string $date = null,
) {}
// </SECTION>
// <SECTION name="endpoint_resolver" intent="Define the URI for the universal recipients collection.">
// <BELIEF_STATE "The endpoint is the static collection URI; all filters are applied via query parameters.">
public function resolveEndpoint(): string
{
return '/api/na/jp/v1/universal-recipients';
}
// </SECTION>
// <SECTION name="response_caster" intent="Map the JSON response to a collection DTO.">
// <BELIEF_STATE "Casting the response to a `DataCollection` of `UniversalRecipientData` provides a type-safe, iterable object. The specific API response structure requires extracting from the `universalRecipients` key.">
public function createDtoFromResponse(Response $response): DataCollection
{
return UniversalRecipientData::collect($response->json('universalRecipients'), DataCollection::class);
}
// </SECTION>
// <SECTION name="query_builder" intent="Construct the query string from the provided filters.">
// <BELIEF_STATE "Using `array_filter` is a robust way to build the query array, as it automatically omits any optional parameters that were not provided (i.e., are `null`), resulting in a clean URL.">
protected function defaultQuery(): array
{
return array_filter([
'accountNumber' => $this->accountNumber,
'type' => $this->type,
'limit' => $this->limit,
'offset' => $this->offset,
'isActive' => $this->isActive,
'date' => $this->date,
], fn ($val) => $val !== null);
}
// </SECTION>
}