Files
alfa-bank-sdk/src/Requests/Webhooks/CreateWebhookRequest.php
2026-01-14 16:48:36 +03:00

50 lines
1.1 KiB
PHP

<?php
namespace Apoloz\AlfaBank\Requests\Webhooks;
use Gemini\AlfaBank\Data\WebhookData;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use Saloon\Contracts\Body\HasBody;
class CreateWebhookRequest extends Request implements HasBody
{
use HasJsonBody;
protected Method $method = Method::POST;
public function __construct(
protected string $object,
protected string $callbackUri,
protected ?array $accounts = null,
protected int $version = 1
) {}
public function resolveEndpoint(): string
{
return '/api/v1/webhooks';
}
protected function defaultBody(): array
{
$body = [
'object' => $this->object,
'callbackUri' => $this->callbackUri,
'version' => $this->version,
];
if ($this->accounts !== null) {
$body['data'] = ['accounts' => $this->accounts];
}
return $body;
}
public function createDtoFromResponse(Response $response): WebhookData
{
return WebhookData::from($response->json());
}
}