refactor(core): enhance SDK structure and documentation
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -1,30 +1,51 @@
|
||||
<?php
|
||||
/*
|
||||
// MODULE_CONTRACT: Represents the SBP API call to get a list of participating banks.
|
||||
// RESPONSIBILITY: To define the POST request for retrieving a registry of banks connected to the SBP.
|
||||
// INPUTS: Optional message ID and Bank Member ID filter.
|
||||
// OUTPUTS: GetBankListResponseData (DTO).
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Requests\Registry;
|
||||
|
||||
// <SECTION name="module_imports" intent="Import DTO and Saloon components for a JSON body request.">
|
||||
// <BELIEF_STATE "This POST request requires the `GetBankListResponseData` DTO for its response and utilizes `HasBody` and `HasJsonBody` for proper payload serialization.">
|
||||
use Apoloz\AlfaBank\Sbp\Data\Registry\GetBankListResponseData;
|
||||
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 get the SBP bank list.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for querying the list of SBP participating banks, which is essential for routing payments.">
|
||||
class GetBankListRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "Even though it retrieves data, SBP list requests are often performed via POST requests with a JSON body.">
|
||||
protected Method $method = Method::POST;
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="constructor" intent="Inject optional message ID and bank member ID filter.">
|
||||
// <BELIEF_STATE "The constructor allows for optional filtering of the bank list by `BankMemberIdFilter` and includes a `messageID` for request tracking.">
|
||||
public function __construct(
|
||||
protected ?string $messageID = null,
|
||||
protected ?string $BankMemberIdFilter = null
|
||||
) {}
|
||||
|
||||
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP bank list 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. Optional fields are conditionally added to the body.">
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
$body = [
|
||||
@@ -36,9 +57,13 @@ class GetBankListRequest extends Request implements HasBody
|
||||
|
||||
return $body;
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="response_caster" intent="Map the JSON response to a DTO.">
|
||||
// <BELIEF_STATE "Casting the response to a `GetBankListResponseData` DTO provides a type-safe and structured object for the list of SBP banks.">
|
||||
public function createDtoFromResponse(Response $response): GetBankListResponseData
|
||||
{
|
||||
return GetBankListResponseData::from($response->json());
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user