forked from apoloz/alfa-bank-sdk
refactor(Sbp)
This commit is contained in:
@@ -13,20 +13,21 @@ namespace Apoloz\AlfaBank\Sbp\Requests\Management;
|
||||
// <SECTION name="module_imports" intent="Import DTO and Saloon components for a JSON body request.">
|
||||
// <BELIEF_STATE "This POST request requires the `BlockQrRequestData` 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\Management\BlockQrRequestData;
|
||||
use Apoloz\AlfaBank\Sbp\Data\Management\SbpManagementResponseData;
|
||||
use Apoloz\AlfaBank\Utils\CmsSigner;
|
||||
use Saloon\Contracts\Body\HasBody;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Traits\Body\HasJsonBody;
|
||||
use Saloon\Http\Response;
|
||||
use Saloon\Traits\Body\HasStringBody;
|
||||
|
||||
// <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 block a QR Code.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for blocking an SBP QR Code, which is a critical management operation.">
|
||||
class BlockQrRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
use HasStringBody;
|
||||
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "Blocking a resource is an action that changes the system state, so POST is the correct verb.">
|
||||
@@ -49,20 +50,22 @@ class BlockQrRequest extends Request implements HasBody
|
||||
|
||||
// <SECTION name="response_caster" intent="Map the JSON response to a DTO.">
|
||||
// <BELIEF_STATE "Casting the response to a `SbpManagementResponseData` DTO provides a structured object for the result of the block operation.">
|
||||
public function createDtoFromResponse(\Saloon\Http\Response $response): \Apoloz\AlfaBank\Sbp\Data\Management\SbpManagementResponseData
|
||||
public function createDtoFromResponse(Response $response): SbpManagementResponseData
|
||||
{
|
||||
return \Apoloz\AlfaBank\Sbp\Data\Management\SbpManagementResponseData::from($response->json());
|
||||
return SbpManagementResponseData::from($response->json());
|
||||
}
|
||||
// </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. Using the DTO's `toArray` method ensures the payload is correctly structured.">
|
||||
protected function defaultBody(): array
|
||||
protected function defaultBody(): string
|
||||
{
|
||||
return array_merge(
|
||||
$bodyArray = array_merge(
|
||||
['command' => 'BlockQRcId'],
|
||||
$this->data->toArray()
|
||||
);
|
||||
|
||||
return CmsSigner::canonicalize($bodyArray);
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
@@ -12,20 +12,21 @@ namespace Apoloz\AlfaBank\Sbp\Requests\Management;
|
||||
|
||||
// <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 Apoloz\AlfaBank\Sbp\Data\Management\GetBlockedQrListResponseData;
|
||||
use Apoloz\AlfaBank\Utils\CmsSigner;
|
||||
use Saloon\Contracts\Body\HasBody;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Traits\Body\HasJsonBody;
|
||||
use Saloon\Http\Response;
|
||||
use Saloon\Traits\Body\HasStringBody;
|
||||
|
||||
// <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 a list of blocked QR Codes.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for querying blocked QR Codes, which is part of managing payment terminals.">
|
||||
class GetBlockedQrListRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
use HasStringBody;
|
||||
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "Even though it retrieves data, SBP list requests are often performed via POST requests with a JSON body.">
|
||||
@@ -48,20 +49,22 @@ class GetBlockedQrListRequest extends Request implements HasBody
|
||||
|
||||
// <SECTION name="response_caster" intent="Map the JSON response to a DTO.">
|
||||
// <BELIEF_STATE "Casting the response to a `GetBlockedQrListResponseData` DTO provides a type-safe object for the list of blocked QR Codes.">
|
||||
public function createDtoFromResponse(\Saloon\Http\Response $response): \Apoloz\AlfaBank\Sbp\Data\Management\GetBlockedQrListResponseData
|
||||
public function createDtoFromResponse(Response $response): GetBlockedQrListResponseData
|
||||
{
|
||||
return \Apoloz\AlfaBank\Sbp\Data\Management\GetBlockedQrListResponseData::from($response->json());
|
||||
return GetBlockedQrListResponseData::from($response->json());
|
||||
}
|
||||
// </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` is included in the body to identify the terminal.">
|
||||
protected function defaultBody(): array
|
||||
protected function defaultBody(): string
|
||||
{
|
||||
return [
|
||||
$bodyArray = [
|
||||
'command' => 'GetBlockedQRcIdList',
|
||||
'TermNo' => $this->TermNo,
|
||||
];
|
||||
|
||||
return CmsSigner::canonicalize($bodyArray);
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
@@ -13,20 +13,21 @@ namespace Apoloz\AlfaBank\Sbp\Requests\Management;
|
||||
// <SECTION name="module_imports" intent="Import DTO and Saloon components for a JSON body request.">
|
||||
// <BELIEF_STATE "This POST request requires the `BlockQrRequestData` 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\Management\BlockQrRequestData;
|
||||
use Apoloz\AlfaBank\Sbp\Data\Management\SbpManagementResponseData;
|
||||
use Apoloz\AlfaBank\Utils\CmsSigner;
|
||||
use Saloon\Contracts\Body\HasBody;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Traits\Body\HasJsonBody;
|
||||
use Saloon\Http\Response;
|
||||
use Saloon\Traits\Body\HasStringBody;
|
||||
|
||||
// <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 unblock a QR Code.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for unblocking an SBP QR Code, which is a critical management operation.">
|
||||
class UnblockQrRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
use HasStringBody;
|
||||
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "Unblocking a resource is an action that changes the system state, so POST is the correct verb.">
|
||||
@@ -49,20 +50,22 @@ class UnblockQrRequest extends Request implements HasBody
|
||||
|
||||
// <SECTION name="response_caster" intent="Map the JSON response to a DTO.">
|
||||
// <BELIEF_STATE "Casting the response to a `SbpManagementResponseData` DTO provides a structured object for the result of the unblock operation.">
|
||||
public function createDtoFromResponse(\Saloon\Http\Response $response): \Apoloz\AlfaBank\Sbp\Data\Management\SbpManagementResponseData
|
||||
public function createDtoFromResponse(Response $response): SbpManagementResponseData
|
||||
{
|
||||
return \Apoloz\AlfaBank\Sbp\Data\Management\SbpManagementResponseData::from($response->json());
|
||||
return SbpManagementResponseData::from($response->json());
|
||||
}
|
||||
// </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. Using the DTO's `toArray` method ensures the payload is correctly structured.">
|
||||
protected function defaultBody(): array
|
||||
protected function defaultBody(): string
|
||||
{
|
||||
return array_merge(
|
||||
$bodyArray = array_merge(
|
||||
['command' => 'UnblockQRcId'],
|
||||
$this->data->toArray()
|
||||
);
|
||||
|
||||
return CmsSigner::canonicalize($bodyArray);
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user