feat(integrations): resolve payment context from events

This commit is contained in:
2026-09-28 19:14:23 +00:00
parent 7996d53e12
commit 3f9b773367
7 changed files with 173 additions and 42 deletions

View File

@@ -3,8 +3,9 @@
namespace App\Shared\Integration\Services;
use App\Domains\Core\Client\Models\Client;
use App\Domains\Core\Tenant\Models\Tenant;
use App\Domains\Core\Tenant\Models\AdminWebsiteType;
use App\Domains\Core\Tenant\Models\Tenant;
use App\Domains\Ticketing\Event\Models\Event;
use Exception;
use Illuminate\Contracts\Mail\Factory as MailFactory;
use Illuminate\Contracts\Mail\Mailer;
@@ -39,14 +40,7 @@ class MailService extends BaseIntegrationService
public function forTenant(string $tenantCode): self
{
parent::forTenant($tenantCode);
if ($this->integrationInstance) {
$this->mailer = $this->resolveMailer();
$this->usesInstanceMailer = true;
} else {
$this->mailer = $this->mailFactory->mailer();
$this->usesInstanceMailer = false;
}
$this->configureMailer();
return $this;
}
@@ -55,16 +49,30 @@ class MailService extends BaseIntegrationService
{
parent::forClient($client);
$this->tenant = $this->clientContext?->tenants()->first();
$this->configureMailer();
return $this;
}
public function forEvent(Event $event): self
{
parent::forEvent($event);
$this->configureMailer();
return $this;
}
private function configureMailer(): void
{
if ($this->integrationInstance) {
$this->mailer = $this->resolveMailer();
$this->usesInstanceMailer = true;
} else {
$this->mailer = $this->mailFactory->mailer();
$this->usesInstanceMailer = false;
return;
}
return $this;
$this->mailer = $this->mailFactory->mailer();
$this->usesInstanceMailer = false;
}
public function getHeaders(): array
@@ -83,7 +91,7 @@ class MailService extends BaseIntegrationService
array $attachments = [],
): void {
if (! $this->mailer || ! $this->tenant) {
throw new Exception('MailService no está configurado. Llamá a forTenant() o forClient() primero.');
throw new Exception('MailService no está configurado. Llamá a forTenant(), forClient() o forEvent() primero.');
}
$brand ??= $this->tenant;
@@ -160,7 +168,7 @@ class MailService extends BaseIntegrationService
public function onSetup(): void
{
if (! $this->mailer || ! $this->clientContext) {
throw new Exception('MailService no está configurado. Llamá a forTenant() o forClient() primero.');
throw new Exception('MailService no está configurado. Llamá a forTenant(), forClient() o forEvent() primero.');
}
$recipient = $this->getIntegrationSetting('MAIL_FROM_ADDRESS');