Bill all meet sessions per participant instead of per hour.
Deploy Ladill Meet / deploy (push) Successful in 46s

Meetings and webinars now share GHS 0.30 per peak participant, with usage UI and plan quotas updated to match.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-01 18:28:35 +00:00
co-authored by Cursor
parent d0a3361f37
commit 5c1affcca5
8 changed files with 38 additions and 127 deletions
+8 -82
View File
@@ -14,7 +14,7 @@ use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Log;
use RuntimeException;
/** Pay-as-you-go Meet billing: streaming hours + monthly storage per GB (same model as Transfer). */
/** Pay-as-you-go Meet billing: per-participant sessions + monthly storage per GB. */
class MeetBillingService
{
private const BYTES_PER_GB = 1073741824;
@@ -23,21 +23,11 @@ class MeetBillingService
protected BillingClient $billing,
) {}
public function pricePerHourGhs(): float
{
return (float) config('meet.billing.price_per_hour_ghs', 0.30);
}
public function pricePerParticipantGhs(): float
{
return (float) config('meet.billing.price_per_participant_ghs', 0.30);
}
public function usesParticipantBilling(?Room $room): bool
{
return $room?->isWebinar() ?? false;
}
public function pricePerGbMonthGhs(): float
{
return (float) config('meet.billing.price_per_gb_month_ghs', 0.30);
@@ -48,19 +38,6 @@ class MeetBillingService
return max(1, (int) config('meet.billing.grace_period_days', 15));
}
public function streamingHoursFor(Session $session): float
{
if (! $session->started_at) {
return 0;
}
$ended = $session->ended_at ?? now();
$hours = $session->started_at->diffInSeconds($ended) / 3600;
$minimum = max(1, (int) config('meet.billing.minimum_streaming_hours', 1));
return max($minimum, ceil($hours));
}
public function storageGb(int $bytes): float
{
if ($bytes <= 0) {
@@ -70,13 +47,6 @@ class MeetBillingService
return round($bytes / self::BYTES_PER_GB, 4);
}
public function amountMinorForStreamingHours(float $hours): int
{
$ghs = round($hours * $this->pricePerHourGhs(), 2);
return max((int) round($ghs * 100), 1);
}
public function participantsBillableFor(Session $session): int
{
return max(1, (int) ($session->peak_participants ?? 0));
@@ -102,21 +72,11 @@ class MeetBillingService
public function assertCanStartSession(Organization $organization, ?Room $room = null): void
{
if ($this->usesParticipantBilling($room)) {
$amountMinor = $this->amountMinorForParticipants(1);
$message = sprintf(
'Insufficient wallet balance. Webinars are billed at GHS %.2f per participant — top up your Ladill wallet to start.',
$this->pricePerParticipantGhs(),
);
} else {
$amountMinor = $this->amountMinorForStreamingHours(
max(1, (int) config('meet.billing.minimum_streaming_hours', 1))
);
$message = sprintf(
'Insufficient wallet balance. Meetings are billed at GHS %.2f per hour — top up your Ladill wallet to start.',
$this->pricePerHourGhs(),
);
}
$amountMinor = $this->amountMinorForParticipants(1);
$message = sprintf(
'Insufficient wallet balance. Sessions are billed at GHS %.2f per participant — top up your Ladill wallet to start.',
$this->pricePerParticipantGhs(),
);
$affordable = $this->canAffordSafely($organization->owner_ref, $amountMinor);
@@ -129,41 +89,7 @@ class MeetBillingService
public function chargeSession(Session $session): void
{
$session->loadMissing('room');
if ($this->usesParticipantBilling($session->room)) {
$this->chargeParticipants($session);
return;
}
$this->chargeStreaming($session);
}
public function chargeStreaming(Session $session): void
{
$session->loadMissing('room.organization');
$organization = $session->room->organization;
$hours = $this->streamingHoursFor($session);
$amountMinor = $this->amountMinorForStreamingHours($hours);
if ($amountMinor <= 0) {
return;
}
$this->recordUsage($organization, 'streaming_hours', (int) round($hours * 100), [
'session_uuid' => $session->uuid,
'room_uuid' => $session->room->uuid,
'hours' => $hours,
], $session->room->branch_id);
$this->debit(
$organization->owner_ref,
$amountMinor,
'meet_streaming',
'meet-streaming-'.$session->uuid,
sprintf('Meet streaming: %s (%.1f hr)', $session->room->title, $hours),
);
$this->chargeParticipants($session);
}
public function chargeParticipants(Session $session): void
@@ -188,7 +114,7 @@ class MeetBillingService
$amountMinor,
'meet_participants',
'meet-participants-'.$session->uuid,
sprintf('Meet webinar: %s (%d participants)', $session->room->title, $count),
sprintf('Meet session: %s (%d participants)', $session->room->title, $count),
);
}