fix(events): point Messaging settings at suite defaults, not API keys
Deploy Ladill Events / deploy (push) Successful in 48s
Deploy Ladill Events / deploy (push) Successful in 48s
Mirror Care: suite platform keys count as ready for attendee email/SMS; Account Messaging is primary, product Bird/SMS keys are advanced. SmsService now prefers channel=suite before customer API keys.
This commit is contained in:
@@ -5,6 +5,10 @@ namespace App\Services\Billing;
|
||||
use App\Services\Messaging\CustomerSmsClient;
|
||||
use App\Services\Messaging\MessagingCredentialsService;
|
||||
|
||||
/**
|
||||
* Attendee SMS: prefer platform suite messaging (zero-config), fall back to
|
||||
* product SMS API keys when suite is unavailable.
|
||||
*/
|
||||
class SmsService
|
||||
{
|
||||
private ?string $lastError = null;
|
||||
@@ -12,6 +16,7 @@ class SmsService
|
||||
public function __construct(
|
||||
private readonly CustomerSmsClient $customer,
|
||||
private readonly MessagingCredentialsService $credentials,
|
||||
private readonly PlatformSmsClient $platformSms,
|
||||
) {}
|
||||
|
||||
public function lastError(): ?string
|
||||
@@ -19,6 +24,15 @@ class SmsService
|
||||
return $this->lastError;
|
||||
}
|
||||
|
||||
public function isConfiguredForOwner(string $ownerPublicId): bool
|
||||
{
|
||||
if ($this->platformSms->isConfigured()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->credentials->forOwner($ownerPublicId)->hasValidSms();
|
||||
}
|
||||
|
||||
public function send(string $ownerPublicId, string $to, string $message): bool
|
||||
{
|
||||
$this->lastError = null;
|
||||
@@ -37,15 +51,43 @@ class SmsService
|
||||
}
|
||||
|
||||
$credential = $this->credentials->forOwner($ownerPublicId);
|
||||
|
||||
if ($this->platformSms->isConfigured()) {
|
||||
$sender = $credential->sms_sender_id ?: null;
|
||||
$sent = $this->platformSms->send(
|
||||
$ownerPublicId,
|
||||
$phone,
|
||||
$message,
|
||||
$sender ? (string) $sender : null,
|
||||
);
|
||||
if ($sent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$suiteError = $this->platformSms->lastError();
|
||||
if ($this->tryCustomerSms($credential, $phone, $message)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->lastError = $suiteError ?: $this->lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->tryCustomerSms($credential, $phone, $message);
|
||||
}
|
||||
|
||||
private function tryCustomerSms(object $credential, string $phone, string $message): bool
|
||||
{
|
||||
if (! $credential->hasValidSms()) {
|
||||
$this->lastError = 'Connect Ladill SMS in Integrations before sending attendee SMS.';
|
||||
$this->lastError = 'SMS is not available (platform SMS key missing and no product SMS credentials).';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$apiKey = $credential->smsApiKey();
|
||||
if (! $apiKey) {
|
||||
$this->lastError = 'SMS credentials could not be decrypted. Reconnect SMS in Integrations.';
|
||||
$this->lastError = 'SMS credentials could not be decrypted. Reconnect SMS under Advanced keys.';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user