mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-17 04:15:02 +00:00
feat(subscription): display next billing date and billing interval
Add current_period_end to refund eligibility checks and display next billing date and billing interval in the subscription overview. Refactor the plan overview layout to show subscription status more prominently.
This commit is contained in:
1 parent
23f9156c73
commit
426a708374
5 files changed
+113
-57
No files matched your search
@@ -19,7 +19,7 @@ class RefundSubscription
|
||||
/**
|
||||
* Check if the team's subscription is eligible for a refund.
|
||||
*
|
||||
* @return array{eligible: bool, days_remaining: int, reason: string}
|
||||
* @return array{eligible: bool, days_remaining: int, reason: string, current_period_end: int|null}
|
||||
*/
|
||||
public function checkEligibility(Team $team): array
|
||||
{
|
||||
@@ -43,8 +43,10 @@ class RefundSubscription
|
||||
return $this->ineligible('Subscription not found in Stripe.');
|
||||
}
|
||||
|
||||
$currentPeriodEnd = $stripeSubscription->current_period_end;
|
||||
|
||||
if (! in_array($stripeSubscription->status, ['active', 'trialing'])) {
|
||||
return $this->ineligible("Subscription status is '{$stripeSubscription->status}'.");
|
||||
return $this->ineligible("Subscription status is '{$stripeSubscription->status}'.", $currentPeriodEnd);
|
||||
}
|
||||
|
||||
$startDate = \Carbon\Carbon::createFromTimestamp($stripeSubscription->start_date);
|
||||
@@ -52,13 +54,14 @@ class RefundSubscription
|
||||
$daysRemaining = self::REFUND_WINDOW_DAYS - $daysSinceStart;
|
||||
|
||||
if ($daysRemaining <= 0) {
|
||||
return $this->ineligible('The 30-day refund window has expired.');
|
||||
return $this->ineligible('The 30-day refund window has expired.', $currentPeriodEnd);
|
||||
}
|
||||
|
||||
return [
|
||||
'eligible' => true,
|
||||
'days_remaining' => $daysRemaining,
|
||||
'reason' => 'Eligible for refund.',
|
||||
'current_period_end' => $currentPeriodEnd,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -128,14 +131,15 @@ class RefundSubscription
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{eligible: bool, days_remaining: int, reason: string}
|
||||
* @return array{eligible: bool, days_remaining: int, reason: string, current_period_end: int|null}
|
||||
*/
|
||||
private function ineligible(string $reason): array
|
||||
private function ineligible(string $reason, ?int $currentPeriodEnd = null): array
|
||||
{
|
||||
return [
|
||||
'eligible' => false,
|
||||
'days_remaining' => 0,
|
||||
'reason' => $reason,
|
||||
'current_period_end' => $currentPeriodEnd,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use App\Actions\Stripe\RefundSubscription;
|
||||
use App\Actions\Stripe\ResumeSubscription;
|
||||
use App\Actions\Stripe\UpdateSubscriptionQuantity;
|
||||
use App\Models\Team;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Livewire\Component;
|
||||
use Stripe\StripeClient;
|
||||
@@ -31,10 +32,15 @@ class Actions extends Component
|
||||
|
||||
public bool $refundAlreadyUsed = false;
|
||||
|
||||
public string $billingInterval = 'monthly';
|
||||
|
||||
public ?string $nextBillingDate = null;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->server_limits = Team::serverLimit();
|
||||
$this->quantity = (int) $this->server_limits;
|
||||
$this->billingInterval = currentTeam()->subscription?->billingInterval() ?? 'monthly';
|
||||
}
|
||||
|
||||
public function loadPricePreview(int $quantity): void
|
||||
@@ -198,6 +204,10 @@ class Actions extends Component
|
||||
$result = (new RefundSubscription)->checkEligibility(currentTeam());
|
||||
$this->isRefundEligible = $result['eligible'];
|
||||
$this->refundDaysRemaining = $result['days_remaining'];
|
||||
|
||||
if ($result['current_period_end']) {
|
||||
$this->nextBillingDate = Carbon::createFromTimestamp($result['current_period_end'])->format('M j, Y');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::warning('Refund eligibility check failed: '.$e->getMessage());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user