Skip to content

Commit 8e7e029

Browse files
committed
add "renewable" option to product prices
1 parent 4097385 commit 8e7e029

4 files changed

Lines changed: 17 additions & 2 deletions

File tree

billing/database/migrations/004_create_product_prices_table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function up(): void
1414
$table->string('stripe_id')->nullable();
1515
$table->string('name');
1616
$table->float('cost', 2);
17+
$table->boolean('renewable')->default(true);
1718
$table->string('interval_type')->default(PriceInterval::Month);
1819
$table->unsignedInteger('interval_value')->default(1);
1920

billing/src/Filament/Admin/Resources/Products/RelationManagers/PriceRelationManager.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
use Filament\Actions\EditAction;
1111
use Filament\Forms\Components\Select;
1212
use Filament\Forms\Components\TextInput;
13+
use Filament\Forms\Components\Toggle;
1314
use Filament\Resources\RelationManagers\RelationManager;
1415
use Filament\Schemas\Schema;
16+
use Filament\Tables\Columns\IconColumn;
1517
use Filament\Tables\Columns\TextColumn;
1618
use Filament\Tables\Table;
1719

@@ -27,12 +29,17 @@ public function form(Schema $schema): Schema
2729
return $schema
2830
->components([
2931
TextInput::make('name')
30-
->required(),
32+
->required()
33+
->label('Internal Name')
34+
->columnSpanFull(),
3135
TextInput::make('cost')
3236
->required()
3337
->suffix(config('billing.currency'))
3438
->numeric()
3539
->minValue(0),
40+
Toggle::make('renewable')
41+
->label('Can be renewed?')
42+
->inline(false),
3643
Select::make('interval_type')
3744
->required()
3845
->selectablePlaceholder(false)
@@ -49,10 +56,14 @@ public function table(Table $table): Table
4956
return $table
5057
->columns([
5158
TextColumn::make('name')
59+
->label('Internal Name')
5260
->sortable(),
5361
TextColumn::make('cost')
5462
->sortable()
5563
->state(fn (ProductPrice $price) => $price->formatCost()),
64+
IconColumn::make('renewable')
65+
->label('Can be renewed?')
66+
->boolean(),
5667
TextColumn::make('interval')
5768
->state(fn (ProductPrice $price) => $price->interval_value . ' ' . $price->interval_type->name),
5869
])

billing/src/Filament/App/Resources/Orders/OrdersResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static function table(Table $table): Table
8888
->requiresConfirmation()
8989
->action(fn (Order $order) => $order->close()),
9090
Action::make('renew')
91-
->visible(fn (Order $order) => $order->status === OrderStatus::Expired)
91+
->visible(fn (Order $order) => $order->status === OrderStatus::Expired && $order->productPrice->renewable)
9292
->color('warning')
9393
->requiresConfirmation()
9494
->action(fn (Order $order) => redirect($order->getCheckoutSession()->url)),

billing/src/Models/ProductPrice.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @property ?string $stripe_id
1515
* @property string $name
1616
* @property int $cost
17+
* @property bool $renewable
1718
* @property PriceInterval $interval_type
1819
* @property int $interval_value
1920
* @property int $product_id
@@ -26,13 +27,15 @@ class ProductPrice extends Model implements HasLabel
2627
'product_id',
2728
'name',
2829
'cost',
30+
'renewable',
2931
'interval_type',
3032
'interval_value',
3133
];
3234

3335
protected function casts(): array
3436
{
3537
return [
38+
'renewable' => 'bool',
3639
'interval_type' => PriceInterval::class,
3740
];
3841
}

0 commit comments

Comments
 (0)