refactor(core): enhance SDK structure and documentation

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
2026-01-18 21:48:25 +03:00
parent 3da69c03e1
commit d214eecebe
378 changed files with 10514 additions and 496 deletions

View File

@@ -1,29 +1,53 @@
<?php
/*
// 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 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 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 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 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 '';
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. Other fields are conditionally added, ensuring the payload precisely matches the API specification.">
protected function defaultBody(): array
{
$body = [
@@ -38,9 +62,13 @@ class GetQrSubStatusRequest extends Request implements HasBody
return $body;
}
// </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>
}

View File

@@ -1,19 +1,35 @@
<?php
/*
// MODULE_CONTRACT: Represents the SBP API call to petition a QR Code subscription payment.
// RESPONSIBILITY: To define the POST request for initiating a payment based on an existing SBP subscription.
// INPUTS: Terminal number (TermNo), subscription token, sender member ID, and QR Code ID.
// 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 Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
// </SECTION>
// <SECTION name="class_definition" intent="Define the request to petition a QR Code subscription payment.">
// <BELIEF_STATE "This class encapsulates the logic for initiating a payment through an SBP subscription, which is a key part of recurring payment flows.">
class QrcSubPayPetitionRequest extends Request implements HasBody
{
use HasJsonBody;
// <SECTION name="http_method" intent="Declare the HTTP verb.">
// <BELIEF_STATE "Initiating a payment action that changes the system state is correctly represented by a POST request.">
protected Method $method = Method::POST;
// </SECTION>
// <SECTION name="constructor" intent="Inject the mandatory parameters for the subscription payment petition.">
// <BELIEF_STATE "The constructor requires the `TermNo`, `subscriptionToken`, `SenderMemberId`, and `qrcId` to identify the transaction and subscription.">
public function __construct(
protected string $TermNo,
protected string $subscriptionToken,
@@ -21,11 +37,16 @@ class QrcSubPayPetitionRequest extends Request implements HasBody
protected string $qrcId,
) {}
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP subscription payment petitions.">
// <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. All constructor properties are directly mapped to the request body.">
protected function defaultBody(): array
{
return [
@@ -36,9 +57,13 @@ class QrcSubPayPetitionRequest extends Request implements HasBody
'qrcId' => $this->qrcId,
];
}
// </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>
}

View File

@@ -1,29 +1,50 @@
<?php
/*
// MODULE_CONTRACT: Represents the SBP API call to register a QR Code subscription.
// RESPONSIBILITY: To define the POST request for setting up a new SBP subscription for recurring payments.
// INPUTS: RegQrSubRequestData (DTO).
// OUTPUTS: Raw array response from the API.
*/
namespace Apoloz\AlfaBank\Sbp\Requests\Subscription;
// <SECTION name="module_imports" intent="Import DTO and Saloon components for a JSON body request.">
// <BELIEF_STATE "This POST request requires the `RegQrSubRequestData` DTO for its JSON body and utilizes `HasBody` and `HasJsonBody` for proper payload serialization. It currently returns a raw array response.">
use Apoloz\AlfaBank\Sbp\Data\Subscription\RegQrSubRequestData;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
// </SECTION>
// <SECTION name="class_definition" intent="Define the request to register a QR Code subscription.">
// <BELIEF_STATE "This class encapsulates the logic for initiating an SBP subscription, which is crucial for recurring payment models.">
class RegQrSubRequest extends Request implements HasBody
{
use HasJsonBody;
// <SECTION name="http_method" intent="Declare the HTTP verb.">
// <BELIEF_STATE "Registering a new resource or initiating an action that changes the system state is correctly represented by a POST request.">
protected Method $method = Method::POST;
// </SECTION>
// <SECTION name="constructor" intent="Inject the DTO containing the subscription registration data.">
// <BELIEF_STATE "Using a strongly-typed DTO (`RegQrSubRequestData`) ensures that all necessary information for the subscription is provided and correctly structured.">
public function __construct(
protected RegQrSubRequestData $data
) {}
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP subscription registration.">
// <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. Fields from the DTO are mapped, including conditional and nested `queryData` for notification URLs.">
protected function defaultBody(): array
{
$body = [
@@ -43,9 +64,13 @@ class RegQrSubRequest extends Request implements HasBody
return $body;
}
// </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>
}