forked from apoloz/alfa-bank-sdk
76 lines
3.3 KiB
PHP
76 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
/*
|
|
// 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 Apoloz\AlfaBank\Utils\CmsSigner;
|
|
use Saloon\Contracts\Body\HasBody;
|
|
use Saloon\Enums\Method;
|
|
use Saloon\Http\Request;
|
|
use Saloon\Http\Response;
|
|
use Saloon\Traits\Body\HasStringBody;
|
|
|
|
// </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 HasStringBody;
|
|
|
|
// <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,
|
|
protected string $dateFrom,
|
|
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 ''; // Endpoint is determined by SbpConnector's base URL
|
|
}
|
|
// </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>
|
|
|
|
// <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(): string
|
|
{
|
|
$bodyArray = [
|
|
'command' => 'GetCashQrcId',
|
|
'TermNo' => $this->TermNo,
|
|
'qrcId' => $this->qrcId,
|
|
'dateFrom' => $this->dateFrom,
|
|
'dateTo' => $this->dateTo,
|
|
];
|
|
|
|
return CmsSigner::canonicalize($bodyArray);
|
|
}
|
|
// </SECTION>
|
|
}
|