refactor(core): enhance SDK structure and documentation
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -2,12 +2,13 @@
|
||||
|
||||
namespace Apoloz\AlfaBank\Requests\Webhooks;
|
||||
|
||||
use Apoloz\AlfaBank\Data\WebhookData;
|
||||
use Apoloz\AlfaBank\Data\Webhooks\Subscriptions\WebhookSubscriptionData;
|
||||
use Apoloz\AlfaBank\Data\Webhooks\Subscriptions\WebhookSubscriptionRequestData;
|
||||
use Saloon\Contracts\Body\HasBody;
|
||||
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
|
||||
{
|
||||
@@ -16,34 +17,21 @@ class CreateWebhookRequest extends Request implements HasBody
|
||||
protected Method $method = Method::POST;
|
||||
|
||||
public function __construct(
|
||||
protected string $object,
|
||||
protected string $callbackUri,
|
||||
protected ?array $accounts = null,
|
||||
protected int $version = 1
|
||||
protected WebhookSubscriptionRequestData $data
|
||||
) {}
|
||||
|
||||
public function resolveEndpoint(): string
|
||||
{
|
||||
return '/api/v1/webhooks';
|
||||
return '/api/v2/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;
|
||||
return $this->data->toArray();
|
||||
}
|
||||
|
||||
public function createDtoFromResponse(Response $response): WebhookData
|
||||
public function createDtoFromResponse(Response $response): WebhookSubscriptionData
|
||||
{
|
||||
return WebhookData::from($response->json());
|
||||
return WebhookSubscriptionData::from($response->json());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user