diff --git a/app/Livewire/Subscription/Index.php b/app/Livewire/Subscription/Index.php index df450cf7e..3e77768a0 100644 --- a/app/Livewire/Subscription/Index.php +++ b/app/Livewire/Subscription/Index.php @@ -12,19 +12,30 @@ class Index extends Component public bool $alreadySubscribed = false; + public bool $isUnpaid = false; + + public bool $isCancelled = false; + + public bool $isMember = false; + + public bool $loading = true; + public function mount() { if (! isCloud()) { return redirect(RouteServiceProvider::HOME); } if (auth()->user()?->isMember()) { - return redirect()->route('dashboard'); + $this->isMember = true; } if (data_get(currentTeam(), 'subscription') && isSubscriptionActive()) { return redirect()->route('subscription.show'); } $this->settings = instanceSettings(); $this->alreadySubscribed = currentTeam()->subscription()->exists(); + if (! $this->alreadySubscribed) { + $this->loading = false; + } } public function stripeCustomerPortal() @@ -37,6 +48,33 @@ class Index extends Component return redirect($session->url); } + public function getStripeStatus() + { + $subscription = currentTeam()->subscription; + $stripe = new \Stripe\StripeClient(config('subscription.stripe_api_key')); + $customer = $stripe->customers->retrieve(currentTeam()->subscription->stripe_customer_id); + if ($customer) { + $subscriptions = $stripe->subscriptions->all(['customer' => $customer->id]); + $currentTeam = currentTeam()->id ?? null; + if (count($subscriptions->data) > 0 && $currentTeam) { + $foundSubscription = collect($subscriptions->data)->firstWhere('metadata.team_id', $currentTeam); + if ($foundSubscription) { + $status = data_get($foundSubscription, 'status'); + $subscription->update([ + 'stripe_subscription_id' => $foundSubscription->id, + ]); + if ($status === 'unpaid') { + $this->isUnpaid = true; + } + } + } + if (count($subscriptions->data) === 0) { + $this->isCancelled = true; + } + } + $this->loading = false; + } + public function render() { return view('livewire.subscription.index'); diff --git a/app/Models/Team.php b/app/Models/Team.php index d36f8c1ab..42b88f9e7 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -192,8 +192,6 @@ class Team extends Model implements SendsDiscord, SendsEmail, SendsPushover, Sen public function subscriptionEnded() { $this->subscription->update([ - 'stripe_subscription_id' => null, - 'stripe_plan_id' => null, 'stripe_cancel_at_period_end' => false, 'stripe_invoice_paid' => false, 'stripe_trial_already_ended' => false, diff --git a/resources/views/livewire/dashboard.blade.php b/resources/views/livewire/dashboard.blade.php index 806704d5d..10794e79f 100644 --- a/resources/views/livewire/dashboard.blade.php +++ b/resources/views/livewire/dashboard.blade.php @@ -8,13 +8,8 @@

Dashboard

Your self-hosted infrastructure.
@if (request()->query->get('success')) -
- - - - Your subscription has been activated! Welcome onboard!
It could take a few seconds before your +
+ Your subscription has been activated! Welcome onboard! It could take a few seconds before your subscription is activated.
Please be patient.
@endif diff --git a/resources/views/livewire/subscription/index.blade.php b/resources/views/livewire/subscription/index.blade.php index c29fdae89..974b209c7 100644 --- a/resources/views/livewire/subscription/index.blade.php +++ b/resources/views/livewire/subscription/index.blade.php @@ -3,37 +3,62 @@ Subscribe | Coolify @if (auth()->user()->isAdminFromSession()) -
-
-

Subscriptions

- @if (subscriptionProvider() === 'stripe' && $alreadySubscribed) - Manage My Subscription - @endif + @if (request()->query->get('cancelled')) +
+ + + + Something went wrong with your subscription. Please try again or contact + support.
- @if (request()->query->get('cancelled')) -
- - - - Something went wrong with your subscription. Please try again or contact - support. -
- @endif - - @if (config('subscription.provider') === 'stripe') - - @endif + @endif +
+

Subscriptions

+ @if ($loading) +
+ Loading your subscription status... +
+ @else + @if ($isUnpaid) +
+ Your last payment was failed for Coolify Cloud. +
+
+

Open the following link, navigate to the button and pay your unpaid/past due + subscription. +

+ Billing Portal +
+ @else + @if (config('subscription.provider') === 'stripe') +
$isCancelled, + 'pb-10' => !$isCancelled, + ])> + @if ($isCancelled) +
+ It looks like your previous subscription has been cancelled, because you forgot to + pay + the bills.
Please subscribe again to continue using Coolify.
+
+ @endif +
+ + @endif + @endif + @endif @else

Subscription

-
You are not an admin or have been removed from this team. If this does not make sense, please contact - us.
+
You are not an admin so you cannot manage your Team's subscription. If this does not make sense, please + contact + us. +
@endif
diff --git a/resources/views/livewire/subscription/pricing-plans.blade.php b/resources/views/livewire/subscription/pricing-plans.blade.php index 027c9de4d..19b795102 100644 --- a/resources/views/livewire/subscription/pricing-plans.blade.php +++ b/resources/views/livewire/subscription/pricing-plans.blade.php @@ -1,4 +1,4 @@ -
+
- - Subscribe - - - Subscribe - +
+ + Subscribe + + + Subscribe + +