72 lines
3.2 KiB
PHP
72 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
/*
|
|
// MODULE_CONTRACT: Represents the SBP API call to block a QR Code.
|
|
// RESPONSIBILITY: To define the POST request for deactivating a specific QR Code associated with a terminal.
|
|
// INPUTS: BlockQrRequestData (TermNo, qrcId, reason).
|
|
// OUTPUTS: Raw array response from the API.
|
|
*/
|
|
|
|
namespace Apoloz\AlfaBank\Sbp\Requests\Management;
|
|
|
|
// <SECTION name="module_imports" intent="Import DTO and Saloon components for a JSON body request.">
|
|
// <BELIEF_STATE "This POST request requires the `BlockQrRequestData` DTO for its JSON body and utilizes `HasBody` and `HasJsonBody` for proper payload serialization. It currently returns a raw array response.">
|
|
use Apoloz\AlfaBank\Sbp\Data\Management\BlockQrRequestData;
|
|
use Apoloz\AlfaBank\Sbp\Data\Management\SbpManagementResponseData;
|
|
use Apoloz\AlfaBank\Utils\CmsSigner;
|
|
use Saloon\Contracts\Body\HasBody;
|
|
use Saloon\Enums\Method;
|
|
use Saloon\Http\Request;
|
|
use Saloon\Http\Response;
|
|
use Saloon\Traits\Body\HasStringBody;
|
|
|
|
// </SECTION>
|
|
|
|
// <SECTION name="class_definition" intent="Define the request to block a QR Code.">
|
|
// <BELIEF_STATE "This class encapsulates the logic for blocking an SBP QR Code, which is a critical management operation.">
|
|
class BlockQrRequest extends Request implements HasBody
|
|
{
|
|
use HasStringBody;
|
|
|
|
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
|
// <BELIEF_STATE "Blocking a resource is an action that changes the system state, so POST is the correct verb.">
|
|
protected Method $method = Method::POST;
|
|
// </SECTION>
|
|
|
|
// <SECTION name="constructor" intent="Inject the DTO containing the blocking request data.">
|
|
// <BELIEF_STATE "Using a strongly-typed DTO (`BlockQrRequestData`) ensures that all necessary information for blocking the QR Code is provided and correctly structured.">
|
|
public function __construct(
|
|
protected BlockQrRequestData $data
|
|
) {}
|
|
|
|
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP QR Code blocking.">
|
|
// <BELIEF_STATE "The SBP API often uses generic endpoints with a 'command' field in the body, implying the endpoint itself might be empty or a base SBP URL.">
|
|
public function resolveEndpoint(): string
|
|
{
|
|
return ''; // Endpoint is determined by SbpConnector's base URL
|
|
}
|
|
// </SECTION>
|
|
|
|
// <SECTION name="response_caster" intent="Map the JSON response to a DTO.">
|
|
// <BELIEF_STATE "Casting the response to a `SbpManagementResponseData` DTO provides a structured object for the result of the block operation.">
|
|
public function createDtoFromResponse(Response $response): SbpManagementResponseData
|
|
{
|
|
return SbpManagementResponseData::from($response->json());
|
|
}
|
|
// </SECTION>
|
|
|
|
// <SECTION name="body_builder" intent="Construct the JSON body for the request.">
|
|
// <BELIEF_STATE "The `command` field specifies the operation to the SBP API. Using the DTO's `toArray` method ensures the payload is correctly structured.">
|
|
protected function defaultBody(): string
|
|
{
|
|
$bodyArray = array_merge(
|
|
['command' => 'BlockQRcId'],
|
|
$this->data->toArray()
|
|
);
|
|
|
|
return CmsSigner::canonicalize($bodyArray);
|
|
}
|
|
// </SECTION>
|
|
}
|