feat: clean credits users
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\BillingProducts;
|
||||
|
||||
use App\Filament\Resources\BillingProducts\Pages\CreateBillingProduct;
|
||||
use App\Filament\Resources\BillingProducts\Pages\EditBillingProduct;
|
||||
use App\Filament\Resources\BillingProducts\Pages\ListBillingProducts;
|
||||
use App\Filament\Resources\BillingProducts\Schemas\BillingProductForm;
|
||||
use App\Filament\Resources\BillingProducts\Tables\BillingProductsTable;
|
||||
use App\Models\BillingProduct;
|
||||
use App\Services\StripeBillingProductSyncer;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class BillingProductResource extends Resource
|
||||
{
|
||||
protected static ?string $model = BillingProduct::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCreditCard;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.billing_products.navigation.label');
|
||||
}
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('admin.billing_products.navigation.singular');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('admin.billing_products.navigation.plural');
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return BillingProductForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return BillingProductsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function syncStripeAction(): Action
|
||||
{
|
||||
return Action::make('syncStripe')
|
||||
->label(__('admin.billing_products.actions.sync_stripe'))
|
||||
->icon(Heroicon::OutlinedArrowPath)
|
||||
->visible(fn (BillingProduct $record): bool => blank($record->stripe_price_id) && $record->purpose !== null)
|
||||
->requiresConfirmation()
|
||||
->action(function (BillingProduct $record): void {
|
||||
app(StripeBillingProductSyncer::class)->sync($record);
|
||||
|
||||
Notification::make()
|
||||
->title(__('admin.billing_products.actions.sync_stripe_success'))
|
||||
->success()
|
||||
->send();
|
||||
});
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListBillingProducts::route('/'),
|
||||
'create' => CreateBillingProduct::route('/create'),
|
||||
'edit' => EditBillingProduct::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\BillingProducts\Pages;
|
||||
|
||||
use App\Filament\Resources\BillingProducts\BillingProductResource;
|
||||
use App\Services\StripeBillingProductSyncer;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateBillingProduct extends CreateRecord
|
||||
{
|
||||
protected static string $resource = BillingProductResource::class;
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
app(StripeBillingProductSyncer::class)->sync($this->record);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\BillingProducts\Pages;
|
||||
|
||||
use App\Filament\Resources\BillingProducts\BillingProductResource;
|
||||
use App\Services\StripeBillingProductSyncer;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditBillingProduct extends EditRecord
|
||||
{
|
||||
protected static string $resource = BillingProductResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
BillingProductResource::syncStripeAction(),
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
app(StripeBillingProductSyncer::class)->sync($this->record);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\BillingProducts\Pages;
|
||||
|
||||
use App\Filament\Resources\BillingProducts\BillingProductResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListBillingProducts extends ListRecords
|
||||
{
|
||||
protected static string $resource = BillingProductResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
+14
-20
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CreditProducts\Schemas;
|
||||
namespace App\Filament\Resources\BillingProducts\Schemas;
|
||||
|
||||
use App\Enums\BillingProductPurpose;
|
||||
use App\Enums\CreditProductType;
|
||||
use Filament\Forms\Components\Hidden;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
@@ -12,60 +10,56 @@ use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class CreditProductForm
|
||||
class BillingProductForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make(__('admin.credit_products.sections.product'))
|
||||
Section::make(__('admin.billing_products.sections.product'))
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label(__('admin.credit_products.fields.name'))
|
||||
->label(__('admin.billing_products.fields.name'))
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Select::make('purpose')
|
||||
->label(__('admin.credit_products.fields.purpose'))
|
||||
->label(__('admin.billing_products.fields.purpose'))
|
||||
->options(BillingProductPurpose::class)
|
||||
->unique(ignoreRecord: true)
|
||||
->required(),
|
||||
Hidden::make('type')
|
||||
->default(CreditProductType::ONE_TIME->value),
|
||||
Hidden::make('credits')
|
||||
->default(0),
|
||||
TextInput::make('amount')
|
||||
->label(__('admin.credit_products.fields.amount'))
|
||||
->helperText(__('admin.credit_products.helpers.amount'))
|
||||
->label(__('admin.billing_products.fields.amount'))
|
||||
->helperText(__('admin.billing_products.helpers.amount'))
|
||||
->integer()
|
||||
->minValue(1)
|
||||
->required(),
|
||||
TextInput::make('currency')
|
||||
->label(__('admin.credit_products.fields.currency'))
|
||||
->label(__('admin.billing_products.fields.currency'))
|
||||
->default('eur')
|
||||
->required()
|
||||
->maxLength(3),
|
||||
TextInput::make('sort_order')
|
||||
->label(__('admin.credit_products.fields.sort_order'))
|
||||
->label(__('admin.billing_products.fields.sort_order'))
|
||||
->integer()
|
||||
->default(0)
|
||||
->required(),
|
||||
Textarea::make('description')
|
||||
->label(__('admin.credit_products.fields.description'))
|
||||
->label(__('admin.billing_products.fields.description'))
|
||||
->rows(3)
|
||||
->columnSpanFull(),
|
||||
Toggle::make('is_active')
|
||||
->label(__('admin.credit_products.fields.is_active'))
|
||||
->label(__('admin.billing_products.fields.is_active'))
|
||||
->default(true),
|
||||
]),
|
||||
Section::make(__('admin.credit_products.sections.stripe'))
|
||||
Section::make(__('admin.billing_products.sections.stripe'))
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('stripe_product_id')
|
||||
->label(__('admin.credit_products.fields.stripe_product_id'))
|
||||
->label(__('admin.billing_products.fields.stripe_product_id'))
|
||||
->maxLength(255),
|
||||
TextInput::make('stripe_price_id')
|
||||
->label(__('admin.credit_products.fields.stripe_price_id'))
|
||||
->label(__('admin.billing_products.fields.stripe_price_id'))
|
||||
->unique(ignoreRecord: true)
|
||||
->maxLength(255),
|
||||
]),
|
||||
+13
-13
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CreditProducts\Tables;
|
||||
namespace App\Filament\Resources\BillingProducts\Tables;
|
||||
|
||||
use App\Enums\BillingProductPurpose;
|
||||
use App\Filament\Resources\CreditProducts\CreditProductResource;
|
||||
use App\Filament\Resources\BillingProducts\BillingProductResource;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
@@ -13,7 +13,7 @@ use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class CreditProductsTable
|
||||
class BillingProductsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
@@ -21,45 +21,45 @@ class CreditProductsTable
|
||||
->defaultSort('sort_order')
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label(__('admin.credit_products.fields.name'))
|
||||
->label(__('admin.billing_products.fields.name'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('purpose')
|
||||
->label(__('admin.credit_products.fields.purpose'))
|
||||
->label(__('admin.billing_products.fields.purpose'))
|
||||
->badge()
|
||||
->sortable(),
|
||||
TextColumn::make('amount')
|
||||
->label(__('admin.credit_products.fields.amount'))
|
||||
->label(__('admin.billing_products.fields.amount'))
|
||||
->money(fn ($record): string => $record->currency, divideBy: 100)
|
||||
->sortable(),
|
||||
TextColumn::make('stripe_price_id')
|
||||
->label(__('admin.credit_products.fields.stripe_price_id'))
|
||||
->label(__('admin.billing_products.fields.stripe_price_id'))
|
||||
->copyable()
|
||||
->searchable()
|
||||
->toggleable(),
|
||||
IconColumn::make('is_active')
|
||||
->label(__('admin.credit_products.fields.is_active'))
|
||||
->label(__('admin.billing_products.fields.is_active'))
|
||||
->boolean()
|
||||
->sortable(),
|
||||
TextColumn::make('sort_order')
|
||||
->label(__('admin.credit_products.fields.sort_order'))
|
||||
->label(__('admin.billing_products.fields.sort_order'))
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('created_at')
|
||||
->label(__('admin.credit_products.fields.created_at'))
|
||||
->label(__('admin.billing_products.fields.created_at'))
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('purpose')
|
||||
->label(__('admin.credit_products.fields.purpose'))
|
||||
->label(__('admin.billing_products.fields.purpose'))
|
||||
->options(BillingProductPurpose::class),
|
||||
TernaryFilter::make('is_active')
|
||||
->label(__('admin.credit_products.fields.is_active')),
|
||||
->label(__('admin.billing_products.fields.is_active')),
|
||||
])
|
||||
->recordActions([
|
||||
CreditProductResource::syncStripeAction(),
|
||||
BillingProductResource::syncStripeAction(),
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CreditProducts;
|
||||
|
||||
use App\Filament\Resources\CreditProducts\Pages\CreateCreditProduct;
|
||||
use App\Filament\Resources\CreditProducts\Pages\EditCreditProduct;
|
||||
use App\Filament\Resources\CreditProducts\Pages\ListCreditProducts;
|
||||
use App\Filament\Resources\CreditProducts\Schemas\CreditProductForm;
|
||||
use App\Filament\Resources\CreditProducts\Tables\CreditProductsTable;
|
||||
use App\Models\CreditProduct;
|
||||
use App\Services\StripeCreditProductSyncer;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class CreditProductResource extends Resource
|
||||
{
|
||||
protected static ?string $model = CreditProduct::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCreditCard;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.credit_products.navigation.label');
|
||||
}
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('admin.credit_products.navigation.singular');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('admin.credit_products.navigation.plural');
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return CreditProductForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return CreditProductsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function syncStripeAction(): Action
|
||||
{
|
||||
return Action::make('syncStripe')
|
||||
->label(__('admin.credit_products.actions.sync_stripe'))
|
||||
->icon(Heroicon::OutlinedArrowPath)
|
||||
->visible(fn (CreditProduct $record): bool => blank($record->stripe_price_id) && $record->purpose !== null)
|
||||
->requiresConfirmation()
|
||||
->action(function (CreditProduct $record): void {
|
||||
app(StripeCreditProductSyncer::class)->sync($record);
|
||||
|
||||
Notification::make()
|
||||
->title(__('admin.credit_products.actions.sync_stripe_success'))
|
||||
->success()
|
||||
->send();
|
||||
});
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListCreditProducts::route('/'),
|
||||
'create' => CreateCreditProduct::route('/create'),
|
||||
'edit' => EditCreditProduct::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CreditProducts\Pages;
|
||||
|
||||
use App\Filament\Resources\CreditProducts\CreditProductResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateCreditProduct extends CreateRecord
|
||||
{
|
||||
protected static string $resource = CreditProductResource::class;
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
app(\App\Services\StripeCreditProductSyncer::class)->sync($this->record);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CreditProducts\Pages;
|
||||
|
||||
use App\Filament\Resources\CreditProducts\CreditProductResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditCreditProduct extends EditRecord
|
||||
{
|
||||
protected static string $resource = CreditProductResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreditProductResource::syncStripeAction(),
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
app(\App\Services\StripeCreditProductSyncer::class)->sync($this->record);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CreditProducts\Pages;
|
||||
|
||||
use App\Filament\Resources\CreditProducts\CreditProductResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListCreditProducts extends ListRecords
|
||||
{
|
||||
protected static string $resource = CreditProductResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -28,18 +28,13 @@ class PaymentTransactionInfolist
|
||||
->label(__('admin.payment_transactions.fields.user'))
|
||||
->placeholder(__('admin.payment_transactions.placeholders.empty'))
|
||||
->copyable(),
|
||||
TextEntry::make('creditProduct.name')
|
||||
->label(__('admin.payment_transactions.fields.credit_product'))
|
||||
TextEntry::make('billingProduct.name')
|
||||
->label(__('admin.payment_transactions.fields.billing_product'))
|
||||
->placeholder(__('admin.payment_transactions.placeholders.empty')),
|
||||
TextEntry::make('amount')
|
||||
->label(__('admin.payment_transactions.fields.amount'))
|
||||
->money(fn ($record): string => $record->currency ?: 'eur', divideBy: 100)
|
||||
->placeholder(__('admin.payment_transactions.placeholders.empty')),
|
||||
TextEntry::make('credits_expected')
|
||||
->label(__('admin.payment_transactions.fields.credits_expected'))
|
||||
->placeholder(__('admin.payment_transactions.placeholders.empty')),
|
||||
TextEntry::make('credits_granted')
|
||||
->label(__('admin.payment_transactions.fields.credits_granted')),
|
||||
TextEntry::make('processed_at')
|
||||
->label(__('admin.payment_transactions.fields.processed_at'))
|
||||
->dateTime()
|
||||
|
||||
@@ -32,8 +32,8 @@ class PaymentTransactionsTable
|
||||
->label(__('admin.payment_transactions.fields.user'))
|
||||
->searchable()
|
||||
->placeholder(__('admin.payment_transactions.placeholders.empty')),
|
||||
TextColumn::make('creditProduct.name')
|
||||
->label(__('admin.payment_transactions.fields.credit_product'))
|
||||
TextColumn::make('billingProduct.name')
|
||||
->label(__('admin.payment_transactions.fields.billing_product'))
|
||||
->searchable()
|
||||
->placeholder(__('admin.payment_transactions.placeholders.empty')),
|
||||
TextColumn::make('amount')
|
||||
@@ -41,15 +41,6 @@ class PaymentTransactionsTable
|
||||
->money(fn ($record): string => $record->currency ?: 'eur', divideBy: 100)
|
||||
->sortable()
|
||||
->placeholder(__('admin.payment_transactions.placeholders.empty')),
|
||||
TextColumn::make('credits_expected')
|
||||
->label(__('admin.payment_transactions.fields.credits_expected'))
|
||||
->numeric(decimalPlaces: 0)
|
||||
->sortable()
|
||||
->placeholder(__('admin.payment_transactions.placeholders.empty')),
|
||||
TextColumn::make('credits_granted')
|
||||
->label(__('admin.payment_transactions.fields.credits_granted'))
|
||||
->numeric(decimalPlaces: 0)
|
||||
->sortable(),
|
||||
TextColumn::make('stripe_event_type')
|
||||
->label(__('admin.payment_transactions.fields.stripe_event_type'))
|
||||
->toggleable(),
|
||||
|
||||
Reference in New Issue
Block a user