refactor(core): enhance SDK structure and documentation
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
<?php
|
||||
/*
|
||||
// MODULE_CONTRACT: Represents the SBP API call to register a CashLink QR Code.
|
||||
// RESPONSIBILITY: To define the POST request for creating a new CashLink QR Code.
|
||||
// INPUTS: RegCashQrRequestData (DTO) containing QR Code parameters.
|
||||
// OUTPUTS: RegCashQrResponseData (DTO).
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Requests\CashLink;
|
||||
|
||||
// <SECTION name="module_imports" intent="Import DTOs and Saloon components for a JSON body request.">
|
||||
// <BELIEF_STATE "This POST request requires specific DTOs for its JSON body and its response, along with Saloon's body-handling traits.">
|
||||
use Apoloz\AlfaBank\Sbp\Data\CashLink\RegCashQrRequestData;
|
||||
use Apoloz\AlfaBank\Sbp\Data\CashLink\RegCashQrResponseData;
|
||||
use Saloon\Contracts\Body\HasBody;
|
||||
@@ -9,22 +17,35 @@ 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 CashLink QR Code.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for generating a CashLink QR Code, a key feature in SBP payment systems.">
|
||||
class RegCashQrRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "Creating a new QR Code resource or initiating a generation action is correctly represented by a POST request.">
|
||||
protected Method $method = Method::POST;
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="constructor" intent="Inject the DTO containing the CashLink QR Code registration data.">
|
||||
// <BELIEF_STATE "Using a strongly-typed DTO (`RegCashQrRequestData`) ensures that all necessary information for QR Code generation is provided and correctly structured.">
|
||||
public function __construct(
|
||||
protected RegCashQrRequestData $data
|
||||
) {}
|
||||
|
||||
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP CashLink QR Code 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 parameters for media type, dimensions, redirect URL, and QR Code ID.">
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
$body = [
|
||||
@@ -40,9 +61,13 @@ class RegCashQrRequest 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 `RegCashQrResponseData` DTO provides a type-safe and structured object for the result of the QR Code registration.">
|
||||
public function createDtoFromResponse(Response $response): RegCashQrResponseData
|
||||
{
|
||||
return RegCashQrResponseData::from($response->json());
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user