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

87 lines
3.8 KiB
PHP

<?php
declare(strict_types=1);
/*
// MODULE_CONTRACT: Represents the SBP API call to change the account for a CashLink QR Code.
// RESPONSIBILITY: To define the POST request for updating the linked account for a specific CashLink QR.
// INPUTS: Terminal number (TermNo), QR Code ID, new account, and optional merchant/redirect details.
// OUTPUTS: Raw array response from the API.
*/
namespace Apoloz\AlfaBank\Sbp\Requests\CashLink;
// <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\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 change the account for a CashLink QR Code.">
// <BELIEF_STATE "This class encapsulates the logic for modifying a CashLink QR Code, which is a key management operation.">
class ChangeAccountForCashQrRequest extends Request implements HasBody
{
use HasStringBody;
// <SECTION name="http_method" intent="Declare the HTTP verb.">
// <BELIEF_STATE "Modifying a resource via an action is correctly represented by a POST request in the SBP API context.">
protected Method $method = Method::POST;
// </SECTION>
// <SECTION name="constructor" intent="Inject the mandatory and optional parameters for the account change request.">
// <BELIEF_STATE "The constructor requires `TermNo`, `qrcId`, and the new `account`. Optional parameters (`NewTermNo`, `NewMerchantId`, `redirectUrl`) allow for more complex reconfigurations.">
public function __construct(
protected string $TermNo,
protected string $qrcId,
protected string $account,
protected ?string $NewTermNo = null,
protected ?string $NewMerchantId = null,
protected ?string $redirectUrl = null,
) {}
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP CashLink QR Code account changes.">
// <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="Return the raw JSON response as an array.">
// <BELIEF_STATE "For this specific request, the response is currently returned as a raw array. A dedicated DTO could be created if a structured object is required.">
public function createDtoFromResponse(Response $response): array
{
return $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. Fields are conditionally added based on constructor parameters, ensuring the payload precisely matches the API specification.">
protected function defaultBody(): string
{
$bodyArray = [
'command' => 'ChangeAccForCashQRc',
'TermNo' => $this->TermNo,
'qrcId' => $this->qrcId,
'account' => $this->account,
];
if ($this->NewTermNo !== null) {
$bodyArray['NewTermNo'] = $this->NewTermNo;
}
if ($this->NewMerchantId !== null) {
$bodyArray['NewMerchantId'] = $this->NewMerchantId;
}
if ($this->redirectUrl !== null) {
$bodyArray['redirectUrl'] = $this->redirectUrl;
}
return CmsSigner::canonicalize($bodyArray);
}
// </SECTION>
}