Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

1.5 KB
Raw Blame
<?php

namespace HiEvents\Services\Domain;

use HiEvents\DomainObjects\Generated\WebhookDomainObjectAbstract;
use HiEvents\DomainObjects\WebhookDomainObject;
use HiEvents\Repository\Interfaces\WebhookRepositoryInterface;
use Illuminate\Support\Str;
use Psr\Log\LoggerInterface;

class CreateWebhookService
{
    public function __construct(
        private readonly WebhookRepositoryInterface $webhookRepository,
        private readonly LoggerInterface $logger,
    ) {}

    public function createWebhook(WebhookDomainObject $webhookDomainObject): WebhookDomainObject
    {
        $webhook = $this->webhookRepository->create([
            WebhookDomainObjectAbstract::URL => $webhookDomainObject->getUrl(),
            WebhookDomainObjectAbstract::EVENT_TYPES => $webhookDomainObject->getEventTypes(),
            WebhookDomainObjectAbstract::ACCOUNT_ID => $webhookDomainObject->getAccountId(),
            WebhookDomainObjectAbstract::STATUS => $webhookDomainObject->getStatus(),
            WebhookDomainObjectAbstract::EVENT_ID => $webhookDomainObject->getEventId(),
            WebhookDomainObjectAbstract::ORGANIZER_ID => $webhookDomainObject->getOrganizerId(),
            WebhookDomainObjectAbstract::USER_ID => $webhookDomainObject->getUserId(),
            WebhookDomainObjectAbstract::SECRET => Str::random(32),
        ]);

        $this->logger->info('Created webhook', [
            'webhook' => $webhookDomainObject->toArray(),
        ]);

        return $webhook;
    }
}