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

79 lines
3.6 KiB
PHP

<?php
declare(strict_types=1);
/*
// MODULE_CONTRACT: Represents the SBP API call to get the status of a CashLink Universal QR Code.
// RESPONSIBILITY: To define the POST request for checking the state of a specific Digital Ruble CashLink QR.
// INPUTS: GetCashUniQrStatusRequestData (DTO) with relevant parameters.
// OUTPUTS: GetCashUniQrStatusResponseData (DTO).
*/
namespace Apoloz\AlfaBank\Sbp\Requests\DigitalRuble\CashLink;
// <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.">
use Apoloz\AlfaBank\Sbp\Data\DigitalRuble\CashLink\GetCashUniQrStatusRequestData;
use Apoloz\AlfaBank\Sbp\Data\DigitalRuble\CashLink\GetCashUniQrStatusResponseData;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
// </SECTION>
// <SECTION name="class_definition" intent="Define the request to get the status of a CashLink Uni QR Code.">
// <BELIEF_STATE "This class encapsulates the logic for querying the status of a Digital Ruble CashLink QR Code, which is crucial for tracking payment flows.">
class GetCashUniQrStatusRequest 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 DTO containing the status request data.">
// <BELIEF_STATE "Using a strongly-typed DTO (`GetCashUniQrStatusRequestData`) ensures that all necessary information for the status query is provided and correctly structured.">
public function __construct(
protected GetCashUniQrStatusRequestData $data
) {}
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP CashLink Uni QR Code status queries.">
// <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 `GetCashUniQrStatusResponseData` DTO provides a type-safe and structured object for the status of the CashLink Uni QR Code.">
public function createDtoFromResponse(Response $response): GetCashUniQrStatusResponseData
{
return GetCashUniQrStatusResponseData::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. The `TermNo`, `uniQrId`, and `paramsId` identify the target. Optional fields like `messageID` and `payrrn` provide additional context.">
protected function defaultBody(): string
{
$bodyArray = [
'command' => 'GetCashUniQrStatus',
'TermNo' => $this->data->TermNo,
'uniQrId' => $this->data->uniQrId,
'paramsId' => $this->data->paramsId,
];
if ($this->data->messageID !== null) {
$bodyArray['messageID'] = $this->data->messageID;
}
if ($this->data->payrrn !== null) {
$bodyArray['payrrn'] = $this->data->payrrn;
}
return CmsSigner::canonicalize($bodyArray);
}
// </SECTION>
}