Files
alfa-bank-sdk/src/Sbp/Requests/Subscription/GetQrSubStatusRequest.php
Anatoliy Poloz b7b2a8fd61 refactor(Sbp)
2026-03-17 12:26:30 +03:00

78 lines
3.4 KiB
PHP

<?php
declare(strict_types=1);
/*
// MODULE_CONTRACT: Represents the SBP API call to get the status of a QR Code subscription.
// RESPONSIBILITY: To define the POST request for checking the state of a specific SBP subscription.
// INPUTS: Terminal number (TermNo), QR Code ID, and optional request period (RQperiod).
// OUTPUTS: Raw array response from the API.
*/
namespace Apoloz\AlfaBank\Sbp\Requests\Subscription;
// <SECTION name="module_imports" intent="Import Saloon components for a JSON body request.">
// <BELIEF_STATE "This POST request utilizes `HasBody` and `HasJsonBody` for proper payload serialization. It currently returns a raw array response.">
use Apoloz\AlfaBank\Sbp\Data\Subscription\GetQrSubStatusResponseData;
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 get the status of a QR Code subscription.">
// <BELIEF_STATE "This class encapsulates the logic for querying the status of an SBP subscription, which is crucial for managing recurring payments.">
class GetQrSubStatusRequest extends Request implements HasBody
{
use HasStringBody;
// <SECTION name="http_method" intent="Declare the HTTP verb.">
// <BELIEF_STATE "Even though it retrieves data, SBP status checks are often performed via POST requests with a JSON body.">
protected Method $method = Method::POST;
// </SECTION>
// <SECTION name="constructor" intent="Inject the mandatory and optional parameters for the subscription status request.">
// <BELIEF_STATE "The constructor requires `TermNo` and `qrcId` to identify the subscription. `RQperiod` is an optional filter.">
public function __construct(
protected string $TermNo,
protected string $qrcId,
protected ?string $RQperiod = null
) {}
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP subscription status checks.">
// <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 `GetQrSubStatusResponseData` DTO provides a structured object for the status of the subscription.">
public function createDtoFromResponse(Response $response): GetQrSubStatusResponseData
{
return GetQrSubStatusResponseData::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. Other fields are conditionally added, ensuring the payload precisely matches the API specification.">
protected function defaultBody(): string
{
$bodyArray = [
'command' => 'GetQRCSubStatus',
'TermNo' => $this->TermNo,
'qrcId' => $this->qrcId,
];
if ($this->RQperiod !== null) {
$bodyArray['RQperiod'] = $this->RQperiod;
}
return CmsSigner::canonicalize($bodyArray);
}
// </SECTION>
}