refactor: dto, requests, connector

This commit is contained in:
2026-01-19 10:46:57 +03:00
parent b2786d8606
commit 78e1e82331
32 changed files with 894 additions and 42 deletions

View File

@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace Apoloz\AlfaBank\Http\Middleware;
use Apoloz\AlfaBank\Utils\JwsSigner;
use Saloon\Http\Response;
class VerifyJwsResponseMiddleware
{
public function __construct(
protected ?string $publicKey = null
) {}
public function __invoke(Response $response): Response
{
$contentType = $response->header('Content-Type');
if (str_contains((string)$contentType, 'application/jose')) {
if (!$this->publicKey) {
return $response;
}
$jws = $response->body();
$decoded = JwsSigner::verify($jws, $this->publicKey);
if ($decoded) {
// We create a new response with the decoded JSON body
return $response->fake(json_encode($decoded), $response->status(), $response->headers()->all());
}
}
return $response;
}
}