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,7 +1,15 @@
<?php
/*
// MODULE_CONTRACT: Represents the SBP API call to change the account for a CashLink Universal QR Code.
// RESPONSIBILITY: To define the POST request for updating the linked account for a Digital Ruble CashLink QR.
// INPUTS: ChangeAccForCashUniQrRequestData (DTO) with relevant parameters.
// OUTPUTS: ChangeAccForCashUniQrResponseData (DTO).
*/
namespace Apoloz\AlfaBank\Sbp\Requests\DigitalRuble\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\DigitalRuble\CashLink\ChangeAccForCashUniQrRequestData;
use Apoloz\AlfaBank\Sbp\Data\DigitalRuble\CashLink\ChangeAccForCashUniQrResponseData;
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 change the account for a CashLink Uni QR Code.">
// <BELIEF_STATE "This class encapsulates the logic for modifying a Digital Ruble CashLink QR Code, which is a key management operation.">
class ChangeAccForCashUniQrRequest extends Request implements HasBody
{
use HasJsonBody;
// <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 DTO containing the account change data.">
// <BELIEF_STATE "Using a strongly-typed DTO (`ChangeAccForCashUniQrRequestData`) ensures that all necessary information for the account change is provided and correctly structured.">
public function __construct(
protected ChangeAccForCashUniQrRequestData $data
) {}
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP CashLink Uni QR Code account 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 '';
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 the new account, merchant, redirect URL, etc.">
protected function defaultBody(): array
{
$body = [
@@ -44,9 +65,13 @@ class ChangeAccForCashUniQrRequest 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 `ChangeAccForCashUniQrResponseData` DTO provides a type-safe and structured object for the result of the account change operation.">
public function createDtoFromResponse(Response $response): ChangeAccForCashUniQrResponseData
{
return ChangeAccForCashUniQrResponseData::from($response->json());
}
// </SECTION>
}

View File

@@ -1,7 +1,15 @@
<?php
/*
// MODULE_CONTRACT: Represents the SBP API call to create a CashLink Universal QR Code for Digital Ruble.
// RESPONSIBILITY: To define the POST request for generating a new Digital Ruble CashLink QR.
// INPUTS: CreateCashUniQrRequestData (DTO) containing QR Code parameters.
// OUTPUTS: CreateCashUniQrResponseData (DTO).
*/
namespace Apoloz\AlfaBank\Sbp\Requests\DigitalRuble\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\DigitalRuble\CashLink\CreateCashUniQrRequestData;
use Apoloz\AlfaBank\Sbp\Data\DigitalRuble\CashLink\CreateCashUniQrResponseData;
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 create a CashLink Uni QR Code.">
// <BELIEF_STATE "This class encapsulates the logic for generating a Digital Ruble CashLink QR Code, a key feature in the SBP Digital Ruble operations.">
class CreateCashUniQrRequest 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 Uni QR Code creation data.">
// <BELIEF_STATE "Using a strongly-typed DTO (`CreateCashUniQrRequestData`) ensures that all necessary information for QR Code generation is provided and correctly structured.">
public function __construct(
protected CreateCashUniQrRequestData $data
) {}
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP CashLink Uni QR Code creation.">
// <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 = [
@@ -46,9 +67,13 @@ class CreateCashUniQrRequest 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 `CreateCashUniQrResponseData` DTO provides a type-safe and structured object for the result of the QR Code creation.">
public function createDtoFromResponse(Response $response): CreateCashUniQrResponseData
{
return CreateCashUniQrResponseData::from($response->json());
}
// </SECTION>
}

View File

@@ -1,7 +1,15 @@
<?php
/*
// MODULE_CONTRACT: Represents the SBP API call to get the status of a CashLink Universal QR Code.
// RESPONSIBILITY: To define the POST request for checking the state of a specific Digital Ruble CashLink QR.
// INPUTS: GetCashUniQrStatusRequestData (DTO) with relevant parameters.
// OUTPUTS: GetCashUniQrStatusResponseData (DTO).
*/
namespace Apoloz\AlfaBank\Sbp\Requests\DigitalRuble\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\DigitalRuble\CashLink\GetCashUniQrStatusRequestData;
use Apoloz\AlfaBank\Sbp\Data\DigitalRuble\CashLink\GetCashUniQrStatusResponseData;
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 get the status of a CashLink Uni QR Code.">
// <BELIEF_STATE "This class encapsulates the logic for querying the status of a Digital Ruble CashLink QR Code, which is crucial for tracking payment flows.">
class GetCashUniQrStatusRequest 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 DTO containing the status request data.">
// <BELIEF_STATE "Using a strongly-typed DTO (`GetCashUniQrStatusRequestData`) ensures that all necessary information for the status query is provided and correctly structured.">
public function __construct(
protected GetCashUniQrStatusRequestData $data
) {}
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP CashLink 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`, `uniQrId`, and `paramsId` identify the target. Optional fields like `messageID` and `payrrn` provide additional context.">
protected function defaultBody(): array
{
$body = [
@@ -39,9 +60,13 @@ class GetCashUniQrStatusRequest 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 `GetCashUniQrStatusResponseData` DTO provides a type-safe and structured object for the status of the CashLink Uni QR Code.">
public function createDtoFromResponse(Response $response): GetCashUniQrStatusResponseData
{
return GetCashUniQrStatusResponseData::from($response->json());
}
// </SECTION>
}

View File

@@ -1,28 +1,52 @@
<?php
/*
// MODULE_CONTRACT: Represents the SBP API call to create a Universal QR Code for Digital Ruble.
// RESPONSIBILITY: To define the POST request for generating a new Uni QR Code for digital ruble transactions.
// INPUTS: CreateUniQrRequestData (DTO) containing QR Code parameters.
// OUTPUTS: Raw array response from the API.
*/
namespace Apoloz\AlfaBank\Sbp\Requests\DigitalRuble;
// <SECTION name="module_imports" intent="Import DTO and Saloon components for a JSON body request.">
// <BELIEF_STATE "This POST request requires the `CreateUniQrRequestData` 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\DigitalRuble\CreateUniQrRequestData;
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 create a Universal QR Code.">
// <BELIEF_STATE "This class encapsulates the logic for generating a Uni QR Code for digital ruble, a key feature in the SBP Digital Ruble operations.">
class CreateUniQrRequest 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 Uni QR Code creation data.">
// <BELIEF_STATE "Using a strongly-typed DTO (`CreateUniQrRequestData`) ensures that all necessary information for QR Code generation is provided and correctly structured.">
public function __construct(
protected CreateUniQrRequestData $data
) {}
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP Uni QR Code creation.">
// <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 sender information and notification URLs.">
protected function defaultBody(): array
{
$body = [
@@ -54,9 +78,13 @@ class CreateUniQrRequest 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,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>
}

View File

@@ -1,14 +1,29 @@
<?php
/*
// MODULE_CONTRACT: Provides a utility for parsing incoming Digital Ruble payment notifications.
// RESPONSIBILITY: To transform a raw array payload (typically from a webhook) into a structured DTO.
// INPUTS: Raw array representing the payment notification payload.
// OUTPUTS: PaymentDrNotificationData (DTO).
// LINKS: Webhooks/WebhookFactory.php (could potentially integrate this for DR-specific parsing)
*/
namespace Apoloz\AlfaBank\Sbp\Requests\DigitalRuble\Notifications;
// <SECTION name="module_imports" intent="Import the DTO for Digital Ruble payment notifications and Laravel's Request class.">
// <BELIEF_STATE "This utility uses the `PaymentDrNotificationData` DTO to structure the incoming data. The Laravel `Request` class is typically used for obtaining raw input in a web context.">
use Apoloz\AlfaBank\Sbp\Data\DigitalRuble\Notifications\PaymentDrNotificationData;
use Illuminate\Http\Request;
use Illuminate\Http\Request; // Assuming this is used to get the raw incoming data, not directly as a Saloon Request.
// </SECTION>
// <SECTION name="class_definition" intent="Define a utility class for parsing Digital Ruble payment notifications.">
// <BELIEF_STATE "This class acts as a parser, converting unstructured incoming notification data into a type-safe and easily consumable DTO, which is critical for reliable webhook handling.">
class ParsePaymentDrNotification
{
// <SECTION name="execute_method" intent="Parse the raw incoming notification data into a structured DTO.">
// <BELIEF_STATE "The `execute` method is the entry point for parsing. It directly leverages the `PaymentDrNotificationData::from()` method to perform the conversion, taking advantage of Spatie Laravel Data's automatic mapping capabilities.">
public function execute(array $data): PaymentDrNotificationData
{
return PaymentDrNotificationData::from($data);
}
// </SECTION>
}