Bill all meet sessions per participant instead of per hour.
Deploy Ladill Meet / deploy (push) Successful in 46s
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:
@@ -11,19 +11,19 @@ class LicenseService
|
||||
/** @var array<string, array<string, int>> */
|
||||
public const TIERS = [
|
||||
'standard' => [
|
||||
'streaming_hours' => 100,
|
||||
'participant_count' => 100,
|
||||
'recording_storage_bytes' => 5_368_709_120, // 5 GB
|
||||
'file_storage_bytes' => 5_368_709_120,
|
||||
'ai_minutes' => 120,
|
||||
],
|
||||
'professional' => [
|
||||
'streaming_hours' => 500,
|
||||
'participant_count' => 500,
|
||||
'recording_storage_bytes' => 26_843_545_600, // 25 GB
|
||||
'file_storage_bytes' => 26_843_545_600,
|
||||
'ai_minutes' => 600,
|
||||
],
|
||||
'enterprise' => [
|
||||
'streaming_hours' => 5000,
|
||||
'participant_count' => 5000,
|
||||
'recording_storage_bytes' => 107_374_182_400, // 100 GB
|
||||
'file_storage_bytes' => 107_374_182_400,
|
||||
'ai_minutes' => 5000,
|
||||
|
||||
@@ -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),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,9 +47,7 @@ class UsageMeteringService
|
||||
|
||||
$summary = [];
|
||||
foreach ($raw as $metric => $total) {
|
||||
if ($metric === 'streaming_hours') {
|
||||
$summary['streaming_hours'] = round(((int) $total) / 100, 2);
|
||||
} elseif ($metric === 'participant_count') {
|
||||
if ($metric === 'participant_count') {
|
||||
$summary['participant_count'] = (int) $total;
|
||||
} else {
|
||||
$summary[$metric] = (int) $total;
|
||||
@@ -61,13 +59,11 @@ class UsageMeteringService
|
||||
|
||||
public function estimatedCostGhs(array $summary): array
|
||||
{
|
||||
$streamingHours = (float) ($summary['streaming_hours'] ?? 0);
|
||||
$participantCount = (int) ($summary['participant_count'] ?? 0);
|
||||
$recordingBytes = (int) ($summary['recording_storage_bytes'] ?? 0);
|
||||
$fileBytes = (int) ($summary['file_storage_bytes'] ?? 0);
|
||||
|
||||
return [
|
||||
'streaming' => round($streamingHours * $this->billing->pricePerHourGhs(), 2),
|
||||
'participants' => round($participantCount * $this->billing->pricePerParticipantGhs(), 2),
|
||||
'recording_storage' => round($this->billing->storageGb($recordingBytes) * $this->billing->pricePerGbMonthGhs(), 2),
|
||||
'file_storage' => round($this->billing->storageGb($fileBytes) * $this->billing->pricePerGbMonthGhs(), 2),
|
||||
|
||||
Reference in New Issue
Block a user