forked from apoloz/alfa-bank-sdk
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 get detailed data about a QR Code reversal.
|
||||
// RESPONSIBILITY: To define the POST request for retrieving specific information about a reversal transaction.
|
||||
// INPUTS: Reversal data request (TermNo, currency, qrcId, payrrn, etc.).
|
||||
// OUTPUTS: GetQrcReversalDataResponseData (DTO).
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Requests\Reversal;
|
||||
|
||||
// <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\Reversal\GetQrcReversalDataRequestData;
|
||||
use Apoloz\AlfaBank\Sbp\Data\Reversal\GetQrcReversalDataResponseData;
|
||||
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 detailed QR Code reversal data.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for querying detailed SBP reversal information, which is crucial for auditing and reconciliation.">
|
||||
class GetQrcReversalDataRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "Even though it retrieves data, SBP data requests 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 reversal data request parameters.">
|
||||
// <BELIEF_STATE "Using a strongly-typed DTO (`GetQrcReversalDataRequestData`) ensures that all necessary information for the data query is provided and correctly structured.">
|
||||
public function __construct(
|
||||
protected GetQrcReversalDataRequestData $data
|
||||
) {}
|
||||
|
||||
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP reversal data 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. Other fields from the DTO are conditionally added, ensuring the payload precisely matches the API specification.">
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
$body = [
|
||||
@@ -43,9 +64,13 @@ class GetQrcReversalDataRequest 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 `GetQrcReversalDataResponseData` DTO provides a type-safe and structured object for the detailed reversal data.">
|
||||
public function createDtoFromResponse(Response $response): GetQrcReversalDataResponseData
|
||||
{
|
||||
return GetQrcReversalDataResponseData::from($response->json());
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
<?php
|
||||
/*
|
||||
// MODULE_CONTRACT: Represents the SBP API call to get the status of a QR Code reversal request.
|
||||
// RESPONSIBILITY: To define the POST request for checking the state of a previously initiated reversal.
|
||||
// INPUTS: Reversal status request data (TermNo, payrrn, originalTrxId, etc.).
|
||||
// OUTPUTS: GetQrcReversalStatusResponseData (DTO).
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Requests\Reversal;
|
||||
|
||||
// <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\Reversal\GetQrcReversalStatusRequestData;
|
||||
use Apoloz\AlfaBank\Sbp\Data\Reversal\GetQrcReversalStatusResponseData;
|
||||
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 QR Code reversal.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for querying the status of an SBP reversal, which is a critical operation in payment systems.">
|
||||
class GetQrcReversalStatusRequest 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 reversal status request data.">
|
||||
// <BELIEF_STATE "Using a strongly-typed DTO (`GetQrcReversalStatusRequestData`) ensures that all necessary information for the status query is provided and correctly structured.">
|
||||
public function __construct(
|
||||
protected GetQrcReversalStatusRequestData $data
|
||||
) {}
|
||||
|
||||
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP reversal status checks.">
|
||||
// <BELIEF_STATE "The SBP API often uses generic endpoints with a 'command' field in the body, which implies 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 from the DTO are conditionally added, ensuring the payload precisely matches the API specification.">
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
$body = [
|
||||
@@ -39,9 +60,13 @@ class GetQrcReversalStatusRequest 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 `GetQrcReversalStatusResponseData` DTO provides a type-safe and structured object for the status of the reversal.">
|
||||
public function createDtoFromResponse(Response $response): GetQrcReversalStatusResponseData
|
||||
{
|
||||
return GetQrcReversalStatusResponseData::from($response->json());
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
<?php
|
||||
/*
|
||||
// MODULE_CONTRACT: Represents the SBP API call to initiate a QR Code reversal.
|
||||
// RESPONSIBILITY: To define the POST request for reversing a payment made via QR code.
|
||||
// INPUTS: QR Code reversal request data (TermNo, currency, qrcId, payrrn, etc.).
|
||||
// OUTPUTS: QrcReversalResponseData (DTO).
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Requests\Reversal;
|
||||
|
||||
// <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\Reversal\QrcReversalRequestData;
|
||||
use Apoloz\AlfaBank\Sbp\Data\Reversal\QrcReversalResponseData;
|
||||
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 initiate a QR Code reversal.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for initiating an SBP reversal, which is a critical operation in payment systems.">
|
||||
class QrcReversalRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "Initiating a new transaction or action that changes the system state (like a reversal) is correctly represented by a POST request.">
|
||||
protected Method $method = Method::POST;
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="constructor" intent="Inject the DTO containing the QR Code reversal request data.">
|
||||
// <BELIEF_STATE "Using a strongly-typed DTO (`QrcReversalRequestData`) ensures that all necessary information for the reversal is provided and correctly structured.">
|
||||
public function __construct(
|
||||
protected QrcReversalRequestData $data
|
||||
) {}
|
||||
|
||||
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP reversal requests.">
|
||||
// <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 from the DTO are conditionally added, ensuring the payload precisely matches the API specification.">
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
$body = [
|
||||
@@ -44,9 +65,13 @@ class QrcReversalRequest 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 `QrcReversalResponseData` DTO provides a type-safe and structured object for the result of the reversal.">
|
||||
public function createDtoFromResponse(Response $response): QrcReversalResponseData
|
||||
{
|
||||
return QrcReversalResponseData::from($response->json());
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user