- RegisterSubscriberOnPage: persist subscriber then dispatch integrations - IssueWeeztixCouponForSubscriber on weeztix queue; dispatches Mailwizz after coupon attempt (idempotent if coupon_code already set); failed() fallback - SyncSubscriberToMailwizz implements ShouldQueueAfterCommit - Deployment: worker listens weeztix,mailwizz,default; warn against sync in prod - .env.example: QUEUE_CONNECTION notes for subscribe UX Made-with: Cursor
50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Jobs\IssueWeeztixCouponForSubscriber;
|
|
use App\Jobs\SyncSubscriberToMailwizz;
|
|
use App\Models\PreregistrationPage;
|
|
use App\Models\Subscriber;
|
|
use App\Models\WeeztixConfig;
|
|
|
|
/**
|
|
* Orchestrates public registration: local persist first, then queue external integrations
|
|
* so Weeztix/Mailwizz failures never prevent a subscriber row from being stored.
|
|
*/
|
|
final class RegisterSubscriberOnPage
|
|
{
|
|
/**
|
|
* @param array<string, mixed> $validated
|
|
*/
|
|
public function storeAndQueueIntegrations(PreregistrationPage $page, array $validated): Subscriber
|
|
{
|
|
$subscriber = $page->subscribers()->create($validated);
|
|
|
|
$page->loadMissing('weeztixConfig', 'mailwizzConfig');
|
|
$weeztix = $page->weeztixConfig;
|
|
|
|
if ($this->weeztixCanIssueCodes($weeztix)) {
|
|
IssueWeeztixCouponForSubscriber::dispatch($subscriber);
|
|
} elseif ($page->mailwizzConfig !== null) {
|
|
SyncSubscriberToMailwizz::dispatch($subscriber->fresh());
|
|
}
|
|
|
|
return $subscriber;
|
|
}
|
|
|
|
private function weeztixCanIssueCodes(?WeeztixConfig $config): bool
|
|
{
|
|
if ($config === null || ! $config->is_connected) {
|
|
return false;
|
|
}
|
|
|
|
$company = $config->company_guid;
|
|
$coupon = $config->coupon_guid;
|
|
|
|
return is_string($company) && $company !== '' && is_string($coupon) && $coupon !== '';
|
|
}
|
|
}
|