forked from apoloz/alfa-bank-sdk
Улучшена документация, добавлена поддержка цифрового рубля и улучшена структура DTO
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -1,46 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
// MODULE_CONTRACT: Represents a Sandbox API call for testing signature and encryption mechanisms.
|
||||
// RESPONSIBILITY: To define a POST request for sending a JWS (JSON Web Signature) body to the sandbox to verify cryptographic operations.
|
||||
// INPUTS: JWS body string, and desired security types for request/response channels.
|
||||
// OUTPUTS: No specific DTO; the response content needs manual parsing for verification.
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Requests\Sandbox;
|
||||
|
||||
// <SECTION name="module_imports" intent="Import Saloon framework components for handling string bodies.">
|
||||
// <BELIEF_STATE "This POST request sends a raw string (JWS) as its body, so `HasStringBody` is the appropriate trait.">
|
||||
use Apoloz\AlfaBank\Data\Sandbox\SandboxTestResponseData;
|
||||
use Saloon\Contracts\Body\HasBody;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Http\Response;
|
||||
use Saloon\Traits\Body\HasJsonBody;
|
||||
use Saloon\Traits\Body\HasStringBody;
|
||||
|
||||
class SignatureEncryptionTestRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
use HasStringBody;
|
||||
|
||||
protected Method $method = Method::POST;
|
||||
|
||||
/**
|
||||
* @param string $data Raw content (JWS, TEXT or XML)
|
||||
* @param string $format json|text|xml
|
||||
* @param string $requestSecurity NO|SIGNATURE|ENCRYPTION
|
||||
* @param string $responseSecurity NO|SIGNATURE|ENCRYPTION
|
||||
*/
|
||||
public function __construct(
|
||||
protected string $data
|
||||
protected string $data,
|
||||
protected string $format = 'json',
|
||||
protected string $requestSecurity = 'SIGNATURE',
|
||||
protected string $responseSecurity = 'SIGNATURE'
|
||||
) {}
|
||||
|
||||
public function resolveEndpoint(): string
|
||||
{
|
||||
return '/api/sandbox/v1/test/signature-encryption';
|
||||
return "/api/signature-encryption-tests/{$this->format}";
|
||||
}
|
||||
|
||||
protected function defaultBody(): ?string
|
||||
protected function defaultHeaders(): array
|
||||
{
|
||||
$headers = [
|
||||
'X-Request-ChannelSecurity' => $this->requestSecurity,
|
||||
'X-Response-ChannelSecurity' => $this->responseSecurity,
|
||||
];
|
||||
|
||||
if ($this->format === 'json') {
|
||||
$headers['Content-Type'] = 'application/jose';
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
protected function defineBody(): string
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function createDtoFromResponse(Response $response): SandboxTestResponseData
|
||||
{
|
||||
return SandboxTestResponseData::from(['result' => $response->body()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user