refactor(core): enhance SDK structure and documentation
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -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>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user