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,29 +1,50 @@
|
||||
<?php
|
||||
/*
|
||||
// MODULE_CONTRACT: Represents the SBP API call to activate a CashLink QR Code.
|
||||
// RESPONSIBILITY: To define the POST request for making a previously registered CashLink QR Code active and scannable.
|
||||
// INPUTS: ActivateCashQrRequestData (DTO) containing QR Code activation parameters.
|
||||
// OUTPUTS: Raw array response from the API.
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Requests\CashLink;
|
||||
|
||||
// <SECTION name="module_imports" intent="Import DTO and Saloon components for a JSON body request.">
|
||||
// <BELIEF_STATE "This POST request requires the `ActivateCashQrRequestData` 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\CashLink\ActivateCashQrRequestData;
|
||||
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 activate a CashLink QR Code.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for activating a CashLink QR Code, a key management operation in SBP payment systems.">
|
||||
class ActivateCashQrRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "Activating a resource is an action that changes the system state, so POST is the correct verb.">
|
||||
protected Method $method = Method::POST;
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="constructor" intent="Inject the DTO containing the QR Code activation data.">
|
||||
// <BELIEF_STATE "Using a strongly-typed DTO (`ActivateCashQrRequestData`) ensures that all necessary information for QR Code activation is provided and correctly structured.">
|
||||
public function __construct(
|
||||
protected ActivateCashQrRequestData $data
|
||||
) {}
|
||||
|
||||
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP CashLink QR Code activation.">
|
||||
// <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 order number, payment purpose, QR TTL, and notification URLs.">
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
$body = [
|
||||
@@ -44,9 +65,13 @@ class ActivateCashQrRequest 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>
|
||||
}
|
||||
|
||||
@@ -1,18 +1,37 @@
|
||||
<?php
|
||||
/*
|
||||
// MODULE_CONTRACT: Represents the SBP API call to change the account for a CashLink QR Code.
|
||||
// RESPONSIBILITY: To define the POST request for updating the linked account for a specific CashLink QR.
|
||||
// INPUTS: Terminal number (TermNo), QR Code ID, new account, and optional merchant/redirect details.
|
||||
// OUTPUTS: Raw array response from the API.
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Requests\CashLink;
|
||||
|
||||
// <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 change the account for a CashLink QR Code.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for modifying a CashLink QR Code, which is a key management operation.">
|
||||
class ChangeAccountForCashQrRequest 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 mandatory and optional parameters for the account change request.">
|
||||
// <BELIEF_STATE "The constructor requires `TermNo`, `qrcId`, and the new `account`. Optional parameters (`NewTermNo`, `NewMerchantId`, `redirectUrl`) allow for more complex reconfigurations.">
|
||||
public function __construct(
|
||||
protected string $TermNo,
|
||||
protected string $qrcId,
|
||||
@@ -22,11 +41,16 @@ class ChangeAccountForCashQrRequest extends Request implements HasBody
|
||||
protected ?string $redirectUrl = null,
|
||||
) {}
|
||||
|
||||
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP CashLink 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 are conditionally added based on constructor parameters, ensuring the payload precisely matches the API specification.">
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
$body = [
|
||||
@@ -42,9 +66,13 @@ class ChangeAccountForCashQrRequest 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>
|
||||
}
|
||||
|
||||
@@ -1,28 +1,52 @@
|
||||
<?php
|
||||
/*
|
||||
// MODULE_CONTRACT: Represents the SBP API call to change the terminal number for a CashLink QR Code.
|
||||
// RESPONSIBILITY: To define the POST request for updating the linked terminal for a specific CashLink QR.
|
||||
// INPUTS: Terminal number (TermNo) and QR Code ID.
|
||||
// OUTPUTS: Raw array response from the API.
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Requests\CashLink;
|
||||
|
||||
// <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 change the terminal number for a CashLink QR Code.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for modifying a CashLink QR Code, specifically its associated terminal, which is a key management operation.">
|
||||
class ChangeTermNoForCashQrRequest 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 mandatory terminal number and QR Code ID.">
|
||||
// <BELIEF_STATE "The constructor requires `TermNo` and `qrcId` to identify the target QR Code for which the terminal number is being changed.">
|
||||
public function __construct(
|
||||
protected string $TermNo,
|
||||
protected string $qrcId
|
||||
) {}
|
||||
|
||||
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP CashLink QR Code terminal number 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. The `TermNo` and `qrcId` are included in the body to identify the target.">
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
return [
|
||||
@@ -31,9 +55,13 @@ class ChangeTermNoForCashQrRequest extends Request implements HasBody
|
||||
'qrcId' => $this->qrcId,
|
||||
];
|
||||
}
|
||||
// </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>
|
||||
}
|
||||
|
||||
@@ -1,28 +1,52 @@
|
||||
<?php
|
||||
/*
|
||||
// MODULE_CONTRACT: Represents the SBP API call to delete a CashLink QR Code.
|
||||
// RESPONSIBILITY: To define the POST request for deactivating and removing a specific CashLink QR.
|
||||
// INPUTS: Terminal number (TermNo) and QR Code ID.
|
||||
// OUTPUTS: Raw array response from the API.
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Requests\CashLink;
|
||||
|
||||
// <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 delete a CashLink QR Code.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for deleting a CashLink QR Code, which is a critical management operation.">
|
||||
class DeleteCashQrRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "Deleting 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 mandatory terminal number and QR Code ID.">
|
||||
// <BELIEF_STATE "The constructor requires `TermNo` and `qrcId` to identify the target QR Code for deletion.">
|
||||
public function __construct(
|
||||
protected string $TermNo,
|
||||
protected string $qrcId
|
||||
) {}
|
||||
|
||||
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP CashLink QR Code deletion.">
|
||||
// <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 `qrcId` are included in the body to identify the target.">
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
return [
|
||||
@@ -31,9 +55,13 @@ class DeleteCashQrRequest extends Request implements HasBody
|
||||
'qrcId' => $this->qrcId,
|
||||
];
|
||||
}
|
||||
// </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>
|
||||
}
|
||||
|
||||
@@ -1,18 +1,37 @@
|
||||
<?php
|
||||
/*
|
||||
// MODULE_CONTRACT: Represents the SBP API call to get the history of a CashLink QR Code.
|
||||
// RESPONSIBILITY: To define the POST request for retrieving historical data for a specific CashLink QR Code.
|
||||
// INPUTS: Terminal number (TermNo), QR Code ID, and a date range.
|
||||
// OUTPUTS: Raw array response from the API.
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Requests\CashLink;
|
||||
|
||||
// <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 history of a CashLink QR Code.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for querying the history of a CashLink QR Code, which is useful for auditing and reconciliation.">
|
||||
class GetCashQrHistoryRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "Even though it retrieves data, SBP history requests are often performed via POST requests with a JSON body.">
|
||||
protected Method $method = Method::POST;
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="constructor" intent="Inject the mandatory parameters for the CashLink QR Code history request.">
|
||||
// <BELIEF_STATE "The constructor requires `TermNo`, `qrcId`, and a `dateFrom`/`dateTo` range to specify the target QR Code and the period of interest.">
|
||||
public function __construct(
|
||||
protected string $TermNo,
|
||||
protected string $qrcId,
|
||||
@@ -20,11 +39,16 @@ class GetCashQrHistoryRequest extends Request implements HasBody
|
||||
protected string $dateTo
|
||||
) {}
|
||||
|
||||
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP CashLink QR Code history 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. All constructor properties are directly mapped to the request body to identify the QR Code and the date range.">
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
return [
|
||||
@@ -35,9 +59,13 @@ class GetCashQrHistoryRequest extends Request implements HasBody
|
||||
'dateTo' => $this->dateTo,
|
||||
];
|
||||
}
|
||||
// </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>
|
||||
}
|
||||
|
||||
@@ -1,28 +1,52 @@
|
||||
<?php
|
||||
/*
|
||||
// MODULE_CONTRACT: Represents the SBP API call to get the status of a CashLink QR Code.
|
||||
// RESPONSIBILITY: To define the POST request for checking the state of a specific CashLink QR.
|
||||
// INPUTS: Terminal number (TermNo) and QR Code ID.
|
||||
// OUTPUTS: Raw array response from the API.
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Requests\CashLink;
|
||||
|
||||
// <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 a CashLink QR Code.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for querying the status of a CashLink QR Code, which is crucial for tracking payment flows.">
|
||||
class GetCashQrStatusRequest 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 QR Code ID.">
|
||||
// <BELIEF_STATE "The constructor requires `TermNo` and `qrcId` to specify the target QR Code whose status is being queried.">
|
||||
public function __construct(
|
||||
protected string $TermNo,
|
||||
protected string $qrcId
|
||||
) {}
|
||||
|
||||
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP CashLink 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 `qrcId` identify the target.">
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
return [
|
||||
@@ -31,9 +55,13 @@ class GetCashQrStatusRequest extends Request implements HasBody
|
||||
'qrcId' => $this->qrcId,
|
||||
];
|
||||
}
|
||||
// </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>
|
||||
}
|
||||
|
||||
@@ -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