Skip to content

Commit 4097385

Browse files
committed
improve "free" products
1 parent f4fc1a4 commit 4097385

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

billing/src/Filament/App/Widgets/ProductWidget.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Boy132\Billing\Filament\App\Widgets;
44

5+
use App\Filament\Server\Pages\Console;
56
use Boy132\Billing\Models\Customer;
67
use Boy132\Billing\Models\Order;
78
use Boy132\Billing\Models\Product;
@@ -47,6 +48,13 @@ public function content(Schema $schema): Schema
4748
'product_price_id' => $price->id,
4849
]);
4950

51+
if ($price->isFree()) {
52+
$order->activate(null);
53+
$order->refresh();
54+
55+
return redirect(Console::getUrl(panel: 'server', tenant: $order->server));
56+
}
57+
5058
return $this->redirect($order->getCheckoutSession()->url);
5159
});
5260
}

billing/src/Models/ProductPrice.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,17 @@ public function sync(): void
8989
}
9090
}
9191

92+
public function isFree(): bool
93+
{
94+
return !$this->cost;
95+
}
96+
9297
public function formatCost(): string
9398
{
99+
if ($this->isFree()) {
100+
return 'Free';
101+
}
102+
94103
$formatter = new NumberFormatter(user()->language ?? 'en', NumberFormatter::CURRENCY);
95104

96105
return $formatter->formatCurrency($this->cost, config('billing.currency'));

0 commit comments

Comments
 (0)