forked from apoloz/alfa-bank-sdk
72 lines
3.1 KiB
PHP
72 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
/*
|
|
// MODULE_CONTRACT: Represents the SBP API call to change the terminal number for a CashLink QR Code.
|
|
// RESPONSIBILITY: To define the POST request for updating the linked terminal for a specific CashLink QR.
|
|
// INPUTS: Terminal number (TermNo) and QR Code ID.
|
|
// 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 terminal number for a CashLink QR Code.">
|
|
// <BELIEF_STATE "This class encapsulates the logic for modifying a CashLink QR Code, specifically its associated terminal, which is a key management operation.">
|
|
class ChangeTermNoForCashQrRequest 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 terminal number and QR Code ID.">
|
|
// <BELIEF_STATE "The constructor requires `TermNo` and `qrcId` to identify the target QR Code for which the terminal number is being changed.">
|
|
public function __construct(
|
|
protected string $TermNo,
|
|
protected string $qrcId
|
|
) {}
|
|
|
|
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP CashLink QR Code terminal number 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. The `TermNo` and `qrcId` are included in the body to identify the target.">
|
|
protected function defaultBody(): string
|
|
{
|
|
$bodyArray = [
|
|
'command' => 'ChangeTermNoForCashQRc',
|
|
'TermNo' => $this->TermNo,
|
|
'qrcId' => $this->qrcId,
|
|
];
|
|
|
|
return CmsSigner::canonicalize($bodyArray);
|
|
}
|
|
// </SECTION>
|
|
}
|