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

@@ -1,100 +0,0 @@
<?php
namespace App\Jobs\Packages;
use App\Jobs\Concerns\LogsTenantNotifications;
use App\Models\Tenant;
use App\Notifications\Packages\TenantCreditsLowNotification;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
class SendTenantCreditsLowNotification implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use LogsTenantNotifications;
use Queueable;
use SerializesModels;
public function __construct(
public int $tenantId,
public int $balance,
public int $threshold,
) {}
public function handle(): void
{
$tenant = Tenant::find($this->tenantId);
if (! $tenant) {
Log::warning('Tenant credits low job skipped; tenant missing', [
'tenant_id' => $this->tenantId,
]);
return;
}
$preferences = app(\App\Services\Packages\TenantNotificationPreferences::class);
if (! $preferences->shouldNotify($tenant, 'credits_low')) {
$this->logNotification($tenant, [
'type' => 'credits_low',
'status' => 'skipped',
'context' => [
'balance' => $this->balance,
'threshold' => $this->threshold,
'reason' => 'opt_out',
],
]);
return;
}
$emails = collect([
$tenant->contact_email,
$tenant->user?->email,
])->filter(fn ($email) => is_string($email) && filter_var($email, FILTER_VALIDATE_EMAIL))
->unique();
if ($emails->isEmpty()) {
Log::info('Tenant credits low notification skipped due to missing recipients', [
'tenant_id' => $tenant->id,
]);
$this->logNotification($tenant, [
'type' => 'credits_low',
'status' => 'skipped',
'context' => [
'balance' => $this->balance,
'threshold' => $this->threshold,
'reason' => 'no_recipient',
],
]);
return;
}
$context = [
'balance' => $this->balance,
'threshold' => $this->threshold,
];
$this->dispatchToRecipients(
$tenant,
$emails,
'credits_low',
function (string $email) use ($tenant) {
Notification::route('mail', $email)->notify(new TenantCreditsLowNotification(
$tenant,
$this->balance,
$this->threshold,
));
},
$context
);
}
}

View File

@@ -66,14 +66,6 @@ class ProcessRevenueCatWebhook implements ShouldQueue
?? $this->value('event.entitlement_id');
$credits = $this->mapCreditsFromProduct($productId);
if ($credits <= 0) {
Log::info('RevenueCat webhook ignored due to unmapped product', [
'event_id' => $this->eventId,
'product_id' => $productId,
]);
return;
}
$transactionId = $this->value('event.transaction_id')
?? $this->value('event.id')
?? $this->eventId
@@ -101,9 +93,6 @@ class ProcessRevenueCatWebhook implements ShouldQueue
'status' => 'completed',
'purchased_at' => now(),
]);
$note = sprintf('RevenueCat product: %s', $productId ?? 'unknown');
$tenant->incrementCredits($credits, 'purchase', $note, $purchase->id);
});
$tenant->refresh();

View File

@@ -88,7 +88,6 @@ class ValidateStripeWebhookJob implements ShouldQueue
'purchased_at' => now(),
]);
$tenant->incrementCredits($eventsPurchased, 'purchase', null, $purchase->id);
});
Log::info('Processed Stripe purchase via job', ['receipt_id' => $receiptId, 'tenant_id' => $tenantId]);
@@ -96,4 +95,4 @@ class ValidateStripeWebhookJob implements ShouldQueue
Log::info('Unhandled Stripe event in job', ['type' => $event['type']]);
}
}
}
}