F
Filamentβ€’3w ago
Bart

Laravel Spark Stripe and Filament - subscriptions per user

Hi all, I'm struggling a bit with Laravel Spark Stripe and Filament. I noticed there's the spark-billing-provider for Filament, but I think it's designed for multi-tenancy and subscriptions per tenant. I'm building a setup to do subscriptions per user. Got the Laravel Spark integration working for the billing page and communication with Stripe. But I'm not figuring out how to check for these subscriptions, show banners below the top bar when someone is on a trial etc. Did anyone do this before, subscriptions per user? I'm in need of a small push into the right direction πŸ˜… Thanks πŸ™
Solution:
Update: I used a custom blade file (subscriptionBanner) for the banner and attached it using a renderHook in the panel provider. It was as simple as that in the end πŸ˜… renderHook('panels::body.start', fn () => view('subscriptionBanner'), )...
Jump to solution
5 Replies
wewewe
weweweβ€’3w ago
You can set up multi tenancy and limit the user to have only one tenant
neverything
neverythingβ€’3w ago
Might be useful in general to see what you can do, I set this up, not per user, but it's totally doable: https://silvanhagen.com/writing/free-users-filament-laravel-spark/
Silvan Hagen
Free users with Filament and Laravel Spark
How to handle free users in a multi-tenant Filament app using Laravel Spark and a custom Middleware.
neverything
neverythingβ€’3w ago
On the admin panel, I use a render hook, to display the subscription status: ->renderHook('panels::global-search.before', fn (): string => Blade::render('@livewire('project.subscription-status')')) Maybe this helps to render a banner
<?php

namespace App\Livewire\Project;

use App\Models\Project;
use Filament\Facades\Filament;
use Livewire\Component;

class SubscriptionStatus extends Component
{
protected ?Project $project;

public ?array $status;

public ?string $billingPortalUrl;

public function mount(): void
{
$this->project = Filament::getTenant();
$this->status = $this->project->subscription_status;
$this->billingPortalUrl = Filament::getTenantBillingUrl();
}

public function render()
{
return view('livewire.project.subscription-status');
}
}
<?php

namespace App\Livewire\Project;

use App\Models\Project;
use Filament\Facades\Filament;
use Livewire\Component;

class SubscriptionStatus extends Component
{
protected ?Project $project;

public ?array $status;

public ?string $billingPortalUrl;

public function mount(): void
{
$this->project = Filament::getTenant();
$this->status = $this->project->subscription_status;
$this->billingPortalUrl = Filament::getTenantBillingUrl();
}

public function render()
{
return view('livewire.project.subscription-status');
}
}
`
<div>
@if ($status)
@if ($status['type'] === 'on-trial')
<x-filament::badge tag="a" tooltip="Get a paid subscription to keep using the app." href="{{ $billingPortalUrl }}" color="warning">
{{ $status['message'] }}
</x-filament::badge>
@elseif ($status['type'] === 'active')
<x-filament::badge tag="a" tooltip="You are awesome! Thank you for being a paying customer." href="{{ $billingPortalUrl }}" color="success">
{{ $status['message'] }}
</x-filament::badge>
@elseif ($status['type'] === 'needs-subscription')
<x-filament::badge tag="a" tooltip="You need an active subscription to use all the features." href="{{ $billingPortalUrl }}" color="danger">
{{ $status['message'] }}
</x-filament::badge>
@elseif ($status['type'] === 'free')
<x-filament::badge tooltip="Thank you for testing this little app." color="gray">
{{ $status['message'] }}
</x-filament::badge>
@endif
@endif
</div>
<div>
@if ($status)
@if ($status['type'] === 'on-trial')
<x-filament::badge tag="a" tooltip="Get a paid subscription to keep using the app." href="{{ $billingPortalUrl }}" color="warning">
{{ $status['message'] }}
</x-filament::badge>
@elseif ($status['type'] === 'active')
<x-filament::badge tag="a" tooltip="You are awesome! Thank you for being a paying customer." href="{{ $billingPortalUrl }}" color="success">
{{ $status['message'] }}
</x-filament::badge>
@elseif ($status['type'] === 'needs-subscription')
<x-filament::badge tag="a" tooltip="You need an active subscription to use all the features." href="{{ $billingPortalUrl }}" color="danger">
{{ $status['message'] }}
</x-filament::badge>
@elseif ($status['type'] === 'free')
<x-filament::badge tooltip="Thank you for testing this little app." color="gray">
{{ $status['message'] }}
</x-filament::badge>
@endif
@endif
</div>
Bart
Bartβ€’3w ago
πŸ™ will look into it!
Solution
Bart
Bartβ€’2w ago
Update: I used a custom blade file (subscriptionBanner) for the banner and attached it using a renderHook in the panel provider. It was as simple as that in the end πŸ˜… renderHook('panels::body.start', fn () => view('subscriptionBanner'), )
Want results from more Discord servers?
Add your server