2023-07-13 20:03:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
2023-08-14 12:00:10 +00:00
|
|
|
function getSubscriptionLink($type)
|
2023-07-13 20:03:27 +00:00
|
|
|
{
|
2023-08-14 12:00:10 +00:00
|
|
|
$checkout_id = config("coolify.lemon_squeezy_checkout_id_$type");
|
2023-07-27 14:22:13 +00:00
|
|
|
if (!$checkout_id) {
|
|
|
|
return null;
|
|
|
|
}
|
2023-07-13 20:03:27 +00:00
|
|
|
$user_id = auth()->user()->id;
|
|
|
|
$team_id = auth()->user()->currentTeam()->id ?? null;
|
|
|
|
$email = auth()->user()->email ?? null;
|
|
|
|
$name = auth()->user()->name ?? null;
|
2023-07-14 11:58:05 +00:00
|
|
|
$url = "https://store.coollabs.io/checkout/buy/$checkout_id?";
|
2023-07-13 20:03:27 +00:00
|
|
|
if ($user_id) {
|
|
|
|
$url .= "&checkout[custom][user_id]={$user_id}";
|
|
|
|
}
|
|
|
|
if (isset($team_id)) {
|
|
|
|
$url .= "&checkout[custom][team_id]={$team_id}";
|
|
|
|
}
|
|
|
|
if ($email) {
|
|
|
|
$url .= "&checkout[email]={$email}";
|
|
|
|
}
|
|
|
|
if ($name) {
|
|
|
|
$url .= "&checkout[name]={$name}";
|
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-14 09:27:08 +00:00
|
|
|
function getPaymentLink()
|
|
|
|
{
|
2023-07-13 20:03:27 +00:00
|
|
|
return auth()->user()->currentTeam()->subscription->lemon_update_payment_menthod_url;
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-14 09:27:08 +00:00
|
|
|
function getRenewDate()
|
|
|
|
{
|
2023-07-13 20:03:27 +00:00
|
|
|
return Carbon::parse(auth()->user()->currentTeam()->subscription->lemon_renews_at)->format('Y-M-d H:i:s');
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-14 09:27:08 +00:00
|
|
|
function getEndDate()
|
|
|
|
{
|
2023-07-14 10:09:56 +00:00
|
|
|
return Carbon::parse(auth()->user()->currentTeam()->subscription->lemon_renews_at)->format('Y-M-d H:i:s');
|
2023-07-14 09:27:08 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-08-14 13:22:29 +00:00
|
|
|
function is_subscription_active()
|
2023-07-14 09:27:08 +00:00
|
|
|
{
|
2023-08-14 13:22:29 +00:00
|
|
|
$team = auth()->user()?->currentTeam();
|
2023-08-14 14:56:13 +00:00
|
|
|
|
2023-08-14 13:22:29 +00:00
|
|
|
if (!$team) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-08-14 14:56:13 +00:00
|
|
|
if (is_instance_admin()) {
|
|
|
|
return true;
|
|
|
|
}
|
2023-08-14 13:22:29 +00:00
|
|
|
$subscription = $team?->subscription;
|
2023-08-14 14:56:13 +00:00
|
|
|
|
2023-08-14 13:22:29 +00:00
|
|
|
if (!$subscription) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$is_active = $subscription->lemon_status === 'active';
|
|
|
|
|
2023-08-14 14:56:13 +00:00
|
|
|
return $is_active;
|
2023-08-14 13:22:29 +00:00
|
|
|
}
|
|
|
|
function is_subscription_in_grace_period()
|
|
|
|
{
|
|
|
|
$team = auth()->user()?->currentTeam();
|
|
|
|
if (!$team) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-08-14 14:56:13 +00:00
|
|
|
if (is_instance_admin()) {
|
|
|
|
return true;
|
|
|
|
}
|
2023-08-14 13:22:29 +00:00
|
|
|
$subscription = $team?->subscription;
|
|
|
|
if (!$subscription) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$is_still_grace_period = $subscription->lemon_ends_at &&
|
|
|
|
Carbon::parse($subscription->lemon_ends_at) > Carbon::now();
|
|
|
|
|
2023-08-14 14:56:13 +00:00
|
|
|
return $is_still_grace_period;
|
2023-07-14 09:27:08 +00:00
|
|
|
}
|