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

68 lines
3.2 KiB
PHP

<?php
declare(strict_types=1);
/*
// MODULE_CONTRACT: Represents the API call to add a new requisite to a universal recipient.
// RESPONSIBILITY: To define the POST request for registering a new payment requisite for a universal recipient.
// INPUTS: Universal recipient ID, and a CreateRequisiteRequestData DTO.
// OUTPUTS: RequisiteData (DTO) of the newly added requisite.
*/
namespace Apoloz\AlfaBank\Requests\NominalAccounts\UniversalRecipients\Requisites;
// <SECTION name="module_imports" intent="Import DTOs and Saloon components for a JSON body request.">
// <BELIEF_STATE "This POST request requires specific DTOs for its JSON body and its response, along with Saloon's body-handling traits. It reuses `CreateRequisiteRequestData` from the Beneficiaries module.">
use Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries\Requisites\CreateRequisiteRequestData;
use Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries\Requisites\RequisiteData;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
// </SECTION>
// <SECTION name="class_definition" intent="Define the request to add a requisite to a universal recipient.">
// <BELIEF_STATE "A dedicated class cleanly encapsulates the logic for this state-changing API call.">
class AddUniversalRecipientRequisiteRequest extends Request implements HasBody
{
use HasJsonBody;
// <SECTION name="http_method" intent="Declare the HTTP verb.">
// <BELIEF_STATE "Adding a new sub-resource (requisite) to an existing resource (universal recipient) is typically a POST operation to the sub-resource collection.">
protected Method $method = Method::POST;
// </SECTION>
// <SECTION name="constructor" intent="Inject the universal recipient ID and the requisite data.">
// <BELIEF_STATE "The `universalRecipientId` is a mandatory path parameter, and `CreateRequisiteRequestData` ensures the payload is type-safe and valid.">
public function __construct(
protected string $universalRecipientId,
protected CreateRequisiteRequestData $data
) {}
// </SECTION>
// <SECTION name="endpoint_resolver" intent="Construct the request URI for adding a requisite.">
// <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 response to a RequisiteData DTO.">
// <BELIEF_STATE "The API returns the newly created requisite object. Casting it to a DTO provides a clean, type-safe object for the user.">
public function createDtoFromResponse(Response $response): RequisiteData
{
return RequisiteData::from($response->json());
}
// </SECTION>
// <SECTION name="body_builder" intent="Serialize the DTO for the request body.">
// <BELIEF_STATE "Delegating serialization to the DTO's `toArray` method ensures the payload is correctly formatted for the API.">
protected function defaultBody(): array
{
return $this->data->toArray();
}
// </SECTION>
}