removed all references to credits. now credits are completely replaced by addons.

This commit is contained in:
Codex Agent
2025-12-01 15:50:17 +01:00
parent b8e515a03c
commit 28539754a7
76 changed files with 97 additions and 2533 deletions

View File

@@ -109,84 +109,6 @@ class Tenant extends Model
$this->attributes['settings'] = json_encode($value ?? []);
}
public function incrementCredits(int $amount, string $reason = 'manual', ?string $note = null, ?int $purchaseId = null): bool
{
if ($amount <= 0) {
return false;
}
$balance = (int) ($this->event_credits_balance ?? 0) + $amount;
$this->forceFill(['event_credits_balance' => $balance])->save();
$maxThreshold = collect(config('package-limits.credit_thresholds', []))
->filter(fn ($value) => is_numeric($value) && $value >= 0)
->map(fn ($value) => (int) $value)
->max();
if (
$maxThreshold !== null
&& $balance > $maxThreshold
&& ($this->credit_warning_sent_at !== null || $this->credit_warning_threshold !== null)
) {
$this->forceFill([
'credit_warning_sent_at' => null,
'credit_warning_threshold' => null,
])->save();
}
EventCreditsLedger::create([
'tenant_id' => $this->id,
'delta' => $amount,
'reason' => $reason,
'related_purchase_id' => $purchaseId,
'note' => $note,
]);
Log::info('Tenant credits incremented', [
'tenant_id' => $this->id,
'delta' => $amount,
'reason' => $reason,
'purchase_id' => $purchaseId,
]);
return true;
}
public function decrementCredits(int $amount, string $reason = 'usage', ?string $note = null, ?int $purchaseId = null): bool
{
$current = (int) ($this->event_credits_balance ?? 0);
if ($amount <= 0 || $amount > $current) {
return false;
}
$balance = $current - $amount;
$this->forceFill(['event_credits_balance' => $balance])->save();
app(\App\Services\Packages\TenantUsageTracker::class)->recordCreditBalance(
$this,
$current,
$balance
);
EventCreditsLedger::create([
'tenant_id' => $this->id,
'delta' => -$amount,
'reason' => $reason,
'related_purchase_id' => $purchaseId,
'note' => $note,
]);
Log::info('Tenant credits decremented', [
'tenant_id' => $this->id,
'delta' => -$amount,
'reason' => $reason,
'purchase_id' => $purchaseId,
]);
return true;
}
public function hasEventAllowance(): bool
{
$package = $this->getActiveResellerPackage();
@@ -194,7 +116,7 @@ class Tenant extends Model
return true;
}
return (int) ($this->event_credits_balance ?? 0) > 0;
return false;
}
public function consumeEventAllowance(int $amount = 1, string $reason = 'event.create', ?string $note = null): bool
@@ -221,7 +143,12 @@ class Tenant extends Model
return true;
}
return $this->decrementCredits($amount, $reason, $note);
Log::warning('Event allowance missing for tenant', [
'tenant_id' => $this->id,
'reason' => $reason,
]);
return false;
}
public function getActiveResellerPackage(): ?TenantPackage