first commit
This commit is contained in:
49
src/Requests/Webhooks/CreateWebhookRequest.php
Normal file
49
src/Requests/Webhooks/CreateWebhookRequest.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Gemini\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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user