lasthourcloud/bootstrap/helpers/subscriptions.php

93 lines
1.9 KiB
PHP
Raw Normal View History

2023-07-13 22:03:27 +02:00
<?php
2023-08-24 16:14:09 +02:00
use App\Models\Team;
use Stripe\Stripe;
2023-07-13 22:03:27 +02:00
2023-08-24 16:14:09 +02:00
function isSubscriptionActive()
2023-07-14 11:27:08 +02:00
{
2024-06-10 20:43:34 +00:00
if (! isCloud()) {
2023-09-02 15:37:25 +02:00
return false;
}
2023-08-22 17:44:49 +02:00
$team = currentTeam();
2024-06-10 20:43:34 +00:00
if (! $team) {
2023-08-14 15:22:29 +02:00
return false;
}
$subscription = $team?->subscription;
2023-08-14 16:56:13 +02:00
2023-09-15 11:19:36 +02:00
if (is_null($subscription)) {
2023-08-14 15:22:29 +02:00
return false;
}
2023-08-30 18:23:55 +02:00
if (isStripe()) {
return $subscription->stripe_invoice_paid === true;
2023-08-24 16:14:09 +02:00
}
2024-06-10 20:43:34 +00:00
2023-08-24 16:14:09 +02:00
return false;
2023-08-14 15:22:29 +02:00
}
2023-08-24 16:14:09 +02:00
function isSubscriptionOnGracePeriod()
2023-08-14 15:22:29 +02:00
{
2023-08-22 17:44:49 +02:00
$team = currentTeam();
2024-06-10 20:43:34 +00:00
if (! $team) {
2023-08-14 15:22:29 +02:00
return false;
}
$subscription = $team?->subscription;
2024-06-10 20:43:34 +00:00
if (! $subscription) {
2023-08-14 15:22:29 +02:00
return false;
}
2023-08-30 18:23:55 +02:00
if (isStripe()) {
2023-08-24 16:14:09 +02:00
return $subscription->stripe_cancel_at_period_end;
}
2024-06-10 20:43:34 +00:00
2023-08-24 16:14:09 +02:00
return false;
}
function subscriptionProvider()
{
return config('subscription.provider');
}
2023-08-31 15:00:59 +02:00
function isStripe()
{
2023-08-30 18:23:55 +02:00
return config('subscription.provider') === 'stripe';
}
2023-08-24 16:14:09 +02:00
function getStripeCustomerPortalSession(Team $team)
{
Stripe::setApiKey(config('subscription.stripe_api_key'));
$return_url = route('subscription.show');
2024-06-10 20:43:34 +00:00
$stripe_customer_id = data_get($team, 'subscription.stripe_customer_id');
if (! $stripe_customer_id) {
return null;
}
2023-08-24 16:14:09 +02:00
$session = \Stripe\BillingPortal\Session::create([
'customer' => $stripe_customer_id,
'return_url' => $return_url,
]);
2024-06-10 20:43:34 +00:00
2023-08-24 16:14:09 +02:00
return $session;
}
2023-08-24 17:41:11 +02:00
function allowedPathsForUnsubscribedAccounts()
2023-08-24 16:14:09 +02:00
{
return [
'subscription/new',
2023-08-24 16:14:09 +02:00
'login',
2023-10-09 14:20:55 +02:00
'logout',
2023-08-24 16:14:09 +02:00
'waitlist',
'force-password-reset',
2024-06-10 20:43:34 +00:00
'livewire/update',
2023-08-24 16:14:09 +02:00
];
2023-07-14 11:27:08 +02:00
}
2023-08-24 17:41:11 +02:00
function allowedPathsForBoardingAccounts()
{
return [
...allowedPathsForUnsubscribedAccounts(),
2024-03-13 12:11:37 +01:00
'onboarding',
2024-06-10 20:43:34 +00:00
'livewire/update',
2023-08-24 17:41:11 +02:00
];
}
2024-06-10 20:43:34 +00:00
function allowedPathsForInvalidAccounts()
{
2023-10-09 14:20:55 +02:00
return [
'logout',
'verify',
'force-password-reset',
2024-06-10 20:43:34 +00:00
'livewire/update',
2023-10-09 14:20:55 +02:00
];
}