24 lines
567 B
PHP
24 lines
567 B
PHP
<?php
|
|
|
|
namespace App\Services\Newsletter;
|
|
|
|
use App\Contracts\NewsletterSyncClient;
|
|
use App\Models\NewsletterSubscription;
|
|
|
|
class NewsletterSyncService
|
|
{
|
|
public function __construct(
|
|
private readonly NewsletterSyncClient $client
|
|
) {}
|
|
|
|
public function syncSubscription(NewsletterSubscription $subscription): void
|
|
{
|
|
if ($subscription->is_confirmed && $subscription->unsubscribed_at === null) {
|
|
$this->client->subscribe($subscription);
|
|
|
|
return;
|
|
}
|
|
|
|
$this->client->unsubscribe($subscription);
|
|
}
|
|
}
|