Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions app/Console/Commands/BackfillSubscriptionPrices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Sleep;
use Laravel\Cashier\Cashier;
use Laravel\Cashier\Subscription;

class BackfillSubscriptionPrices extends Command
{
protected $signature = 'subscriptions:backfill-prices';

protected $description = 'Backfill price_paid on subscriptions from Stripe invoices';

public function handle(): int
{
$subscriptions = Subscription::whereNull('price_paid')->get();

if ($subscriptions->isEmpty()) {
$this->info('No subscriptions need backfilling.');

return self::SUCCESS;
}

$this->info("Backfilling {$subscriptions->count()} subscriptions...");

$bar = $this->output->createProgressBar($subscriptions->count());
$bar->start();

$errors = 0;

foreach ($subscriptions as $subscription) {
try {
$invoices = Cashier::stripe()->invoices->all([
'subscription' => $subscription->stripe_id,
'limit' => 1,
]);

if (! empty($invoices->data)) {
$subscription->update([
'price_paid' => max(0, $invoices->data[0]->total),
]);
}
} catch (\Exception $e) {
$errors++;
$this->newLine();
$this->error("Failed for subscription {$subscription->stripe_id}: {$e->getMessage()}");
}

$bar->advance();
Sleep::usleep(100_000);
}

$bar->finish();
$this->newLine(2);

if ($errors > 0) {
$this->warn("{$errors} subscription(s) failed to backfill.");
}

$this->info('Backfill complete.');

return self::SUCCESS;
}
}
4 changes: 2 additions & 2 deletions app/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace App\Filament\Pages;

use App\Filament\Widgets\LicenseDistributionChart;
use App\Filament\Widgets\LicensesChart;
use App\Filament\Widgets\PluginRevenueChart;
use App\Filament\Widgets\StatsOverview;
use App\Filament\Widgets\SubscriberIncomeChart;
use App\Filament\Widgets\UsersChart;
use Filament\Pages\Dashboard as BaseDashboard;

Expand All @@ -24,7 +24,7 @@ public function getWidgets(): array
{
return [
UsersChart::class,
LicensesChart::class,
SubscriberIncomeChart::class,
LicenseDistributionChart::class,
PluginRevenueChart::class,
];
Expand Down
11 changes: 11 additions & 0 deletions app/Filament/Resources/SubscriptionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ public static function table(Table $table): Table
})
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('billing_interval')
->label('Interval')
->state(fn (Subscription $record): string => $record->stripe_price === config('subscriptions.plans.max.stripe_price_id_monthly')
? 'Monthly'
: 'Annual'
)
->badge(),
Tables\Columns\TextColumn::make('price_paid')
->label('Price Paid')
->money('usd', divideBy: 100)
->sortable(),
// Tables\Columns\TextColumn::make('trial_ends_at')
// ->dateTime()
// ->sortable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public function infolist(Schema $schema): Schema
}
}),
Components\TextEntry::make('quantity'),
Components\TextEntry::make('billing_interval')
->label('Billing Interval')
->state(fn ($record): string => $record->stripe_price === config('subscriptions.plans.max.stripe_price_id_monthly')
? 'Monthly'
: 'Annual'
)
->badge(),
Components\TextEntry::make('price_paid')
->label('Price Paid')
->money('usd', divideBy: 100),
Components\TextEntry::make('trial_ends_at')
->dateTime(),
Components\TextEntry::make('ends_at')
Expand Down
167 changes: 0 additions & 167 deletions app/Filament/Widgets/LicensesChart.php

This file was deleted.

Loading
Loading