Added billing information to inertia data

This commit is contained in:
Constantin Graf
2024-07-01 18:33:59 +02:00
parent 726c2ee623
commit 8ddce667cc
3 changed files with 32 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Http\Middleware; namespace App\Http\Middleware;
use App\Service\BillingContract;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Inertia\Middleware; use Inertia\Middleware;
use Nwidart\Modules\Facades\Module; use Nwidart\Modules\Facades\Module;
@@ -38,8 +39,20 @@ class HandleInertiaRequests extends Middleware
*/ */
public function share(Request $request): array public function share(Request $request): array
{ {
$hasBilling = Module::has('Billing') && Module::isEnabled('Billing');
$billing = null;
if ($hasBilling) {
/** @var BillingContract $billing */
$billing = app(BillingContract::class);
}
$currentOrganization = $request->user()?->currentTeam;
return array_merge(parent::share($request), [ return array_merge(parent::share($request), [
'has_billing_extension' => Module::has('Billing'), 'has_billing_extension' => $hasBilling,
'billing' => $billing !== null ? [
'has_subscription' => $currentOrganization !== null ? $billing->hasSubscription($currentOrganization) : null,
] : null,
'flash' => [ 'flash' => [
'message' => fn () => $request->session()->get('message'), 'message' => fn () => $request->session()->get('message'),
], ],

View File

@@ -13,6 +13,7 @@ use App\Models\Tag;
use App\Models\Task; use App\Models\Task;
use App\Models\TimeEntry; use App\Models\TimeEntry;
use App\Models\User; use App\Models\User;
use App\Service\BillingContract;
use App\Service\IpLookup\IpLookupServiceContract; use App\Service\IpLookup\IpLookupServiceContract;
use App\Service\IpLookup\NoIpLookupService; use App\Service\IpLookup\NoIpLookupService;
use App\Service\PermissionStore; use App\Service\PermissionStore;
@@ -87,7 +88,9 @@ class AppServiceProvider extends ServiceProvider
return new PermissionStore(); return new PermissionStore();
}); });
// Extensions
$this->app->bind(IpLookupServiceContract::class, NoIpLookupService::class); $this->app->bind(IpLookupServiceContract::class, NoIpLookupService::class);
$this->app->bind(BillingContract::class);
Route::model('member', Member::class); Route::model('member', Member::class);
Route::model('invitation', OrganizationInvitation::class); Route::model('invitation', OrganizationInvitation::class);

View File

@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace App\Service;
use App\Models\Organization;
class BillingContract
{
public function hasSubscription(Organization $organization): bool
{
return false;
}
}