Add per-customer SMS and Bird credentials to Frontdesk Integrations.
Deploy Ladill Frontdesk / deploy (push) Successful in 45s

NotificationDispatcher sends via customer relay and skips Frontdesk wallet debit when tenant keys are configured.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-12 17:05:54 +00:00
co-authored by Cursor
parent 0b45e08016
commit 8300cafc36
17 changed files with 1110 additions and 40 deletions
@@ -4,6 +4,7 @@ namespace App\Services\Frontdesk;
use App\Models\Organization;
use App\Services\Billing\BillingClient;
use App\Services\Messaging\MessagingCredentialsService;
use Illuminate\Support\Str;
class NotificationBillingService
@@ -13,10 +14,25 @@ class NotificationBillingService
protected NotificationPricingService $pricing,
protected NotificationUsageService $usage,
protected PlanService $plans,
protected MessagingCredentialsService $credentials,
) {}
public function usesCustomerEmail(Organization $organization): bool
{
return $this->credentials->forOrganization($organization)->hasValidBird();
}
public function usesCustomerSms(Organization $organization): bool
{
return $this->credentials->forOrganization($organization)->hasValidSms();
}
public function emailCostMinor(Organization $organization): int
{
if ($this->usesCustomerEmail($organization)) {
return 0;
}
$allowance = $this->plans->freeEmailsPerMonth($organization);
if ($allowance === null || $this->usage->emailCountThisMonth($organization) < $allowance) {
return 0;
@@ -27,6 +43,10 @@ class NotificationBillingService
public function canAffordEmail(Organization $organization): bool
{
if ($this->usesCustomerEmail($organization)) {
return true;
}
$cost = $this->emailCostMinor($organization);
if ($cost <= 0) {
return true;
@@ -37,6 +57,10 @@ class NotificationBillingService
public function canAffordSms(Organization $organization, string $message): bool
{
if ($this->usesCustomerSms($organization)) {
return true;
}
$cost = $this->pricing->smsCostMinor($message);
if ($cost <= 0) {
return true;
@@ -47,9 +71,16 @@ class NotificationBillingService
/**
* Debit after a successful send. Returns false if the wallet could not be charged.
* Customer relay keys bill the Ladill SMS/Bird wallet directly never double-debit Frontdesk.
*/
public function chargeEmail(Organization $organization, string $reference, string $description): bool
{
if ($this->usesCustomerEmail($organization)) {
$this->usage->recordEmail($organization, 0);
return true;
}
$cost = $this->emailCostMinor($organization);
if ($cost <= 0) {
$this->usage->recordEmail($organization, 0);
@@ -68,6 +99,12 @@ class NotificationBillingService
public function chargeSms(Organization $organization, string $message, string $reference, string $description): bool
{
if ($this->usesCustomerSms($organization)) {
$this->usage->recordSms($organization, 0);
return true;
}
$cost = $this->pricing->smsCostMinor($message);
if ($cost <= 0) {
$this->usage->recordSms($organization, 0);