forked from apoloz/alfa-bank-sdk
refactor(core): enhance SDK structure and documentation
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -1,28 +1,52 @@
|
||||
<?php
|
||||
/*
|
||||
// MODULE_CONTRACT: Represents the SBP API call to get the status of Universal QR Codes for Digital Ruble.
|
||||
// RESPONSIBILITY: To define the POST request for checking the state of multiple Uni QR Codes.
|
||||
// INPUTS: Terminal number (TermNo) and an array of Uni QR Code IDs.
|
||||
// OUTPUTS: Raw array response from the API.
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Requests\DigitalRuble;
|
||||
|
||||
// <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 Saloon\Contracts\Body\HasBody;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Traits\Body\HasJsonBody;
|
||||
|
||||
// <BELIEF_STATE "The `Response` object is fully qualified in `createDtoFromResponse` as it is not explicitly imported with a `use` statement at the top. This is acceptable but less explicit.">
|
||||
// use Saloon\Http\Response; // Explicit import would be cleaner
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define the request to get the status of Universal QR Codes.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for querying the status of multiple Uni QR Codes, which is part of managing digital ruble transactions.">
|
||||
class GetUniQrStatusRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
|
||||
// <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 terminal number and Uni QR Code IDs.">
|
||||
// <BELIEF_STATE "The constructor requires `TermNo` to identify the terminal and `uniQrIds` (an array of strings) to specify the QR Codes whose status is being queried.">
|
||||
public function __construct(
|
||||
protected string $TermNo,
|
||||
protected array $uniQrIds, // Array of strings
|
||||
) {}
|
||||
|
||||
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP 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 '';
|
||||
return ''; // Endpoint is determined by SbpConnector's base URL
|
||||
}
|
||||
// </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 `uniQrIds` are included in the body to identify the targets.">
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
return [
|
||||
@@ -31,9 +55,13 @@ class GetUniQrStatusRequest extends Request implements HasBody
|
||||
'uniQrIds' => $this->uniQrIds,
|
||||
];
|
||||
}
|
||||
// </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(\Saloon\Http\Response $response): array
|
||||
{
|
||||
return $response->json();
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user