Skip to content

Commit c8ff2b6

Browse files
committed
send notification when order expires
1 parent ba626a6 commit c8ff2b6

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

billing/src/Console/Commands/CheckOrdersCommand.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
namespace Boy132\Billing\Console\Commands;
44

5+
use Boy132\Billing\Enums\OrderStatus;
6+
use Boy132\Billing\Filament\App\Resources\Orders\Pages\ListOrders;
57
use Boy132\Billing\Models\Order;
8+
use Filament\Actions\Action;
9+
use Filament\Notifications\Notification;
610
use Illuminate\Console\Command;
711

812
class CheckOrdersCommand extends Command
@@ -25,7 +29,26 @@ public function handle(): int
2529
foreach ($orders as $order) {
2630
$bar->clear();
2731

28-
$order->checkExpire();
32+
if ($order->checkExpire()) {
33+
Notification::make()
34+
->success()
35+
->title('Order expired')
36+
->body($order->getLabel())
37+
->actions([
38+
Action::make('goto_orders')
39+
->label('Go to orders')
40+
->markAsRead()
41+
->url(ListOrders::getUrl(panel: 'app')),
42+
Action::make('renew')
43+
->visible(fn (Order $order) => $order->status === OrderStatus::Expired && $order->productPrice->renewable)
44+
->label('Renew')
45+
->color('warning')
46+
->requiresConfirmation()
47+
->markAsRead()
48+
->action(fn (Order $order) => redirect($order->getCheckoutSession()->url)),
49+
])
50+
->sendToDatabase($order->customer->user);
51+
}
2952

3053
$bar->advance();
3154
$bar->display();

0 commit comments

Comments
 (0)