Add subscription tiers, notification preferences, and logging infrastructure
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled

- Add database migrations for plans, subscriptions, notification preferences, and notification log tables
- Implement DispatchUserNotificationJob to handle channel resolution, daily limits, and logging (sent/tier_restricted/daily_limit)
- Add SendScheduledWhatsAppJob for scheduled notification delivery
- Create PlanFeatures service to resolve tier capabilities, check daily limits, and validate fuel
This commit is contained in:
Ovidiu U
2026-04-14 16:20:51 +01:00
parent 3cd3467178
commit 4220b1b86a
37 changed files with 2749 additions and 2 deletions

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Filament\Resources\Plans\Pages;
use App\Filament\Resources\Plans\PlanResource;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Cache;
class EditPlan extends EditRecord
{
protected static string $resource = PlanResource::class;
protected function getHeaderActions(): array
{
return [];
}
protected function afterSave(): void
{
if (Cache::supportsTags()) {
Cache::tags(['plans'])->flush();
}
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Filament\Resources\Plans\Pages;
use App\Filament\Resources\Plans\PlanResource;
use Filament\Resources\Pages\ListRecords;
class ListPlans extends ListRecords
{
protected static string $resource = PlanResource::class;
protected function getHeaderActions(): array
{
return [];
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Filament\Resources\Plans;
use App\Filament\NavigationGroup;
use App\Filament\Resources\Plans\Pages\EditPlan;
use App\Filament\Resources\Plans\Pages\ListPlans;
use App\Filament\Resources\Plans\Schemas\PlanForm;
use App\Filament\Resources\Plans\Tables\PlansTable;
use App\Models\Plan;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Tables\Table;
class PlanResource extends Resource
{
protected static ?string $model = Plan::class;
protected static string|\UnitEnum|null $navigationGroup = NavigationGroup::System;
protected static ?int $navigationSort = 10;
public static function form(Schema $schema): Schema
{
return PlanForm::configure($schema);
}
public static function table(Table $table): Table
{
return PlansTable::configure($table);
}
public static function getPages(): array
{
return [
'index' => ListPlans::route('/'),
'edit' => EditPlan::route('/{record}/edit'),
];
}
}

View File

@@ -0,0 +1,91 @@
<?php
namespace App\Filament\Resources\Plans\Schemas;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
class PlanForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
Section::make('Fuel Types')
->schema([
TextInput::make('features.fuel_types.max')
->label('Max fuel types')
->helperText('Leave blank for unlimited.')
->numeric()
->integer()
->minValue(1)
->nullable(),
]),
Section::make('Email')
->columns(2)
->schema([
Toggle::make('features.email.enabled')
->label('Enabled'),
Select::make('features.email.frequency')
->label('Frequency')
->options([
'weekly_digest' => 'Weekly digest',
'daily' => 'Daily',
'triggered' => 'Triggered',
]),
]),
Section::make('Push')
->schema([
Toggle::make('features.push.enabled')
->label('Enabled'),
]),
Section::make('WhatsApp')
->columns(3)
->schema([
Toggle::make('features.whatsapp.enabled')
->label('Enabled'),
TextInput::make('features.whatsapp.daily_limit')
->label('Daily limit')
->numeric()
->integer()
->minValue(0)
->required(),
TextInput::make('features.whatsapp.scheduled_updates')
->label('Scheduled updates per day')
->numeric()
->integer()
->minValue(0)
->required(),
]),
Section::make('SMS')
->columns(2)
->schema([
Toggle::make('features.sms.enabled')
->label('Enabled'),
TextInput::make('features.sms.daily_limit')
->label('Daily limit')
->numeric()
->integer()
->minValue(0)
->required(),
]),
Section::make('Features')
->schema([
Toggle::make('features.ai_predictions')
->label('AI predictions'),
Toggle::make('features.price_threshold')
->label('Price threshold alerts'),
Toggle::make('features.score_alerts')
->label('Score change alerts'),
]),
]);
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Filament\Resources\Plans\Tables;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
class PlansTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('name')
->label('Tier')
->badge()
->sortable(),
TextColumn::make('features.email.frequency')
->label('Email')
->placeholder('—'),
TextColumn::make('features.sms.daily_limit')
->label('SMS/day')
->placeholder('—'),
TextColumn::make('features.whatsapp.daily_limit')
->label('WhatsApp/day')
->placeholder('—'),
TextColumn::make('features.fuel_types.max')
->label('Fuel types')
->placeholder('Unlimited'),
IconColumn::make('active')
->boolean(),
])
->defaultSort('id', 'asc')
->recordActions([
EditAction::make(),
]);
}
}