Files
alfa-bank-sdk/src/Requests/NominalAccounts/UniversalRecipients/Requisites/GetUniversalRecipientRequisitesRequest.php

52 lines
2.5 KiB
PHP

<?php
/*
// MODULE_CONTRACT: Represents the API call to retrieve all requisites for a specific universal recipient.
// RESPONSIBILITY: To define the GET request for fetching payment requisites associated with a universal recipient.
// INPUTS: Universal recipient ID (string).
// OUTPUTS: A collection of RequisiteData DTOs.
*/
namespace Apoloz\AlfaBank\Requests\NominalAccounts\UniversalRecipients\Requisites;
// <SECTION name="module_imports" intent="Import DTO and Saloon components.">
// <BELIEF_STATE "This request returns a collection of `RequisiteData` DTOs.">
use Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries\Requisites\RequisiteData;
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 requisites for a universal recipient.">
// <BELIEF_STATE "This class encapsulates the logic for fetching all requisites related to a specific universal recipient.">
class GetUniversalRecipientRequisitesRequest 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 the universal recipient's unique identifier.">
// <BELIEF_STATE "The `universalRecipientId` is mandatory to specify which universal recipient's requisites are being queried.">
public function __construct(
protected string $universalRecipientId
) {}
// </SECTION>
// <SECTION name="endpoint_resolver" intent="Construct the request URI for universal recipient requisites.">
// <BELIEF_STATE "The endpoint targets the `requisites` sub-resource of a specific universal recipient.">
public function resolveEndpoint(): string
{
return "/api/na/jp/v1/universal-recipients/{$this->universalRecipientId}/requisites";
}
// </SECTION>
// <SECTION name="response_caster" intent="Map the JSON array response to a collection of DTOs.">
// <BELIEF_STATE "The API returns a JSON array. Using `RequisiteData::collect` automatically converts this array into a type-safe, iterable `DataCollection` of `RequisiteData` objects.">
public function createDtoFromResponse(Response $response): DataCollection
{
return RequisiteData::collect($response->json(), DataCollection::class);
}
// </SECTION>
}